react-x11 2.15.3 → 2.16.1
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/README.md +37 -0
- package/package.json +3 -3
- package/src/Reconciler.js +85 -22
- package/src/acceleratorhooks.js +40 -6
- package/src/anchor.js +79 -19
- package/src/capabilities.js +29 -4
- package/src/cocoa/app.js +211 -11
- package/src/cocoa/context2d.js +23 -0
- package/src/cocoa/fonts.js +78 -0
- package/src/cocoa/presenter.js +17 -0
- package/src/cocoa/promotion.js +20 -0
- package/src/cocoa/relaunch.js +8 -3
- package/src/cocoa/symbols.js +64 -0
- package/src/cocoa/threaded.js +24 -4
- package/src/cocoa/window.js +362 -139
- package/src/components/ProgressBar.js +1 -1
- package/src/components/Slider.js +72 -39
- package/src/components/anchor.js +7 -2
- package/src/components/index.js +1 -0
- package/src/components/theme.js +32 -28
- package/src/desktopcapabilityhooks.js +29 -6
- package/src/filedialoghooks.js +3 -5
- package/src/frame/childmain.js +8 -20
- package/src/frame/env.js +2 -10
- package/src/icontheme.js +240 -0
- package/src/imagesource.js +83 -1
- package/src/index.d.ts +10 -1
- package/src/index.js +3 -0
- package/src/keysymchars.js +47 -0
- package/src/keysyms.d.ts +19 -1
- package/src/keysyms.js +107 -8
- package/src/node.d.ts +7 -0
- package/src/nodes/animation.js +17 -47
- package/src/nodes/cascade.js +17 -2
- package/src/nodes/image.js +63 -1
- package/src/nodes/kinds.js +12 -0
- package/src/nodes/layout.js +5 -1
- package/src/nodes/node.js +17 -3
- package/src/nodes/paint.js +117 -0
- package/src/nodes/scope.js +259 -0
- package/src/nodes/scrollable.js +53 -6
- package/src/nodes/text.js +2 -0
- package/src/nodes/textarea.js +1 -1
- package/src/nodes/textinput.js +1 -1
- package/src/nodes/window/anchoring.js +45 -18
- package/src/nodes/window/flush.js +6 -5
- package/src/nodes/window/popup.js +10 -0
- package/src/nodes/window/size.js +40 -2
- package/src/nodes/window/window.js +41 -14
- package/src/registry.js +2 -1
- package/src/screens.js +159 -24
- package/src/settings.js +332 -0
- package/src/statusnotifier.js +164 -17
- package/src/styles.js +212 -8
- package/src/symbols.js +200 -0
- package/src/testing/mock-app.js +10 -0
- package/src/trayhooks.js +21 -5
- package/src/types/capabilities.d.ts +13 -1
- package/src/types/components.d.ts +33 -0
- package/src/types/elements.d.ts +57 -6
- package/src/types/events.d.ts +5 -0
- package/src/types/filedialog.d.ts +3 -1
- package/src/types/style.d.ts +57 -0
- package/src/types/system.d.ts +104 -0
- package/src/types/tray.d.ts +14 -2
- package/src/wayland/xkb.js +170 -59
- package/src/windowid.js +62 -20
package/README.md
CHANGED
|
@@ -609,6 +609,43 @@ The full threat model, including what react-x11 does and does not defend
|
|
|
609
609
|
against, is [docs/security.md](docs/security.md). To report something,
|
|
610
610
|
[SECURITY.md](SECURITY.md).
|
|
611
611
|
|
|
612
|
+
## Similar projects
|
|
613
|
+
|
|
614
|
+
- [GPUIX](https://github.com/remorses/gpuix) — React for
|
|
615
|
+
[GPUI](https://github.com/zed-industries/zed/tree/main/crates/gpui), Zed's
|
|
616
|
+
GPU UI framework. Each commit crosses a napi-rs addon as one batch of
|
|
617
|
+
mutations to a retained Rust tree, which GPUI lays out with Taffy's flexbox
|
|
618
|
+
and paints through Metal, DirectX or Vulkan, on macOS, Windows and Linux.
|
|
619
|
+
- [react-native-gpui](https://github.com/natew/react-native-gpui) — React
|
|
620
|
+
Native's component API (`View`, `Text`, `Pressable`, `TextInput`,
|
|
621
|
+
`FlatList`) on GPUI as well, hosted the other way round: a Rust binary
|
|
622
|
+
embeds the system's JavaScriptCore and runs the bundled app, and commits
|
|
623
|
+
reach GPUI in memory. macOS on Apple silicon only, for now.
|
|
624
|
+
- [GTKX](https://github.com/gtkx-org/gtkx) — React for GNOME: every GObject
|
|
625
|
+
is a JSX element, so the tree is the platform's own GTK4 and Adwaita
|
|
626
|
+
widgets. The TypeScript bindings are generated from GObject-Introspection
|
|
627
|
+
and call into GTK through a Rust core on Node.js. Linux-only by design.
|
|
628
|
+
- React Native for [Windows](https://github.com/microsoft/react-native-windows)
|
|
629
|
+
and [macOS](https://github.com/microsoft/react-native-macos) — Microsoft's
|
|
630
|
+
desktop platforms for React Native. On Windows the new architecture's
|
|
631
|
+
renderer targets Composition from the start, in Windows App SDK apps by
|
|
632
|
+
default, with XAML islands for advanced controls; on macOS a fork of React
|
|
633
|
+
Native maps its UIKit views onto AppKit. [docs/windows.md](docs/windows.md)
|
|
634
|
+
cites its threading as prior art: JS on a thread of its own, and every
|
|
635
|
+
mount posted to the UI thread that alone touches the visuals.
|
|
636
|
+
- [React Native Skia](https://github.com/Shopify/react-native-skia) — 2D
|
|
637
|
+
graphics for React Native, with a React renderer of its own: the
|
|
638
|
+
components inside a `<Canvas>` become a Skia display list, cheap to
|
|
639
|
+
animate with Reanimated. On iOS, Android, macOS and tvOS, in the browser
|
|
640
|
+
through CanvasKit, and headless on Node. Its experimental Graphite builds
|
|
641
|
+
render through Dawn and can share a GPU device with React Native WebGPU.
|
|
642
|
+
- [React Native WebGPU](https://github.com/wcandillon/react-native-webgpu) —
|
|
643
|
+
not a renderer but a GPU surface for React Native: the WebGPU API
|
|
644
|
+
(`navigator.gpu` and a `<Canvas>` view) on iOS, Android, macOS and
|
|
645
|
+
visionOS, implemented over Dawn, Chrome's WebGPU implementation. It runs
|
|
646
|
+
three.js's WebGPU renderer and React Three Fiber. The nearest thing in
|
|
647
|
+
react-x11 is [`<glarea>`](#3d), which speaks GL instead.
|
|
648
|
+
|
|
612
649
|
## See also
|
|
613
650
|
|
|
614
651
|
- [awesome-react-renderer](https://github.com/chentsulin/awesome-react-renderer)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-x11",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.1",
|
|
4
4
|
"description": "react renderer with X11 as a target",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -102,12 +102,12 @@
|
|
|
102
102
|
"dependencies": {
|
|
103
103
|
"ical.js": "^2.2.1",
|
|
104
104
|
"linebreak": "^1.1.0",
|
|
105
|
-
"ntk": "^8.
|
|
105
|
+
"ntk": "^8.9.0",
|
|
106
106
|
"react-reconciler": "^0.34.0",
|
|
107
107
|
"yoga-layout": "^3.2.1"
|
|
108
108
|
},
|
|
109
109
|
"optionalDependencies": {
|
|
110
|
-
"@windowkit/appkit": "^0.
|
|
110
|
+
"@windowkit/appkit": "^0.12.0",
|
|
111
111
|
"@windowkit/wayland": "^3.1.1",
|
|
112
112
|
"dbus-native": "^0.15.1",
|
|
113
113
|
"x11-dri": "^0.9.0"
|
package/src/Reconciler.js
CHANGED
|
@@ -24,6 +24,13 @@ import {
|
|
|
24
24
|
} from './nodes/window/window.js';
|
|
25
25
|
import { PopupNode } from './nodes/window/popup.js';
|
|
26
26
|
import { BoxNode } from './nodes/box.js';
|
|
27
|
+
import { THEME_SCOPE } from './nodes/kinds.js';
|
|
28
|
+
import {
|
|
29
|
+
ThemeBoxNode,
|
|
30
|
+
ThemeScopeNode,
|
|
31
|
+
attachTopLevel,
|
|
32
|
+
detachTopLevel,
|
|
33
|
+
} from './nodes/scope.js';
|
|
27
34
|
import { TextNode, TextChunkNode, setTextStripBelow } from './nodes/text.js';
|
|
28
35
|
import { ImageNode } from './nodes/image.js';
|
|
29
36
|
import { CanvasNode } from './nodes/canvas.js';
|
|
@@ -60,7 +67,11 @@ import { watchAppearance } from './appearance.js';
|
|
|
60
67
|
import { setDesktopIntegration } from './desktopintegration.js';
|
|
61
68
|
import { ForeignNode } from './foreignnodes.js';
|
|
62
69
|
import { GlAreaNode } from './glnodes.js';
|
|
63
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
createRegisteredNode,
|
|
72
|
+
elementDefinition,
|
|
73
|
+
registeredElements,
|
|
74
|
+
} from './registry.js';
|
|
64
75
|
import { SvgNode, SvgChildNode } from './svgnodes.js';
|
|
65
76
|
import { loadLayout } from './yoga.js';
|
|
66
77
|
|
|
@@ -97,6 +108,36 @@ export const HOST_TYPES = [
|
|
|
97
108
|
'foreign',
|
|
98
109
|
];
|
|
99
110
|
|
|
111
|
+
// The host context of the root's own children. `atRoot` is what lets
|
|
112
|
+
// `createInstance` see that an element has no window above it — there is no
|
|
113
|
+
// other moment to know it: a node is built bottom-up, before it has a parent
|
|
114
|
+
// to ask, and appended to the container only in the commit.
|
|
115
|
+
const ROOT_CONTEXT = Object.freeze({
|
|
116
|
+
isInsideText: false,
|
|
117
|
+
isInsideSvg: false,
|
|
118
|
+
atRoot: true,
|
|
119
|
+
inWindow: false,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// What the root of the tree can hold: the elements that are windows of their
|
|
123
|
+
// own, and the provider's node, which holds more of them. Everything else
|
|
124
|
+
// draws into a window, so it has to be inside one.
|
|
125
|
+
const ROOT_TYPES = new Set(['window', 'popup', THEME_SCOPE]);
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A drawn element with no window above it. Without this it reached
|
|
129
|
+
* `appendChildToContainer` and failed there as `child.realize is not a
|
|
130
|
+
* function` — or, under a `<ThemeProvider>`, as a `<window>` nested in a
|
|
131
|
+
* `<box>` the app never wrote (#584).
|
|
132
|
+
*/
|
|
133
|
+
function notAtRoot(type) {
|
|
134
|
+
return new Error(
|
|
135
|
+
`react-x11: <${type}> must be inside a <window> — it is at the root of ` +
|
|
136
|
+
'the tree, which holds only <window> and <popup> elements. Render it ' +
|
|
137
|
+
`inside one: <window><${type} …/></window>.`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
100
141
|
const HostConfig = {
|
|
101
142
|
supportsMutation: true,
|
|
102
143
|
supportsPersistence: false,
|
|
@@ -135,10 +176,7 @@ const HostConfig = {
|
|
|
135
176
|
scheduleMicrotask: queueMicrotask,
|
|
136
177
|
|
|
137
178
|
getRootHostContext() {
|
|
138
|
-
return
|
|
139
|
-
isInsideText: false,
|
|
140
|
-
isInsideSvg: false,
|
|
141
|
-
};
|
|
179
|
+
return ROOT_CONTEXT;
|
|
142
180
|
},
|
|
143
181
|
|
|
144
182
|
getChildHostContext(parentHostContext, type) {
|
|
@@ -150,6 +188,12 @@ const HostConfig = {
|
|
|
150
188
|
isInsideText: parentHostContext.isInsideText || type === 'text',
|
|
151
189
|
// <svg> children are declarative SVG elements, not react-x11 nodes
|
|
152
190
|
isInsideSvg: parentHostContext.isInsideSvg || type === 'svg',
|
|
191
|
+
// Still at the root under a `<ThemeProvider>` written there, which
|
|
192
|
+
// draws nothing; under anything else, inside a window.
|
|
193
|
+
atRoot: parentHostContext.atRoot && type === THEME_SCOPE,
|
|
194
|
+
// Directly inside a window, where a provider can hand a nested window
|
|
195
|
+
// on to it.
|
|
196
|
+
inWindow: type === 'window' || type === 'popup',
|
|
153
197
|
};
|
|
154
198
|
},
|
|
155
199
|
|
|
@@ -195,6 +239,17 @@ const HostConfig = {
|
|
|
195
239
|
'<text> spans and strings are.',
|
|
196
240
|
);
|
|
197
241
|
}
|
|
242
|
+
// Asked here, in the render phase, rather than when the node reaches the
|
|
243
|
+
// container: an error boundary above can catch it, and nothing has been
|
|
244
|
+
// built yet. A name nobody knows gets the unknown-element error below,
|
|
245
|
+
// which lists what there is.
|
|
246
|
+
if (
|
|
247
|
+
hostContext.atRoot &&
|
|
248
|
+
!ROOT_TYPES.has(type) &&
|
|
249
|
+
(HOST_TYPES.includes(type) || elementDefinition(type))
|
|
250
|
+
) {
|
|
251
|
+
throw notAtRoot(type);
|
|
252
|
+
}
|
|
198
253
|
let node;
|
|
199
254
|
switch (type) {
|
|
200
255
|
case 'window':
|
|
@@ -216,6 +271,18 @@ const HostConfig = {
|
|
|
216
271
|
case 'box':
|
|
217
272
|
node = new BoxNode(props, rootContainer);
|
|
218
273
|
break;
|
|
274
|
+
case THEME_SCOPE:
|
|
275
|
+
// `<ThemeProvider>`'s node (nodes/kinds.js). Above the windows it
|
|
276
|
+
// draws nothing and hands its palette to the windows under it; inside
|
|
277
|
+
// a window it is the box that fills its parent it has always been, so
|
|
278
|
+
// `style` means what it says and a `$token` beneath resolves — and
|
|
279
|
+
// directly inside one, a box that passes nested windows on to it.
|
|
280
|
+
node = hostContext.atRoot
|
|
281
|
+
? new ThemeScopeNode(props, rootContainer)
|
|
282
|
+
: hostContext.inWindow
|
|
283
|
+
? new ThemeBoxNode(props, rootContainer)
|
|
284
|
+
: new BoxNode(props, rootContainer);
|
|
285
|
+
break;
|
|
219
286
|
case 'textinput':
|
|
220
287
|
node = new TextInputNode(props, rootContainer);
|
|
221
288
|
break;
|
|
@@ -278,6 +345,13 @@ const HostConfig = {
|
|
|
278
345
|
},
|
|
279
346
|
|
|
280
347
|
createTextInstance(text, rootContainer, hostContext) {
|
|
348
|
+
if (hostContext.atRoot) {
|
|
349
|
+
throw new Error(
|
|
350
|
+
`react-x11: raw text ${JSON.stringify(text)} must be inside a ` +
|
|
351
|
+
'<window>, in a <text> element — it is at the root of the tree, ' +
|
|
352
|
+
'which holds only <window> and <popup> elements.',
|
|
353
|
+
);
|
|
354
|
+
}
|
|
281
355
|
if (!hostContext.isInsideText && !hostContext.isInsideSvg) {
|
|
282
356
|
throw new Error(
|
|
283
357
|
`react-x11: raw text ${JSON.stringify(text)} must be wrapped in a ` +
|
|
@@ -338,19 +412,11 @@ const HostConfig = {
|
|
|
338
412
|
parentInstance.insertBefore(child, null);
|
|
339
413
|
},
|
|
340
414
|
|
|
415
|
+
// The root holds windows, popups and theme scopes (`createInstance` turned
|
|
416
|
+
// everything else away), and nodes/scope.js is what knows how to put each
|
|
417
|
+
// of them there — a scope's windows can arrive after the scope did.
|
|
341
418
|
appendChildToContainer(container, child) {
|
|
342
|
-
|
|
343
|
-
// Top-level window: realize the whole subtree top-down against the
|
|
344
|
-
// screen root.
|
|
345
|
-
child.realize(null);
|
|
346
|
-
}
|
|
347
|
-
// React's getPublicRootInstance answers from the root fiber's first
|
|
348
|
-
// child, and only when that child is a host component. `render()` wraps
|
|
349
|
-
// the tree in a context provider, which is not one, so it would answer
|
|
350
|
-
// null — the container keeps the list instead. Same answer as before:
|
|
351
|
-
// the first top-level node the tree put here.
|
|
352
|
-
(container._rootChildren ??= []).push(child);
|
|
353
|
-
a11yHooks.rootMounted?.(child);
|
|
419
|
+
attachTopLevel(container, child);
|
|
354
420
|
},
|
|
355
421
|
|
|
356
422
|
insertBefore(parentInstance, child, beforeChild) {
|
|
@@ -358,7 +424,7 @@ const HostConfig = {
|
|
|
358
424
|
},
|
|
359
425
|
|
|
360
426
|
insertInContainerBefore(container, child) {
|
|
361
|
-
|
|
427
|
+
attachTopLevel(container, child);
|
|
362
428
|
},
|
|
363
429
|
|
|
364
430
|
removeChild(parentInstance, child) {
|
|
@@ -366,11 +432,8 @@ const HostConfig = {
|
|
|
366
432
|
},
|
|
367
433
|
|
|
368
434
|
removeChildFromContainer(container, child) {
|
|
369
|
-
const roots = container._rootChildren;
|
|
370
|
-
const at = roots ? roots.indexOf(child) : -1;
|
|
371
|
-
if (at !== -1) roots.splice(at, 1);
|
|
372
435
|
// before the destroy, while the subtree is still walkable
|
|
373
|
-
|
|
436
|
+
detachTopLevel(container, child);
|
|
374
437
|
child.destroySubtree();
|
|
375
438
|
},
|
|
376
439
|
|
package/src/acceleratorhooks.js
CHANGED
|
@@ -11,6 +11,35 @@ import { useEffect, useMemo, useRef } from 'react';
|
|
|
11
11
|
import { matchesShortcut } from './accelerators.js';
|
|
12
12
|
import { useTopLevelWindow } from './windowid.js';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* A binding whose anchor resolved to nothing binds nothing — there is no
|
|
16
|
+
* event manager to register it with, and the effect runs once, so it will
|
|
17
|
+
* not come back. Silent, that is a shortcut that simply never fires, with
|
|
18
|
+
* the tree, the chord and the handler all looking correct (issue #616).
|
|
19
|
+
*
|
|
20
|
+
* Once per process, in development: the mistake is structural, and an app
|
|
21
|
+
* that made it once made it for every chord it declares.
|
|
22
|
+
*/
|
|
23
|
+
let warnedAboutAnchor = false;
|
|
24
|
+
export function resetAcceleratorWarningForTests() {
|
|
25
|
+
warnedAboutAnchor = false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function warnUnanchored() {
|
|
29
|
+
if (process.env.NODE_ENV === 'production' || warnedAboutAnchor) return;
|
|
30
|
+
warnedAboutAnchor = true;
|
|
31
|
+
console.warn(
|
|
32
|
+
'react-x11: a shortcut was bound in a component with no window to hang ' +
|
|
33
|
+
'it off, so it is bound to nothing and will never fire. By default a ' +
|
|
34
|
+
"binding belongs to the tree's top-level <window> or, in an app with " +
|
|
35
|
+
'none, the root-level <popup> holding the keyboard. Anchor it ' +
|
|
36
|
+
'explicitly with `scope`:\n' +
|
|
37
|
+
' const here = useRef(null);\n' +
|
|
38
|
+
" useAccelerator([['space']], onToggle, { scope: here });\n" +
|
|
39
|
+
' return <box ref={here}>…</box>;',
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
14
43
|
/**
|
|
15
44
|
* Bind a chord for as long as this component is mounted, anchored at
|
|
16
45
|
* `anchorRef` — the node the binding belongs to, which is what decides
|
|
@@ -30,7 +59,10 @@ export function useAcceleratorEntry(anchorRef, handle, enabled = true) {
|
|
|
30
59
|
useEffect(() => {
|
|
31
60
|
if (!enabled) return undefined;
|
|
32
61
|
const manager = anchorRef.current?.root?.events;
|
|
33
|
-
if (!manager)
|
|
62
|
+
if (!manager) {
|
|
63
|
+
warnUnanchored();
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
34
66
|
return manager.registerAccelerator({
|
|
35
67
|
anchor: () => anchorRef.current ?? null,
|
|
36
68
|
handle: (ev) => live.current?.(ev) ?? false,
|
|
@@ -52,11 +84,13 @@ export function useAcceleratorEntry(anchorRef, handle, enabled = true) {
|
|
|
52
84
|
* The handler is called with the key event, and the key is consumed.
|
|
53
85
|
*
|
|
54
86
|
* By default the binding belongs to the window the component is in, which is
|
|
55
|
-
* what an application-wide shortcut wants
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
87
|
+
* what an application-wide shortcut wants — or, in an app with no `<window>`
|
|
88
|
+
* at all, to the root-level `<popup>` that took the keyboard, which is the
|
|
89
|
+
* whole of a tray popover's UI (`useTopLevelWindow`). Two options for when
|
|
90
|
+
* that is not it: `enabled: false` unbinds it without unmounting anything,
|
|
91
|
+
* and `scope` takes a ref to a node the binding hangs off instead — the way
|
|
92
|
+
* to give a modal `<Dialog>` a shortcut of its own, since a binding on the
|
|
93
|
+
* window behind it is one the modal has taken the keyboard from.
|
|
60
94
|
*/
|
|
61
95
|
export function useAccelerator(shortcut, handler, options = {}) {
|
|
62
96
|
const { enabled = true, scope } = options;
|
package/src/anchor.js
CHANGED
|
@@ -148,7 +148,20 @@ export function deviceAnchorArea(node) {
|
|
|
148
148
|
if (!app) return null;
|
|
149
149
|
const at = screenRect(node);
|
|
150
150
|
const s = node.scale ?? 1;
|
|
151
|
-
|
|
151
|
+
// The whole rect, not its corner: a window straddling two monitors has
|
|
152
|
+
// nodes on each, and the monitor a node is on is the one it covers most of
|
|
153
|
+
// (`monitorAt`, src/screens.js).
|
|
154
|
+
return availableArea(
|
|
155
|
+
app,
|
|
156
|
+
at
|
|
157
|
+
? {
|
|
158
|
+
x: at.x * s,
|
|
159
|
+
y: at.y * s,
|
|
160
|
+
width: at.width * s,
|
|
161
|
+
height: at.height * s,
|
|
162
|
+
}
|
|
163
|
+
: null,
|
|
164
|
+
);
|
|
152
165
|
}
|
|
153
166
|
|
|
154
167
|
/**
|
|
@@ -204,44 +217,91 @@ export function anchorRect(node, options = {}) {
|
|
|
204
217
|
// popup's `x`/`y` props. The math between runs in device pixels, because
|
|
205
218
|
// `abs`, the window origin and the monitor area are (src/scale.js).
|
|
206
219
|
const s = node.scale ?? 1;
|
|
220
|
+
// The anchor is the sub-rect where there is one, all the way through:
|
|
221
|
+
// the side that flips, the edge that aligns, and — since a popup with no
|
|
222
|
+
// size of its own is as wide as the thing it hangs off — the default
|
|
223
|
+
// width.
|
|
224
|
+
const anchor = subRect(node, deviceAt(options.at, s));
|
|
225
|
+
// the rect the *alignment* reads, which is the anchor's own unless the
|
|
226
|
+
// caller split the two axes — one origin serves both, since both nodes are
|
|
227
|
+
// in the same window
|
|
228
|
+
const cross = options.alignTo ? (subRect(options.alignTo) ?? anchor) : anchor;
|
|
229
|
+
const origin = windowOrigin(node);
|
|
230
|
+
const onScreen = (r) => ({
|
|
231
|
+
x: origin.x + r.x,
|
|
232
|
+
y: origin.y + r.y,
|
|
233
|
+
width: r.width,
|
|
234
|
+
height: r.height,
|
|
235
|
+
});
|
|
236
|
+
return placeAgainst(
|
|
237
|
+
onScreen(anchor),
|
|
238
|
+
onScreen(cross),
|
|
239
|
+
deviceAnchorArea(node),
|
|
240
|
+
s,
|
|
241
|
+
{ ...options, direction: options.direction ?? node.direction },
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* The same placement against a rect **on the screen**, with no node behind
|
|
247
|
+
* it: the frame of the tray item a click reports, or a point where the
|
|
248
|
+
* pointer was. `rect` is logical screen pixels, the unit a popup's `x`/`y`
|
|
249
|
+
* are in, and `{ x, y }` alone is a point; the result is logical too.
|
|
250
|
+
*
|
|
251
|
+
* `scale` is the display's, since there is no node to ask, and `direction`
|
|
252
|
+
* decides what `'start'` and `'end'` mean — a node's anchor takes both from
|
|
253
|
+
* the node. The popup is kept on the monitor the rect is on.
|
|
254
|
+
*/
|
|
255
|
+
export function anchorScreenRect(app, rect, options = {}) {
|
|
256
|
+
if (typeof rect?.x !== 'number' || typeof rect?.y !== 'number') return null;
|
|
257
|
+
const s = options.scale ?? 1;
|
|
258
|
+
const anchor = {
|
|
259
|
+
x: rect.x * s,
|
|
260
|
+
y: rect.y * s,
|
|
261
|
+
width: (rect.width ?? 0) * s,
|
|
262
|
+
height: (rect.height ?? 0) * s,
|
|
263
|
+
};
|
|
264
|
+
// The monitor is picked from the whole rect rather than its top-left
|
|
265
|
+
// corner, because a tray item's frame is not inside its own display: a
|
|
266
|
+
// menu-bar button reports a rect that starts a few points above the top
|
|
267
|
+
// edge, and the corner alone lands on whichever display happens to reach
|
|
268
|
+
// up past it — a different one, on a desk with a taller head (#618).
|
|
269
|
+
const area = app ? availableArea(app, anchor) : null;
|
|
270
|
+
return placeAgainst(anchor, anchor, area, s, options);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* The placement both anchors share, in device pixels: `anchor` is the rect
|
|
275
|
+
* the popup hangs off, `cross` the one it aligns to, both on the screen, and
|
|
276
|
+
* `area` what it is kept inside — null where there is nothing to ask, and it
|
|
277
|
+
* then neither flips nor clamps.
|
|
278
|
+
*/
|
|
279
|
+
function placeAgainst(anchor, cross, area, s, options) {
|
|
207
280
|
const {
|
|
208
281
|
placement = 'bottom',
|
|
209
282
|
align = 'start',
|
|
210
283
|
alignOffset: logicalAlignOffset = 0,
|
|
211
284
|
offset: logicalOffset = 2,
|
|
212
|
-
at,
|
|
213
|
-
alignTo,
|
|
214
285
|
// A popup that covers its own anchor — a native popup button's menu,
|
|
215
286
|
// which opens with the chosen row over the control — has no other side
|
|
216
287
|
// to flip to: it is clamped into the screen instead, as AppKit clamps.
|
|
217
288
|
flip = true,
|
|
218
|
-
direction
|
|
289
|
+
direction,
|
|
219
290
|
} = options;
|
|
220
291
|
const alignOffset = logicalAlignOffset * s;
|
|
221
292
|
const offset = logicalOffset * s;
|
|
222
293
|
const rtl = direction === 'rtl';
|
|
223
294
|
|
|
224
|
-
// The anchor is the sub-rect where there is one, all the way through:
|
|
225
|
-
// the side that flips, the edge that aligns, and — since a popup with no
|
|
226
|
-
// size of its own is as wide as the thing it hangs off — the default
|
|
227
|
-
// width.
|
|
228
|
-
const anchor = subRect(node, deviceAt(at, s));
|
|
229
295
|
const width = options.width !== undefined ? options.width * s : anchor.width;
|
|
230
296
|
const height = options.height !== undefined ? options.height * s : 0;
|
|
231
297
|
|
|
232
|
-
const
|
|
233
|
-
const
|
|
234
|
-
const ay = origin.y + anchor.y;
|
|
298
|
+
const ax = anchor.x;
|
|
299
|
+
const ay = anchor.y;
|
|
235
300
|
const aw = anchor.width;
|
|
236
301
|
const ah = anchor.height;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
// in the same window
|
|
240
|
-
const cross = alignTo ? (subRect(alignTo) ?? anchor) : anchor;
|
|
241
|
-
const cx = origin.x + cross.x;
|
|
242
|
-
const cy = origin.y + cross.y;
|
|
302
|
+
const cx = cross.x;
|
|
303
|
+
const cy = cross.y;
|
|
243
304
|
|
|
244
|
-
const area = deviceAnchorArea(node);
|
|
245
305
|
const left = area?.x ?? 0;
|
|
246
306
|
const top = area?.y ?? 0;
|
|
247
307
|
const right = area ? area.x + area.width : null;
|
package/src/capabilities.js
CHANGED
|
@@ -176,8 +176,8 @@ async function probeNotifications({ app } = {}) {
|
|
|
176
176
|
// tray
|
|
177
177
|
// ---------------------------------------------------------------------------
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
/** The tray on an app that has one of its own, which needs nothing asked. */
|
|
180
|
+
function trayNow(target) {
|
|
181
181
|
if (typeof target?.createStatusItem === 'function') {
|
|
182
182
|
return frozen('cocoa', {
|
|
183
183
|
menu: true,
|
|
@@ -194,6 +194,12 @@ async function probeTray({ app } = {}) {
|
|
|
194
194
|
scroll: false,
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function probeTray({ app } = {}) {
|
|
201
|
+
const now = trayNow(app ?? soleApp());
|
|
202
|
+
if (now) return now;
|
|
197
203
|
|
|
198
204
|
const ref = await sessionBus();
|
|
199
205
|
if (!ref) return NONE;
|
|
@@ -226,8 +232,8 @@ async function probeTray({ app } = {}) {
|
|
|
226
232
|
// launcher
|
|
227
233
|
// ---------------------------------------------------------------------------
|
|
228
234
|
|
|
229
|
-
|
|
230
|
-
|
|
235
|
+
/** The Dock tile on an app that has one, which needs nothing asked. */
|
|
236
|
+
function launcherNow(target) {
|
|
231
237
|
if (typeof target?.setDockBadge === 'function') {
|
|
232
238
|
return frozen('cocoa', {
|
|
233
239
|
badge: true,
|
|
@@ -239,6 +245,12 @@ async function probeLauncher({ app } = {}) {
|
|
|
239
245
|
needsDesktopFile: false,
|
|
240
246
|
});
|
|
241
247
|
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function probeLauncher({ app } = {}) {
|
|
252
|
+
const now = launcherNow(app ?? soleApp());
|
|
253
|
+
if (now) return now;
|
|
242
254
|
|
|
243
255
|
// The Linux rung needs two things that are not the bus: an app id to
|
|
244
256
|
// attribute the entry to, and a `.desktop` file of that name for the
|
|
@@ -322,3 +334,16 @@ export async function desktopCapability(name, options = {}) {
|
|
|
322
334
|
/** The "nothing here" answer, exported so a caller can compare against it and
|
|
323
335
|
* so the hook has something stable to return on the first frame. */
|
|
324
336
|
export const NO_CAPABILITY = NONE;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The answer for a capability where it is known without asking anything —
|
|
340
|
+
* the Cocoa app's own tray and Dock tile — or null where finding out takes a
|
|
341
|
+
* round trip. What lets `useDesktopCapability` be settled on its first frame
|
|
342
|
+
* where the answer never needed waiting for.
|
|
343
|
+
*/
|
|
344
|
+
export function capabilityNow(name, { app } = {}) {
|
|
345
|
+
const target = app ?? soleApp();
|
|
346
|
+
if (name === 'tray') return trayNow(target);
|
|
347
|
+
if (name === 'launcher') return launcherNow(target);
|
|
348
|
+
return null;
|
|
349
|
+
}
|