@amaster.ai/pi-computer-use-cua-driver-linux-x64 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SOURCE.md +4 -4
- package/bin/.version +1 -1
- package/bin/cua-cursor-theme +0 -0
- package/bin/cua-driver +2 -2
- package/bin/tools.json +1 -0
- package/bin/wayland-helper/README.md +43 -7
- package/bin/wayland-helper/winrects@cua/extension.js +345 -288
- package/bin/wayland-helper/winrects@cua/metadata.json +2 -2
- package/package.json +3 -2
|
@@ -5,6 +5,7 @@ import St from 'gi://St';
|
|
|
5
5
|
import Clutter from 'gi://Clutter';
|
|
6
6
|
import Cogl from 'gi://Cogl';
|
|
7
7
|
import Cairo from 'cairo';
|
|
8
|
+
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
|
|
8
9
|
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
|
9
10
|
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
|
|
10
11
|
|
|
@@ -22,6 +23,8 @@ const IFACE = `<node><interface name="org.cua.WinRects">
|
|
|
22
23
|
<method name="ClickPulse"><arg type="i" direction="in" name="x"/><arg type="i" direction="in" name="y"/></method>
|
|
23
24
|
<method name="SetCursorColor"><arg type="s" direction="in" name="fill_color"/></method>
|
|
24
25
|
<method name="SetCursorState"><arg type="s" direction="in" name="action"/><arg type="s" direction="in" name="delivery"/><arg type="s" direction="in" name="target"/><arg type="b" direction="in" name="active"/></method>
|
|
26
|
+
<method name="SetCursorLook"><arg type="s" direction="in" name="look_json"/></method>
|
|
27
|
+
<method name="PlayCursorPath"><arg type="s" direction="in" name="track_json"/></method>
|
|
25
28
|
<method name="SetSessionLabel"><arg type="s" direction="in" name="label"/></method>
|
|
26
29
|
<method name="HideCursor"></method>
|
|
27
30
|
</interface></node>`;
|
|
@@ -33,7 +36,6 @@ const DISPLAY_SIZE = 42;
|
|
|
33
36
|
const ACTOR_SIZE = 112;
|
|
34
37
|
const ACTOR_CENTER = ACTOR_SIZE / 2;
|
|
35
38
|
const SCALE = DISPLAY_SIZE / CANVAS_SIZE;
|
|
36
|
-
const FLOAT_DURATION = 4.0;
|
|
37
39
|
const GLOW_SURFACE_SCALE = 3;
|
|
38
40
|
const GLOW_PADDING = 24;
|
|
39
41
|
const BADGE_Y_OFFSET = 29;
|
|
@@ -70,6 +72,208 @@ const ACTION_DURATIONS = {
|
|
|
70
72
|
system: 1.6,
|
|
71
73
|
};
|
|
72
74
|
|
|
75
|
+
// cua-driver plans every move with the shared planner and sends it as poses
|
|
76
|
+
// (PlayCursorPath), with the resting float and halo it paints with
|
|
77
|
+
// (SetCursorLook). The helper only plays them back and carries the float on at
|
|
78
|
+
// rest from the clock each track ends on; it plans nothing.
|
|
79
|
+
const TIP_X = 55;
|
|
80
|
+
const TIP_Y = 30;
|
|
81
|
+
const MAX_POSE_JSON = 256 * 1024;
|
|
82
|
+
const MAX_PATH_SAMPLES = 2000;
|
|
83
|
+
const PATH_FRAME_MS = 16;
|
|
84
|
+
|
|
85
|
+
function finiteWithin(value, limit) {
|
|
86
|
+
return typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= limit;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parseJsonObject(json) {
|
|
90
|
+
if (typeof json !== 'string' || json.length === 0 || json.length > MAX_POSE_JSON) return null;
|
|
91
|
+
try {
|
|
92
|
+
const value = JSON.parse(json);
|
|
93
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
94
|
+
} catch (_error) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function parseFloatLook(value) {
|
|
100
|
+
if (value === null || value === undefined) return null;
|
|
101
|
+
const f = value;
|
|
102
|
+
const ok =
|
|
103
|
+
finiteWithin(f?.secs, 60) && f.secs >= 0.1 &&
|
|
104
|
+
finiteWithin(f.sway, 50) && f.sway >= 0 &&
|
|
105
|
+
finiteWithin(f.bob, 50) && f.bob >= 0 &&
|
|
106
|
+
finiteWithin(f.lift, 50) && f.lift >= 0 &&
|
|
107
|
+
finiteWithin(f.tilt, 1) && f.tilt >= 0 &&
|
|
108
|
+
finiteWithin(f.hold, 60) && f.hold >= 0 &&
|
|
109
|
+
finiteWithin(f.ease_in, 60) && f.ease_in > 0 &&
|
|
110
|
+
finiteWithin(f.ease_out, 60) && f.ease_out > 0;
|
|
111
|
+
if (!ok) return undefined;
|
|
112
|
+
return {
|
|
113
|
+
secs: f.secs,
|
|
114
|
+
sway: f.sway,
|
|
115
|
+
bob: f.bob,
|
|
116
|
+
lift: f.lift,
|
|
117
|
+
tilt: f.tilt,
|
|
118
|
+
hold: f.hold,
|
|
119
|
+
easeIn: f.ease_in,
|
|
120
|
+
easeOut: f.ease_out,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function parseCursorLook(json) {
|
|
125
|
+
const look = parseJsonObject(json);
|
|
126
|
+
if (!look) return null;
|
|
127
|
+
const float = parseFloatLook(look.float);
|
|
128
|
+
if (float === undefined) return null;
|
|
129
|
+
let halo = null;
|
|
130
|
+
if (look.halo !== null && look.halo !== undefined) {
|
|
131
|
+
const h = look.halo;
|
|
132
|
+
const rgb = typeof h?.rgb === 'string' ? /^#([0-9a-fA-F]{6})$/.exec(h.rgb) : null;
|
|
133
|
+
const stops = Array.isArray(h?.stops) ? h.stops : [];
|
|
134
|
+
const body = Array.isArray(h?.body) ? h.body : [];
|
|
135
|
+
if (
|
|
136
|
+
!rgb ||
|
|
137
|
+
!finiteWithin(h.radius, 200) ||
|
|
138
|
+
h.radius <= 0 ||
|
|
139
|
+
!finiteWithin(h.peak, 1) ||
|
|
140
|
+
h.peak < 0 ||
|
|
141
|
+
stops.length < 1 ||
|
|
142
|
+
stops.length > 8 ||
|
|
143
|
+
!stops.every(
|
|
144
|
+
(stop) =>
|
|
145
|
+
Array.isArray(stop) &&
|
|
146
|
+
stop.length === 2 &&
|
|
147
|
+
stop.every((part) => finiteWithin(part, 1) && part >= 0)
|
|
148
|
+
) ||
|
|
149
|
+
body.length !== 2 ||
|
|
150
|
+
!body.every((part) => finiteWithin(part, 200))
|
|
151
|
+
)
|
|
152
|
+
return null;
|
|
153
|
+
const value = Number.parseInt(rgb[1], 16);
|
|
154
|
+
halo = {
|
|
155
|
+
rgb: [(value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff],
|
|
156
|
+
radius: h.radius,
|
|
157
|
+
peak: h.peak,
|
|
158
|
+
stops: stops.map(([offset, share]) => [offset, share]),
|
|
159
|
+
body: [body[0], body[1]],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return { float, halo };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function parseCursorPath(json) {
|
|
166
|
+
const track = parseJsonObject(json);
|
|
167
|
+
if (!track || !Array.isArray(track.samples)) return null;
|
|
168
|
+
const samples = track.samples;
|
|
169
|
+
if (samples.length < 1 || samples.length > MAX_PATH_SAMPLES) return null;
|
|
170
|
+
let previous = 0;
|
|
171
|
+
for (const sample of samples) {
|
|
172
|
+
if (!Array.isArray(sample) || sample.length !== 6) return null;
|
|
173
|
+
const [t, x, y, dx, dy, rotation] = sample;
|
|
174
|
+
if (!finiteWithin(t, 30) || t < previous) return null;
|
|
175
|
+
if (!finiteWithin(x, 100000) || !finiteWithin(y, 100000)) return null;
|
|
176
|
+
if (!finiteWithin(dx, 100) || !finiteWithin(dy, 100) || !finiteWithin(rotation, 8)) return null;
|
|
177
|
+
previous = t;
|
|
178
|
+
}
|
|
179
|
+
const arrival = track.arrival;
|
|
180
|
+
if (arrival !== null && arrival !== undefined && (!finiteWithin(arrival, 30) || arrival < 0))
|
|
181
|
+
return null;
|
|
182
|
+
// The float clock at the last sample: [phase, hold, from].
|
|
183
|
+
const rest = track.rest;
|
|
184
|
+
if (
|
|
185
|
+
!Array.isArray(rest) ||
|
|
186
|
+
rest.length !== 3 ||
|
|
187
|
+
!finiteWithin(rest[0], 1e7) ||
|
|
188
|
+
!finiteWithin(rest[1], 3600) ||
|
|
189
|
+
rest[1] < 0 ||
|
|
190
|
+
!finiteWithin(rest[2], 1) ||
|
|
191
|
+
rest[2] < 0
|
|
192
|
+
)
|
|
193
|
+
return null;
|
|
194
|
+
return {
|
|
195
|
+
samples,
|
|
196
|
+
arrival: arrival ?? null,
|
|
197
|
+
rest: { phase: rest[0], hold: rest[1], from: rest[2] },
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Linear interpolation between the planner's samples, clamped to the ends.
|
|
202
|
+
function samplePath(samples, t) {
|
|
203
|
+
if (t <= samples[0][0]) return samples[0];
|
|
204
|
+
const last = samples[samples.length - 1];
|
|
205
|
+
if (t >= last[0]) return last;
|
|
206
|
+
let lo = 0;
|
|
207
|
+
let hi = samples.length - 1;
|
|
208
|
+
while (hi - lo > 1) {
|
|
209
|
+
const mid = (lo + hi) >> 1;
|
|
210
|
+
if (samples[mid][0] <= t) lo = mid;
|
|
211
|
+
else hi = mid;
|
|
212
|
+
}
|
|
213
|
+
const a = samples[lo];
|
|
214
|
+
const b = samples[hi];
|
|
215
|
+
const f = b[0] > a[0] ? (t - a[0]) / (b[0] - a[0]) : 1;
|
|
216
|
+
return a.map((value, index) => value + (b[index] - value) * f);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function smoothstep(x) {
|
|
220
|
+
const t = Math.min(1, Math.max(0, x));
|
|
221
|
+
return t * t * (3 - 2 * t);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// cursor_pose::rest_amplitude: `from` eases out to 0, holds at 0 for the
|
|
225
|
+
// click, drop or typing that follows, then eases back in to 1.
|
|
226
|
+
function restAmplitude(float, hold, from) {
|
|
227
|
+
const out = Math.min(1, Math.max(0, from)) * (1 - smoothstep(hold / float.easeOut));
|
|
228
|
+
const back = smoothstep((hold - float.hold) / float.easeIn);
|
|
229
|
+
return Math.max(out, back);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const STILL = Object.freeze({ dx: 0, dy: 0, rotation: 0 });
|
|
233
|
+
|
|
234
|
+
// cursor_pose::float_at at the rest amplitude: the 4 s sway, bob and tilt,
|
|
235
|
+
// `now - rest.at` seconds on from the clock `rest` (phase, hold, from). The
|
|
236
|
+
// phase never restarts.
|
|
237
|
+
function restingFloat(look, rest, now) {
|
|
238
|
+
const float = look?.float;
|
|
239
|
+
if (!float || !rest) return STILL;
|
|
240
|
+
const elapsed = Math.max(0, now - rest.at);
|
|
241
|
+
const amp = restAmplitude(float, rest.hold + elapsed, rest.from);
|
|
242
|
+
if (amp <= 0) return STILL;
|
|
243
|
+
const angle = (((rest.phase + elapsed) % float.secs) / float.secs) * 2 * Math.PI;
|
|
244
|
+
return {
|
|
245
|
+
dx: amp * float.sway * Math.sin(angle),
|
|
246
|
+
dy: amp * (float.bob * Math.cos(angle) - float.lift),
|
|
247
|
+
rotation: amp * float.tilt * Math.cos(angle),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// The halo of cursor_pose::paint_halo, centred on the arrow body, in canvas
|
|
252
|
+
// units with the tip at (TIP_X, TIP_Y).
|
|
253
|
+
function drawCursorHalo(cr, halo, rotation) {
|
|
254
|
+
const sin = Math.sin(rotation);
|
|
255
|
+
const cos = Math.cos(rotation);
|
|
256
|
+
const bx = halo.body[0] / SCALE;
|
|
257
|
+
const by = halo.body[1] / SCALE;
|
|
258
|
+
const cx = TIP_X + bx * cos - by * sin;
|
|
259
|
+
const cy = TIP_Y + bx * sin + by * cos;
|
|
260
|
+
const radius = halo.radius / SCALE;
|
|
261
|
+
const gradient = new Cairo.RadialGradient(cx, cy, 0, cx, cy, radius);
|
|
262
|
+
for (const [offset, share] of halo.stops)
|
|
263
|
+
gradient.addColorStopRGBA(
|
|
264
|
+
offset,
|
|
265
|
+
halo.rgb[0] / 255,
|
|
266
|
+
halo.rgb[1] / 255,
|
|
267
|
+
halo.rgb[2] / 255,
|
|
268
|
+
halo.peak * share
|
|
269
|
+
);
|
|
270
|
+
cr.save();
|
|
271
|
+
cr.setSource(gradient);
|
|
272
|
+
cr.arc(cx, cy, radius, 0, 2 * Math.PI);
|
|
273
|
+
cr.fill();
|
|
274
|
+
cr.restore();
|
|
275
|
+
}
|
|
276
|
+
|
|
73
277
|
function nowSeconds() {
|
|
74
278
|
return GLib.get_monotonic_time() / 1_000_000;
|
|
75
279
|
}
|
|
@@ -196,7 +400,16 @@ function roundedRect(cr, x, y, width, height, radius) {
|
|
|
196
400
|
cr.closePath();
|
|
197
401
|
}
|
|
198
402
|
|
|
403
|
+
// Upright like the system pointer, matching cua.default: the dart outline is
|
|
404
|
+
// turned 20 degrees clockwise about the hotspot (55, 30) so its left edge
|
|
405
|
+
// stands vertical.
|
|
406
|
+
const UPRIGHT_RADIANS = (20 * Math.PI) / 180;
|
|
407
|
+
|
|
199
408
|
function traceCursorBody(cr) {
|
|
409
|
+
cr.save();
|
|
410
|
+
cr.translate(55, 30);
|
|
411
|
+
cr.rotate(UPRIGHT_RADIANS);
|
|
412
|
+
cr.translate(-55, -30);
|
|
200
413
|
cr.moveTo(55, 30);
|
|
201
414
|
cr.curveTo(48, 28, 42, 33, 43, 41);
|
|
202
415
|
cr.lineTo(64, 98);
|
|
@@ -206,6 +419,7 @@ function traceCursorBody(cr) {
|
|
|
206
419
|
cr.lineTo(108, 63);
|
|
207
420
|
cr.curveTo(115, 59, 114, 53, 107, 50);
|
|
208
421
|
cr.closePath();
|
|
422
|
+
cr.restore();
|
|
209
423
|
}
|
|
210
424
|
|
|
211
425
|
function drawCursorGlowShape(cr, fillColor) {
|
|
@@ -247,16 +461,6 @@ function createGlowSurface(fillColor) {
|
|
|
247
461
|
return surface;
|
|
248
462
|
}
|
|
249
463
|
|
|
250
|
-
function sharedFloatMotion(progress) {
|
|
251
|
-
const angle = progress * Math.PI * 2;
|
|
252
|
-
return {
|
|
253
|
-
dx: Math.sin(angle) * 5,
|
|
254
|
-
dy: Math.cos(angle) * 6 - 5,
|
|
255
|
-
rotation: Math.cos(angle) * ((2.5 * Math.PI) / 180),
|
|
256
|
-
scale: 1,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
464
|
function cursorBodyMotion(progress, action) {
|
|
261
465
|
let dx = 0;
|
|
262
466
|
let dy = 0;
|
|
@@ -276,11 +480,13 @@ function cursorBodyMotion(progress, action) {
|
|
|
276
480
|
return { dx, dy, rotation, scale };
|
|
277
481
|
}
|
|
278
482
|
|
|
483
|
+
// About the tip, like the Rust renderer's click squish, so a press never
|
|
484
|
+
// moves the point the arrow clicks.
|
|
279
485
|
function applyCursorBodyMotion(cr, motion) {
|
|
280
|
-
cr.translate(
|
|
486
|
+
cr.translate(TIP_X + motion.dx, TIP_Y + motion.dy);
|
|
281
487
|
cr.rotate(motion.rotation);
|
|
282
488
|
cr.scale(motion.scale, motion.scale);
|
|
283
|
-
cr.translate(-
|
|
489
|
+
cr.translate(-TIP_X, -TIP_Y);
|
|
284
490
|
}
|
|
285
491
|
|
|
286
492
|
function drawCursorGlow(cr, progress, action, glowSurface) {
|
|
@@ -309,270 +515,6 @@ function drawCursorBody(cr, progress, action, fillColor) {
|
|
|
309
515
|
cr.restore();
|
|
310
516
|
}
|
|
311
517
|
|
|
312
|
-
function drawActionCue(cr, action, progress, fillColor) {
|
|
313
|
-
const wave = triangleWave(progress);
|
|
314
|
-
const strokeCue = (width, alpha = 1) => strokePath(cr, width, alpha, fillColor);
|
|
315
|
-
const lineCue = (points, width = 4, alpha = 1) => linePath(cr, points, width, alpha, fillColor);
|
|
316
|
-
cr.save();
|
|
317
|
-
switch (action) {
|
|
318
|
-
case 'observe': {
|
|
319
|
-
const opacity = Math.min(1, progress * 7);
|
|
320
|
-
cr.translate(8, -10);
|
|
321
|
-
cr.moveTo(38, 28);
|
|
322
|
-
cr.curveTo(27, 29, 20, 38, 20, 49);
|
|
323
|
-
strokeCue(4, opacity);
|
|
324
|
-
cr.moveTo(42, 19);
|
|
325
|
-
cr.curveTo(23, 19, 11, 33, 11, 51);
|
|
326
|
-
strokeCue(4, opacity);
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
case 'click': {
|
|
330
|
-
const cueProgress = Math.max(0, Math.min(1, progress / 0.65));
|
|
331
|
-
const opacity = Math.max(
|
|
332
|
-
0,
|
|
333
|
-
Math.min(1, Math.min(1 - Math.pow(cueProgress, 1.35), cueProgress * 5))
|
|
334
|
-
);
|
|
335
|
-
const cueScale = 1.1 + easeInOut(cueProgress) * 0.4;
|
|
336
|
-
cr.translate(35, 28);
|
|
337
|
-
cr.scale(cueScale, cueScale);
|
|
338
|
-
cr.translate(-25, -25);
|
|
339
|
-
lineCue(
|
|
340
|
-
[
|
|
341
|
-
[35, 20],
|
|
342
|
-
[34, 11],
|
|
343
|
-
],
|
|
344
|
-
4,
|
|
345
|
-
opacity
|
|
346
|
-
);
|
|
347
|
-
lineCue(
|
|
348
|
-
[
|
|
349
|
-
[27, 25],
|
|
350
|
-
[19, 19],
|
|
351
|
-
],
|
|
352
|
-
4,
|
|
353
|
-
opacity
|
|
354
|
-
);
|
|
355
|
-
lineCue(
|
|
356
|
-
[
|
|
357
|
-
[25, 34],
|
|
358
|
-
[15, 34],
|
|
359
|
-
],
|
|
360
|
-
4,
|
|
361
|
-
opacity
|
|
362
|
-
);
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
case 'drag': {
|
|
366
|
-
const offset = easeInOut(wave) * 7;
|
|
367
|
-
cr.translate(offset, offset * 0.43);
|
|
368
|
-
lineCue(
|
|
369
|
-
[
|
|
370
|
-
[28, 38],
|
|
371
|
-
[16, 35],
|
|
372
|
-
],
|
|
373
|
-
4,
|
|
374
|
-
0.2 + wave * 0.8
|
|
375
|
-
);
|
|
376
|
-
lineCue(
|
|
377
|
-
[
|
|
378
|
-
[26, 48],
|
|
379
|
-
[12, 45],
|
|
380
|
-
],
|
|
381
|
-
4,
|
|
382
|
-
0.2 + wave * 0.8
|
|
383
|
-
);
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
case 'scroll': {
|
|
387
|
-
cr.translate(-5, 4 - wave * 8);
|
|
388
|
-
lineCue(
|
|
389
|
-
[
|
|
390
|
-
[23, 31],
|
|
391
|
-
[31, 22],
|
|
392
|
-
[39, 31],
|
|
393
|
-
],
|
|
394
|
-
4,
|
|
395
|
-
0.42 + wave * 0.58
|
|
396
|
-
);
|
|
397
|
-
lineCue(
|
|
398
|
-
[
|
|
399
|
-
[23, 49],
|
|
400
|
-
[31, 58],
|
|
401
|
-
[39, 49],
|
|
402
|
-
],
|
|
403
|
-
4,
|
|
404
|
-
0.42 + wave * 0.58
|
|
405
|
-
);
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
case 'text': {
|
|
409
|
-
const opacity = progress < 0.34 || progress > 0.64 ? 1 : 0.18;
|
|
410
|
-
cr.translate(-4, 0);
|
|
411
|
-
lineCue(
|
|
412
|
-
[
|
|
413
|
-
[31, 22],
|
|
414
|
-
[31, 58],
|
|
415
|
-
],
|
|
416
|
-
4,
|
|
417
|
-
opacity
|
|
418
|
-
);
|
|
419
|
-
lineCue(
|
|
420
|
-
[
|
|
421
|
-
[24, 22],
|
|
422
|
-
[38, 22],
|
|
423
|
-
],
|
|
424
|
-
4,
|
|
425
|
-
opacity
|
|
426
|
-
);
|
|
427
|
-
lineCue(
|
|
428
|
-
[
|
|
429
|
-
[24, 58],
|
|
430
|
-
[38, 58],
|
|
431
|
-
],
|
|
432
|
-
4,
|
|
433
|
-
opacity
|
|
434
|
-
);
|
|
435
|
-
break;
|
|
436
|
-
}
|
|
437
|
-
case 'key': {
|
|
438
|
-
const bounce = Math.sin(progress * Math.PI * 2) * (1 - progress) * 3;
|
|
439
|
-
cr.translate(-9, bounce);
|
|
440
|
-
roundedRect(cr, 14, 25, 28, 28, 6);
|
|
441
|
-
strokeCue(3.5);
|
|
442
|
-
lineCue(
|
|
443
|
-
[
|
|
444
|
-
[23, 32],
|
|
445
|
-
[23, 46],
|
|
446
|
-
[23, 39],
|
|
447
|
-
[33, 32],
|
|
448
|
-
[24, 39],
|
|
449
|
-
[34, 46],
|
|
450
|
-
],
|
|
451
|
-
3.5
|
|
452
|
-
);
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
case 'navigate': {
|
|
456
|
-
cr.translate(-10 + easeInOut(progress) * 9, 0);
|
|
457
|
-
lineCue(
|
|
458
|
-
[
|
|
459
|
-
[15, 29],
|
|
460
|
-
[25, 40],
|
|
461
|
-
[15, 51],
|
|
462
|
-
],
|
|
463
|
-
4,
|
|
464
|
-
0.2 + wave * 0.8
|
|
465
|
-
);
|
|
466
|
-
lineCue(
|
|
467
|
-
[
|
|
468
|
-
[29, 29],
|
|
469
|
-
[39, 40],
|
|
470
|
-
[29, 51],
|
|
471
|
-
],
|
|
472
|
-
4,
|
|
473
|
-
0.2 + wave * 0.8
|
|
474
|
-
);
|
|
475
|
-
break;
|
|
476
|
-
}
|
|
477
|
-
case 'app': {
|
|
478
|
-
const s = 0.2 + easeInOut(Math.min(1, progress * 2)) * 0.8;
|
|
479
|
-
cr.translate(21, 39);
|
|
480
|
-
cr.scale(s, s);
|
|
481
|
-
cr.translate(-26, -39);
|
|
482
|
-
for (const [x, y] of [
|
|
483
|
-
[13, 26],
|
|
484
|
-
[29, 26],
|
|
485
|
-
[13, 42],
|
|
486
|
-
[29, 42],
|
|
487
|
-
]) {
|
|
488
|
-
roundedRect(cr, x, y, 10, 10, 2);
|
|
489
|
-
strokeCue(3.5);
|
|
490
|
-
}
|
|
491
|
-
break;
|
|
492
|
-
}
|
|
493
|
-
case 'transfer':
|
|
494
|
-
cr.translate(-9, 6 - wave * 12);
|
|
495
|
-
lineCue(
|
|
496
|
-
[
|
|
497
|
-
[22, 50],
|
|
498
|
-
[22, 20],
|
|
499
|
-
[14, 28],
|
|
500
|
-
[22, 20],
|
|
501
|
-
[30, 28],
|
|
502
|
-
],
|
|
503
|
-
4,
|
|
504
|
-
0.38 + wave * 0.62
|
|
505
|
-
);
|
|
506
|
-
lineCue(
|
|
507
|
-
[
|
|
508
|
-
[37, 28],
|
|
509
|
-
[37, 58],
|
|
510
|
-
[29, 50],
|
|
511
|
-
[37, 58],
|
|
512
|
-
[45, 50],
|
|
513
|
-
],
|
|
514
|
-
4,
|
|
515
|
-
0.38 + wave * 0.62
|
|
516
|
-
);
|
|
517
|
-
break;
|
|
518
|
-
case 'record':
|
|
519
|
-
cr.translate(-12, 0);
|
|
520
|
-
cr.arc(29, 39, 17, 0, Math.PI * 2);
|
|
521
|
-
strokeCue(4);
|
|
522
|
-
cr.arc(29, 39, 3.6 + wave * 2.1, 0, Math.PI * 2);
|
|
523
|
-
fillPath(cr, (3.6 + wave * 2.1) * 1.25, 0.42 + wave * 0.58, fillColor);
|
|
524
|
-
break;
|
|
525
|
-
case 'system': {
|
|
526
|
-
cr.translate(15, 39);
|
|
527
|
-
cr.rotate(((easeInOut(progress) * 68 - 18) * Math.PI) / 180);
|
|
528
|
-
cr.translate(-29, -39);
|
|
529
|
-
for (const radius of [12, 4]) {
|
|
530
|
-
cr.arc(29, 39, radius, 0, Math.PI * 2);
|
|
531
|
-
strokeCue(3.5);
|
|
532
|
-
}
|
|
533
|
-
for (const points of [
|
|
534
|
-
[
|
|
535
|
-
[29, 20],
|
|
536
|
-
[29, 25],
|
|
537
|
-
],
|
|
538
|
-
[
|
|
539
|
-
[29, 53],
|
|
540
|
-
[29, 58],
|
|
541
|
-
],
|
|
542
|
-
[
|
|
543
|
-
[10, 39],
|
|
544
|
-
[15, 39],
|
|
545
|
-
],
|
|
546
|
-
[
|
|
547
|
-
[43, 39],
|
|
548
|
-
[48, 39],
|
|
549
|
-
],
|
|
550
|
-
[
|
|
551
|
-
[16, 26],
|
|
552
|
-
[20, 30],
|
|
553
|
-
],
|
|
554
|
-
[
|
|
555
|
-
[38, 48],
|
|
556
|
-
[42, 52],
|
|
557
|
-
],
|
|
558
|
-
[
|
|
559
|
-
[16, 52],
|
|
560
|
-
[20, 48],
|
|
561
|
-
],
|
|
562
|
-
[
|
|
563
|
-
[38, 30],
|
|
564
|
-
[42, 26],
|
|
565
|
-
],
|
|
566
|
-
])
|
|
567
|
-
lineCue(points, 3.5);
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
default:
|
|
571
|
-
break;
|
|
572
|
-
}
|
|
573
|
-
cr.restore();
|
|
574
|
-
}
|
|
575
|
-
|
|
576
518
|
function drawBadgeChip(cr, glyph, filled, fillColor) {
|
|
577
519
|
roundedRect(cr, 0.5, 0.5, 17, 17, 5);
|
|
578
520
|
if (filled) {
|
|
@@ -685,6 +627,8 @@ function drawBadgeChip(cr, glyph, filled, fillColor) {
|
|
|
685
627
|
export default class WinRectsExtension extends Extension {
|
|
686
628
|
enable() {
|
|
687
629
|
this._captureClones = new Map();
|
|
630
|
+
if (Number.parseInt(Config.PACKAGE_VERSION, 10) >= 50)
|
|
631
|
+
throw new Error('winrects@cua is unsupported on GNOME Shell 50 or newer for session safety');
|
|
688
632
|
this._impl = Gio.DBusExportedObject.wrapJSObject(IFACE, this);
|
|
689
633
|
this._impl.export(Gio.DBus.session, '/org/cua/WinRects');
|
|
690
634
|
this._nameId = Gio.bus_own_name(
|
|
@@ -696,6 +640,8 @@ export default class WinRectsExtension extends Extension {
|
|
|
696
640
|
null
|
|
697
641
|
);
|
|
698
642
|
this._action = 'idle';
|
|
643
|
+
// Whether cua-driver asked for the current action's cue.
|
|
644
|
+
this._cueRequested = false;
|
|
699
645
|
this._delivery = '';
|
|
700
646
|
this._target = '';
|
|
701
647
|
this._actionStarted = nowSeconds();
|
|
@@ -703,6 +649,12 @@ export default class WinRectsExtension extends Extension {
|
|
|
703
649
|
this._fillColor = [94, 192, 232];
|
|
704
650
|
this._fillColorCss = '#5ec0e8';
|
|
705
651
|
this._glowSurface = createGlowSurface(this._fillColor);
|
|
652
|
+
// Null until cua-driver sends a look: an older driver keeps the glow.
|
|
653
|
+
this._look = null;
|
|
654
|
+
this._path = null;
|
|
655
|
+
this._pathFrameId = 0;
|
|
656
|
+
// The float clock at `at`: a fresh cursor floats fully.
|
|
657
|
+
this._rest = { at: nowSeconds(), phase: 0, hold: 3600, from: 0 };
|
|
706
658
|
this._cursor = new St.DrawingArea({
|
|
707
659
|
width: ACTOR_SIZE,
|
|
708
660
|
height: ACTOR_SIZE,
|
|
@@ -715,14 +667,24 @@ export default class WinRectsExtension extends Extension {
|
|
|
715
667
|
const duration = ACTION_DURATIONS[this._action] ?? 1.6;
|
|
716
668
|
const elapsed = nowSeconds() - this._actionStarted;
|
|
717
669
|
const progress = (elapsed % duration) / duration;
|
|
718
|
-
const
|
|
670
|
+
const pose = this._pose(nowSeconds());
|
|
719
671
|
cr.save();
|
|
672
|
+
// The actor is placed with its centre on the cursor point (see
|
|
673
|
+
// _placeCursor), so the tip, not the canvas centre, goes there. Mapping
|
|
674
|
+
// the canvas centre drew the tip (55, 30) about 3 px left of and 11 px
|
|
675
|
+
// above the click point.
|
|
720
676
|
cr.translate(ACTOR_CENTER, ACTOR_CENTER);
|
|
721
677
|
cr.scale(SCALE, SCALE);
|
|
722
|
-
cr.translate(-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
678
|
+
cr.translate(-TIP_X, -TIP_Y);
|
|
679
|
+
// The float moves the whole cursor; the rotation (heading plus the
|
|
680
|
+
// float tilt) turns it about its tip.
|
|
681
|
+
cr.translate(pose.dx / SCALE, pose.dy / SCALE);
|
|
682
|
+
if (!this._look) drawCursorGlow(cr, progress, this._action, this._glowSurface);
|
|
683
|
+
else if (this._look.halo) drawCursorHalo(cr, this._look.halo, pose.rotation);
|
|
684
|
+
cr.translate(TIP_X, TIP_Y);
|
|
685
|
+
cr.rotate(pose.rotation);
|
|
686
|
+
cr.translate(-TIP_X, -TIP_Y);
|
|
687
|
+
// The cursor draws no action marks: every action is the plain arrow.
|
|
726
688
|
drawCursorBody(cr, progress, this._action, this._fillColor);
|
|
727
689
|
cr.restore();
|
|
728
690
|
cr.$dispose();
|
|
@@ -836,6 +798,7 @@ export default class WinRectsExtension extends Extension {
|
|
|
836
798
|
GLib.source_remove(this._frameId);
|
|
837
799
|
this._frameId = 0;
|
|
838
800
|
}
|
|
801
|
+
this._stopPath();
|
|
839
802
|
if (this._cursor) {
|
|
840
803
|
this._cursor.destroy();
|
|
841
804
|
this._cursor = null;
|
|
@@ -861,7 +824,7 @@ export default class WinRectsExtension extends Extension {
|
|
|
861
824
|
}
|
|
862
825
|
}
|
|
863
826
|
GetVersion() {
|
|
864
|
-
return
|
|
827
|
+
return 12;
|
|
865
828
|
}
|
|
866
829
|
GetRects() {
|
|
867
830
|
const actors = global.get_window_actors();
|
|
@@ -1027,6 +990,7 @@ export default class WinRectsExtension extends Extension {
|
|
|
1027
990
|
}
|
|
1028
991
|
MoveCursor(x, y) {
|
|
1029
992
|
if (!this._cursor) return;
|
|
993
|
+
this._stopPath();
|
|
1030
994
|
const revealBadge = !this._cursor.visible;
|
|
1031
995
|
this._cursorX = x;
|
|
1032
996
|
this._cursorY = y;
|
|
@@ -1043,12 +1007,22 @@ export default class WinRectsExtension extends Extension {
|
|
|
1043
1007
|
ClickPulse(x, y) {
|
|
1044
1008
|
if (!this._cursor) return;
|
|
1045
1009
|
const revealBadge = !this._cursor.visible;
|
|
1046
|
-
|
|
1047
|
-
this.
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1010
|
+
// A move still settling onto the click point finishes by itself.
|
|
1011
|
+
const end = this._path?.samples[this._path.samples.length - 1];
|
|
1012
|
+
const settling = end && Math.hypot(end[1] - x, end[2] - y) <= 2;
|
|
1013
|
+
if (!settling) {
|
|
1014
|
+
this._stopPath();
|
|
1015
|
+
this._cursor.remove_all_transitions();
|
|
1016
|
+
this._cursorX = x;
|
|
1017
|
+
this._cursorY = y;
|
|
1018
|
+
this._cursor.set_position(x - ACTOR_CENTER, y - ACTOR_CENTER);
|
|
1019
|
+
this._positionBadge(x, y, 0);
|
|
1020
|
+
}
|
|
1021
|
+
if (['idle', 'navigate', 'click'].includes(this._action)) {
|
|
1051
1022
|
this._setCursorState('click', this._delivery, this._target);
|
|
1023
|
+
this._cueRequested = false;
|
|
1024
|
+
}
|
|
1025
|
+
this._settleFloat();
|
|
1052
1026
|
this._cursor.show();
|
|
1053
1027
|
this._cursor.queue_repaint();
|
|
1054
1028
|
if (revealBadge) this._revealBadge();
|
|
@@ -1066,10 +1040,92 @@ export default class WinRectsExtension extends Extension {
|
|
|
1066
1040
|
this._glowSurface = createGlowSurface(this._fillColor);
|
|
1067
1041
|
if (this._cursor) this._cursor.queue_repaint();
|
|
1068
1042
|
}
|
|
1043
|
+
SetCursorLook(lookJson) {
|
|
1044
|
+
const look = parseCursorLook(lookJson);
|
|
1045
|
+
if (!look) return;
|
|
1046
|
+
this._look = look;
|
|
1047
|
+
if (this._cursor) this._cursor.queue_repaint();
|
|
1048
|
+
}
|
|
1049
|
+
PlayCursorPath(trackJson) {
|
|
1050
|
+
if (!this._cursor) return;
|
|
1051
|
+
const track = parseCursorPath(trackJson);
|
|
1052
|
+
if (!track) return;
|
|
1053
|
+
const revealBadge = !this._cursor.visible;
|
|
1054
|
+
const now = nowSeconds();
|
|
1055
|
+
this._stopPath();
|
|
1056
|
+
this._cursor.remove_all_transitions();
|
|
1057
|
+
this._badge?.remove_all_transitions();
|
|
1058
|
+
// At rest the float carries on from the clock the track ends on.
|
|
1059
|
+
const end = track.samples[track.samples.length - 1][0];
|
|
1060
|
+
this._rest = { at: now + end, ...track.rest };
|
|
1061
|
+
const first = track.samples[0];
|
|
1062
|
+
this._placeCursor(first[1], first[2]);
|
|
1063
|
+
this._cursor.show();
|
|
1064
|
+
if (track.samples.length > 1) {
|
|
1065
|
+
this._path = { samples: track.samples, start: now };
|
|
1066
|
+
this._pathFrameId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, PATH_FRAME_MS, () => {
|
|
1067
|
+
if (!this._cursor || !this._path) {
|
|
1068
|
+
this._pathFrameId = 0;
|
|
1069
|
+
return GLib.SOURCE_REMOVE;
|
|
1070
|
+
}
|
|
1071
|
+
const t = nowSeconds() - this._path.start;
|
|
1072
|
+
const samples = this._path.samples;
|
|
1073
|
+
const [, x, y] = samplePath(samples, t);
|
|
1074
|
+
this._placeCursor(x, y);
|
|
1075
|
+
this._cursor.queue_repaint();
|
|
1076
|
+
if (t >= samples[samples.length - 1][0]) {
|
|
1077
|
+
this._path = null;
|
|
1078
|
+
this._pathFrameId = 0;
|
|
1079
|
+
return GLib.SOURCE_REMOVE;
|
|
1080
|
+
}
|
|
1081
|
+
return GLib.SOURCE_CONTINUE;
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
this._cursor.queue_repaint();
|
|
1085
|
+
if (revealBadge) this._revealBadge();
|
|
1086
|
+
}
|
|
1087
|
+
// Float offset (points) and rotation (radians) painted at `now`.
|
|
1088
|
+
_pose(now) {
|
|
1089
|
+
if (this._path) {
|
|
1090
|
+
const [, , , dx, dy, rotation] = samplePath(this._path.samples, now - this._path.start);
|
|
1091
|
+
return { dx, dy, rotation };
|
|
1092
|
+
}
|
|
1093
|
+
return restingFloat(this._look, this._rest, now);
|
|
1094
|
+
}
|
|
1095
|
+
// RenderStateCore::settle_float: a click or cue at rest eases the float
|
|
1096
|
+
// out from where it is and holds it at 0. The phase runs on. A path in
|
|
1097
|
+
// flight already settles at its arrival.
|
|
1098
|
+
_settleFloat() {
|
|
1099
|
+
if (this._path || !this._look?.float) return;
|
|
1100
|
+
const now = nowSeconds();
|
|
1101
|
+
// Negative when a click cut a path short: the phase is linear in time.
|
|
1102
|
+
const elapsed = now - this._rest.at;
|
|
1103
|
+
const amp = restAmplitude(
|
|
1104
|
+
this._look.float,
|
|
1105
|
+
Math.max(0, this._rest.hold + elapsed),
|
|
1106
|
+
this._rest.from
|
|
1107
|
+
);
|
|
1108
|
+
this._rest = { at: now, phase: this._rest.phase + elapsed, hold: 0, from: amp };
|
|
1109
|
+
}
|
|
1110
|
+
_placeCursor(x, y) {
|
|
1111
|
+
this._cursorX = x;
|
|
1112
|
+
this._cursorY = y;
|
|
1113
|
+
this._cursor.set_position(Math.round(x - ACTOR_CENTER), Math.round(y - ACTOR_CENTER));
|
|
1114
|
+
this._positionBadge(x, y, 0);
|
|
1115
|
+
}
|
|
1116
|
+
_stopPath() {
|
|
1117
|
+
if (this._pathFrameId) {
|
|
1118
|
+
GLib.source_remove(this._pathFrameId);
|
|
1119
|
+
this._pathFrameId = 0;
|
|
1120
|
+
}
|
|
1121
|
+
this._path = null;
|
|
1122
|
+
}
|
|
1069
1123
|
SetCursorState(action, delivery, target, active) {
|
|
1070
1124
|
if (!ACTIONS.has(action)) return;
|
|
1071
1125
|
if (active) {
|
|
1072
1126
|
this._setCursorState(action, delivery, target);
|
|
1127
|
+
this._cueRequested = true;
|
|
1128
|
+
this._settleFloat();
|
|
1073
1129
|
} else if (this._action === action && !ONE_SHOT_ACTIONS.has(action)) {
|
|
1074
1130
|
this._endingAt = nowSeconds() + 0.4;
|
|
1075
1131
|
}
|
|
@@ -1142,6 +1198,7 @@ export default class WinRectsExtension extends Extension {
|
|
|
1142
1198
|
}
|
|
1143
1199
|
}
|
|
1144
1200
|
HideCursor() {
|
|
1201
|
+
this._stopPath();
|
|
1145
1202
|
if (this._cursor) this._cursor.hide();
|
|
1146
1203
|
if (this._badge) this._badge.hide();
|
|
1147
1204
|
this._badgeRevealedAt = null;
|