Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Layers: one stacking order for the desktop, menus always above the Dock

Federico Pereiraa5d7433bea47
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8d6faf..00aee05 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,12 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
### Fixed
+- **Menus are always above the Dock.** With the Dock on the left, the crown menu opened underneath
+ it and the Dock took its clicks; select lists inside apps (Passwords' category list) were drawn
+ under the form fields after them. The desktop now has one stacking order, in layers (Dock < menu
+ bar < fullscreen < launcher < menus and popovers < sheets < notifications < tooltips < drag
+ images < system prompts), and clicks follow it, in every Dock position, light and dark, RTL and
+ the Classic theme ([docs/LAYERS.md](docs/LAYERS.md)).
- **The menu bar names a Linux app, not its window.** Next to the crown it showed the window title
(for a browser, the whole page title); it now shows the app's short
name, "Chromium", in every language. The Dock tooltip and Linux app notifications use the same
diff --git a/apps/passwords/ui.jsx b/apps/passwords/ui.jsx
index 53a711c..76a2c03 100644
--- a/apps/passwords/ui.jsx
+++ b/apps/passwords/ui.jsx
@@ -1,7 +1,7 @@
// ui.jsx — small pieces of Passwords: category and item icons, sheets (dialogs), the strength
// bar, a QR code image, a multi-line field, a file picker and pop-up menus. Spacing, type and
// controls follow docs/DESIGN.md; icons are drawn (glyphs.jsx), never color emoji.
-import { View, Text, Image, useTheme, useStore, createStore, Button, ScrollView, TextInput, ToolbarButton, takeTextFocus, releaseTextFocus, fs, t } from '@lordos/sdk';
+import { View, Text, Image, useTheme, useStore, createStore, Button, ScrollView, TextInput, ToolbarButton, takeTextFocus, releaseTextFocus, fs, t, Overlay } from '@lordos/sdk';
import { useEffect, useRef, useState } from 'react';
import { builtinById } from './templates.js';
import { appMode } from './api.js';
@@ -297,18 +297,22 @@ export function Choice({ value, options, onChange, width = 200 }) {
const th = useTheme();
const [open, setOpen] = useState(false);
const cur = options.find((o) => o[0] === value);
+ const btn = useRef(null);
return (
<View style={{ width }}>
- <View onClick={() => setOpen(!open)} style={{ height: 28, paddingHorizontal: 10, borderRadius: 7, flexDirection: 'row', alignItems: 'center', gap: 6,
+ <View ref={btn} onClick={() => setOpen(!open)} style={{ height: 28, paddingHorizontal: 10, borderRadius: 7, flexDirection: 'row', alignItems: 'center', gap: 6,
backgroundColor: th.control, border: `1px solid ${open ? th.accent : 'transparent'}` }}>
<Text style={{ flex: 1, minWidth: 0, fontSize: 13, color: th.text, whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}>{cur ? cur[1] : String(value ?? '')}</Text>
<Text style={{ fontSize: 9, color: th.textDim }}>▼</Text>
</View>
+ {/* the list goes in the window's overlay layer (sdk/layers.js), above every field of the form */}
{open && (
- <View style={{ position: 'absolute', top: 32, insetInlineStart: 0, width, zIndex: 60, borderRadius: 8, padding: 5,
- backgroundColor: th.mode === 'dark' ? '#2c2c31' : '#ffffff', border: `1px solid ${th.separator}`, boxShadow: '0 10px 30px rgba(0,0,0,0.35)' }}>
- {options.map(([v, label]) => <ChoiceRow key={String(v)} label={label} on={v === value} onClick={() => { setOpen(false); onChange(v); }} />)}
- </View>
+ <Overlay anchor={btn} onClose={() => setOpen(false)}>
+ <View style={{ position: 'absolute', top: 32, insetInlineStart: 0, width, borderRadius: 8, padding: 5,
+ backgroundColor: th.mode === 'dark' ? '#2c2c31' : '#ffffff', border: `1px solid ${th.separator}`, boxShadow: '0 10px 30px rgba(0,0,0,0.35)' }}>
+ {options.map(([v, label]) => <ChoiceRow key={String(v)} label={label} on={v === value} onClick={() => { setOpen(false); onChange(v); }} />)}
+ </View>
+ </Overlay>
)}
</View>
);
diff --git a/apps/settings/ui.jsx b/apps/settings/ui.jsx
index d5403c0..09b8e78 100644
--- a/apps/settings/ui.jsx
+++ b/apps/settings/ui.jsx
@@ -1,7 +1,7 @@
// ui.jsx — the building blocks of every Settings page, on top of the SDK's GroupBox (docs/DESIGN.md,
// "Settings"): a page column, titled sections (inset grouped boxes with hairlines between rows),
// rows with the control or the value at the trailing edge, form rows, a pop-up button, a page header, badges and notes.
-import { View, Text, useTheme, addListener, GroupBox as InsetBox, spacing, typeScale, createStore, useStore, screen, ScrollView } from '@lordos/sdk';
+import { View, Text, useTheme, addListener, GroupBox as InsetBox, spacing, typeScale, createStore, useStore, screen, ScrollView, Overlay } from '@lordos/sdk';
import { createElement as h, useEffect, useRef, useState } from 'react';
@@ -145,8 +145,8 @@ export function StatusDot({ color, size = 8 }) {
return <View style={{ width: size, height: size, borderRadius: size / 2, backgroundColor: color }} />;
}
-// The page: a column of sections 20 px apart. It also hosts the open pop-up menu (PopUpLayer), drawn
-// last so it covers the rows below its button (zIndex only orders siblings).
+// The page: a column of sections 20 px apart. It also hosts the open pop-up menu (PopUpLayer), which
+// draws itself in the overlay layer (sdk/layers.js).
export function Stack({ children, gap = 20 }) {
return (
<View style={{ gap, paddingBottom: 24 }}>
@@ -185,36 +185,32 @@ export function PopUp({ value, options, onChange, width = 190, disabled }) {
function PopUpLayer() {
const t = useTheme();
const p = useStore(popup);
- const origin = useRef(null), menu = useRef(null);
- const [, relayout] = useState(0);
+ const menu = useRef(null);
useEffect(() => {
if (!p) return undefined;
- relayout((x) => x + 1); // the origin is known after the first layout
return addListener('pointerdown', (e) => {
const inside = (n) => { if (!n) return false; const [x, y, w, h] = lord.getLayout(n.id); return e.x >= x && e.x <= x + w && e.y >= y && e.y <= y + h; };
if (!inside(menu.current) && !inside(p.node)) popup.set(null);
});
}, [p]);
- const anchor = <View ref={origin} style={{ position: 'absolute', left: 0, top: 0, width: 0, height: 0 }} />;
- if (!p || !p.node || !origin.current) return anchor;
- const [ox, oy] = lord.getLayout(origin.current.id);
- const [bx, by, bw, bh] = lord.getLayout(p.node.id);
+ if (!p || !p.node) return null;
+ const [, by, bw, bh] = lord.getLayout(p.node.id);
const rows = p.options.length;
const mh = rows * 24 + 12;
const below = by + bh + 4 + Math.min(mh, 320) < screen.height - 70;
const height = Math.min(mh, 320);
- const top = below ? by + bh + 4 - oy : by - 4 - height - oy;
+ // in the overlay layer (sdk/layers.js), placed against the button: above the rows below it and
+ // not clipped by the page's scroll view
return (
- <>
- {anchor}
- <View ref={menu} style={{ position: 'absolute', left: bx - ox, top, width: Math.max(bw, p.width), height, padding: 5, borderRadius: 8, overflow: 'hidden',
+ <Overlay anchor={p.node}>
+ <View ref={menu} style={{ position: 'absolute', left: 0, top: below ? bh + 4 : -4 - height, width: Math.max(bw, p.width), height, padding: 5, borderRadius: 8, overflow: 'hidden',
backgroundColor: t.mode === 'dark' ? '#2c2c31' : '#ffffff', border: `1px solid ${t.separator}`, boxShadow: '0 10px 30px rgba(0,0,0,0.35)' }}>
<ScrollView style={{ flex: 1 }}>
{p.options.map(([v, label], i) => (v === '-' ? <View key={`s${i}`} style={{ height: 1, marginVertical: 4, marginHorizontal: 6, backgroundColor: t.separator }} />
: <PopRow key={String(v)} label={label} Icon={p.options[i][2]} checked={v === p.value} onClick={() => { popup.set(null); if (v !== p.value) p.onChange(v); }} />))}
</ScrollView>
</View>
- </>
+ </Overlay>
);
}
diff --git a/docs/DOCK.md b/docs/DOCK.md
index cf7c633..3085c90 100644
--- a/docs/DOCK.md
+++ b/docs/DOCK.md
@@ -208,6 +208,13 @@ The state only changes when crossing those limits. Moving the mouse over the res
doesn't redraw anything, and the animation redraws only the Dock, not the desktop. Magnification
already worked this way: its state belongs to the Dock component.
+## Above and below
+
+The Dock is in the `dock` layer: above the windows and under the menu bar. Its own menus are in
+`popover` (above the windows and the menu bar), its name tooltip in `tooltip` (hidden while the
+icon's menu is open) and the dragged icon and the «poof» in `drag`. Every other menu, popover and
+the Control Center are above it whatever its side, auto-hide or magnification. See `LAYERS.md`.
+
## Right to left (Arabic, Hebrew)
**Left and right are physical sides of the screen**, as on popular desktop systems: with an RTL language a Dock on the
diff --git a/docs/LAYERS.md b/docs/LAYERS.md
new file mode 100644
index 0000000..f34f03d
--- /dev/null
+++ b/docs/LAYERS.md
@@ -0,0 +1,93 @@
+# Layers: what is drawn above what
+
+One stacking order for the whole desktop (0.8.1). Menus, popovers, select lists, the Control
+Center, notifications, tooltips and prompts are always above the Dock, the menu bar and the
+windows, whatever the Dock's position (bottom, left, right), auto-hide, magnification, light or
+dark mode, and in right-to-left languages. Clicks follow the same order: a click on a menu that
+covers the Dock goes to the menu.
+
+| | |
+|---|---|
+| ![crown menu, Dock on the left](layers-crown-dock-left-light.png) | ![dark](layers-crown-dock-left-dark.png) |
+| The crown menu over the Dock on the left (it used to open underneath it) | Dark mode |
+| ![Dock menu over a window](layers-dock-menu-left-dark.png) | ![Dock menu over the menu bar](layers-dock-menu-bottom-light.png) |
+| A Dock menu over the windows | A tall Dock menu over the menu bar |
+| ![Dock on the right](layers-dock-menu-right-dark.png) | ![Control Center](layers-control-center-dock-right.png) |
+| Dock on the right: its menu over the window and the menu bar | The Control Center over the Dock on the right |
+| ![select list](layers-select-passwords-light.png) | ![select list, dark](layers-select-passwords-dark.png) |
+| Passwords → New item → Category: the list covers the form (the fields used to show through it) | Dark mode |
+| ![Classic](layers-classic-left-menu.png) | ![RTL](layers-crown-dock-right-rtl.png) |
+| Classic theme, taskbar on the left: its menu over the windows | Arabic, Dock on the right: the crown menu over the Dock |
+
+## Why it broke
+
+The engine's `zIndex` only orders **siblings** (`node_children_ordered` in `server/src/ui/node.c`),
+and hit testing walks the same order (`hit` in `paint.c`). The theme drew the menu bar, then the
+Dock, and each menu bar menu was a child of the menu bar: with the Dock on the left, the Dock came
+later in the tree and covered the crown menu, and also took its clicks. Inside apps, a select
+list drawn inside a form row sat under the rows that came after it, whatever its `zIndex`.
+
+## The order
+
+Each layer is a root node of the screen's size with a fixed `zIndex`, above the theme's tree;
+content enters it through a React portal (`runtime/index.js`: `layerContainer`, `createPortal`).
+A layer node is `pointerEvents: 'box-none'`: lord-server never hits the layer itself, only what is
+in it, so an empty part of a layer lets the click through to whatever is below.
+
+| Layer | zIndex | What goes there |
+|---|---|---|
+| base | 0 | the theme's own tree: wallpaper, desktop widgets, windows (in tree order) |
+| `dock` | 10 | the Dock; the Classic taskbar |
+| `menubar` | 20 | the top menu bar |
+| `floating` | 30 | fullscreen and picture-in-picture windows |
+| `overlay` | 40 | the app launcher, search |
+| `popover` | 50 | menus, context menus, the Dock's menus, the Control Center, select lists, popovers, the clipboard and emoji panels, the Classic start menu |
+| `modal` | 60 | shell sheets and confirmations (Empty Trash), the print dialog |
+| `notification` | 70 | notification banners, the clipboard toast, the remote desktop badge |
+| `tooltip` | 80 | tooltips (the Dock's names) |
+| `drag` | 90 | drag images, the Dock's «poof» |
+| `system` | 100 | permission prompts, the keyring password prompt, Bluetooth pairing, «Keep this display?», the file chooser |
+| `input` | 110 | the input method's candidate window |
+
+Inside one layer, what opened last is on top. The lock screen and the login screen are another
+session (`lord-sessiond`, see `SESSIONS.md`), above all of this. Menus of Wayland apps
+(`xdg_popup`) are painted by the compositor above everything (`wl_paint_popups`).
+
+## Using it
+
+```js
+import { Layer, Overlay, LAYERS } from '@lordos/sdk';
+
+// a shell surface (themes): drawn in its layer wherever it is rendered from
+<Layer name="popover"><ControlCenter … /></Layer>
+
+// a list, popover or menu opened from a control (apps and the SDK)
+<Overlay anchor={buttonRef} onClose={() => setOpen(false)}>
+ <View style={{ position: 'absolute', top: 32, insetInlineStart: 0, … }}>…</View>
+</Overlay>
+```
+
+- **Themes:** put every surface above the windows in its layer. The default theme's `Menu.jsx`
+ does it by itself, so any menu built with it is in `popover`. `startShell` places the SDK's own
+ surfaces (search, notifications, prompts, fullscreen windows) in theirs.
+- **`Overlay`:** its children are positioned against the anchor's box, so `top: h + 4, left: 0`
+ still means «below the button». It is not clipped by a scroll view or the rows below it.
+ `onClose` is called on a click outside (the anchor included toggles itself) and on Escape. In
+ the desktop's process it goes to the `popover` layer, above the Dock and the other windows; a
+ protected window's list stays black in screenshots. In an isolated app's process (`.lpk`
+ apps and Passwords, `"process": "isolated"`) it goes to the window's own overlay host, above all
+ of the window's content (the app's surface is the window, so it can't leave it).
+- Used today by: the shell's menus, the SDK's `MenuButton`, the «fill from Passwords» button
+ (`AutofillButton`), Settings' pop-up buttons and Passwords' pop-up menus. Calendar, Contacts and
+ Reminders keep their own per-window popover host; the Terminal's preferences use an inline list.
+- **Don't** fight the order with large `zIndex` values: they only order siblings. A new kind of
+ surface gets a row in the table above (and in `sdk/layers.js`) instead.
+
+## Tests
+
+- `build/engine-test` (`make -C server test`), `test_layers`: layers created in the «wrong» tree
+ order still paint and hit in `zIndex` order; an empty layer lets the click through; a `zIndex`
+ inside the base can't climb above a layer; `pointerEvents: 'none'` still hides a subtree.
+- On the VM: the screenshots above (VM 122), clicking the crown menu's items over the Dock (they
+ open their item, not the Dock's app) and the Passwords category list (picking «Licenses» changes
+ the form).
diff --git a/docs/layers-classic-left-menu.png b/docs/layers-classic-left-menu.png
new file mode 100644
index 0000000..28df039
Binary files /dev/null and b/docs/layers-classic-left-menu.png differ
diff --git a/docs/layers-control-center-dock-right.png b/docs/layers-control-center-dock-right.png
new file mode 100644
index 0000000..33907ac
Binary files /dev/null and b/docs/layers-control-center-dock-right.png differ
diff --git a/docs/layers-crown-dock-left-dark.png b/docs/layers-crown-dock-left-dark.png
new file mode 100644
index 0000000..117cdb7
Binary files /dev/null and b/docs/layers-crown-dock-left-dark.png differ
diff --git a/docs/layers-crown-dock-left-light.png b/docs/layers-crown-dock-left-light.png
new file mode 100644
index 0000000..7a52a4b
Binary files /dev/null and b/docs/layers-crown-dock-left-light.png differ
diff --git a/docs/layers-crown-dock-right-rtl.png b/docs/layers-crown-dock-right-rtl.png
new file mode 100644
index 0000000..7f9c79a
Binary files /dev/null and b/docs/layers-crown-dock-right-rtl.png differ
diff --git a/docs/layers-dock-menu-bottom-light.png b/docs/layers-dock-menu-bottom-light.png
new file mode 100644
index 0000000..cc293b6
Binary files /dev/null and b/docs/layers-dock-menu-bottom-light.png differ
diff --git a/docs/layers-dock-menu-left-dark.png b/docs/layers-dock-menu-left-dark.png
new file mode 100644
index 0000000..f674e3b
Binary files /dev/null and b/docs/layers-dock-menu-left-dark.png differ
diff --git a/docs/layers-dock-menu-right-dark.png b/docs/layers-dock-menu-right-dark.png
new file mode 100644
index 0000000..358fba6
Binary files /dev/null and b/docs/layers-dock-menu-right-dark.png differ
diff --git a/docs/layers-select-passwords-dark.png b/docs/layers-select-passwords-dark.png
new file mode 100644
index 0000000..9736b91
Binary files /dev/null and b/docs/layers-select-passwords-dark.png differ
diff --git a/docs/layers-select-passwords-light.png b/docs/layers-select-passwords-light.png
new file mode 100644
index 0000000..45b7be9
Binary files /dev/null and b/docs/layers-select-passwords-light.png differ
diff --git a/runtime/index.js b/runtime/index.js
index 9a665a6..400eb07 100644
--- a/runtime/index.js
+++ b/runtime/index.js
@@ -62,6 +62,7 @@ globalThis.__lordScreen = () => {
screen.height = lord.screen.height;
readDisplays();
if (rootNode) { lord.setStyle(rootNode, 'width', screen.width); lord.setStyle(rootNode, 'height', screen.height); }
+ for (const c of layerNodes.values()) { lord.setStyle(c.id, 'width', screen.width); lord.setStyle(c.id, 'height', screen.height); }
for (const fn of screenListeners) { try { fn(screen, old); } catch (e) { console.error('pantalla:', e?.message || e); } }
};
@@ -174,6 +175,30 @@ const host = {
const reconciler = Reconciler(host);
+// ---- layers: one stacking order for the whole screen (sdk/layers.js, docs/LAYERS.md) ----
+// Each layer is a root node of the screen's size, above the React tree (zIndex > 0) and
+// pointerEvents 'box-none' (lord-server never hits the layer itself, only what is in it), so paint
+// order and hit testing follow the same order. Content goes in with createPortal.
+const layerNodes = new Map(); // zIndex → container
+export function layerContainer(z) {
+ if (!rootNode || !(z > 0)) return null;
+ let c = layerNodes.get(z);
+ if (!c) {
+ const id = lord.createNode('view');
+ for (const [k, v] of [['position', 'absolute'], ['left', 0], ['top', 0], ['width', screen.width], ['height', screen.height],
+ ['pointerEvents', 'box-none'], ['zIndex', z]]) lord.setStyle(id, k, v);
+ lord.appendChild(rootNode, id);
+ c = { id, isContainer: true };
+ layerNodes.set(z, c);
+ }
+ return c;
+}
+// A portal into a host node: a layer container (above), or a View instance (the window's overlay
+// host: events then bubble from the portal's content to that View and up to the window).
+export function createPortal(children, container, key = null) {
+ return reconciler.createPortal(children, container, null, key);
+}
+
export function render(element) {
const rootId = lord.createNode('view');
rootNode = rootId;
diff --git a/sdk/components.jsx b/sdk/components.jsx
index 172df5b..382c6e2 100644
--- a/sdk/components.jsx
+++ b/sdk/components.jsx
@@ -273,7 +273,7 @@ export function Slider({ value, onChange, min = 0, max = 1, width = 160 }) {
// ---- context of each app's window ----
-const AppWindowContext = createContext({ id: null, focused: false, args: null });
+export const AppWindowContext = createContext({ id: null, focused: false, args: null });
export const useAppWindow = () => useContext(AppWindowContext);
// State of a window that survives the app being remounted (going fullscreen
@@ -300,13 +300,17 @@ export function AppHost({ id, focused }) {
const args = useStore(windows, (ws) => ws.find((w) => w.id === id)?.args || null);
const prot = useStore(windows, (ws) => !!ws.find((w) => w.id === id)?.protected);
const mode = useStore(windows, (ws) => { const w = ws.find((x) => x.id === id); return w?.fullscreen ? 'fullscreen' : w?.pip ? 'pip' : 'window'; });
+ // the window's overlay host (sdk/layers.js): lists and popovers of an isolated app's process go
+ // here, above all of the window's content; in the desktop's process they go to the shell layers
+ const [overlayHost, setOverlayHost] = useState(null);
if (!app) return null;
const C = app.Component;
// the content goes in its own node: `protected` paints it black in screenshots (wm.setProtected)
return (
- <AppWindowContext.Provider value={{ id, focused, args, mode }}>
+ <AppWindowContext.Provider value={{ id, focused, args, mode, protected: prot, overlayHost }}>
<View protected={prot} style={{ flex: 1, alignSelf: 'stretch' }}>
<C />
+ <View ref={setOverlayHost} style={{ position: 'absolute', left: 0, top: 0, right: 0, bottom: 0, pointerEvents: 'box-none' }} />
</View>
</AppWindowContext.Provider>
);
diff --git a/sdk/controls.jsx b/sdk/controls.jsx
index f8371fd..9469bf4 100644
--- a/sdk/controls.jsx
+++ b/sdk/controls.jsx
@@ -8,6 +8,7 @@ import { TextInput, useAppWindow } from './components.jsx';
import { wm } from './windows.js';
import { direction } from './i18n.js';
import { Lumo } from './mascot.js';
+import { Overlay } from './layers.js';
// Design tokens (docs/DESIGN.md): an 8 px grid, desktop-standard type sizes and control heights.
export const spacing = { xxs: 2, xs: 4, s: 8, m: 12, l: 16, xl: 20, xxl: 24, xxxl: 32 };
@@ -124,16 +125,20 @@ export function MenuButton({ icon = '⋯', title, items, small }) {
});
}, [open]);
const end = open && nearEnd(winId, btn.current);
+ // the menu goes in the overlay layer (sdk/layers.js): above the rest of the window, whatever
+ // comes after the button, and not clipped by a scrolling parent
return (
- <View ref={btn} style={{ zIndex: open ? 1000 : 0 }}>
+ <View ref={btn}>
<ToolbarButton icon={icon} title={open ? null : title} small={small} active={open} onClick={() => setOpen((o) => !o)} />
{open && (
- <View ref={menu} style={{ position: 'absolute', top: (small ? controlSize.small : controlSize.regular) + 4, [end ? 'right' : 'left']: 0, zIndex: 1000,
- minWidth: 200, paddingVertical: 5, paddingHorizontal: 5, borderRadius: 8, backgroundColor: t.mode === 'dark' ? '#2c2c31' : '#ffffff',
- border: `1px solid ${t.separator}`, boxShadow: '0 10px 30px rgba(0,0,0,0.35)' }}>
- {items.map((it, i) => (it === '-' ? <View key={`s${i}`} style={{ height: 1, marginVertical: 4, marginHorizontal: 6, backgroundColor: t.separator }} />
- : <MenuRow key={it.label} it={it} onDone={() => setOpen(false)} />))}
- </View>
+ <Overlay anchor={btn}>
+ <View ref={menu} style={{ position: 'absolute', top: (small ? controlSize.small : controlSize.regular) + 4, [end ? 'right' : 'left']: 0,
+ minWidth: 200, paddingVertical: 5, paddingHorizontal: 5, borderRadius: 8, backgroundColor: t.mode === 'dark' ? '#2c2c31' : '#ffffff',
+ border: `1px solid ${t.separator}`, boxShadow: '0 10px 30px rgba(0,0,0,0.35)' }}>
+ {items.map((it, i) => (it === '-' ? <View key={`s${i}`} style={{ height: 1, marginVertical: 4, marginHorizontal: 6, backgroundColor: t.separator }} />
+ : <MenuRow key={it.label} it={it} onDone={() => setOpen(false)} />))}
+ </View>
+ </Overlay>
)}
</View>
);
diff --git a/sdk/index.js b/sdk/index.js
index ebb398d..f241705 100644
--- a/sdk/index.js
+++ b/sdk/index.js
@@ -78,6 +78,9 @@ export {
AppHost, useAppWindow, useKeyboard, focusToken, restoreFocus, pasteIntoFocused, FloatingWindows, useWindowState,
} from './components.jsx';
import { FloatingWindows } from './components.jsx';
+// One stacking order for the desktop: <Layer name>, <Overlay anchor> (docs/LAYERS.md)
+export { LAYERS, Layer, Overlay, shellLayers } from './layers.js';
+import { Layer, enableShellLayers } from './layers.js';
export {
ToolbarButton, ToolbarGroup, Toolbar, ToolbarSpacer, ToolbarDivider, Hairline, MenuButton, SearchField, EmptyState, GroupBox, FormRow, spacing, typeScale, controlSize, ConfirmDialog,
} from './controls.jsx';
@@ -152,6 +155,7 @@ export function startShell(element) {
const current = themes.current();
if (wanted && current && wanted !== current && lord.themes.use(wanted)) return;
refreshPackages(); // after the theme's configureWindows
+ enableShellLayers(); // menus, popovers and prompts go to their layer (sdk/layers.js)
render(createElement(LocaleRoot, null, element));
// live ISO: the installation assistant opens by itself, in front
if (isLiveSystemOf() && getAppOf('installer')) setTimeout(() => wmOf.open('installer'), 300);
@@ -167,5 +171,14 @@ export function startShell(element) {
function LocaleRoot({ children }) {
const { lang, region } = useStore(locale);
const rev = useStore(screenRev);
- return createElement(Fragment, { key: `${lang}|${region}` }, rev ? cloneElement(children, { screenRev: rev }) : children, createElement(ClipboardPanel), createElement(SpotlightPanel), createElement(ClipboardToast), createElement(RemoteBadge), createElement(ImeOverlay), createElement(FloatingWindows), createElement(PermissionPrompt), createElement(EmojiPanel), createElement(PrintDialog), createElement(Powerbox), createElement(NotificationBanner), createElement(KeyringPrompt), createElement(BluetoothPrompt), createElement(DisplayConfirm));
+ // the SDK's own surfaces, each in its layer (sdk/layers.js); the theme's tree is the base
+ const at = (name, ...kids) => createElement(Layer, { name }, ...kids.map((k, i) => createElement(k, { key: i })));
+ return createElement(Fragment, { key: `${lang}|${region}` }, rev ? cloneElement(children, { screenRev: rev }) : children,
+ at('floating', FloatingWindows),
+ at('overlay', SpotlightPanel),
+ at('popover', ClipboardPanel, EmojiPanel),
+ at('modal', PrintDialog),
+ at('notification', NotificationBanner, ClipboardToast, RemoteBadge),
+ at('system', PermissionPrompt, Powerbox, KeyringPrompt, BluetoothPrompt, DisplayConfirm),
+ at('input', ImeOverlay));
}
diff --git a/sdk/layers.js b/sdk/layers.js
new file mode 100644
index 0000000..c53a7df
--- /dev/null
+++ b/sdk/layers.js
@@ -0,0 +1,93 @@
+// layers.js — ONE stacking order for the whole desktop (docs/LAYERS.md).
+//
+// The engine's zIndex only orders siblings, so a menu drawn inside the menu bar can never rise
+// above a Dock drawn after it. Instead every shell surface goes into a named layer: a root node of
+// the screen's size (runtime/index.js `layerContainer`) that the content enters through a React
+// portal. Paint order and hit testing follow the same order (lord-server's hit test walks the
+// children in paint order, and a layer is `pointerEvents: 'box-none'`: it never takes a click
+// itself), so a click on a menu over the Dock goes to the menu.
+//
+// base (0) the theme's own tree: wallpaper, desktop widgets, windows (tree order)
+// dock the Dock / the Classic taskbar
+// menubar the top menu bar
+// floating fullscreen and picture-in-picture windows (above the Dock and the bar)
+// overlay full-screen shell overlays: the app launcher, search
+// popover menus, context menus, popovers, Control Center, select lists, panels
+// modal shell sheets and confirmations (Empty Trash), the print dialog
+// notification notification banners and toasts
+// tooltip tooltips
+// drag drag images and the «poof»
+// system system prompts: permissions, passwords and the keyring, Bluetooth pairing,
+// «keep this display?», the file chooser
+// input the input method's candidate window (it serves the field below it)
+//
+// Inside one layer, what opened last is on top. The lock screen and the login screen are another
+// session (lord-sessiond), above all of this.
+//
+// <Layer name="popover">…</Layer> a shell surface (themes, startShell)
+// <Overlay anchor={ref} onClose={…}>…</Overlay>
+// a list, popover or menu opened from a control: its children are positioned against the
+// anchor's box (`position: 'absolute', top: h + 4, left: 0` keeps meaning «below the
+// button»), drawn above the whole window and, in the desktop's process, above the Dock and
+// other windows. In an isolated app's process it goes to the window's own overlay host
+// (the app's surface is the window, so it is clipped to it). Clicking outside or Escape
+// calls onClose.
+import { createElement as h, Fragment, useContext, useEffect, useRef } from 'react';
+import { View, layerContainer, createPortal, addListener } from '@lordos/runtime';
+import { AppWindowContext } from './components.jsx';
+import { direction } from './i18n.js';
+
+export const LAYERS = Object.freeze({
+ dock: 10, menubar: 20, floating: 30, overlay: 40, popover: 50, modal: 60,
+ notification: 70, tooltip: 80, drag: 90, system: 100, input: 110,
+});
+
+let shell = false;
+// startShell turns the layers on (the desktop's process). Elsewhere (an isolated app's process)
+// <Layer> draws its children in place and <Overlay> uses the window's overlay host.
+export function enableShellLayers() { shell = true; }
+export const shellLayers = () => shell;
+
+export function Layer({ name, children }) {
+ const z = LAYERS[name];
+ if (z == null) throw new Error(`unknown layer: ${name}`);
+ const c = shell ? layerContainer(z) : null;
+ return c ? createPortal(children, c) : h(Fragment, null, children);
+}
+
+const insideOf = (inst, ref) => {
+ for (let n = inst; n; n = n.parent) if (n === ref) return true;
+ return false;
+};
+const boxOf = (inst) => { try { return inst ? lord.getLayout(inst.id) : null; } catch (e) { return null; } };
+
+export function Overlay({ anchor, children, onClose, layer = 'popover' }) {
+ const win = useContext(AppWindowContext);
+ const box = useRef(null);
+ const close = useRef(onClose);
+ close.current = onClose;
+ const a = anchor && typeof anchor === 'object' && 'current' in anchor ? anchor.current : anchor;
+ useEffect(() => {
+ if (!onClose) return undefined;
+ const offPtr = addListener('pointerdown', (e) => {
+ const an = anchor && typeof anchor === 'object' && 'current' in anchor ? anchor.current : anchor;
+ if (insideOf(e.target, box.current) || insideOf(e.target, an)) return;
+ // geometric too: the anchor may be a wrapper whose children are not its own hit target
+ const r = boxOf(an);
+ if (r && e.x >= r[0] && e.x < r[0] + r[2] && e.y >= r[1] && e.y < r[1] + r[3]) return;
+ close.current?.();
+ });
+ const offKey = addListener('keydown', (e) => { if (e.key === 'Escape') close.current?.(); });
+ return () => { offPtr(); offKey(); };
+ }, [!!onClose]);
+ const target = shell ? layerContainer(LAYERS[layer] || LAYERS.popover) : win?.overlayHost || null;
+ const r = boxOf(a);
+ // no layer: drawn in place, as before (a window's host exists from its first frame on)
+ if (!target || !r) return win?.id && !target ? null : h(Fragment, null, children);
+ const o = shell ? [0, 0] : boxOf(target) || [0, 0];
+ return createPortal(h(View, {
+ ref: box,
+ protected: !!win?.protected, // a protected window's list stays black in screenshots
+ style: { position: 'absolute', left: r[0] - o[0], top: r[1] - o[1], width: r[2], height: r[3], pointerEvents: 'box-none', direction: direction() },
+ }, children), target);
+}
diff --git a/sdk/vault.js b/sdk/vault.js
index 3ffee7b..504f0e3 100644
--- a/sdk/vault.js
+++ b/sdk/vault.js
@@ -11,12 +11,13 @@
// autofill(app, { url | service }) → [{ id, title, username }] from Passwords (if it is unlocked)
// <KeyringPrompt /> system prompt to unlock the keyring (mounted by startShell)
// <AutofillButton app service|url|ssid onFill /> "fill from Passwords" next to a login field
-import { createElement as h, useEffect, useState } from 'react';
+import { createElement as h, useEffect, useRef, useState } from 'react';
import { View, Text, mainBox } from '@lordos/runtime';
import { createStore, useStore } from './store.js';
import { useTheme } from './theme.js';
import { t } from './i18n.js';
import { TextInput, Button } from './components.jsx';
+import { Overlay } from './layers.js';
const has = () => typeof lord !== 'undefined' && typeof lord.vault !== 'undefined';
export const vaultAvailable = () => has() && lord.vault.available();
@@ -188,14 +189,16 @@ export function AutofillButton({ app, service, url, ssid, onFill }) {
if (it.kind === 'kr') { onFill({ username: it.username, password: it.secret }); return; }
try { onFill(await autofillReveal(it.id)); } catch (e) { /* locked */ }
};
+ const btn = useRef(null);
+ // the list goes in the overlay layer (sdk/layers.js), above the rest of the form
return h(View, null,
- h(View, { onClick: () => { setOpen(!open); if (!open) load(); }, style: { width: 30, height: 30, borderRadius: 7, alignItems: 'center', justifyContent: 'center',
+ h(View, { ref: btn, onClick: () => { setOpen(!open); if (!open) load(); }, style: { width: 30, height: 30, borderRadius: 7, alignItems: 'center', justifyContent: 'center',
backgroundColor: th.control } }, h(Text, { style: { fontSize: 14 } }, '🔑')),
- open ? h(View, { style: { position: 'absolute', top: 34, right: 0, width: 260, zIndex: 100, padding: 4, borderRadius: 9, backgroundColor: th.windowBg,
+ open ? h(Overlay, { anchor: btn, onClose: () => setOpen(false) }, h(View, { style: { position: 'absolute', top: 34, right: 0, width: 260, padding: 4, borderRadius: 9, backgroundColor: th.windowBg,
border: `1px solid ${th.separator}`, boxShadow: '0 10px 28px rgba(0,0,0,0.4)' } },
h(Text, { style: { fontSize: 11, fontWeight: 600, color: th.textDim, padding: 6 } }, t('passwords.autofill.title')),
items == null ? null : !items.length ? h(Text, { style: { fontSize: 12, color: th.textDim, padding: 6 } }, t('passwords.autofill.none'))
: items.map((it, i) => h(View, { key: i, onClick: () => pick(it), style: { padding: 6, borderRadius: 6 } },
h(Text, { style: { fontSize: 13, color: th.text } }, it.title),
- it.username ? h(Text, { style: { fontSize: 11, color: th.textDim } }, it.username) : null))) : null);
+ it.username ? h(Text, { style: { fontSize: 11, color: th.textDim } }, it.username) : null)))) : null);
}
diff --git a/server/src/ui/paint.c b/server/src/ui/paint.c
index 3b10512..8a8fc9c 100644
--- a/server/src/ui/paint.c
+++ b/server/src/ui/paint.c
@@ -779,7 +779,7 @@ void paint_capture(Canvas *c, Node *root) {
}
static Node *hit(Node *n, float x, float y) {
- if (n->type == NODE_RAW || n->s.display_none || n->s.pointer_none) return NULL;
+ if (n->type == NODE_RAW || n->s.display_none || n->s.pointer_none == POINTER_NONE) return NULL;
float lx = x, ly = y; /* through the transforms: the box as it is painted */
if (n->has_tf) affine_apply(n->tf->inv, x, y, &lx, &ly);
int inside = lx >= n->ax && ly >= n->ay && lx < n->ax + n->w && ly < n->ay + n->h;
@@ -792,7 +792,7 @@ static Node *hit(Node *n, float x, float y) {
if (h) return h;
}
}
- return inside ? n : NULL;
+ return inside && n->s.pointer_none != POINTER_BOX_NONE ? n : NULL;
}
Node *hit_test(Node *root, float x, float y) {
diff --git a/server/src/ui/style.c b/server/src/ui/style.c
index 9164d28..fb779fc 100644
--- a/server/src/ui/style.c
+++ b/server/src/ui/style.c
@@ -24,7 +24,8 @@ static const char *const E_JUSTIFY[] = {"flex-start", "center", "flex-end", "sp
"space-around", "space-evenly", NULL};
static const char *const E_ALIGN[] = {"auto", "stretch", "flex-start", "center", "flex-end", NULL};
static const char *const E_OVERFLOW[] = {"visible", "hidden", NULL};
-static const char *const E_POINTER[] = {"auto", "none", NULL};
+/* box-none: the node itself never takes the pointer, its children do (shell layers, overlay hosts) */
+static const char *const E_POINTER[] = {"auto", "none", "box-none", NULL};
static const char *const E_TALIGN[] = {"left", "center", "right", "start", "end", NULL};
static const char *const E_DIRECTION[] = {"inherit", "ltr", "rtl", NULL};
static const char *const E_FIT[] = {"fill", "cover", "contain", NULL};
diff --git a/server/src/ui/ui.h b/server/src/ui/ui.h
index 532862b..7004882 100644
--- a/server/src/ui/ui.h
+++ b/server/src/ui/ui.h
@@ -16,11 +16,12 @@ enum { ALIGN_AUTO, ALIGN_STRETCH, ALIGN_START, ALIGN_CENTER, ALIGN_END };
enum { TEXT_LEFT, TEXT_CENTER, TEXT_RIGHT, TEXT_START, TEXT_END }; /* start/end according to direction */
enum { EDGE_L, EDGE_T, EDGE_R, EDGE_B };
enum { DIR_INHERIT, DIR_LTR, DIR_RTL };
+enum { POINTER_AUTO, POINTER_NONE, POINTER_BOX_NONE }; /* pointerEvents; box-none: only the children are hit */
/* Subset of CSS the engine understands (the JS names are in style.c). */
typedef struct {
uint8_t display_none, absolute, row, justify, align_items, align_self;
- uint8_t overflow_hidden, pointer_none, text_align, object_fit, nowrap;
+ uint8_t overflow_hidden, pointer_none, text_align, object_fit, nowrap; /* pointer_none: POINTER_* */
uint8_t dir; /* DIR_INHERIT / DIR_LTR / DIR_RTL (CSS direction) */
uint8_t wrap; /* flexWrap: 'wrap' (children that don't fit move to another line) */
uint8_t mono; /* fontFamily: 0 'sans-serif' (Inter), 1 'monospace' (JetBrains Mono), 2 'brand' (Plus Jakarta Sans) */
diff --git a/server/tests/engine_test.c b/server/tests/engine_test.c
index c67bded..9c3fcf5 100644
--- a/server/tests/engine_test.c
+++ b/server/tests/engine_test.c
@@ -354,6 +354,54 @@ static void test_transform_math(void) {
free(st.ext);
}
+/* Shell layers (sdk/layers.js, docs/LAYERS.md): full-screen root children with zIndex and
+ * pointerEvents box-none. Paint and hit order follow the zIndex whatever the tree order, a layer
+ * never takes a click itself, and pointerEvents none still hides a whole subtree. */
+static Node *layer_node(Node *root, float z, float w, float h) {
+ Node *l = view(root);
+ ss(l, "position", "absolute");
+ sn(l, "left", 0); sn(l, "top", 0); sn(l, "width", w); sn(l, "height", h);
+ ss(l, "pointerEvents", "box-none");
+ sn(l, "zIndex", z);
+ return l;
+}
+static Node *box_in(Node *parent, float x, float y, float w, float h, uint32_t color) {
+ Node *b = view(parent);
+ ss(b, "position", "absolute");
+ sn(b, "left", x); sn(b, "top", y); sn(b, "width", w); sn(b, "height", h);
+ sn(b, "backgroundColor", color);
+ return b;
+}
+static void test_layers(void) {
+ ui_reset();
+ Node *root = view(NULL);
+ ui.root = root;
+ sn(root, "backgroundColor", 0xffffffff);
+ /* created in the "wrong" tree order on purpose: popover before dock, both before the windows */
+ Node *pop = layer_node(root, 50, 160, 100);
+ Node *dockl = layer_node(root, 10, 160, 100);
+ Node *base = view(root); /* the theme's tree (zIndex 0) */
+ sn(base, "width", 160); sn(base, "height", 100);
+ Node *win = box_in(base, 0, 0, 160, 100, 0xff0000ff); /* a window: blue */
+ Node *dock = box_in(dockl, 0, 10, 30, 80, 0xff00ff00); /* the Dock on the left: green */
+ Node *menu = box_in(pop, 10, 20, 60, 30, 0xffff0000); /* the crown menu: red */
+ Node *ghost = box_in(pop, 100, 60, 20, 20, 0xff000000); /* pointerEvents none: never hit */
+ ss(ghost, "pointerEvents", "none");
+ render(root, 160, 100);
+
+ CHECK(pix(20, 30) == 0xff0000, "menu painted over the Dock: %06x", pix(20, 30));
+ CHECK(pix(5, 70) == 0x00ff00, "Dock painted over the window: %06x", pix(5, 70));
+ CHECK(pix(100, 30) == 0x0000ff, "window painted under empty layers: %06x", pix(100, 30));
+ CHECK(hit_test(root, 20, 30) == menu, "a click on the menu over the Dock goes to the menu");
+ CHECK(hit_test(root, 5, 70) == dock, "a click on the Dock goes to the Dock");
+ CHECK(hit_test(root, 100, 30) == win, "an empty layer lets the click through to the window");
+ CHECK(hit_test(root, 110, 70) == win, "pointerEvents none: the click goes through");
+ /* the base can't climb above a layer, the order holds after a re-render */
+ sn(win, "zIndex", 5);
+ render(root, 160, 100);
+ CHECK(hit_test(root, 20, 30) == menu && pix(20, 30) == 0xff0000, "a zIndex inside the base stays under the layers");
+}
+
static void test_transform_paint_hit(void) {
ui_reset();
Node *root = view(NULL);
@@ -625,6 +673,7 @@ int main(int argc, char **argv) {
test_logical();
test_transform_math();
test_transform_paint_hit();
+ test_layers();
printf("engine-test: %d checks, %d failures\n", checks, fails);
return fails ? 1 : 0;
#endif
diff --git a/themes/README.md b/themes/README.md
index fe201c3..45bbaf9 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -45,6 +45,11 @@ respected on the next start.
and drop-down menus open to the left if `direction() === 'rtl'` (see the default theme and
`docs/LANGUAGES.md`). The input method's candidate window is placed by `startShell`: the
theme doesn't need to do anything.
+ - everything above the windows in its layer (`<Layer name="dock|menubar|overlay|popover|modal|tooltip|drag">`
+ from the SDK): menus, the Control Center, the app launcher, tooltips and drag images. The
+ order is the layers', not the tree's, and clicks follow it, so a menu is never under the Dock
+ (see `docs/LAYERS.md`). `startShell` places the SDK's own surfaces (search, notifications,
+ prompts, fullscreen windows).
- Linux app windows (Wayland) arrive as windows of the internal app `linux`: if
`win.args.csd` is true the app draws its own frame and the theme shows only `<AppHost>`;
and `configureWindows({ chrome: { w, h } })` says how much the theme's frame adds (borders +
@@ -103,7 +108,8 @@ A theme draws `<DesktopWidgets layer="below" />` between the wallpaper and the w
move to another line; `gap` also separates the lines, which go at the start: no
`wrap-reverse` or `alignContent`), `justifyContent`, `alignItems`, `alignSelf`, `flex`,
`flexGrow`, `flexShrink`, `flexBasis`, `gap`, `width`/`height` (px, `%`, `auto`),
- `min*`/`max*`, `left`/`top`/`right`/`bottom`, `inset`, `margin*`, `padding*`, `overflow`, `zIndex`.
+ `min*`/`max*`, `left`/`top`/`right`/`bottom`, `inset`, `margin*`, `padding*`, `overflow`, `zIndex`
+ (it only orders siblings: what goes above the windows uses the layers, see below).
`flex` follows React Native: `flex: N > 0` grows and shrinks from a zero basis, `flex: 0` keeps its
`width`/`height` and doesn't flex, `flex: -N` only shrinks.
- **Logical edges** (they follow the node's `direction`, and win over the physical side as in React
@@ -112,7 +118,8 @@ A theme draws `<DesktopWidgets layer="below" />` between the wallpaper and the w
`insetInlineStart`/`insetInlineEnd` (`start`/`end`, `insetInline`).
- **Visual:** `backgroundColor`, `background: linear-gradient(...)`, `borderRadius`, `border`,
`borderWidth`, `borderColor`, `opacity`, `boxShadow`, `backdropFilter: blur(px)`,
- `pointerEvents`, `cursor` (`default`, `pointer`,
+ `pointerEvents` (`auto`, `none`: the node and its children are never hit, `box-none`: only its
+ children are), `cursor` (`default`, `pointer`,
`text`, `move`, `grab`, `grabbing`, `not-allowed`, `wait`, `progress`, `crosshair`, `n-resize`… `ew-resize`,
`ns-resize`, `nesw-resize`, `nwse-resize`; the one of the first node upwards that has it applies).
- **Per-side borders:** `borderTop`/`borderRight`/`borderBottom`/`borderLeft` (`'1px solid #ccc'`), their
diff --git a/themes/classic/index.jsx b/themes/classic/index.jsx
index 46db4d0..50975d7 100644
--- a/themes/classic/index.jsx
+++ b/themes/classic/index.jsx
@@ -10,7 +10,7 @@ import {
ScrollView, useLauncherApps, launchApp, windowIcon, APP_CATEGORIES, appCategory, useDockEntries, dockActivate, dockMenu,
DesktopWidgets, PrivacyIndicators, registerGestureActions, WindowShell, StatusItems, dockPrefs, mainDisplay,
useStore, dock, dockIdOf, dockDrag, dockPoof, beginDockDrag, registerDockTarget, dockDragJustEnded, useTrash, openTrash, emptyTrash, trashMenu,
- refreshTrash, ConfirmDialog, takeTextFocus, releaseTextFocus,
+ refreshTrash, ConfirmDialog, takeTextFocus, releaseTextFocus, Layer,
} from '@lordos/sdk';
import { apps } from '@lordos/apps';
import { useEffect, useRef, useState } from 'react';
@@ -53,6 +53,21 @@ function nextToBar(pos, along) {
if (pos === 'right') return { right: b, top: along };
return { left: along, bottom: b };
}
+// The bar's box in screen coordinates (main display), so a menu drawn in another layer can still
+// be placed against the bar with nextToBar.
+function barBox(pos, m = mainDisplay()) {
+ const b = barSize(pos);
+ if (pos === 'left' || pos === 'right') return { left: m.x + (pos === 'right' ? m.w - b : 0), top: m.y, width: b, height: m.h };
+ return { left: m.x, top: m.y + (pos === 'top' ? 0 : m.h - b), width: m.w, height: b };
+}
+// A menu next to the bar: in the popover layer (sdk/layers.js), above the bar and the windows.
+function NextToBar({ pos, children }) {
+ return (
+ <Layer name="popover">
+ <View style={{ position: 'absolute', ...barBox(pos), pointerEvents: 'box-none' }}>{children}</View>
+ </Layer>
+ );
+}
// Is the point over the bar? (a click there doesn't close the menu: the start button toggles it)
function onBar(pos, x, y) {
const b = barSize(pos), m = mainDisplay();
@@ -324,9 +339,9 @@ function Taskbar({ t, onStart, pos, onEmptyTrash }) {
<PrivacyIndicators />
<Text style={{ fontSize: vert ? 12 : 13, fontWeight: 600, color: t.text, marginRight: vert ? 0 : 10, marginBottom: vert ? 6 : 0 }}>{clock}</Text>
{dropLine && <View style={{ position: 'absolute', ...dropLine, backgroundColor: t.accent, pointerEvents: 'none' }} />}
- {jump && <JumpList t={t} pos={pos} entry={entries.find((x) => x.id === jump.entry.id) || jump.entry} x={jump.x} onClose={() => setJump(null)} />}
- {trashMenuAt != null && <PopupMenu t={t} pos={pos} x={trashMenuAt} onClose={() => setTrashMenuAt(null)}
- items={trashMenu({ onEmpty: onEmptyTrash }).filter((it) => it !== '-')} />}
+ {jump && <NextToBar pos={pos}><JumpList t={t} pos={pos} entry={entries.find((x) => x.id === jump.entry.id) || jump.entry} x={jump.x} onClose={() => setJump(null)} /></NextToBar>}
+ {trashMenuAt != null && <NextToBar pos={pos}><PopupMenu t={t} pos={pos} x={trashMenuAt} onClose={() => setTrashMenuAt(null)}
+ items={trashMenu({ onEmpty: onEmptyTrash }).filter((it) => it !== '-')} /></NextToBar>}
</View>
);
}
@@ -407,17 +422,30 @@ function App() {
<DesktopWidgets layer="below" />
{visible.map((w) => <Window key={w.id} win={w} t={t} focused={w.id === focused} />)}
<DesktopWidgets layer="above" />
- {/* the bar and the start menu on the main display */}
- <View style={{ position: 'absolute', left: m.x, top: m.y, width: m.w, height: m.h }}>
- <Taskbar t={t} pos={pos} onStart={() => setStart((v) => !v)} onEmptyTrash={() => setAskEmpty(true)} />
- {start && <StartMenu t={t} pos={pos} onClose={() => setStart(false)} />}
- </View>
- <DragGhost t={t} />
- <PoofFade />
+ {/* the bar on the main display, and above it the start menu: each in its layer
+ (sdk/layers.js, docs/LAYERS.md), so the order and the clicks are the layers' */}
+ <Layer name="dock">
+ <View style={{ position: 'absolute', left: m.x, top: m.y, width: m.w, height: m.h, pointerEvents: 'box-none' }}>
+ <Taskbar t={t} pos={pos} onStart={() => setStart((v) => !v)} onEmptyTrash={() => setAskEmpty(true)} />
+ </View>
+ </Layer>
+ {start && (
+ <Layer name="popover">
+ <View style={{ position: 'absolute', left: m.x, top: m.y, width: m.w, height: m.h, pointerEvents: 'box-none' }}>
+ <StartMenu t={t} pos={pos} onClose={() => setStart(false)} />
+ </View>
+ </Layer>
+ )}
+ <Layer name="drag">
+ <DragGhost t={t} />
+ <PoofFade />
+ </Layer>
{askEmpty && (
- <ConfirmDialog title={tr('shell.trash.confirmTitle')} detail={tr('shell.trash.confirmDetail')} okLabel={tr('shell.trash.empty')}
- cancelLabel={tr('shell.trash.cancel')} destructive area={m}
- onCancel={() => setAskEmpty(false)} onOk={() => { setAskEmpty(false); emptyTrash(); }} />
+ <Layer name="modal">
+ <ConfirmDialog title={tr('shell.trash.confirmTitle')} detail={tr('shell.trash.confirmDetail')} okLabel={tr('shell.trash.empty')}
+ cancelLabel={tr('shell.trash.cancel')} destructive area={m}
+ onCancel={() => setAskEmpty(false)} onOk={() => { setAskEmpty(false); emptyTrash(); }} />
+ </Layer>
)}
</View>
</ThemeProvider>
diff --git a/themes/default/components/Dock.jsx b/themes/default/components/Dock.jsx
index aa46690..6b2ed20 100644
--- a/themes/default/components/Dock.jsx
+++ b/themes/default/components/Dock.jsx
@@ -9,7 +9,7 @@
// this file only draws it and says where things are. The Trash is always the last item.
import {
View, Text, screen, appName, useLocale, addListener, t as tr, useStore, settings, dockDrag, dockPoof, beginDockDrag,
- registerDockTarget, dockDragJustEnded, refreshTrash,
+ registerDockTarget, dockDragJustEnded, refreshTrash, Layer,
} from '@lordos/sdk';
import { useEffect, useRef, useState } from 'react';
@@ -324,7 +324,7 @@ export function Dock({ t, items: list, running, onOpen, onContext, onTrash, onTr
return () => { a(); b(); };
}, []);
- if (autohide && shown <= 0 && !dragging) return <Poof poof={poof} size={BASE} reduce={reduce} />;
+ if (autohide && shown <= 0 && !dragging) return <Layer name="drag"><Poof poof={poof} size={BASE} reduce={reduce} /></Layer>;
// The hit box covers only the bar until the pointer is on it; then it grows to fit the magnified
// icons and the tooltip. A full-height box at rest would swallow clicks on windows just above the Dock.
@@ -342,6 +342,7 @@ export function Dock({ t, items: list, running, onOpen, onContext, onTrash, onTr
const anchor = (i) => (position === 'bottom' ? { x: start + iconC[i], y: AB - MARGIN - bar - 6 }
: position === 'left' ? { x: AX + MARGIN + bar + 8, y: start + iconC[i] } : { x: AR - MARGIN - bar - 8, y: start + iconC[i] });
const hit = hovered >= 0 ? items[hovered] : null;
+ const showTip = hovered >= 0 && !keepOpen;
const label = !hit ? '' : hit.trash ? tr('shell.trash.name') : hit.launcher ? tr('shell.menu.apps') : appName(hit);
const tip = (
<View style={{ paddingHorizontal: 10, paddingVertical: 4, borderRadius: 7, backgroundColor: t.panelBg,
@@ -410,17 +411,22 @@ export function Dock({ t, items: list, running, onOpen, onContext, onTrash, onTr
)}
</View>
)))}
- {hovered >= 0 && position === 'bottom' && (
- <View style={{ position: 'absolute', left: iconC[hovered] - 90, width: 180, bottom: sizes[hovered] + PAD + 12,
- alignItems: 'center', pointerEvents: 'none' }}>{tip}</View>
- )}
</View>
- {hovered >= 0 && vert && (
- <View style={{ position: 'absolute', top: start + iconC[hovered] - 13, pointerEvents: 'none', direction: 'ltr',
- ...(position === 'left' ? { left: AX + MARGIN - hide + PAD + sizes[hovered] + 14 } : { right: screen.width - AR + MARGIN - hide + PAD + sizes[hovered] + 14 }) }}>{tip}</View>
- )}
- {ghost}
- <Poof poof={poof} size={BASE} reduce={reduce} />
+ {/* the name tooltip (not while the icon's menu is open: the menu takes that place) */}
+ <Layer name="tooltip">
+ {showTip && position === 'bottom' && (
+ <View style={{ position: 'absolute', left: start + iconC[hovered] - 90, width: 180, bottom: screen.height - (AB - MARGIN + hide) + sizes[hovered] + PAD + 12,
+ alignItems: 'center', pointerEvents: 'none', direction: 'ltr' }}>{tip}</View>
+ )}
+ {showTip && vert && (
+ <View style={{ position: 'absolute', top: start + iconC[hovered] - 13, pointerEvents: 'none', direction: 'ltr',
+ ...(position === 'left' ? { left: AX + MARGIN - hide + PAD + sizes[hovered] + 14 } : { right: screen.width - AR + MARGIN - hide + PAD + sizes[hovered] + 14 }) }}>{tip}</View>
+ )}
+ </Layer>
+ <Layer name="drag">
+ {ghost}
+ <Poof poof={poof} size={BASE} reduce={reduce} />
+ </Layer>
</>
);
}
diff --git a/themes/default/components/Launchpad.jsx b/themes/default/components/Launchpad.jsx
index 77cb571..ed16c12 100644
--- a/themes/default/components/Launchpad.jsx
+++ b/themes/default/components/Launchpad.jsx
@@ -64,7 +64,7 @@ export function Launchpad({ t, apps, onOpen, onClose, area = { x: 0, y: 0, w: sc
</View>
</ScrollView>
{ctx && (
- <Menu x={ctx.x - area.x} y={ctx.y - area.y} onClose={() => setCtx(null)} items={[
+ <Menu x={ctx.x} y={ctx.y} onClose={() => setCtx(null)} items={[
{ label: tr('shell.dock.open'), onClick: () => open(ctx.app.id) },
...(dockIdOf(ctx.app) ? [{ label: tr('shell.dock.keep'), checked: dock.isPinned(ctx.app), disabled: dock.isPinned(ctx.app) && !dock.canRemove(ctx.app),
onClick: () => (dock.isPinned(ctx.app) ? dock.unpin(ctx.app) : dock.pin(ctx.app)) }] : []),
diff --git a/themes/default/components/Menu.jsx b/themes/default/components/Menu.jsx
index b7a9b24..9f0c2bf 100644
--- a/themes/default/components/Menu.jsx
+++ b/themes/default/components/Menu.jsx
@@ -1,7 +1,7 @@
// Drop-down / context menu. Closes when clicking outside or with Escape. Keyboard: ↑/↓ move,
// Home/End jump, Enter/Space choose, → opens a submenu and ← closes it. A menu taller than the
// screen scrolls (wheel or touchpad), and the keyboard keeps the highlighted item in view.
-import { View, Text, addListener, useTheme, screen, direction, ScrollView, takeTextFocus, releaseTextFocus, focusToken, restoreFocus } from '@lordos/sdk';
+import { View, Text, addListener, useTheme, screen, direction, ScrollView, takeTextFocus, releaseTextFocus, focusToken, restoreFocus, Layer } from '@lordos/sdk';
import { useEffect, useRef, useState } from 'react';
const ROW = 24, SEP_H = 9, HEAD_H = 22;
@@ -52,6 +52,8 @@ function fitWidth(items, min) {
// side: 'left' opens the menu to the left of x and 'right' to the right, regardless of the language
// (the side Dock; screen sides are physical). centered: y is the center of the menu.
// keys: this menu has the keyboard (a submenu takes it while it is open; onBack gives it back).
+// Every menu is drawn in the shell's popover layer (sdk/layers.js), above the Dock, the menu bar and
+// the windows wherever it is rendered from; its submenus go in the same layer, beside it.
export function Menu({ x, y, items, onClose, anchor, width: minWidth = 220, above = false, sub = false, nodeRef, side = null, centered = false, onBack }) {
const t = useTheme();
const own = useRef(null);
@@ -127,7 +129,7 @@ export function Menu({ x, y, items, onClose, anchor, width: minWidth = 220, abov
<Item key={i} item={it} onClose={onClose} active={i === active}
onHover={() => setActive(selectable(it) ? i : -1)} onSub={(s) => setSubMenu(s ? { ...s, keys: false } : null)} />
));
- return (
+ const body = (
<>
<View ref={ref} style={{
position: 'absolute', left: x, top: y, width, height: scrolls ? height : undefined, paddingVertical: scrolls ? 0 : 5, borderRadius: 9,
@@ -142,4 +144,5 @@ export function Menu({ x, y, items, onClose, anchor, width: minWidth = 220, abov
onBack={subMenu.keys ? () => setSubMenu(null) : undefined} />}
</>
);
+ return sub ? body : <Layer name="popover">{body}</Layer>;
}
diff --git a/themes/default/index.jsx b/themes/default/index.jsx
index 10e28c0..e87911b 100644
--- a/themes/default/index.jsx
+++ b/themes/default/index.jsx
@@ -5,7 +5,7 @@ import {
startShell, View, Text, Image, screen, ThemeProvider, useSettings, useWindows, configureWindows, getApp, wm, addListener, t as tr,
useLauncherApps, launchApp, useDockEntries, dockActivate, dockMenu, dockPrefs, DOCK_LAUNCHER,
useTrash, openTrash, emptyTrash, trashMenu, ConfirmDialog,
- DesktopWidgets, registerGestureActions, screenDisplays, mainDisplay, settings,
+ DesktopWidgets, registerGestureActions, screenDisplays, mainDisplay, settings, Layer,
} from '@lordos/sdk';
import { apps } from '@lordos/apps';
import { useEffect, useRef, useState } from 'react';
@@ -140,24 +140,33 @@ function App() {
{minimizing.map(({ win, p }) => <Window key={win.id} win={win} app={getApp(win.id)} t={t} focused={false}
fx={{ p, x: main.x + main.w / 2, y: main.y + main.h - 36 }} />)}
<DesktopWidgets layer="above" />
- {bars.map((d) => (
- <MenuBar key={d.id + ':' + d.x} t={t} height={MENU_H} focused={focused} controlCenter={!!control} area={d}
- onLaunchpad={() => setLaunchpad(true)} onControlCenter={() => setControl((v) => (v ? null : d))} />
- ))}
+ {/* Everything above the windows goes in its layer (sdk/layers.js, docs/LAYERS.md): the
+ order is the layers', not this tree's, and clicks follow it. Menus go to «popover»
+ by themselves (Menu.jsx). */}
+ <Layer name="menubar">
+ {bars.map((d) => (
+ <MenuBar key={d.id + ':' + d.x} t={t} height={MENU_H} focused={focused} controlCenter={!!control} area={d}
+ onLaunchpad={() => setLaunchpad(true)} onControlCenter={() => setControl((v) => (v ? null : d))} />
+ ))}
+ </Layer>
+ <Layer name="dock">
<Dock t={t} items={entries} running={entries.filter((e) => e.running).map((e) => e.id)}
onOpen={(id) => byId.has(id) && dockActivate(byId.get(id))}
onContext={(id, at) => byId.has(id) && setDockCtx({ entry: byId.get(id), at })}
onTrash={openTrash} onTrashContext={(at) => setTrashCtx(at)} trashFull={trash.full}
position={dp.dockPosition} size={dp.dockSize} magnify={dp.dockMagnify} maxSize={dp.dockMagnifySize}
autohide={dp.dockAutohide} top={MENU_H} keepOpen={!!dockCtx || !!trashCtx} area={main} />
+ </Layer>
{dockCtx && <DockMenu pos={dp.dockPosition} at={dockCtx.at} onClose={() => setDockCtx(null)} items={dockMenu(byId.get(dockCtx.entry.id) || dockCtx.entry)} />}
{trashCtx && <DockMenu pos={dp.dockPosition} at={trashCtx} onClose={() => setTrashCtx(null)} items={trashMenu({ onEmpty: () => setAskEmpty(true) })} />}
{askEmpty && (
- <ConfirmDialog title={tr('shell.trash.confirmTitle')} detail={tr('shell.trash.confirmDetail')} okLabel={tr('shell.trash.empty')}
- cancelLabel={tr('shell.trash.cancel')} destructive area={main}
- onCancel={() => setAskEmpty(false)} onOk={() => { setAskEmpty(false); emptyTrash(); }} />
+ <Layer name="modal">
+ <ConfirmDialog title={tr('shell.trash.confirmTitle')} detail={tr('shell.trash.confirmDetail')} okLabel={tr('shell.trash.empty')}
+ cancelLabel={tr('shell.trash.cancel')} destructive area={main}
+ onCancel={() => setAskEmpty(false)} onOk={() => { setAskEmpty(false); emptyTrash(); }} />
+ </Layer>
)}
- {control && <ControlCenter t={t} top={MENU_H} area={control} onClose={() => setControl(null)} />}
+ {control && <Layer name="popover"><ControlCenter t={t} top={MENU_H} area={control} onClose={() => setControl(null)} /></Layer>}
{context && (
<Menu x={context.x} y={context.y} onClose={() => setContext(null)} items={[
{ label: tr('shell.desktop.wallpaper'), onClick: () => setControl(main) },
@@ -167,7 +176,7 @@ function App() {
{ label: tr('shell.menu.about'), onClick: () => wm.open('about') },
]} />
)}
- {launchpad && <Launchpad t={t} apps={launcherApps} onOpen={launchApp} onClose={() => setLaunchpad(false)} area={main} />}
+ {launchpad && <Layer name="overlay"><Launchpad t={t} apps={launcherApps} onOpen={launchApp} onClose={() => setLaunchpad(false)} area={main} /></Layer>}
</View>
</ThemeProvider>
);