Skip to content

Commit 9a82f2a

Browse files
committed
fix : regionselector lag
1 parent 3db0756 commit 9a82f2a

1 file changed

Lines changed: 71 additions & 69 deletions

File tree

screen-toolkit/RegionSelector.qml

Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -59,45 +59,34 @@ Variants {
5959
if (!m) continue
6060
var rw = parseInt(m[3]), rh = parseInt(m[4])
6161
if (rw < 10 || rh < 10) continue
62-
regions.push({
63-
x: parseInt(m[1]),
64-
y: parseInt(m[2]),
65-
w: rw,
66-
h: rh,
67-
title: m[5].trim()
62+
regions.push({
63+
x: parseInt(m[1]),
64+
y: parseInt(m[2]),
65+
w: rw,
66+
h: rh,
67+
title: m[5].trim()
6868
})
6969
}
7070
selectorVariants.windowRegions = regions
7171
selectorVariants.windowRegionsFetched = true
7272
}
7373
}
74-
property bool animateSelection: true
75-
property real targetX: 0; property real targetY: 0
76-
property real targetW: 0; property real targetH: 0
77-
property real selX: 0; property real selY: 0
78-
property real selW: 0; property real selH: 0
79-
Behavior on selX { enabled: win.animateSelection; SpringAnimation { spring: 5; damping: 0.6 } }
80-
Behavior on selY { enabled: win.animateSelection; SpringAnimation { spring: 5; damping: 0.6 } }
81-
Behavior on selW { enabled: win.animateSelection; SpringAnimation { spring: 5; damping: 0.6 } }
82-
Behavior on selH { enabled: win.animateSelection; SpringAnimation { spring: 5; damping: 0.6 } }
83-
onSelXChanged: guides.requestPaint()
84-
onSelYChanged: guides.requestPaint()
85-
onSelWChanged: guides.requestPaint()
86-
onSelHChanged: guides.requestPaint()
87-
property real mouseX: 0; property real mouseY: 0
74+
property real selX: 0
75+
property real selY: 0
76+
property real selW: 0
77+
property real selH: 0
78+
property real mouseX: 0
79+
property real mouseY: 0
8880
property point startPos
8981
property bool dragging: false
90-
Timer {
91-
id: dragSyncTimer; interval: 16; repeat: true; running: win.dragging
92-
onTriggered: {
93-
win.selX = win.targetX; win.selY = win.targetY
94-
win.selW = win.targetW; win.selH = win.targetH
95-
}
96-
}
9782
property real fadeOpacity: 0.0
9883
NumberAnimation {
99-
id: fadeIn; target: win; property: "fadeOpacity"
100-
from: 0.0; to: 1.0; duration: 150; easing.type: Easing.OutCubic
84+
id: fadeIn
85+
target: win
86+
property: "fadeOpacity"
87+
from: 0.0; to: 1.0
88+
duration: 150
89+
easing.type: Easing.OutCubic
10190
}
10291
onVisibleChanged: {
10392
if (visible) {
@@ -125,23 +114,23 @@ Variants {
125114
"fi"
126115
]
127116
})
128-
fadeOpacity = 0.0; dragging = false
129-
animateSelection = false
117+
fadeOpacity = 0.0
118+
dragging = false
130119
selX = 0; selY = 0; selW = 0; selH = 0
131-
targetX = 0; targetY = 0; targetW = 0; targetH = 0
132-
animateSelection = true
133120
fadeIn.restart()
134121
} else {
135-
fadeIn.stop(); dragging = false
122+
fadeIn.stop()
123+
dragging = false
136124
}
137125
}
138-
139126
property var pendingCapture: null
140127
Timer {
141-
id: captureDelay; interval: 80; repeat: false
128+
id: captureDelay
129+
interval: 80; repeat: false
142130
onTriggered: {
143131
if (win.pendingCapture) {
144-
var p = win.pendingCapture; win.pendingCapture = null
132+
var p = win.pendingCapture
133+
win.pendingCapture = null
145134
selectorVariants.regionSelected(p.x, p.y, p.w, p.h, p.screen)
146135
}
147136
}
@@ -157,16 +146,19 @@ Variants {
157146
return -1
158147
}
159148
ShaderEffect {
160-
anchors.fill: parent; z: 0; opacity: win.fadeOpacity
149+
anchors.fill: parent
150+
z: 0
151+
opacity: win.fadeOpacity
161152
property vector4d selectionRect: Qt.vector4d(win.selX, win.selY, win.selW, win.selH)
162153
property real dimOpacity: 0.72
163154
property vector2d screenSize: Qt.vector2d(win.width, win.height)
164155
fragmentShader: Qt.resolvedUrl("dimming.frag.qsb")
165156
}
166-
167157
Canvas {
168158
id: guides
169-
anchors.fill: parent; z: 2; opacity: win.fadeOpacity
159+
anchors.fill: parent
160+
z: 2
161+
opacity: win.fadeOpacity
170162
onPaint: {
171163
var ctx = getContext("2d")
172164
ctx.clearRect(0, 0, width, height)
@@ -213,10 +205,10 @@ Variants {
213205
ctx.setLineDash([])
214206
ctx.strokeStyle = "rgba(255,255,255,0.15)"; ctx.lineWidth = 0.5
215207
ctx.beginPath()
216-
ctx.moveTo(sx + sw/3, sy); ctx.lineTo(sx + sw/3, sy + sh)
217-
ctx.moveTo(sx + 2*sw/3, sy); ctx.lineTo(sx + 2*sw/3, sy + sh)
218-
ctx.moveTo(sx, sy + sh/3); ctx.lineTo(sx + sw, sy + sh/3)
219-
ctx.moveTo(sx, sy+2*sh/3); ctx.lineTo(sx + sw, sy+2*sh/3)
208+
ctx.moveTo(sx + sw/3, sy); ctx.lineTo(sx + sw/3, sy + sh)
209+
ctx.moveTo(sx + 2*sw/3, sy); ctx.lineTo(sx + 2*sw/3, sy + sh)
210+
ctx.moveTo(sx, sy + sh/3); ctx.lineTo(sx + sw, sy + sh/3)
211+
ctx.moveTo(sx, sy+2*sh/3); ctx.lineTo(sx + sw, sy+2*sh/3)
220212
ctx.stroke()
221213
ctx.strokeStyle = "rgba(0,0,0,0.6)"; ctx.lineWidth = 3
222214
ctx.strokeRect(sx, sy, sw, sh)
@@ -241,85 +233,94 @@ Variants {
241233
}
242234
Rectangle {
243235
readonly property real dpr: win.screen?.devicePixelRatio ?? 1.0
244-
visible: win.selW > 30 && win.selH > 10; z: 10; opacity: win.fadeOpacity
236+
visible: win.selW > 30 && win.selH > 10
237+
z: 10
238+
opacity: win.fadeOpacity
245239
width: _szText.implicitWidth + Style.marginL
246240
height: Style.controlHeightS
247241
radius: Style.controlHeightS / 2
248242
color: Qt.rgba(0, 0, 0, 0.85)
249243
border.color: Qt.rgba(1, 1, 1, 0.2); border.width: 1
250244
x: Math.max(4, Math.min(win.selX + win.selW/2 - width/2, win.width - width - 4))
251245
y: win.selY > 48 ? win.selY - height - Style.marginS : win.selY + win.selH + Style.marginS
252-
Behavior on x { NumberAnimation { duration: 80; easing.type: Easing.OutCubic } }
253-
Behavior on y { NumberAnimation { duration: 80; easing.type: Easing.OutCubic } }
254246
NText {
255-
id: _szText; anchors.centerIn: parent; font.weight: Font.Bold
247+
id: _szText
248+
anchors.centerIn: parent
249+
font.weight: Font.Bold
256250
text: Math.round(win.selW * parent.dpr) + " × " + Math.round(win.selH * parent.dpr)
257-
color: "white"; pointSize: Style.fontSizeXS
251+
color: "white"
252+
pointSize: Style.fontSizeXS
258253
}
259254
}
260255
Rectangle {
261-
visible: !win.dragging && win.selW < 4; z: 10; opacity: win.fadeOpacity
256+
visible: !win.dragging && win.selW < 4
257+
z: 10
258+
opacity: win.fadeOpacity
262259
width: _coordText.implicitWidth + Style.marginM
263260
height: Style.controlHeightXXS
264261
radius: Style.radiusS
265262
color: Qt.rgba(0, 0, 0, 0.75)
266263
x: { var bx = win.mouseX + 20; return bx + width > win.width - 4 ? win.mouseX - width - 20 : bx }
267264
y: { var by = win.mouseY + 20; return by + height > win.height - 4 ? win.mouseY - height - 20 : by }
268-
NText { id: _coordText; anchors.centerIn: parent
265+
NText {
266+
id: _coordText
267+
anchors.centerIn: parent
269268
text: Math.round(win.mouseX) + ", " + Math.round(win.mouseY)
270-
color: Qt.rgba(1,1,1,0.9); pointSize: Style.fontSizeXS }
269+
color: Qt.rgba(1,1,1,0.9)
270+
pointSize: Style.fontSizeXS
271+
}
271272
}
272273
Rectangle {
273274
anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: Style.marginXL }
274-
z: 10; opacity: win.fadeOpacity * 0.9
275+
z: 10
276+
opacity: win.fadeOpacity * 0.9
275277
width: _hintRow.implicitWidth + Style.marginXL
276278
height: Style.controlHeightS
277279
radius: Style.controlHeightS / 2
278280
color: Qt.rgba(0, 0, 0, 0.75)
279281
border.color: Qt.rgba(1,1,1,0.1); border.width: 1
280282
Row {
281-
id: _hintRow; anchors.centerIn: parent; spacing: 0
283+
id: _hintRow
284+
anchors.centerIn: parent
285+
spacing: 0
282286
NText { text: pluginApi?.tr("regionSelector.drag"); color: Qt.rgba(1,1,1,0.7); pointSize: Style.fontSizeXS; font.weight: Font.Bold }
283-
NText { text: pluginApi?.tr("regionSelector.toSelect"); color: Qt.rgba(1,1,1,0.4); pointSize: Style.fontSizeXS }
284-
// Window snap hint — hidden on Niri since window detection is unreliable there
287+
NText { text: pluginApi?.tr("regionSelector.toSelect"); color: Qt.rgba(1,1,1,0.4); pointSize: Style.fontSizeXS }
285288
Item { width: Style.marginL; height: 1; visible: !selectorVariants.isNiri }
286289
Rectangle { width: 1; height: 14; color: Qt.rgba(1,1,1,0.25); anchors.verticalCenter: parent.verticalCenter; visible: !selectorVariants.isNiri }
287290
Item { width: Style.marginL; height: 1; visible: !selectorVariants.isNiri }
288291
NText { text: pluginApi?.tr("regionSelector.clickWindow"); color: Qt.rgba(1,1,1,0.7); pointSize: Style.fontSizeXS; font.weight: Font.Bold; visible: !selectorVariants.isNiri }
289-
NText { text: pluginApi?.tr("regionSelector.toSnap"); color: Qt.rgba(1,1,1,0.4); pointSize: Style.fontSizeXS; visible: !selectorVariants.isNiri }
292+
NText { text: pluginApi?.tr("regionSelector.toSnap"); color: Qt.rgba(1,1,1,0.4); pointSize: Style.fontSizeXS; visible: !selectorVariants.isNiri }
290293
Item { width: Style.marginL; height: 1 }
291294
Rectangle { width: 1; height: 14; color: Qt.rgba(1,1,1,0.25); anchors.verticalCenter: parent.verticalCenter }
292295
Item { width: Style.marginL; height: 1 }
293296
NText { text: pluginApi?.tr("regionSelector.esc"); color: Qt.rgba(1,1,1,0.7); pointSize: Style.fontSizeXS; font.weight: Font.Bold }
294-
NText { text: pluginApi?.tr("regionSelector.toCancel"); color: Qt.rgba(1,1,1,0.4); pointSize: Style.fontSizeXS }
297+
NText { text: pluginApi?.tr("regionSelector.toCancel"); color: Qt.rgba(1,1,1,0.4); pointSize: Style.fontSizeXS }
295298
}
296299
}
297300
MouseArea {
298-
anchors.fill: parent; z: 3; hoverEnabled: true
301+
anchors.fill: parent
302+
z: 3
303+
hoverEnabled: true
299304
acceptedButtons: Qt.LeftButton | Qt.RightButton
300305
cursorShape: Qt.CrossCursor
301306
onPressed: (mouse) => {
302307
if (mouse.button === Qt.RightButton) {
303308
selectorVariants.hide(); selectorVariants.cancelled(); return
304309
}
305-
win.animateSelection = false
306310
win.startPos = Qt.point(mouse.x, mouse.y)
307-
win.targetX = mouse.x; win.targetY = mouse.y
308-
win.targetW = 0; win.targetH = 0
309-
win.selX = mouse.x; win.selY = mouse.y
310-
win.selW = 0; win.selH = 0
311-
win.animateSelection = true
311+
win.selX = mouse.x; win.selY = mouse.y
312+
win.selW = 0; win.selH = 0
312313
win.dragging = true
313314
guides.requestPaint()
314315
}
315316
onPositionChanged: (mouse) => {
316317
win.mouseX = mouse.x; win.mouseY = mouse.y
317318
guides.requestPaint()
318319
if (win.dragging) {
319-
win.targetX = Math.min(win.startPos.x, mouse.x)
320-
win.targetY = Math.min(win.startPos.y, mouse.y)
321-
win.targetW = Math.abs(mouse.x - win.startPos.x)
322-
win.targetH = Math.abs(mouse.y - win.startPos.y)
320+
win.selX = Math.min(win.startPos.x, mouse.x)
321+
win.selY = Math.min(win.startPos.y, mouse.y)
322+
win.selW = Math.abs(mouse.x - win.startPos.x)
323+
win.selH = Math.abs(mouse.y - win.startPos.y)
323324
}
324325
}
325326
onReleased: (mouse) => {
@@ -366,3 +367,4 @@ Variants {
366367
}
367368
}
368369
}
370+

0 commit comments

Comments
 (0)