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.

Customizable Dock: drag to add, reorder and remove, quick actions and the Trash

Federico Pereirae0d7d724f900
diff --git a/apps/files/index.jsx b/apps/files/index.jsx
index 96fab54..b845145 100644
--- a/apps/files/index.jsx
+++ b/apps/files/index.jsx
@@ -4,7 +4,7 @@
// Disk operations go through lord.fs (server/src/fsops.c); see docs/FILES.md.
import {
View, Text, useTheme, useAppWindow, useKeyboard, useStore, useLauncherApps, addListener, wm, fs, clipboard, archive, warmDocs,
- formatBytes, t as tr, ScrollView, Toolbar, ToolbarButton, ToolbarGroup, SearchField, Hairline, direction, spacing, typeScale,
+ formatBytes, t as tr, ScrollView, Toolbar, ToolbarButton, ToolbarGroup, SearchField, Hairline, direction, spacing, typeScale, registerDockActions,
} from '@lordos/sdk';
import { useEffect, useMemo, useRef, useState } from 'react';
import { FolderGlyph, DocGlyph, TAG_COLORS, TrashGlyph, DriveGlyph } from './glyphs.jsx';
@@ -39,6 +39,7 @@ const winStates = new Map();
const homeLoc = () => ({ type: 'dir', path: fs.home() });
function argLoc(args) {
+ if (args?.place === 'trash') return { type: 'trash' };
if (!args?.path) return null;
const home = fs.home();
const p = String(args.path).replace(/^~(?=\/|$)/, home);
@@ -47,6 +48,17 @@ function argLoc(args) {
if (archive.isArchive(fs.basename(path))) { try { if (!fs.stat(path).dir) return { type: 'archive', path, inner: '' }; } catch (e) { /* not there */ } }
return { type: 'dir', path };
}
+// The Dock's quick actions: Home, Downloads, Documents and the Trash (sdk/dock.js).
+registerDockActions('files', () => {
+ const dirs = userDirs();
+ const dir = (label) => dirs.find((d) => d.label === label);
+ return [
+ { id: 'home', label: 'files.place.home', args: { path: '~' } },
+ ...['downloads', 'documents'].filter(dir).map((k) => ({ id: k, label: `files.place.${k}`, args: { path: dir(k).path } })),
+ { id: 'trash', label: 'files.place.trash', args: { place: 'trash' } },
+ ];
+});
+
// args.view ('icons' | 'list' | 'columns' | 'gallery') picks the view of the opened folder
const argView = (args) => (VIEWS.includes(args?.view) ? args.view : null);
diff --git a/apps/mail/index.jsx b/apps/mail/index.jsx
index 780f41b..6733588 100644
--- a/apps/mail/index.jsx
+++ b/apps/mail/index.jsx
@@ -5,7 +5,7 @@
import {
View, Text, useTheme, useStore, useAppWindow, useKeyboard, Button, TextInput, ScrollView, t, wm, fs, monthName, formatDate, formatTime,
Toolbar, ToolbarButton, ToolbarSpacer, ToolbarDivider, SearchField, Hairline, direction, textDirection,
- mailRequest, onMailEvent, mailStatus, mailConfig, mailAccounts, mailAvailable, addListener, clipboard,
+ mailRequest, onMailEvent, mailStatus, mailConfig, mailAccounts, mailAvailable, addListener, clipboard, registerDockActions,
} from '@lordos/sdk';
import { useEffect, useRef, useState } from 'react';
import { HtmlView, TextView } from './HtmlView.jsx';
@@ -413,10 +413,13 @@ function MessageView({ msg, width, onLink, cfg, onTrustSender, collapsed, onExpa
export default function Mail() {
const { args } = useAppWindow();
- if (args?.compose) return <Compose draft={args.compose} />;
+ if (args?.compose) return <Compose draft={typeof args.compose === 'object' ? args.compose : {}} />;
return <MailMain />;
}
+// The Dock's quick action: New Message (a compose window; sdk/dock.js).
+registerDockActions('mail', () => [{ id: 'compose', label: 'mail.compose.newMessage', args: { compose: true }, new: true }]);
+
function compose(draft) { wm.open('mail', { new: true, args: { compose: draft || {} } }); }
function replyDraft(msg, mode) {
diff --git a/apps/monitor/index.jsx b/apps/monitor/index.jsx
index 8c91763..31872c7 100644
--- a/apps/monitor/index.jsx
+++ b/apps/monitor/index.jsx
@@ -7,6 +7,7 @@ import {
View, Text, Image, ScrollView, Segmented, SearchField, Toolbar, typeScale, useTheme, useLocale, useStore, useSettings, useAppWindow,
useMonitor, monitor, monitorProcesses, monitorSamples, formatBytes, formatNumber, LordOSLogo, iconFromFile,
} from '@lordos/sdk';
+import { registerDockActions } from '@lordos/sdk';
import * as sdk from '@lordos/sdk';
import { useEffect, useMemo, useState } from 'react';
import { Chart } from './Chart.jsx';
@@ -111,6 +112,12 @@ export function Stat({ label, value, unit, icon, children }) {
}
// Series derived from the sample history
+// The Dock's quick actions: the network map and Cooling (sdk/dock.js).
+registerDockActions('monitor', () => [
+ { id: 'network', label: 'monitor.network', args: { tab: 'network' } },
+ { id: 'cooling', label: 'monitor.tab.cooling', args: { tab: 'cooling' } },
+]);
+
function useSeries(samples) {
return useMemo(() => {
const pick = (f) => samples.map(f);
diff --git a/apps/settings/Dock.jsx b/apps/settings/Dock.jsx
index fb6b31c..e37e4f1 100644
--- a/apps/settings/Dock.jsx
+++ b/apps/settings/Dock.jsx
@@ -1,8 +1,10 @@
// Settings → Desktop & Dock: Dock position (bottom, left, right), size, magnification, auto-hide
// and recent apps; in the Classic theme, the taskbar position. Saved in
// settings.json (sdk/dock.js: DOCK_DEFAULTS) and the theme applies it live, including the work area.
-import { View, Text, useTheme, useLocale, useSettings, Toggle, Slider, dockPrefs, themes, spacing, typeScale } from '@lordos/sdk';
-import { Stack, Section, SettingRow } from './ui.jsx';
+// «Reset Dock to defaults» puts the theme's apps back (dock.reset), after a confirmation in the page.
+import { View, Text, Button, useTheme, useLocale, useSettings, Toggle, Slider, dockPrefs, dock, themes, spacing, typeScale } from '@lordos/sdk';
+import { useState } from 'react';
+import { Stack, Section, SettingRow, Actions } from './ui.jsx';
// A small picture of the screen with the Dock (or the taskbar) on the chosen side.
function Preview({ side, t }) {
@@ -50,6 +52,32 @@ function SizeSlider({ value, min, max, onChange }) {
);
}
+// The pinned apps back to the theme's: the button asks first, in place (never alert()).
+function ResetDock({ classic }) {
+ const t = useTheme();
+ const { t: tr } = useLocale();
+ const [ask, setAsk] = useState(false);
+ const [done, setDone] = useState(false);
+ return (
+ <Section footer={tr(classic ? 'settings.dock.resetHintTaskbar' : 'settings.dock.resetHint')}>
+ {ask ? (
+ <View style={{ gap: spacing.s, paddingVertical: spacing.s }}>
+ <Text style={{ fontSize: typeScale.body, fontWeight: 600, color: t.text, textAlign: 'start' }}>{tr('settings.dock.resetAsk')}</Text>
+ <Text style={{ fontSize: typeScale.callout, color: t.textDim, textAlign: 'start' }}>{tr('settings.dock.resetDetail')}</Text>
+ <Actions>
+ <Button label={tr('settings.dock.resetCancel')} onClick={() => setAsk(false)} />
+ <Button primary label={tr('settings.dock.resetConfirm')} onClick={() => { dock.reset(); setAsk(false); setDone(true); }} />
+ </Actions>
+ </View>
+ ) : (
+ <SettingRow label={tr(classic ? 'settings.dock.resetTaskbar' : 'settings.dock.reset')} hint={done ? tr('settings.dock.resetDone') : undefined}>
+ <Button label={tr('settings.dock.resetButton')} onClick={() => { setDone(false); setAsk(true); }} />
+ </SettingRow>
+ )}
+ </Section>
+ );
+}
+
export function DockSettings() {
const { t: tr } = useLocale();
const [s, set] = useSettings();
@@ -61,6 +89,7 @@ export function DockSettings() {
<Section title={tr('settings.dock.taskbar')} footer={`${tr('settings.dock.taskbarHint')} ${tr('settings.dock.sidesHint')}`}>
<SidePicker value={p.taskbarPosition} sides={['bottom', 'top', 'left', 'right']} onChange={(v) => set({ taskbarPosition: v })} />
</Section>
+ <ResetDock classic />
</Stack>
);
}
@@ -90,6 +119,7 @@ export function DockSettings() {
<Toggle small on={p.dockRecents} onChange={(dockRecents) => set({ dockRecents })} />
</SettingRow>
</Section>
+ <ResetDock />
</Stack>
);
}
diff --git a/apps/settings/index.jsx b/apps/settings/index.jsx
index 764d812..a3a25c7 100644
--- a/apps/settings/index.jsx
+++ b/apps/settings/index.jsx
@@ -5,7 +5,7 @@
import {
View, Text, Image, useTheme, useSettings, themes, session, keyboard, admin, languages, setLanguage, useLocale,
reloadCatalogs, tOptional, statusText, fs, useStore, SidebarItem, Toggle, Button, TextInput, ScrollView, SearchField, Hairline, useSystemInfo, useAppWindow, useTrackpads,
- spacing, typeScale,
+ spacing, typeScale, registerDockActions, hasTouchpad,
} from '@lordos/sdk';
import { useEffect, useState } from 'react';
import { SoundSettings } from './Sound.jsx';
@@ -444,6 +444,13 @@ const GROUPS = [
[['power', PowerSettings, '#30d158', BoltGlyph], ['cooling', CoolingSettings, '#32ade6', FanGlyph], ['privacy', PrivacySettings, '#0a84ff', LockGlyph], ['users', UsersSettings, '#0a84ff', '☺'], ['updates', Updates, '#8e8e93', '↻'], ['themes', Themes, '#ff9f0a', '◧'], ['session', Session, '#ff453a', '↪']],
];
const SECTIONS = GROUPS.flat();
+// Trackpad only if there is a touchpad (lord-sessiond lends them with the monitor)
+const sectionShown = (id, hasPad) => id !== 'trackpad' || hasPad;
+
+// The Dock's right-click menu lists every section, in the sidebar's order and with its names; one
+// opens Settings on that page (sdk/dock.js, quick actions). Built from SECTIONS, so it never drifts.
+registerDockActions('settings', () => SECTIONS.filter(([id]) => sectionShown(id, hasTouchpad()))
+ .map(([id]) => ({ id, label: `settings.section.${id}`, args: { section: id } })));
function SectionIcon({ color, glyph: G, size = 20 }) {
return typeof G === 'string'
@@ -491,7 +498,7 @@ export default function Settings() {
const q = query.trim().toLowerCase();
// Trackpad only if there is a touchpad (lord-sessiond lends them with the monitor)
const hasPad = useTrackpads().some((d) => d.kind === 'touchpad');
- const visible = (id) => (id !== 'trackpad' || hasPad) && `${tr(`settings.section.${id}`)} ${tr(`settings.keywords.${id}`)}`.toLowerCase().includes(q);
+ const visible = (id) => sectionShown(id, hasPad) && `${tr(`settings.section.${id}`)} ${tr(`settings.keywords.${id}`)}`.toLowerCase().includes(q);
const groups = GROUPS.map((g) => g.filter(([id]) => visible(id))).filter((g) => g.length);
return (
<View style={{ flex: 1, flexDirection: 'row' }}>
diff --git a/assets/locales/en/settings.json b/assets/locales/en/settings.json
index 7e40082..1826446 100644
--- a/assets/locales/en/settings.json
+++ b/assets/locales/en/settings.json
@@ -226,6 +226,16 @@
"dock.taskbar": "Taskbar position",
"dock.taskbarHint": "Classic theme. Maximized windows don't go under the taskbar.",
"dock.sidesHint": "Left and right are sides of the screen: they don't swap in a right-to-left language.",
+ "dock.reset": "Reset Dock to defaults",
+ "dock.resetTaskbar": "Reset taskbar to defaults",
+ "dock.resetButton": "Reset…",
+ "dock.resetHint": "Puts the theme’s apps back in their original order. Files stays first and the Trash last; Files, Settings and Apps can’t be removed.",
+ "dock.resetHintTaskbar": "Puts the theme’s apps back on the taskbar in their original order. Files stays first and the Trash last; Files and Settings can’t be unpinned.",
+ "dock.resetAsk": "Reset the Dock to its defaults?",
+ "dock.resetDetail": "The apps you added and the order you chose will be replaced by the theme’s. Open apps stay open.",
+ "dock.resetCancel": "Cancel",
+ "dock.resetConfirm": "Reset",
+ "dock.resetDone": "The defaults are back.",
"section.displays": "Displays",
"section.bluetooth": "Bluetooth",
"section.power": "Energy",
diff --git a/assets/locales/en/shell.json b/assets/locales/en/shell.json
index 3f0c6b3..c17421f 100644
--- a/assets/locales/en/shell.json
+++ b/assets/locales/en/shell.json
@@ -65,7 +65,6 @@
"desktop.openLaunchpad": "Open Apps",
"desktop.wallpaper": "Change Wallpaper…",
"dock.closeAll": "Close all windows",
- "dock.dropHere": "Drop here to keep it in the Dock",
"dock.hide": "Hide",
"dock.keep": "Keep in Dock",
"dock.newWindow": "New Window",
@@ -74,6 +73,11 @@
"dock.pin": "Pin to taskbar",
"dock.quit": "Quit",
"dock.showAll": "Show All Windows",
+ "dock.remove": "Remove from Dock",
+ "dock.showInFiles": "Show in Files",
+ "dock.removeCue": "Remove",
+ "dock.unpin": "Unpin from taskbar",
+ "dock.unpinCue": "Unpin",
"help.theme": "Create a theme: themes/README.md",
"launchpad.empty": "No results",
"launchpad.search": "Search",
@@ -123,5 +127,10 @@
"wallpaper.aurora": "Aurora",
"wallpaper.ocean": "Ocean",
"wallpaper.sunset": "Sunset",
- "wallpaper.graphite": "Graphite"
+ "wallpaper.graphite": "Graphite",
+ "trash.name": "Trash",
+ "trash.empty": "Empty Trash",
+ "trash.confirmTitle": "Empty the Trash?",
+ "trash.confirmDetail": "Everything in the Trash will be deleted permanently. You can’t undo this action.",
+ "trash.cancel": "Cancel"
}
diff --git a/assets/locales/es/settings.json b/assets/locales/es/settings.json
index beee647..789feb0 100644
--- a/assets/locales/es/settings.json
+++ b/assets/locales/es/settings.json
@@ -226,6 +226,16 @@
"dock.taskbar": "Posición de la barra de tareas",
"dock.taskbarHint": "Tema Clásico. Las ventanas maximizadas no quedan debajo de la barra.",
"dock.sidesHint": "Izquierda y derecha son lados de la pantalla: no cambian con un idioma de derecha a izquierda.",
+ "dock.reset": "Restablecer el Dock",
+ "dock.resetTaskbar": "Restablecer la barra de tareas",
+ "dock.resetButton": "Restablecer…",
+ "dock.resetHint": "Vuelve a poner las apps del tema en su orden original. Archivos queda primero y la Papelera última; Archivos, Ajustes y Apps no se pueden quitar.",
+ "dock.resetHintTaskbar": "Vuelve a poner las apps del tema en la barra de tareas, en su orden original. Archivos queda primero y la Papelera última; Archivos y Ajustes no se pueden desanclar.",
+ "dock.resetAsk": "¿Restablecer el Dock?",
+ "dock.resetDetail": "Las apps que agregaste y el orden que elegiste se reemplazan por los del tema. Las apps abiertas siguen abiertas.",
+ "dock.resetCancel": "Cancelar",
+ "dock.resetConfirm": "Restablecer",
+ "dock.resetDone": "Se restableció lo predeterminado.",
"section.displays": "Pantallas",
"section.bluetooth": "Bluetooth",
"section.power": "Energía",
diff --git a/assets/locales/es/shell.json b/assets/locales/es/shell.json
index 403f02a..e2b66a6 100644
--- a/assets/locales/es/shell.json
+++ b/assets/locales/es/shell.json
@@ -65,7 +65,6 @@
"desktop.openLaunchpad": "Abrir Aplicaciones",
"desktop.wallpaper": "Cambiar fondo de pantalla…",
"dock.closeAll": "Cerrar todas las ventanas",
- "dock.dropHere": "Soltá acá para fijarla en el Dock",
"dock.hide": "Ocultar",
"dock.keep": "Mantener en el Dock",
"dock.newWindow": "Nueva ventana",
@@ -74,6 +73,11 @@
"dock.pin": "Anclar a la barra de tareas",
"dock.quit": "Salir",
"dock.showAll": "Mostrar todas las ventanas",
+ "dock.remove": "Quitar del Dock",
+ "dock.showInFiles": "Mostrar en Archivos",
+ "dock.removeCue": "Quitar",
+ "dock.unpin": "Desanclar de la barra de tareas",
+ "dock.unpinCue": "Desanclar",
"help.theme": "Crear un tema: themes/README.md",
"launchpad.empty": "Sin resultados",
"launchpad.search": "Buscar",
@@ -123,5 +127,10 @@
"wallpaper.aurora": "Aurora",
"wallpaper.ocean": "Océano",
"wallpaper.sunset": "Atardecer",
- "wallpaper.graphite": "Grafito"
+ "wallpaper.graphite": "Grafito",
+ "trash.name": "Papelera",
+ "trash.empty": "Vaciar Papelera",
+ "trash.confirmTitle": "¿Vaciar la Papelera?",
+ "trash.confirmDetail": "Todo lo que hay en la Papelera se borrará para siempre. No se puede deshacer.",
+ "trash.cancel": "Cancelar"
}
diff --git a/assets/locales/pt/settings.json b/assets/locales/pt/settings.json
index 7fa0e89..7508f66 100644
--- a/assets/locales/pt/settings.json
+++ b/assets/locales/pt/settings.json
@@ -226,6 +226,16 @@
"dock.taskbar": "Posição da barra de tarefas",
"dock.taskbarHint": "Tema Clássico. As janelas maximizadas não ficam embaixo da barra.",
"dock.sidesHint": "Esquerda e direita são lados da tela: não mudam com um idioma da direita para a esquerda.",
+ "dock.reset": "Redefinir o Dock",
+ "dock.resetTaskbar": "Redefinir a barra de tarefas",
+ "dock.resetButton": "Redefinir…",
+ "dock.resetHint": "Volta a colocar os apps do tema na ordem original. Arquivos fica em primeiro e o Lixo por último; Arquivos, Ajustes e Apps não podem ser removidos.",
+ "dock.resetHintTaskbar": "Volta a colocar os apps do tema na barra de tarefas, na ordem original. Arquivos fica em primeiro e o Lixo por último; Arquivos e Ajustes não podem ser desafixados.",
+ "dock.resetAsk": "Redefinir o Dock?",
+ "dock.resetDetail": "Os apps que você adicionou e a ordem que escolheu serão substituídos pelos do tema. Os apps abertos continuam abertos.",
+ "dock.resetCancel": "Cancelar",
+ "dock.resetConfirm": "Redefinir",
+ "dock.resetDone": "Os padrões foram restaurados.",
"section.displays": "Telas",
"section.bluetooth": "Bluetooth",
"section.power": "Energia",
diff --git a/assets/locales/pt/shell.json b/assets/locales/pt/shell.json
index f1b0e5b..e574cbd 100644
--- a/assets/locales/pt/shell.json
+++ b/assets/locales/pt/shell.json
@@ -65,7 +65,6 @@
"desktop.openLaunchpad": "Abrir Aplicativos",
"desktop.wallpaper": "Alterar papel de parede…",
"dock.closeAll": "Fechar todas as janelas",
- "dock.dropHere": "Solte aqui para fixar no Dock",
"dock.hide": "Ocultar",
"dock.keep": "Manter no Dock",
"dock.newWindow": "Nova janela",
@@ -74,6 +73,11 @@
"dock.pin": "Fixar na barra de tarefas",
"dock.quit": "Sair",
"dock.showAll": "Mostrar todas as janelas",
+ "dock.remove": "Remover do Dock",
+ "dock.showInFiles": "Mostrar em Arquivos",
+ "dock.removeCue": "Remover",
+ "dock.unpin": "Desafixar da barra de tarefas",
+ "dock.unpinCue": "Desafixar",
"help.theme": "Criar um tema: themes/README.md",
"launchpad.empty": "Nenhum resultado",
"launchpad.search": "Pesquisar",
@@ -123,5 +127,10 @@
"wallpaper.aurora": "Aurora",
"wallpaper.ocean": "Oceano",
"wallpaper.sunset": "Pôr do sol",
- "wallpaper.graphite": "Grafite"
+ "wallpaper.graphite": "Grafite",
+ "trash.name": "Lixo",
+ "trash.empty": "Esvaziar Lixo",
+ "trash.confirmTitle": "Esvaziar o Lixo?",
+ "trash.confirmDetail": "Tudo o que está no Lixo será apagado permanentemente. Não é possível desfazer.",
+ "trash.cancel": "Cancelar"
}
diff --git a/sdk/controls.jsx b/sdk/controls.jsx
index 4cb440e..f8371fd 100644
--- a/sdk/controls.jsx
+++ b/sdk/controls.jsx
@@ -228,3 +228,39 @@ export function FormRow({ label, children, labelWidth, minHeight = 36 }) {
</View>
);
}
+
+// A confirmation in the shell (the Dock's «Empty Trash»): a dimmed screen with a small panel,
+// never alert(). Escape cancels and Enter confirms. destructive: the button is red.
+export function ConfirmDialog({ title, detail, okLabel, cancelLabel, onOk, onCancel, destructive, area }) {
+ const t = useTheme();
+ useEffect(() => addListener('keydown', (e) => {
+ if (e.key === 'Escape') onCancel();
+ else if (e.key === 'Enter') onOk();
+ }), [onOk, onCancel]);
+ const a = area || { x: 0, y: 0, w: undefined, h: undefined };
+ return (
+ <View onClick={onCancel} style={{ position: 'absolute', left: a.x, top: a.y, ...(a.w ? { width: a.w, height: a.h } : { right: 0, bottom: 0 }),
+ backgroundColor: 'rgba(0,0,0,0.3)', alignItems: 'center', justifyContent: 'center' }}>
+ <View onClick={(e) => e.stopPropagation()} style={{ width: 360, padding: spacing.xl, gap: spacing.s, borderRadius: 12, backgroundColor: t.windowBg,
+ border: `1px solid ${t.separator}`, boxShadow: '0 14px 36px rgba(0,0,0,0.45)' }}>
+ <Text style={{ fontSize: typeScale.headline, fontWeight: 600, color: t.text, textAlign: 'start' }}>{title}</Text>
+ {detail ? <Text style={{ fontSize: typeScale.body, color: t.textDim, lineHeight: 1.4, textAlign: 'start' }}>{detail}</Text> : null}
+ <View style={{ flexDirection: 'row', justifyContent: 'flex-end', gap: spacing.s, marginTop: spacing.m }}>
+ <DialogButton t={t} label={cancelLabel} onClick={onCancel} />
+ <DialogButton t={t} label={okLabel} onClick={onOk} primary destructive={destructive} />
+ </View>
+ </View>
+ </View>
+ );
+}
+function DialogButton({ t, label, onClick, primary, destructive }) {
+ const [hover, setHover] = useState(false);
+ const bg = primary ? (destructive ? '#e5483f' : t.accent) : t.control;
+ return (
+ <View onClick={onClick} onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}
+ style={{ height: controlSize.regular, paddingHorizontal: 14, borderRadius: controlSize.radius, justifyContent: 'center', alignItems: 'center',
+ backgroundColor: bg, opacity: hover ? 0.85 : 1 }}>
+ <Text style={{ fontSize: typeScale.body, fontWeight: 500, color: primary ? '#fff' : t.text, whiteSpace: 'nowrap' }}>{label}</Text>
+ </View>
+ );
+}
diff --git a/sdk/dock.js b/sdk/dock.js
index 093045b..8cfba90 100644
--- a/sdk/dock.js
+++ b/sdk/dock.js
@@ -1,38 +1,101 @@
-// dock.js — Dock and taskbar: pinned (favorite) apps, windows grouped by app and the
-// right-click menu. Every theme uses it; each one draws it its own way.
+// dock.js — Dock and taskbar: pinned apps, windows grouped by app, the right-click menu, dragging
+// to add, reorder and remove, and the Trash. Every theme uses it; each one draws it its own way.
//
-// const entries = useDockEntries(['files', 'terminal']) // the theme's default pinned apps
-// // entry = { id, name, Icon, windows: [window…], pinned, running, focused }
+// const entries = useDockEntries(['files', 'terminal'], { launcher: { Icon } }) // the theme's defaults
+// // entry = { id, kind, name, Icon, windows: [window…], pinned, running, focused, locked, movable }
// dockActivate(entry) // click: opens the app or brings up its window
// dockMenu(entry) // items for the context menu: [{ label, onClick, checked, submenu, header } | '-']
+// dock.pin(id, index) · dock.move(id, index) · dock.unpin(id) · dock.reset()
+//
+// Pinned items are typed ids (sdk/dockmodel.js): "app:files", "lpk:<id>", "desktop:<desktop id>"
+// and "shell:launcher". The methods also take a plain launcher id ("files", "desktop:firefox").
+// Files is always first and the Trash always last; Files, Settings and the launcher can't be
+// removed (docs/DOCK.md, "Rules").
//
// An app can add its own items to the menu (the Terminal: New Window, New Tab…):
// registerDockMenu('terminal', (entry) => [{ label: '…', onClick }])
+// and quick actions at the top of it (Settings: one per section), from its module or its manifest
+// ("dockActions": [{ id, label: 'i18n.key', args }]); choosing one opens the app with those args:
+// registerDockActions('settings', () => [{ id: 'network', label: 'settings.section.network', args: { section: 'network' } }])
import { createElement as h } from 'react';
+import { useEffect } from 'react';
import { addListener } from '@lordos/runtime';
import { settings } from './settings.js';
-import { useStore } from './store.js';
+import { createStore, useStore } from './store.js';
import { useWindows, wm, windowTitle, appIdOf, getApp, windows } from './windows.js';
-import { useLauncherApps, launchApp, linuxAppFor, isLinuxApp, LetterIcon, windowIcon } from './apps.js';
-import { t } from './i18n.js';
+import { useLauncherApps, launchApp, linuxAppFor, LetterIcon, windowIcon } from './apps.js';
+import { t, locale } from './i18n.js';
+import * as fs from './fs.js';
+import {
+ parseDockId, toTypedId, normalizePinned, ensureItems, moveItem, pinItem, unpinItem, isLocked, isMovable, cleanActions,
+ LAUNCHER, LOCKED, FIRST,
+} from './dockmodel.js';
+
+export { LAUNCHER as DOCK_LAUNCHER };
const menuProviders = new Map();
export function registerDockMenu(appId, fn) { menuProviders.set(appId, fn); return () => menuProviders.delete(appId); }
+const actionProviders = new Map();
+export function registerDockActions(appId, fn) { actionProviders.set(appId, fn); return () => actionProviders.delete(appId); }
+
+// ---- ids ----
+
+// What an old untyped id is now: a package or a LordOS app (null if unknown).
+const classify = (id) => { const a = getApp(id); return !a || a.builtin ? null : a.package ? 'lpk' : 'app'; };
+
+// A launcher app object or any id → its typed Dock id (null if it can't be pinned).
+export function dockIdOf(x) {
+ if (x && typeof x === 'object') {
+ if (x.kind === 'linux') return x.desktopId ? `desktop:${x.desktopId}` : null;
+ return toTypedId(x.package ? `lpk:${x.id}` : `app:${x.id}`);
+ }
+ return toTypedId(String(x ?? ''), classify);
+}
+// Typed id → the id launchApp knows ("files", "desktop:firefox"); null for the launcher.
+const launcherKey = (id) => {
+ const p = parseDockId(id);
+ if (!p || p.kind === 'shell') return null;
+ return p.kind === 'desktop' ? `desktop:${p.key}` : p.key;
+};
// ---- pinned (in ~/.config/lordos/settings.json → dockPinned) ----
-let themeDefaults = [];
-const pinnedList = () => settings.get().dockPinned || themeDefaults;
+let themeDefaults = [FIRST, LAUNCHER];
+let shownFn = () => true; // which pinned ids the Dock shows (installed), from the last render
+const fromSettings = () => {
+ const raw = settings.get().dockPinned;
+ const base = raw == null ? themeDefaults : normalizePinned(raw, classify).list;
+ return ensureItems(base, LOCKED, themeDefaults);
+};
+const save = (list) => settings.set({ dockPinned: list });
+
export const dock = {
- pinned: pinnedList,
- isPinned: (id) => pinnedList().includes(id),
+ pinned: fromSettings,
+ isPinned: (id) => fromSettings().includes(dockIdOf(id)),
+ canRemove: (id) => { const d = dockIdOf(id); return !!d && !isLocked(d); },
+ canMove: (id) => { const d = dockIdOf(id); return !!d && isMovable(d); },
+ // index: position among the items the Dock shows (Files is 0; nothing goes before it)
pin(id, index) {
- const list = pinnedList().filter((x) => x !== id);
- list.splice(index == null ? list.length : index, 0, id);
- settings.set({ dockPinned: list });
+ const d = dockIdOf(id);
+ if (!d) return false;
+ const cur = fromSettings(), next = pinItem(cur, d, index, shownFn);
+ if (next !== cur) save(next);
+ return true;
},
- unpin: (id) => settings.set({ dockPinned: pinnedList().filter((x) => x !== id) }),
- move(id, index) { dock.pin(id, index); },
+ move(id, index) {
+ const d = dockIdOf(id), cur = fromSettings();
+ const next = d ? moveItem(cur, d, index, shownFn) : cur;
+ if (next !== cur) save(next);
+ return next !== cur;
+ },
+ unpin(id) {
+ const d = dockIdOf(id), cur = fromSettings();
+ const next = d ? unpinItem(cur, d) : cur;
+ if (next !== cur) save(next);
+ return next !== cur;
+ },
+ // the theme's defaults again (the rules stay: Files first, the locked items present)
+ reset: () => settings.set({ dockPinned: null }),
};
// ---- Dock and taskbar preferences (Settings → Desktop & Dock) ----
@@ -70,7 +133,7 @@ windows.subscribe(() => {
if (next.join('\n') !== cur.join('\n')) settings.set({ dockRecentApps: next });
});
-// Which Dock icon a window belongs to: its LordOS app, or the Linux app from its .desktop.
+// Which launcher app a window belongs to: its LordOS app, or the Linux app from its .desktop.
export function launcherIdOf(w) {
if (!String(w.id).startsWith('linux#')) return appIdOf(w.id);
const appId = w.args?.appId || '';
@@ -78,46 +141,88 @@ export function launcherIdOf(w) {
const a = linuxAppFor(appId);
return a ? a.id : `linux:${appId || w.id}`;
}
+// The Dock entry a window belongs to (a typed id, or "linux:…" for a window with no .desktop).
+export function dockIdOfWindow(w) {
+ const k = launcherIdOf(w);
+ return k.startsWith('linux:') ? k : dockIdOf(k) || k;
+}
// opts.recents: how many recent apps (neither pinned nor open) are appended at the end, with recent: true.
+// opts.launcher: { Icon } draws the app launcher as a Dock item (without it, the theme has its own
+// button and the launcher item is left out).
export function useDockEntries(defaults = [], opts = {}) {
- themeDefaults = defaults;
+ const typedDefaults = [FIRST, ...defaults.map((d) => dockIdOf(d)).filter(Boolean)].filter((x, i, a) => a.indexOf(x) === i);
+ if (!typedDefaults.includes(LAUNCHER)) typedDefaults.splice(1, 0, LAUNCHER);
+ themeDefaults = typedDefaults;
const s = useStore(settings);
- const { windows, focused } = useWindows();
+ const { windows: wins, focused } = useWindows();
const apps = useLauncherApps();
- const pinned = s.dockPinned || defaults;
const byId = new Map(apps.map((a) => [a.id, a]));
+ const appFor = (id) => {
+ const p = parseDockId(id);
+ if (!p) return null;
+ if (p.kind === 'desktop') return byId.get(`desktop:${p.key}`) || null;
+ const a = byId.get(p.key);
+ if (!a || a.kind === 'linux') return null;
+ return (p.kind === 'lpk') === !!a.package ? a : null;
+ };
+ const shown = (id) => (id === LAUNCHER ? !!opts.launcher : !!appFor(id));
+ shownFn = shown;
+ const pinned = fromSettings();
+ // an older settings file (untyped ids, a locked item missing) is rewritten once
+ useEffect(() => {
+ const raw = s.dockPinned;
+ if (raw != null && JSON.stringify(raw) !== JSON.stringify(pinned)) save(pinned);
+ }, [JSON.stringify(s.dockPinned)]);
const groups = new Map();
- for (const w of windows) {
+ for (const w of wins) {
if (getApp(w.id)?.builtin && !String(w.id).startsWith('linux#')) continue;
- const k = launcherIdOf(w);
+ const k = dockIdOfWindow(w);
if (!groups.has(k)) groups.set(k, []);
groups.get(k).push(w);
}
- const entry = (id, a, wins) => ({
- id, name: a?.name || windowTitle(wins[0]) || id, Icon: a?.Icon || (wins[0] ? windowIcon(wins[0], getApp) : ({ size }) => h(LetterIcon, { size, name: id })),
- windows: wins, pinned: pinned.includes(id), running: wins.length > 0, focused: wins.some((w) => w.id === focused), app: a,
+ const entry = (id, a, ws) => ({
+ id, kind: parseDockId(id)?.kind || 'linux', launcherId: launcherKey(id),
+ name: a?.name || windowTitle(ws[0]) || id, Icon: a?.Icon || (ws[0] ? windowIcon(ws[0], getApp) : ({ size }) => h(LetterIcon, { size, name: id })),
+ windows: ws, pinned: pinned.includes(id), running: ws.length > 0, focused: ws.some((w) => w.id === focused), app: a,
+ locked: isLocked(id), movable: isMovable(id),
});
const out = [];
for (const id of pinned) {
- const a = byId.get(id);
- if (!a && !groups.has(id)) continue; // pinned but uninstalled
+ if (id === LAUNCHER) {
+ if (opts.launcher) out.push({ id, kind: 'shell', launcher: true, name: t('shell.menu.apps'), Icon: opts.launcher.Icon, windows: [],
+ pinned: true, running: false, focused: false, locked: true, movable: true, onOpen: opts.launcher.onOpen });
+ continue;
+ }
+ const a = appFor(id);
+ if (!a) continue; // pinned but uninstalled: hidden, keeps its place
out.push(entry(id, a, groups.get(id) || []));
}
- for (const [id, wins] of groups) if (!pinned.includes(id)) out.push(entry(id, byId.get(id), wins));
+ for (const [id, ws] of groups) if (!pinned.includes(id)) out.push(entry(id, appFor(id), ws));
if (opts.recents) {
const have = new Set(out.map((e) => e.id));
- for (const id of (s.dockRecentApps || []).filter((x) => !have.has(x) && byId.has(x)).slice(0, opts.recents)) {
- out.push({ ...entry(id, byId.get(id), []), recent: true });
- }
+ const rec = (s.dockRecentApps || []).map((x) => dockIdOf(x)).filter((x) => x && !have.has(x) && appFor(x)).slice(0, opts.recents);
+ for (const id of rec) out.push({ ...entry(id, appFor(id), []), recent: true });
}
return out;
}
+// Opens a Dock item through the existing safe paths only: wm.open / launchPackage(id) /
+// lord.apps.launch(desktop id), all inside launchApp. No other way to run anything.
+export function launchDockItem(id) {
+ const p = parseDockId(id);
+ if (!p || p.kind === 'shell') return false;
+ if (p.kind === 'desktop') return launchApp(`desktop:${p.key}`);
+ const a = getApp(p.key);
+ if (!a || a.builtin || (p.kind === 'lpk') !== !!a.package) return false;
+ return launchApp(p.key);
+}
+
// Click on the icon: with no windows it opens the app; with windows it brings up the most recent one (if it
// was already in front and there are several, it moves to the next, like ❖`).
export function dockActivate(e) {
- if (!e.windows.length) { launchApp(e.id); return; }
+ if (e.launcher) { e.onOpen?.(); return; }
+ if (!e.windows.length) { if (!launchDockItem(e.id) && e.launcherId) launchApp(e.launcherId); return; }
const top = wm.focused();
const idx = e.windows.findIndex((w) => w.id === top);
const next = idx >= 0 && e.windows.length > 1 ? e.windows[(idx + e.windows.length - 1) % e.windows.length] : e.windows[e.windows.length - 1];
@@ -144,23 +249,57 @@ addListener('keydown', (e) => {
quitApp(windows.get().filter((w) => launcherIdOf(w) === key));
});
-export function dockMenu(e) {
+// ---- quick actions ----
+
+// The quick actions of a Dock item: a LordOS app's (manifest "dockActions" + registerDockActions),
+// or a Linux app's desktop actions (Actions= in its .desktop, run by lord.apps.launchAction).
+export function dockQuickActions(e) {
+ const p = parseDockId(e.id);
+ if (!p) return [];
+ if (p.kind === 'desktop') {
+ if (typeof lord === 'undefined' || typeof lord.apps?.actions !== 'function') return [];
+ let list = [];
+ try { list = lord.apps.actions(p.key, locale.get().lang) || []; } catch (err) { list = []; }
+ return list.filter((a) => a && a.id && a.name).map((a) => ({ label: a.name, onClick: () => lord.apps.launchAction(p.key, a.id) }));
+ }
+ if (p.kind !== 'app') return []; // .lpk: launchPackage takes no arguments
+ const app = getApp(p.key);
+ if (!app || app.isolated) return [];
+ let fromModule = [];
+ try { fromModule = actionProviders.get(p.key)?.() || []; } catch (err) { fromModule = []; }
+ return cleanActions([...(Array.isArray(app.dockActions) ? app.dockActions : []), ...fromModule]).map((a) => ({
+ label: t(a.label),
+ onClick: () => wm.open(p.key, { args: { ...a.args, action: a.id }, new: a.new }),
+ }));
+}
+
+// ---- the menu ----
+
+export function dockMenu(e, opts = {}) {
+ if (e.launcher) return [{ label: t('shell.dock.open'), onClick: () => e.onOpen?.() }];
const top = wm.focused();
const items = [];
+ const quick = dockQuickActions(e);
+ if (quick.length) items.push(...quick, '-');
if (e.windows.length) {
for (const w of [...e.windows].reverse()) {
items.push({ label: windowTitle(w) || e.name, checked: w.id === top, hint: w.minimized ? '–' : '', onClick: () => wm.focus(w.id) });
}
items.push('-');
}
- const appKey = isLinuxApp(e.id) || e.id.startsWith('linux:') ? null : e.id;
+ const p = parseDockId(e.id);
+ const appKey = p && p.kind === 'app' ? p.key : null;
const custom = appKey && menuProviders.get(appKey) ? menuProviders.get(appKey)(e) : null;
if (custom && custom.length) items.push(...custom, '-');
- else if (e.windows.length && !e.id.startsWith('linux:')) items.push({ label: t('shell.dock.newWindow'), onClick: () => (appKey ? wm.open(appKey, { new: true }) : launchApp(e.id)) }, '-');
- if (!e.id.startsWith('linux:')) {
- items.push({ label: t('shell.dock.options'), submenu: [
- { label: t('shell.dock.keep'), checked: dock.isPinned(e.id), onClick: () => (dock.isPinned(e.id) ? dock.unpin(e.id) : dock.pin(e.id)) },
- ] }, '-');
+ else if (e.windows.length && p) items.push({ label: t('shell.dock.newWindow'), onClick: () => (appKey && !getApp(appKey)?.isolated ? wm.open(appKey, { new: true }) : launchDockItem(e.id)) }, '-');
+ if (p) {
+ const options = [];
+ if (!dock.isPinned(e.id)) options.push({ label: opts.keepLabel || t('shell.dock.keep'), onClick: () => dock.pin(e.id) });
+ else if (!isLocked(e.id)) options.push({ label: opts.removeLabel || t('shell.dock.remove'), onClick: () => dock.unpin(e.id) });
+ // where the app lives, when Files can open it (a .lpk's folder; a .desktop of the user's own)
+ if (p.kind === 'lpk' && getApp(p.key)?.dir) options.push({ label: t('shell.dock.showInFiles'), onClick: () => wm.open('files', { args: { path: getApp(p.key).dir } }) });
+ if (p.kind === 'desktop' && e.app?.user) options.push({ label: t('shell.dock.showInFiles'), onClick: () => wm.open('files', { args: { path: '~/.local/share/applications' } }) });
+ if (options.length) items.push({ label: t('shell.dock.options'), submenu: options }, '-');
}
if (e.windows.length) {
items.push(
@@ -168,7 +307,110 @@ export function dockMenu(e) {
{ label: t('shell.dock.hide'), onClick: () => { for (const w of e.windows) wm.minimize(w.id); } },
{ label: t('shell.dock.quit'), onClick: () => quitApp(e.windows) },
);
- } else items.push({ label: t('shell.dock.open'), onClick: () => launchApp(e.id) });
+ } else items.push({ label: t('shell.dock.open'), onClick: () => dockActivate(e) });
while (items[items.length - 1] === '-') items.pop();
return items;
}
+
+// ---- the Trash (always the last Dock item) ----
+// Full or empty, from ~/.local/share/Trash/files: a stat every 2 s while some Dock shows it (its
+// mtime changes when something goes in or out), and the whole list (disks' trashes too) only when
+// it changed or every 30 s. Never a busy loop.
+export const trashState = createStore({ full: false });
+let trashSubs = 0, trashTimer = 0, trashMtime = null, trashTicks = 0;
+function trashCheck(force) {
+ let m = 0;
+ try { m = fs.stat(`${fs.home()}/.local/share/Trash/files`).mtime || 0; } catch (err) { m = 0; }
+ if (!force && m === trashMtime && trashTicks++ % 15) return;
+ trashMtime = m;
+ let full = false;
+ try { full = fs.trashList().length > 0; } catch (err) { full = false; }
+ if (full !== trashState.get().full) trashState.set({ full });
+}
+export function useTrash() {
+ useEffect(() => {
+ if (!trashSubs++) { trashCheck(true); trashTimer = setInterval(() => trashCheck(false), 2000); }
+ return () => { if (!--trashSubs) clearInterval(trashTimer); };
+ }, []);
+ return useStore(trashState);
+}
+export const refreshTrash = () => trashCheck(true);
+export const openTrash = () => wm.open('files', { args: { place: 'trash' } });
+export function emptyTrash() { try { fs.emptyTrash(); } finally { trashCheck(true); } }
+// Right-click on the Trash. onEmpty: the theme asks first (an in-app confirmation), then calls emptyTrash().
+export function trashMenu({ onEmpty }) {
+ return [
+ { label: t('shell.dock.open'), onClick: openTrash },
+ '-',
+ { label: t('shell.trash.empty'), disabled: !trashState.get().full, onClick: onEmpty },
+ ];
+}
+
+// ---- dragging (shared by the Dock and the taskbar) ----
+// The theme starts a press with beginDockDrag on mouse down (an icon of the Dock, the app launcher
+// or the start menu); past DRAG_START px it becomes a drag. The bar that accepts drops registers
+// a target: hit(x, y) → { index } (a position among the shown pinned items) | { trash: true } | null,
+// and near(x, y) → is the pointer still close to the bar. A Dock item taken more than about 60 px
+// away and held there for REMOVE_HOLD ms shows the remove cue; releasing it then unpins it (a
+// locked item springs back). dockDrag holds what is happening, for the theme to draw.
+const DRAG_START = 6, REMOVE_HOLD = 350;
+export const dockDrag = createStore(null); // { id, Icon, x, y, source, over, out, removing, removable }
+export const dockPoof = createStore(null); // { x, y, Icon, t0 }: the removal animation, drawn by the theme
+let target = null, press = null, holdTimer = 0, endedAt = 0;
+export function registerDockTarget(tg) { target = tg; return () => { if (target === tg) target = null; }; }
+// true just after a drag ended (the click that follows a release must not open the app)
+export const dockDragJustEnded = () => Date.now() - endedAt < 250;
+
+export function beginDockDrag({ id, Icon, x, y, source = 'dock', onStart }) {
+ const d = dockIdOf(id);
+ if (!d) return;
+ press = { id: d, Icon, x, y, source, onStart, started: false, outSince: 0 };
+}
+function dragState(x, y) {
+ const over = target ? target.hit(x, y) : null;
+ const removable = press.source === 'dock' && dock.isPinned(press.id) && !isLocked(press.id);
+ const out = press.source === 'dock' && !over && !(target && target.near(x, y));
+ if (out && !press.outSince) {
+ press.outSince = Date.now();
+ clearTimeout(holdTimer);
+ holdTimer = setTimeout(() => { if (press?.started) dockDrag.set(dragState(press.lx, press.ly)); }, REMOVE_HOLD + 10);
+ } else if (!out) press.outSince = 0;
+ const removing = removable && out && Date.now() - press.outSince >= REMOVE_HOLD;
+ return { id: press.id, Icon: press.Icon, x, y, source: press.source, over, out, removing, removable, movable: isMovable(press.id) };
+}
+addListener('pointermove', (e) => {
+ if (!press) return;
+ press.lx = e.x; press.ly = e.y;
+ if (!press.started) {
+ if (Math.hypot(e.x - press.x, e.y - press.y) < DRAG_START) return;
+ press.started = true;
+ press.onStart?.();
+ }
+ dockDrag.set(dragState(e.x, e.y));
+});
+addListener('pointerup', (e) => {
+ const p = press;
+ press = null;
+ clearTimeout(holdTimer);
+ if (!p || !p.started) return;
+ endedAt = Date.now();
+ const over = target ? target.hit(e.x, e.y) : null;
+ const st = dockDrag.get();
+ dockDrag.set(null);
+ if (over && over.trash) {
+ if (p.source === 'dock' && dock.unpin(p.id)) dockPoof.set({ x: e.x, y: e.y, Icon: p.Icon, t0: Date.now() });
+ return;
+ }
+ if (over && over.index != null) {
+ if (p.source === 'dock' && dock.isPinned(p.id)) dock.move(p.id, over.index); else dock.pin(p.id, over.index);
+ return;
+ }
+ if (p.source === 'dock' && st?.removing && dock.unpin(p.id)) dockPoof.set({ x: e.x, y: e.y, Icon: p.Icon, t0: Date.now() });
+});
+// Escape cancels a drag.
+addListener('keydown', (e) => {
+ if (e.key !== 'Escape' || !press) return;
+ press = null;
+ clearTimeout(holdTimer);
+ if (dockDrag.get()) { endedAt = Date.now(); dockDrag.set(null); }
+});
diff --git a/sdk/index.js b/sdk/index.js
index 2bc76d5..8a0b4a4 100644
--- a/sdk/index.js
+++ b/sdk/index.js
@@ -40,7 +40,11 @@ export { LordOSLogo, LordOSGlyph, LordOSWordmark } from './logo.js';
export { Lumo, lumoSource } from './mascot.js';
export { DesktopWidgets, registerWidgetType, setWidgets, desktopWidgets } from './widgets.js';
export { Markdown, markdownHeadings, parseMarkdown, parseInline, toggleTask } from './markdown.jsx';
-export { dock, useDockEntries, dockActivate, dockMenu, registerDockMenu, launcherIdOf, dockPrefs, DOCK_DEFAULTS, quitApp } from './dock.js';
+export {
+ dock, useDockEntries, dockActivate, dockMenu, registerDockMenu, registerDockActions, dockQuickActions, launcherIdOf, dockIdOf, dockIdOfWindow,
+ launchDockItem, dockPrefs, DOCK_DEFAULTS, quitApp, DOCK_LAUNCHER, useTrash, trashState, refreshTrash, openTrash, emptyTrash, trashMenu,
+ dockDrag, dockPoof, beginDockDrag, registerDockTarget, dockDragJustEnded,
+} from './dock.js';
export { sound, useSound, useSoundPeak, soundState, defaultSink, defaultSource, microphones } from './sound.js';
export { monitor, useMonitor, monitorSamples, monitorProcesses, monitorConnections, monitorDevices, MONITOR_HISTORY, firewall, firewallState } from './monitor.js';
export * as fwRule from './fwrule.js'; // checks what the user types for a firewall rule
@@ -75,7 +79,7 @@ export {
} from './components.jsx';
import { FloatingWindows } from './components.jsx';
export {
- ToolbarButton, ToolbarGroup, Toolbar, ToolbarSpacer, ToolbarDivider, Hairline, MenuButton, SearchField, EmptyState, GroupBox, FormRow, spacing, typeScale, controlSize,
+ ToolbarButton, ToolbarGroup, Toolbar, ToolbarSpacer, ToolbarDivider, Hairline, MenuButton, SearchField, EmptyState, GroupBox, FormRow, spacing, typeScale, controlSize, ConfirmDialog,
} from './controls.jsx';
export { media, useMedia, usePlayer, nowPlaying, useNowPlaying, NowPlayingTile, mediaFormatTime, thumbFor, useThumb, userDirs } from './media.js';
export { disks, useDisks } from './disks.js';
diff --git a/server/src/apps.c b/server/src/apps.c
index 3d73c33..0baee9c 100644
--- a/server/src/apps.c
+++ b/server/src/apps.c
@@ -150,7 +150,7 @@ static int parse_desktop(const char *file, const char *lang, Entry *e) {
for (int i = 0; i < e->nact; i++) if (!strcmp(e->act[i].name, name)) dup = 1;
if (valid_action(name) && !dup && e->nact < APPS_MAX_ACTIONS) {
act = &e->act[e->nact++];
- snprintf(act->name, sizeof act->name, "%s", name);
+ memcpy(act->name, name, strlen(name) + 1); /* valid_action: shorter than the field */
}
}
continue;
diff --git a/themes/classic/index.jsx b/themes/classic/index.jsx
index ea2bab9..a4f29ca 100644
--- a/themes/classic/index.jsx
+++ b/themes/classic/index.jsx
@@ -9,6 +9,8 @@ import {
configureWindows, getApp, wm, AppHost, session, windowTitle, t as tr, formatTime,
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,
} from '@lordos/sdk';
import { apps } from '@lordos/apps';
import { useEffect, useRef, useState } from 'react';
@@ -105,9 +107,12 @@ function Window({ win, t, focused }) {
// ---- 3. taskbar + start menu ----
+// An app is pinned by dragging it onto the bar (the menu closes when the drag starts) or with a
+// right click → Pin to taskbar.
function StartMenu({ t, onClose, pos }) {
const ref = useRef(null);
const list = useLauncherApps();
+ const [ctx, setCtx] = useState(null); // { app, x }
const groups = APP_CATEGORIES.map((c) => [c, list.filter((a) => appCategory(a) === c)]).filter(([, items]) => items.length);
useEffect(() => addListener('pointerdown', (e) => {
for (let n = e.target; n; n = n.parent) if (n === ref.current) return;
@@ -122,7 +127,10 @@ function StartMenu({ t, onClose, pos }) {
<View key={c}>
<Text style={{ fontSize: 10, fontWeight: 700, color: t.textDim, marginLeft: 6, marginTop: 8, marginBottom: 2 }}>{tr(`shell.category.${c}`)}</Text>
{items.map((a) => (
- <View key={a.id} onClick={() => { onClose(); launchApp(a.id); }} style={{ flexDirection: 'row', alignItems: 'center', gap: 10, padding: 6 }}>
+ <View key={a.id} onClick={() => { if (dockDragJustEnded()) return; onClose(); launchApp(a.id); }}
+ onMouseDown={(e) => { if (!e.button && dockIdOf(a)) beginDockDrag({ id: dockIdOf(a), Icon: a.Icon, x: e.x, y: e.y, source: 'launcher', onStart: onClose }); }}
+ onContextMenu={(e) => dockIdOf(a) && setCtx({ app: a, x: (pos === 'left' || pos === 'right' ? e.y : e.x) - 20 })}
+ style={{ flexDirection: 'row', alignItems: 'center', gap: 10, padding: 6 }}>
<a.Icon size={28} />
<Text style={{ fontSize: 13, color: t.text, whiteSpace: 'nowrap' }}>{a.name}</Text>
</View>
@@ -138,88 +146,243 @@ function StartMenu({ t, onClose, pos }) {
<View onClick={() => { onClose(); session.switchUser(); }} style={{ padding: 8 }}><Text style={{ fontSize: 13, color: t.text }}>{tr('shell.menu.switchUser')}</Text></View>
) : null}
<View onClick={() => session.quit()} style={{ padding: 8 }}><Text style={{ fontSize: 13, color: t.text }}>{tr('shell.menu.logout')}</Text></View>
+ {ctx && (
+ <PopupMenu t={t} pos={pos} x={ctx.x} onClose={() => setCtx(null)} items={[
+ { label: tr('shell.dock.open'), onClick: () => { onClose(); launchApp(ctx.app.id); } },
+ dock.isPinned(ctx.app)
+ ? { label: tr('shell.dock.unpin'), disabled: !dock.canRemove(ctx.app), onClick: () => dock.unpin(ctx.app) }
+ : { label: tr('shell.dock.pin'), onClick: () => dock.pin(ctx.app) },
+ ]} />
+ )}
</View>
);
}
-// The bar's right-click menu (a jump list). Uses the SDK's
-// items (dockMenu), with submenus flattened and taskbar wording.
-function JumpList({ t, entry, x, onClose, pos }) {
+// A small menu next to the bar (the jump list, the Trash's and the start menu's right click).
+// Keyboard: ↑/↓, Enter, Escape.
+function PopupMenu({ t, items, x, onClose, pos }) {
const ref = useRef(null);
- useEffect(() => addListener('pointerdown', (e) => {
- for (let n = e.target; n; n = n.parent) if (n === ref.current) return;
- onClose();
- }), []);
- const items = [];
- for (const it of dockMenu(entry)) {
- if (it !== '-' && it.submenu) items.push(...it.submenu.map((s) => (s.checked != null && s.label === tr('shell.dock.keep') ? { ...s, label: tr('shell.dock.pin') } : s)));
- else if (it !== '-' && it.label === tr('shell.dock.quit')) items.push({ ...it, label: tr('shell.dock.closeAll') });
- else if (it !== '-' && it.label === tr('shell.dock.hide')) continue;
- else items.push(it);
- }
+ const [active, setActive] = useState(-1);
+ const st = useRef({});
+ st.current = { items, active };
+ const ok = (it) => it && it !== '-' && !it.disabled;
+ useEffect(() => {
+ const offPtr = addListener('pointerdown', (e) => {
+ for (let n = e.target; n; n = n.parent) if (n === ref.current) return;
+ onClose();
+ });
+ const tok = {};
+ takeTextFocus(tok, (e) => {
+ const { items: list, active: a } = st.current;
+ const step = (d) => { for (let k = 1; k <= list.length; k++) { const i = ((a < 0 && d < 0 ? 0 : a) + d * k + list.length * 2) % list.length; if (ok(list[i])) { setActive(i); return; } } };
+ if (e.key === 'Escape') onClose();
+ else if (e.key === 'ArrowDown') step(1);
+ else if (e.key === 'ArrowUp') step(-1);
+ else if ((e.key === 'Enter' || e.key === ' ') && ok(list[a])) { onClose(); list[a].onClick?.(); }
+ });
+ return () => { offPtr(); releaseTextFocus(tok); };
+ }, []);
const W = 250;
+ const H = items.reduce((h, it) => h + (it === '-' ? 9 : 28), 8);
+ const maxH = screen.height - BAR_H - 20;
+ const rows = items.map((it, i) => (it === '-'
+ ? <View key={i} style={{ height: 1, backgroundColor: t.separator, marginVertical: 4 }} />
+ : (
+ <View key={i} onMouseEnter={() => setActive(ok(it) ? i : -1)} onClick={() => { if (it.disabled) return; onClose(); it.onClick?.(); }}
+ style={{ flexDirection: 'row', alignItems: 'center', height: 28, paddingHorizontal: 8, backgroundColor: i === active ? t.hover : 'transparent' }}>
+ <Text style={{ width: 18, fontSize: 12, color: t.accent }}>{it.checked ? '✓' : ''}</Text>
+ <Text style={{ flex: 1, fontSize: 13, color: it.disabled ? t.textDim : t.text, whiteSpace: 'nowrap', overflow: 'hidden' }}>{it.label}</Text>
+ </View>
+ )));
return (
- <View ref={ref} style={{ position: 'absolute', ...nextToBar(pos, pos === 'left' || pos === 'right' ? Math.max(4, Math.min(x, screen.height - 300))
- : Math.max(4, Math.min(x, screen.width - W - 4))), width: W, padding: 4,
+ <View ref={ref} style={{ position: 'absolute', ...nextToBar(pos, pos === 'left' || pos === 'right' ? Math.max(4, Math.min(x, screen.height - Math.min(H, maxH) - 8))
+ : Math.max(4, Math.min(x, screen.width - W - 4))), width: W, padding: 4, direction: 'ltr',
backgroundColor: t.bar, border: `1px solid ${t.separator}`, boxShadow: '0 10px 30px rgba(0,0,0,0.4)' }}>
- {items.map((it, i) => (it === '-'
- ? <View key={i} style={{ height: 1, backgroundColor: t.separator, marginVertical: 4 }} />
- : (
- <View key={i} onClick={() => { onClose(); it.onClick?.(); }} style={{ flexDirection: 'row', alignItems: 'center', height: 28, paddingHorizontal: 8 }}>
- <Text style={{ width: 18, fontSize: 12, color: t.accent }}>{it.checked ? '✓' : ''}</Text>
- <Text style={{ flex: 1, fontSize: 13, color: t.text, whiteSpace: 'nowrap', overflow: 'hidden' }}>{it.label}</Text>
- </View>
- )))}
+ {H > maxH ? <ScrollView style={{ height: maxH }}>{rows}</ScrollView> : rows}
</View>
);
}
-// Taskbar: pinned and open apps, one per app (windows of the same app are grouped).
+// The bar's right-click menu (a jump list): the SDK's items (dockMenu), with submenus flattened
+// and taskbar wording.
+function JumpList({ t, entry, x, onClose, pos }) {
+ const items = [];
+ for (const it of dockMenu(entry, { keepLabel: tr('shell.dock.pin'), removeLabel: tr('shell.dock.unpin') })) {
+ if (it !== '-' && it.submenu) items.push(...it.submenu);
+ else if (it !== '-' && it.label === tr('shell.dock.quit')) items.push({ ...it, label: tr('shell.dock.closeAll') });
+ else if (it !== '-' && it.label === tr('shell.dock.hide')) continue;
+ else items.push(it);
+ }
+ return <PopupMenu t={t} items={items} x={x} pos={pos} onClose={onClose} />;
+}
+
+// Taskbar: Files first, the pinned and open apps (one per app: windows of the same app are
+// grouped), then the Trash, always last. The same rules and SDK calls as the default theme's Dock
+// (sdk/dock.js): drag a button to reorder it (a line shows where it lands), drag it off the bar and
+// hold to unpin it, drop apps from the start menu; Files and Settings can't be unpinned.
// Click: opens the app or brings its window (if it was already in front, minimizes it); right click: JumpList.
-function Taskbar({ t, onStart, pos }) {
+function Taskbar({ t, onStart, pos, onEmptyTrash }) {
const clock = useClock((d) => formatTime(d, { seconds: !!settings.get().clock?.seconds }), 1000); // Settings → Date & Time
- const entries = useDockEntries(['files', 'terminal', 'store']);
+ const entries = useDockEntries(['files', 'terminal', 'store', 'settings']);
const { focused } = useWindows();
const [jump, setJump] = useState(null);
+ const [trashMenuAt, setTrashMenuAt] = useState(null);
+ const trash = useTrash();
+ const drag = useStore(dockDrag);
const vert = pos === 'left' || pos === 'right';
+ const refs = useRef(new Map());
+ const barRef = useRef(null);
+ const trashRef = useRef(null);
const click = (e) => {
+ if (dockDragJustEnded()) return;
const top = e.windows.find((w) => w.id === focused);
if (top && e.windows.length === 1) wm.minimize(top.id); else dockActivate(e);
};
+ // where the buttons are (global coordinates), for the drop position
+ const centerOf = (id) => {
+ const n = refs.current.get(id);
+ if (!n) return null;
+ const [x, y, w, h] = lord.getLayout(n.id);
+ return vert ? y + h / 2 : x + w / 2;
+ };
+ const geo = useRef({});
+ geo.current = { entries, vert, drag };
+ useEffect(() => registerDockTarget({
+ hit(x, y) {
+ const g = geo.current;
+ if (!barRef.current) return null;
+ const [bx, by, bw, bh] = lord.getLayout(barRef.current.id);
+ if (!(x >= bx - 16 && x < bx + bw + 16 && y >= by - 16 && y < by + bh + 16)) return null;
+ if (trashRef.current) {
+ const [tx, ty, tw, th] = lord.getLayout(trashRef.current.id);
+ if (x >= tx && x < tx + tw && y >= ty && y < ty + th) return { trash: true };
+ }
+ const a = g.vert ? y : x;
+ const own = g.drag?.source === 'dock' ? g.drag.id : null;
+ const cs = g.entries.filter((e) => e.pinned && !e.recent && e.id !== own).map((e) => centerOf(e.id)).filter((c) => c != null);
+ return { index: cs.filter((c) => c < a).length };
+ },
+ near(x, y) {
+ if (!barRef.current) return false;
+ const [bx, by, bw, bh] = lord.getLayout(barRef.current.id);
+ const dx = x < bx ? bx - x : x > bx + bw ? x - bx - bw : 0, dy = y < by ? by - y : y > by + bh ? y - by - bh : 0;
+ return Math.hypot(dx, dy) <= 60;
+ },
+ }), []);
+ // the drop line: before the pinned button at that index (after the last one at the end)
+ let dropLine = null;
+ if (drag && drag.over && drag.over.index != null && barRef.current) {
+ const own = drag.source === 'dock' ? drag.id : null;
+ const pinned = entries.filter((e) => e.pinned && !e.recent && e.id !== own);
+ const k = Math.max(1, Math.min(pinned.length, drag.over.index));
+ const ref = refs.current.get((pinned[k] || pinned[pinned.length - 1])?.id);
+ if (ref) {
+ const [bx, by] = lord.getLayout(barRef.current.id);
+ const [x, y, w, h] = lord.getLayout(ref.id);
+ const at = pinned[k] ? (vert ? y - by - 3 : x - bx - 3) : (vert ? y - by + h + 1 : x - bx + w + 1);
+ dropLine = vert ? { top: at, left: 6, right: 6, height: 2 } : { left: at, top: 6, bottom: 6, width: 2 };
+ }
+ }
+ const btn = (e) => {
+ const active = e.focused;
+ const title = e.windows.length ? windowTitle(e.windows.find((w) => w.id === focused) || e.windows[e.windows.length - 1]) : '';
+ const dragged = drag && drag.source === 'dock' && drag.id === e.id;
+ return (
+ <View key={e.id} ref={(n) => { if (n) refs.current.set(e.id, n); else refs.current.delete(e.id); }}
+ onClick={() => click(e)} onContextMenu={(ev) => setJump({ entry: e, x: (vert ? ev.y : ev.x) - 20 })}
+ onMouseDown={(ev) => { if (!ev.button) beginDockDrag({ id: e.id, Icon: e.Icon, x: ev.x, y: ev.y, source: 'dock' }); }}
+ style={{ height: vert ? 44 : 32, width: vert ? 52 : undefined, paddingHorizontal: vert ? 0 : e.running ? 10 : 6, flexDirection: 'row',
+ alignItems: 'center', justifyContent: vert ? 'center' : 'flex-start', gap: 8, opacity: dragged ? 0.35 : 1,
+ backgroundColor: active ? t.hover : 'transparent', border: `1px solid ${active ? t.accent : 'transparent'}` }}>
+ {e.running && <View style={{ position: 'absolute', backgroundColor: t.accent, ...(pos === 'top' ? { left: 0, right: 0, top: 0, height: 2 }
+ : pos === 'left' ? { top: 0, bottom: 0, left: 0, width: 2 } : pos === 'right' ? { top: 0, bottom: 0, right: 0, width: 2 }
+ : { left: 0, right: 0, bottom: 0, height: 2 }) }} />}
+ <e.Icon size={vert ? 26 : 20} />
+ {e.running && !vert && <Text style={{ fontSize: 12, color: t.text, whiteSpace: 'nowrap' }}>{title.slice(0, 24)}</Text>}
+ {e.windows.length > 1 && <Text style={{ fontSize: 10, fontWeight: 700, color: t.textDim }}>{e.windows.length}</Text>}
+ </View>
+ );
+ };
return (
- <View style={{ position: 'absolute', ...(vert ? { top: 0, bottom: 0, width: BAR_W, [pos]: 0, flexDirection: 'column', paddingVertical: 6 }
+ <View ref={barRef} style={{ position: 'absolute', ...(vert ? { top: 0, bottom: 0, width: BAR_W, [pos]: 0, flexDirection: 'column', paddingVertical: 6 }
: { left: 0, right: 0, height: BAR_H, [pos]: 0, flexDirection: 'row', paddingHorizontal: 6 }), alignItems: 'center',
gap: 4, backgroundColor: t.bar, border: `1px solid ${t.separator}`, direction: 'ltr' }}>
<View onClick={onStart} style={{ height: 32, paddingHorizontal: vert ? 0 : 14, width: vert ? 52 : undefined, alignItems: 'center',
justifyContent: 'center', backgroundColor: t.accent }}>
<Text style={{ fontSize: vert ? 11 : 13, fontWeight: 700, color: '#fff' }}>LordOS</Text>
</View>
- {entries.map((e) => {
- const active = e.focused;
- const title = e.windows.length ? windowTitle(e.windows.find((w) => w.id === focused) || e.windows[e.windows.length - 1]) : '';
- return (
- <View key={e.id} onClick={() => click(e)} onContextMenu={(ev) => setJump({ entry: e, x: (vert ? ev.y : ev.x) - 20 })}
- style={{ height: vert ? 44 : 32, width: vert ? 52 : undefined, paddingHorizontal: vert ? 0 : e.running ? 10 : 6, flexDirection: 'row',
- alignItems: 'center', justifyContent: vert ? 'center' : 'flex-start', gap: 8,
- backgroundColor: active ? t.hover : 'transparent', border: `1px solid ${active ? t.accent : 'transparent'}` }}>
- {e.running && <View style={{ position: 'absolute', backgroundColor: t.accent, ...(pos === 'top' ? { left: 0, right: 0, top: 0, height: 2 }
- : pos === 'left' ? { top: 0, bottom: 0, left: 0, width: 2 } : pos === 'right' ? { top: 0, bottom: 0, right: 0, width: 2 }
- : { left: 0, right: 0, bottom: 0, height: 2 }) }} />}
- <e.Icon size={vert ? 26 : 20} />
- {e.running && !vert && <Text style={{ fontSize: 12, color: t.text, whiteSpace: 'nowrap' }}>{title.slice(0, 24)}</Text>}
- {e.windows.length > 1 && <Text style={{ fontSize: 10, fontWeight: 700, color: t.textDim }}>{e.windows.length}</Text>}
- </View>
- );
- })}
+ {entries.map(btn)}
+ <View style={vert ? { width: 30, height: 1, backgroundColor: t.separator } : { width: 1, height: 22, backgroundColor: t.separator }} />
+ <View ref={trashRef} dropTrash onClick={() => { if (!dockDragJustEnded()) openTrash(); }}
+ onContextMenu={(ev) => setTrashMenuAt((vert ? ev.y : ev.x) - 20)} onMouseUp={() => setTimeout(refreshTrash, 60)}
+ style={{ height: vert ? 44 : 32, width: vert ? 52 : 34, alignItems: 'center', justifyContent: 'center',
+ backgroundColor: drag?.over?.trash ? t.hover : 'transparent' }}>
+ <TrashGlyph size={vert ? 26 : 22} full={trash.full} t={t} />
+ </View>
<View style={{ flex: 1 }} />
{vert ? null : <StatusItems color={t.text} />}
<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 !== '-')} />}
</View>
);
}
+// The Trash on the taskbar: a small bin, with papers when it isn't empty.
+function TrashGlyph({ size: s, full, t }) {
+ const line = t.mode === 'dark' ? 'rgba(255,255,255,0.7)' : 'rgba(30,34,44,0.65)';
+ return (
+ <View style={{ width: s, height: s }}>
+ {full && <View style={{ position: 'absolute', left: s * 0.3, top: s * 0.02, width: s * 0.4, height: s * 0.24, borderRadius: 2,
+ backgroundColor: t.mode === 'dark' ? '#d9dde6' : '#ffffff', border: `1px solid ${line}`, transform: 'rotate(-10deg)' }} />}
+ <View style={{ position: 'absolute', left: s * 0.18, top: s * 0.18, width: s * 0.64, height: s * 0.07, backgroundColor: line, borderRadius: 1 }} />
+ <View style={{ position: 'absolute', left: s * 0.24, top: s * 0.28, width: s * 0.52, height: s * 0.62, border: `1.5px solid ${line}`,
+ borderBottomLeftRadius: s * 0.08, borderBottomRightRadius: s * 0.08 }}>
+ {[0.3, 0.6].map((k) => <View key={k} style={{ position: 'absolute', top: s * 0.08, bottom: s * 0.08, left: s * 0.52 * k - 1, width: 1.5, backgroundColor: line }} />)}
+ </View>
+ </View>
+ );
+}
+
+// What is being dragged (from the bar or the start menu), and the remove cue.
+function DragGhost({ t }) {
+ const drag = useStore(dockDrag);
+ if (!drag) return null;
+ return (
+ <View style={{ position: 'absolute', left: drag.x - 14, top: drag.y - 14, pointerEvents: 'none', opacity: drag.removing ? 0.5 : 0.9, alignItems: 'center' }}>
+ {drag.Icon ? <drag.Icon size={28} /> : null}
+ {drag.removing && (
+ <View style={{ marginTop: 4, paddingHorizontal: 6, paddingVertical: 2, backgroundColor: t.bar, border: `1px solid ${t.separator}` }}>
+ <Text style={{ fontSize: 11, color: t.text, whiteSpace: 'nowrap' }}>{tr('shell.dock.unpinCue')}</Text>
+ </View>
+ )}
+ </View>
+ );
+}
+
+// After an unpin: the button fades out where it was dropped (nothing with reduce motion).
+function PoofFade() {
+ const poof = useStore(dockPoof);
+ const reduce = !!useStore(settings).reduceMotion;
+ const [, tick] = useState(0);
+ const p = poof ? Math.min(1, (Date.now() - poof.t0) / 300) : 1;
+ useEffect(() => {
+ if (!poof || p >= 1 || reduce) return undefined;
+ const raf = requestAnimationFrame(() => tick((n) => n + 1));
+ return () => cancelAnimationFrame(raf);
+ });
+ if (!poof || p >= 1 || reduce) return null;
+ return (
+ <View style={{ position: 'absolute', left: poof.x - 14, top: poof.y - 14, pointerEvents: 'none', opacity: 1 - p, transform: `scale(${1 - 0.5 * p})` }}>
+ {poof.Icon ? <poof.Icon size={28} /> : null}
+ </View>
+ );
+}
+
+
// ---- 4. App ----
configureWindows({ apps, workArea: areaFn, chrome: { w: 2, h: 32 } });
wm.open('about');
@@ -229,6 +392,7 @@ function App() {
const t = makeTheme(s);
const { windows, visible, focused } = useWindows();
const [start, setStart] = useState(false);
+ const [askEmpty, setAskEmpty] = useState(false);
const pos = dockPrefs(s).taskbarPosition;
// the work area follows the bar live
useEffect(() => { configureWindows({ apps, workArea: areaFn }); }, [pos, screen.width, screen.height]);
@@ -244,9 +408,16 @@ function App() {
<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)} />
+ <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 />
+ {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(); }} />
+ )}
</View>
</ThemeProvider>
);
diff --git a/themes/default/components/Dock.jsx b/themes/default/components/Dock.jsx
index b389fff..1911197 100644
--- a/themes/default/components/Dock.jsx
+++ b/themes/default/components/Dock.jsx
@@ -2,12 +2,24 @@
// on the left or on the right (Settings → Desktop & Dock), auto-hide and show recent
// apps. Left and right are physical sides of the screen, also in Arabic or Hebrew (as
// on popular desktop systems): the Dock is laid out with direction: 'ltr' and only the bottom row reverses its order in RTL.
-import { View, Text, screen, appName, useLocale, addListener, t as tr } from '@lordos/sdk';
+//
+// Customizing (docs/DOCK.md): an icon is dragged to another place (its neighbours slide aside in
+// 150 ms), dragged out and held to remove it (a «poof»), or dropped from the app launcher at a
+// precise position. The logic is the SDK's (sdk/dock.js: beginDockDrag, registerDockTarget, dock.*);
+// 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,
+} from '@lordos/sdk';
import { useEffect, useRef, useState } from 'react';
const GAP = 8, PAD = 9, MARGIN = 6;
-const SEP = GAP + 1; // separator before the recent apps
+const SEP = GAP + 1; // separator before the recent apps and before the Trash
const SLIDE_MS = 180;
+const REORDER_MS = 150; // neighbours sliding aside while dragging
+const POOF_MS = 320;
+const NEAR = 60; // dragged farther than this from the Dock: the remove cue (after a hold)
+const TRASH = '__trash';
// What the Dock takes up from its screen edge (for the work area).
export const dockThickness = (size) => size + PAD * 2 + MARGIN + 4;
@@ -26,14 +38,47 @@ export function LaunchpadIcon({ size: s }) {
);
}
+// The Trash: a wire basket, empty or with crumpled papers. Light and dark versions.
+export function TrashIcon({ size: s, full, dark }) {
+ const body = dark ? 'linear-gradient(180deg, rgba(235,238,245,0.30), rgba(200,205,215,0.16))' : 'linear-gradient(180deg, rgba(255,255,255,0.85), rgba(215,220,230,0.65))';
+ const line = dark ? 'rgba(255,255,255,0.55)' : 'rgba(60,66,80,0.45)';
+ const w = s * 0.62, hh = s * 0.64, x = (s - w) / 2, y = s * 0.3;
+ return (
+ <View style={{ width: s, height: s }}>
+ {full && (
+ <>
+ <View style={{ position: 'absolute', left: x + w * 0.02, top: y - s * 0.24, width: w * 0.52, height: s * 0.32, borderRadius: s * 0.13,
+ backgroundColor: '#ffffff', border: '1px solid rgba(60,66,80,0.35)', transform: 'rotate(-14deg)' }} />
+ <View style={{ position: 'absolute', left: x + w * 0.4, top: y - s * 0.28, width: w * 0.56, height: s * 0.34, borderRadius: s * 0.08,
+ backgroundColor: '#e9f1ff', border: '1px solid rgba(60,66,80,0.35)', transform: 'rotate(12deg)' }}>
+ {[0.3, 0.5, 0.7].map((k) => <View key={k} style={{ position: 'absolute', left: w * 0.08, right: w * 0.1, top: s * 0.34 * k, height: 1, backgroundColor: 'rgba(60,90,160,0.45)' }} />)}
+ </View>
+ </>
+ )}
+ <View style={{ position: 'absolute', left: x, top: y, width: w, height: hh, borderBottomLeftRadius: s * 0.1, borderBottomRightRadius: s * 0.1,
+ borderTopLeftRadius: s * 0.04, borderTopRightRadius: s * 0.04, background: body, border: `1px solid ${line}`, overflow: 'hidden',
+ boxShadow: `0 ${s * 0.03}px ${s * 0.1}px rgba(0,0,0,0.25)` }}>
+ {[0.2, 0.4, 0.6, 0.8].map((k) => (
+ <View key={k} style={{ position: 'absolute', top: 0, bottom: 0, left: w * k - 0.5, width: 1, backgroundColor: line }} />
+ ))}
+ <View style={{ position: 'absolute', left: 0, right: 0, top: hh * 0.5, height: 1, backgroundColor: line }} />
+ </View>
+ <View style={{ position: 'absolute', left: x - s * 0.03, top: y - 1, width: w + s * 0.06, height: s * 0.05, borderRadius: s * 0.03,
+ backgroundColor: dark ? 'rgba(235,238,245,0.6)' : 'rgba(120,126,140,0.7)' }} />
+ </View>
+ );
+}
+
// Auto-hide: shows when the pointer touches the edge (after a short delay) and hides
// when it leaves the Dock. State only changes when crossing those boundaries: moving the mouse around the rest of the
// screen doesn't redraw anything. The animation belongs to this component, not the desktop.
-function useAutohide(enabled, position, rectRef, keepOpen, areaRef) {
+// force: shown right away (an app being dragged from the app launcher).
+function useAutohide(enabled, position, rectRef, keepOpen, areaRef, force) {
const [p, setP] = useState(enabled ? 0 : 1); // 0 hidden … 1 in view
const want = useRef(!enabled);
const keep = useRef(keepOpen);
keep.current = keepOpen;
+ const show = useRef(null);
useEffect(() => {
if (!enabled) { want.current = true; setP(1); return undefined; }
want.current = false;
@@ -56,6 +101,7 @@ function useAutohide(enabled, position, rectRef, keepOpen, areaRef) {
from = on ? 0 : 1;
animate(on ? 1 : 0);
};
+ show.current = () => set(true);
const off = addListener('pointermove', (e) => {
// the edge of the display the Dock is on (the main one: docs/DISPLAYS.md)
const A = areaRef.current, inX = e.x >= A.x && e.x < A.x + A.w, inY = e.y >= A.y && e.y < A.y + A.h;
@@ -69,80 +115,265 @@ function useAutohide(enabled, position, rectRef, keepOpen, areaRef) {
if (!timer) timer = setTimeout(() => { timer = 0; if (!keep.current) set(false); }, 500);
} else if (timer) { clearTimeout(timer); timer = 0; }
});
- return () => { off(); clearTimeout(timer); cancelAnimationFrame(raf); };
+ return () => { off(); clearTimeout(timer); cancelAnimationFrame(raf); show.current = null; };
}, [enabled, position]);
+ useEffect(() => { if (force && enabled) show.current?.(); }, [force, enabled]);
return p;
}
-export function Dock({ t, items: list, running, onOpen, onContext, position = 'bottom', size = 54, magnify = true, maxSize = 86,
- autohide = false, top = 0, keepOpen = false, area = { x: 0, y: 0, w: screen.width, h: screen.height } }) {
+// Positions that glide to their new value in `ms` (ease-out) while `active`; otherwise they jump.
+// Values are numbers by key; a key seen for the first time starts where `origin(key)` says, or at
+// its target.
+function useGlide(targets, active, ms, origin) {
+ const cur = useRef({});
+ const anim = useRef(null); // { from, to, t0, sig }
+ const running = useRef(false);
+ const [, tick] = useState(0);
+ useEffect(() => {
+ if (!running.current) return undefined;
+ const raf = requestAnimationFrame(() => tick((n) => n + 1));
+ return () => cancelAnimationFrame(raf);
+ });
+ const sig = Object.keys(targets).map((k) => `${k}:${Math.round(targets[k])}`).join('|');
+ const now = performance.now();
+ const valueAt = (a, k) => {
+ const p = Math.min(1, (now - a.t0) / ms), e = 1 - (1 - p) ** 3;
+ const f = a.from[k] ?? a.to[k];
+ return f + (a.to[k] - f) * e;
+ };
+ if (!active || ms <= 0) { anim.current = null; running.current = false; cur.current = { ...targets }; return targets; }
+ if (!anim.current || anim.current.sig !== sig) {
+ const from = {};
+ for (const k of Object.keys(targets)) {
+ const was = anim.current && k in anim.current.to ? valueAt(anim.current, k) : cur.current[k];
+ from[k] = was ?? origin?.(k) ?? targets[k];
+ }
+ anim.current = { from, to: { ...targets }, t0: now, sig };
+ }
+ const out = {};
+ for (const k of Object.keys(targets)) out[k] = valueAt(anim.current, k);
+ cur.current = out;
+ running.current = now - anim.current.t0 < ms;
+ return out;
+}
+
+// The «poof» after an icon is removed: the icon shrinks and fades and five puffs spread out.
+function Poof({ poof, size, reduce }) {
+ const [, tick] = useState(0);
+ const p = poof ? Math.min(1, (Date.now() - poof.t0) / POOF_MS) : 1;
+ useEffect(() => {
+ if (!poof || p >= 1 || reduce) return undefined;
+ const raf = requestAnimationFrame(() => tick((n) => n + 1));
+ return () => cancelAnimationFrame(raf);
+ });
+ if (!poof || p >= 1 || reduce) return null;
+ const s = size;
+ return (
+ <View style={{ position: 'absolute', left: poof.x - s, top: poof.y - s, width: s * 2, height: s * 2, pointerEvents: 'none' }}>
+ <View style={{ position: 'absolute', left: s / 2, top: s / 2, width: s, height: s, opacity: 1 - p, transform: `scale(${1 - 0.6 * p})` }}>
+ {poof.Icon ? <poof.Icon size={s} /> : null}
+ </View>
+ {[0, 72, 144, 216, 288].map((a) => {
+ const r = s * (0.25 + 0.75 * p), d = s * (0.22 + 0.2 * p);
+ const cx = s + Math.cos((a * Math.PI) / 180) * r, cy = s + Math.sin((a * Math.PI) / 180) * r;
+ return <View key={a} style={{ position: 'absolute', left: cx - d / 2, top: cy - d / 2, width: d, height: d, borderRadius: d / 2,
+ backgroundColor: 'rgba(235,238,245,0.9)', opacity: 0.85 * (1 - p) }} />;
+ })}
+ </View>
+ );
+}
+
+export function Dock({ t, items: list, running, onOpen, onContext, onTrash, onTrashContext, trashFull = false, position = 'bottom', size = 54,
+ magnify = true, maxSize = 86, autohide = false, top = 0, keepOpen = false, area = { x: 0, y: 0, w: screen.width, h: screen.height } }) {
// area: the display it is on (global coordinates); everything below is placed inside it
const vert = position !== 'bottom';
const [m, setM] = useState(null); // mouse position along the Dock's axis
const { dir } = useLocale();
+ const drag = useStore(dockDrag);
+ const poof = useStore(dockPoof);
+ const reduce = !!useStore(settings).reduceMotion;
// The magnifier computes positions with the mouse coordinate: in Arabic/Hebrew the bottom row reverses
// the list (the visual result users expect); on the side the order is top to bottom in all of them.
- const items = !vert && dir === 'rtl' ? [...list].reverse() : list;
+ const flip = !vert && dir === 'rtl';
+ const trashItem = { id: TRASH, trash: true };
+ const dragging = !!drag;
+ const own = drag && drag.source === 'dock' ? drag.id : null; // an icon of this Dock is being dragged
+ // tokens in reading order: items, the gap where a drop would land, separators
+ // Tokens on screen (reading order, mirrored for a bottom Dock in RTL): the icons without the one
+ // being dragged, the gap where a drop would land, the separators and the Trash, always last.
+ const tokensFor = (skip, gapAt) => {
+ const out = [];
+ let pi = 0, sepDone = false, gapDone = gapAt < 0;
+ for (const it of list) {
+ if (it.id === skip) continue;
+ const pinned = it.pinned && !it.recent;
+ if (!gapDone && (!pinned || pi === gapAt)) { out.push({ gap: true }); gapDone = true; }
+ if (pinned) pi++;
+ if (it.recent && !sepDone) { out.push({ sep: true }); sepDone = true; }
+ out.push({ item: it });
+ }
+ if (!gapDone) out.push({ gap: true });
+ out.push({ sep: true }, { item: trashItem });
+ return flip ? out.reverse() : out;
+ };
+ const pinnedCount = list.filter((it) => it.pinned && !it.recent && it.id !== own).length;
+ const gapAt = drag && drag.over && drag.over.index != null ? Math.max(0, Math.min(pinnedCount, drag.over.index)) : -1;
+ const vis = tokensFor(own, gapAt);
+ const items = vis.filter((x) => x.item).map((x) => x.item);
const n = items.length;
- const sepAt = items.findIndex((it) => it.recent);
- const sep = sepAt > 0 ? SEP : 0;
+ const seps = vis.filter((x) => x.sep).length;
+ const gaps = vis.filter((x) => x.gap).length;
const origin = vert ? area.y + top : area.x, avail = vert ? area.h - top : area.w;
const AX = area.x, AY = area.y, AR = area.x + area.w, AB = area.y + area.h;
// with many apps the icons shrink so the Dock fits on screen
// (it accounts for magnifier growth: about 2.6 extra icons in total)
const grow = magnify ? 2.6 * Math.max(0, maxSize / size - 1) : 0;
- const fit = Math.floor((avail - 2 * PAD - 16 - (n - 1) * GAP - sep) / (Math.max(1, n) + grow));
+ const fit = Math.floor((avail - 2 * PAD - 16 - (n + gaps - 1) * GAP - seps * SEP) / (Math.max(1, n + gaps) + grow));
const BASE = Math.max(20, Math.min(size, fit));
- const MAX = magnify ? Math.max(BASE, Math.round(maxSize * BASE / size)) : BASE, RANGE = BASE * 3;
- const baseLen = n * BASE + (n - 1) * GAP + sep;
- const baseStart = origin + (avail - baseLen) / 2;
- const centers = items.map((_, i) => baseStart + i * (BASE + GAP) + (sepAt > 0 && i >= sepAt ? sep : 0) + BASE / 2);
+ const MAX = magnify && !dragging ? Math.max(BASE, Math.round(maxSize * BASE / size)) : BASE, RANGE = BASE * 3;
+ // base layout (every icon at BASE): for the magnifier, the tooltip and the drop positions
+ const layout = (sizeOf, toks = vis) => {
+ let x = PAD;
+ const c = [];
+ for (const tk of toks) {
+ if (tk.sep) x += SEP;
+ else if (tk.gap) x += BASE + GAP;
+ else { const s = sizeOf(c.length); c.push(x + s / 2); x += s + GAP; }
+ }
+ return { c, len: x - GAP + PAD };
+ };
+ const base = layout(() => BASE);
+ const baseStart = origin + (avail - base.len) / 2;
+ const centers = base.c.map((c) => baseStart + c);
const sizes = centers.map((c) => {
if (m == null || MAX === BASE) return BASE;
const d = Math.abs(m - c) / RANGE;
return d < 1 ? Math.round(BASE + (MAX - BASE) * Math.cos((d * Math.PI) / 2)) : BASE;
});
- const hovered = m == null ? -1 : centers.findIndex((c) => Math.abs(m - c) <= (BASE + GAP) / 2);
- const len = sizes.reduce((a, b) => a + b, 0) + GAP * (n - 1) + sep + PAD * 2;
- const start = Math.max(origin, origin + (avail - len) / 2);
- let x = PAD;
- const iconC = sizes.map((s, i) => { if (i === sepAt && sep) x += sep; const c = x + s / 2; x += s + GAP; return c; });
+ const hovered = m == null || dragging ? -1 : centers.findIndex((c) => Math.abs(m - c) <= (BASE + GAP) / 2);
+ const real = layout((i) => sizes[i]);
+ const len = real.len;
+ const startT = Math.max(origin, origin + (avail - len) / 2);
const bar = BASE + PAD * 2;
- // where the bar is on screen (for auto-hide) and how far it moves when hiding
+ // glide: every icon's place on screen, the bar's start and length
+ const settle = useRef(0);
+ const wasDragging = useRef(false);
+ const lastGhost = useRef(null);
+ if (wasDragging.current && !dragging) settle.current = Date.now() + REORDER_MS + 40;
+ wasDragging.current = dragging;
+ if (drag) lastGhost.current = { id: drag.id, at: vert ? drag.y : drag.x };
+ const targets = { __start: startT, __len: len };
+ items.forEach((it, i) => { targets[it.id] = startT + real.c[i]; });
+ const glide = useGlide(targets, dragging || Date.now() < settle.current, reduce ? 0 : REORDER_MS,
+ (k) => (lastGhost.current && lastGhost.current.id === k ? lastGhost.current.at : undefined));
+ const start = glide.__start, glen = glide.__len;
+ const iconC = items.map((it) => glide[it.id] - start);
+
+ // where the bar is on screen (for auto-hide, drops) and how far it moves when hiding
const rect = useRef(null);
- rect.current = position === 'bottom' ? { x0: start, x1: start + len, y0: AB - MARGIN - bar, y1: AB }
- : position === 'left' ? { x0: AX, x1: AX + MARGIN + bar, y0: start, y1: start + len }
- : { x0: AR - MARGIN - bar, x1: AR, y0: start, y1: start + len };
+ rect.current = position === 'bottom' ? { x0: startT, x1: startT + len, y0: AB - MARGIN - bar, y1: AB }
+ : position === 'left' ? { x0: AX, x1: AX + MARGIN + bar, y0: startT, y1: startT + len }
+ : { x0: AR - MARGIN - bar, x1: AR, y0: startT, y1: startT + len };
const areaRef = useRef(area);
areaRef.current = area;
- const shown = useAutohide(autohide, position, rect, keepOpen || hovered >= 0, areaRef);
+ const external = !!drag && drag.source !== 'dock';
+ const shown = useAutohide(autohide, position, rect, keepOpen || hovered >= 0 || dragging, areaRef, external);
const hide = Math.round((1 - shown) * (bar + MARGIN + 2));
- if (autohide && shown <= 0) return null;
+
+ // Drop target (sdk/dock.js): the index among the shown pinned items, or the Trash. Computed from
+ // the layout without the dragged icon and without the gap, so it doesn't move under the pointer.
+ const geo = useRef(null);
+ {
+ const toks = tokensFor(own, -1);
+ const r = layout(() => BASE, toks);
+ const rs = origin + (avail - r.len) / 2;
+ const restItems = toks.filter((x) => x.item).map((x) => x.item);
+ const rest = restItems.map((it, i) => (it.pinned && !it.recent ? rs + r.c[i] : null)).filter((c) => c != null);
+ const ti = items.findIndex((it) => it.trash);
+ geo.current = { rest, flip, vert, rect: rect.current, trashC: ti >= 0 ? startT + real.c[ti] : null, BASE };
+ }
+ useEffect(() => registerDockTarget({
+ hit(x, y) {
+ const g = geo.current, r = g.rect, slack = 24;
+ if (!(x >= r.x0 - slack && x < r.x1 + slack && y >= r.y0 - slack && y < r.y1 + slack)) return null;
+ const a = g.vert ? y : x;
+ if (g.trashC != null && Math.abs(a - g.trashC) <= g.BASE / 2 + 2) return { trash: true };
+ const before = g.rest.filter((c) => c < a).length;
+ return { index: g.flip ? g.rest.length - before : before };
+ },
+ near(x, y) {
+ const r = geo.current.rect;
+ const dx = x < r.x0 ? r.x0 - x : x > r.x1 ? x - r.x1 : 0, dy = y < r.y0 ? r.y0 - y : y > r.y1 ? y - r.y1 : 0;
+ return Math.hypot(dx, dy) <= NEAR;
+ },
+ }), []);
+
+ // a Files drag (or any held button) over the Trash lights it up
+ const [trashHover, setTrashHover] = useState(false);
+ const buttonDown = useRef(false);
+ useEffect(() => {
+ const a = addListener('pointerdown', () => { buttonDown.current = true; });
+ const b = addListener('pointerup', () => { buttonDown.current = false; });
+ return () => { a(); b(); };
+ }, []);
+
+ if (autohide && shown <= 0 && !dragging) return <Poof poof={poof} size={BASE} reduce={reduce} />;
// 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.
const BH = m != null ? MAX + PAD * 2 + 34 : bar, BW = m != null ? MAX + PAD * 2 : bar;
- const box = position === 'bottom' ? { left: start, top: AB - (MARGIN - hide) - BH, width: len, height: BH }
- : position === 'left' ? { left: AX + MARGIN - hide, top: start, width: BW, height: len }
- : { left: AR - (MARGIN - hide) - BW, top: start, width: BW, height: len };
+ const box = position === 'bottom' ? { left: start, top: AB - (MARGIN - hide) - BH, width: glen, height: BH }
+ : position === 'left' ? { left: AX + MARGIN - hide, top: start, width: BW, height: glen }
+ : { left: AR - (MARGIN - hide) - BW, top: start, width: BW, height: glen };
const back = position === 'bottom' ? { left: 0, right: 0, bottom: 0, height: bar }
: position === 'left' ? { left: 0, top: 0, bottom: 0, width: bar } : { right: 0, top: 0, bottom: 0, width: bar };
- const strip = position === 'bottom' ? { left: PAD, bottom: PAD, flexDirection: 'row', alignItems: 'flex-end' }
- : position === 'left' ? { left: PAD, top: PAD, flexDirection: 'column', alignItems: 'flex-start' }
- : { right: PAD, top: PAD, flexDirection: 'column', alignItems: 'flex-end' };
+ const place = (i) => (position === 'bottom' ? { left: iconC[i] - sizes[i] / 2, bottom: PAD }
+ : position === 'left' ? { top: iconC[i] - sizes[i] / 2, left: PAD } : { top: iconC[i] - sizes[i] / 2, right: PAD });
const dot = (s) => (position === 'bottom' ? { left: s / 2 - 2, bottom: -7 } : position === 'left' ? { top: s / 2 - 2, left: -7 } : { top: s / 2 - 2, right: -7 });
const dotColor = t.mode === 'dark' ? 'rgba(255,255,255,0.85)' : 'rgba(0,0,0,0.7)';
// where to open the right-click menu and the tooltip: beside the icon, on the inner side
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 label = hovered >= 0 ? (items[hovered].id === 'launchpad' ? tr('shell.menu.apps') : appName(items[hovered])) : '';
+ const hit = hovered >= 0 ? items[hovered] : null;
+ 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,
backdropFilter: `blur(${t.blur}px)`, border: `1px solid ${t.windowBorder}` }}>
<Text style={{ fontSize: 12, fontWeight: 500, color: t.text, whiteSpace: 'nowrap' }}>{label}</Text>
</View>
);
+ // separators: halfway between the icons around them
+ const sepLines = [];
+ {
+ let k = 0;
+ for (let j = 0; j < vis.length; j++) {
+ if (vis[j].item) { k++; continue; }
+ if (!vis[j].sep || k === 0 || k >= n) continue;
+ const mid = (iconC[k - 1] + sizes[k - 1] / 2 + iconC[k] - sizes[k] / 2) / 2;
+ sepLines.push(mid);
+ }
+ }
+ const trashLit = (drag && drag.over && drag.over.trash) || (trashHover && buttonDown.current && !drag);
+ const ghost = drag ? (
+ <View style={{ position: 'absolute', left: drag.x - BASE / 2, top: drag.y - BASE / 2, width: BASE, height: BASE, pointerEvents: 'none',
+ opacity: drag.removing ? 0.55 : 0.92 }}>
+ {drag.Icon ? <drag.Icon size={BASE} /> : null}
+ {drag.removing && (
+ <View style={{ position: 'absolute', left: BASE / 2 - 50, width: 100, top: BASE + 6, alignItems: 'center' }}>
+ <View style={{ paddingHorizontal: 8, paddingVertical: 3, borderRadius: 6, backgroundColor: t.panelBg, border: `1px solid ${t.windowBorder}` }}>
+ <Text style={{ fontSize: 11, fontWeight: 600, color: t.text, whiteSpace: 'nowrap' }}>{tr('shell.dock.removeCue')}</Text>
+ </View>
+ </View>
+ )}
+ {drag.removing && (
+ <View style={{ position: 'absolute', right: -6, top: -6, width: 18, height: 18, borderRadius: 9, backgroundColor: 'rgba(235,238,245,0.95)',
+ alignItems: 'center', justifyContent: 'center', boxShadow: '0 1px 4px rgba(0,0,0,0.35)' }}>
+ <Text style={{ fontSize: 12, fontWeight: 700, color: '#4a4f5c' }}>×</Text>
+ </View>
+ )}
+ </View>
+ ) : null;
return (
<>
@@ -150,21 +381,29 @@ export function Dock({ t, items: list, running, onOpen, onContext, position = 'b
style={{ position: 'absolute', ...box, direction: 'ltr' }}>
<View style={{ position: 'absolute', ...back, borderRadius: 20,
backgroundColor: t.dockBg, backdropFilter: `blur(${t.blur}px)`, border: `1px solid ${t.dockBorder}` }} />
- <View style={{ position: 'absolute', ...strip, gap: GAP }}>
- {items.flatMap((app, i) => [
- i === sepAt && sep ? (
- <View key="sep" style={vert ? { height: 1, width: BASE * 0.7, alignSelf: 'center', backgroundColor: t.dockBorder }
- : { width: 1, height: BASE * 0.7, alignSelf: 'center', backgroundColor: t.dockBorder }} />
- ) : null,
- <View key={app.id} onClick={() => onOpen(app.id)} onContextMenu={() => onContext?.(app.id, anchor(i))}
- style={{ width: sizes[i], height: sizes[i] }}>
- <app.Icon size={sizes[i]} />
- {running.includes(app.id) && (
- <View style={{ position: 'absolute', ...dot(sizes[i]), width: 4, height: 4, borderRadius: 2, backgroundColor: dotColor }} />
- )}
- </View>,
- ]).filter(Boolean)}
- </View>
+ {sepLines.map((c, i) => (
+ <View key={`sep${i}`} style={vert ? { position: 'absolute', top: c, height: 1, width: BASE * 0.7, [position]: PAD + BASE * 0.15, backgroundColor: t.dockBorder }
+ : { position: 'absolute', left: c, width: 1, height: BASE * 0.7, bottom: PAD + BASE * 0.15, backgroundColor: t.dockBorder }} />
+ ))}
+ {items.map((app, i) => (app.trash ? (
+ <View key={TRASH} dropTrash onClick={() => { if (!dockDragJustEnded()) onTrash?.(); }}
+ onContextMenu={() => onTrashContext?.(anchor(i))}
+ onMouseEnter={() => setTrashHover(true)} onMouseLeave={() => setTrashHover(false)}
+ onMouseUp={() => setTimeout(refreshTrash, 60)}
+ style={{ position: 'absolute', ...place(i), width: sizes[i], height: sizes[i], borderRadius: sizes[i] * 0.22,
+ backgroundColor: trashLit ? 'rgba(255,255,255,0.22)' : 'transparent' }}>
+ <TrashIcon size={sizes[i]} full={trashFull} dark={t.mode === 'dark'} />
+ </View>
+ ) : (
+ <View key={app.id} onClick={() => { if (!dockDragJustEnded()) onOpen(app.id); }} onContextMenu={() => onContext?.(app.id, anchor(i))}
+ onMouseDown={(e) => { if (!e.button) beginDockDrag({ id: app.id, Icon: app.Icon, x: e.x, y: e.y, source: 'dock' }); }}
+ style={{ position: 'absolute', ...place(i), width: sizes[i], height: sizes[i] }}>
+ <app.Icon size={sizes[i]} />
+ {running.includes(app.id) && (
+ <View style={{ position: 'absolute', ...dot(sizes[i]), width: 4, height: 4, borderRadius: 2, backgroundColor: dotColor }} />
+ )}
+ </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>
@@ -174,6 +413,8 @@ export function Dock({ t, items: list, running, onOpen, onContext, position = 'b
<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} />
</>
);
}
diff --git a/themes/default/components/Launchpad.jsx b/themes/default/components/Launchpad.jsx
index 15a1508..77cb571 100644
--- a/themes/default/components/Launchpad.jsx
+++ b/themes/default/components/Launchpad.jsx
@@ -1,11 +1,12 @@
// App launcher ("Apps"): all apps in full screen, with keyboard search.
-// An app is pinned to the Dock by dragging it to the bottom strip or with a right click.
-import { View, Text, TextInput, ScrollView, screen, t as tr, appName, APP_CATEGORIES, appCategory, addListener, dock, useStore, settings } from '@lordos/sdk';
-import { useEffect, useRef, useState } from 'react';
+// An app is pinned to the Dock by dragging it onto the Dock (the launcher steps aside as soon as the
+// drag starts, and the app lands where it is dropped) or with a right click → Keep in Dock. It works
+// the same for LordOS apps, .lpk packages and Linux apps (sdk/dock.js).
+import { View, Text, TextInput, ScrollView, screen, t as tr, appName, APP_CATEGORIES, appCategory, dock, dockIdOf, useStore, settings,
+ beginDockDrag, dockDragJustEnded } from '@lordos/sdk';
+import { useRef, useState } from 'react';
import { Menu } from './Menu.jsx';
-const DROP_H = 110; // bottom strip where you drop to pin to the Dock
-
const COLS = 6, CELL = 130, ICON = 72;
// area: the display it covers (the main one; global coordinates)
@@ -23,26 +24,6 @@ export function Launchpad({ t, apps, onOpen, onClose, area = { x: 0, y: 0, w: sc
const open = (id) => { onClose(); onOpen(id); };
useStore(settings); // «Keep in Dock» changes immediately
const [ctx, setCtx] = useState(null); // { app, x, y }
- const [drag, setDrag] = useState(null); // { app, x, y }
- const press = useRef(null);
- const dragged = useRef(false);
- useEffect(() => {
- const offMove = addListener('pointermove', (e) => {
- const p = press.current;
- if (!p) return;
- if (!dragged.current && Math.hypot(e.x - p.x, e.y - p.y) < 8) return;
- dragged.current = true;
- setDrag({ app: p.app, x: e.x, y: e.y });
- });
- const offUp = addListener('pointerup', (e) => {
- const p = press.current;
- press.current = null;
- if (p && dragged.current && e.y > A.current.y + A.current.h - DROP_H) dock.pin(p.app.id);
- setDrag(null);
- setTimeout(() => { dragged.current = false; }, 0);
- });
- return () => { offMove(); offUp(); };
- }, []);
return (
<View onClick={onClose} style={{
@@ -69,8 +50,8 @@ export function Launchpad({ t, apps, onOpen, onClose, area = { x: 0, y: 0, w: sc
{rows.map((row, r) => (
<View key={r} style={{ flexDirection: 'row' }}>
{row.map((a) => (
- <View key={a.id} onClick={(e) => { e.stopPropagation(); if (!dragged.current) open(a.id); }}
- onMouseDown={(e) => { press.current = { app: a, x: e.x, y: e.y }; dragged.current = false; }}
+ <View key={a.id} onClick={(e) => { e.stopPropagation(); if (!dockDragJustEnded()) open(a.id); }}
+ onMouseDown={(e) => { if (!e.button && dockIdOf(a)) beginDockDrag({ id: dockIdOf(a), Icon: a.Icon, x: e.x, y: e.y, source: 'launcher', onStart: onClose }); }}
onContextMenu={(e) => { e.stopPropagation(); setCtx({ app: a, x: e.x, y: e.y }); }}
style={{ width: CELL, alignItems: 'center', gap: 10 }}>
<a.Icon size={ICON} />
@@ -82,22 +63,11 @@ export function Launchpad({ t, apps, onOpen, onClose, area = { x: 0, y: 0, w: sc
{list.length === 0 && <Text style={{ fontSize: 14, color: 'rgba(255,255,255,0.7)', textAlign: 'center' }}>{tr('shell.launchpad.empty')}</Text>}
</View>
</ScrollView>
- {drag && (
- <View style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: DROP_H, alignItems: 'center', justifyContent: 'center',
- backgroundColor: drag.y > area.y + area.h - DROP_H ? 'rgba(255,255,255,0.22)' : 'rgba(255,255,255,0.08)', pointerEvents: 'none' }}>
- <Text style={{ fontSize: 13, fontWeight: 600, color: '#fff' }}>{tr('shell.dock.dropHere')}</Text>
- </View>
- )}
- {drag && (
- <View style={{ position: 'absolute', left: drag.x - area.x - ICON / 2, top: drag.y - area.y - ICON / 2, opacity: 0.85, pointerEvents: 'none' }}>
- <drag.app.Icon size={ICON} />
- </View>
- )}
{ctx && (
<Menu x={ctx.x - area.x} y={ctx.y - area.y} onClose={() => setCtx(null)} items={[
{ label: tr('shell.dock.open'), onClick: () => open(ctx.app.id) },
- { label: tr('shell.dock.keep'), checked: dock.isPinned(ctx.app.id),
- onClick: () => (dock.isPinned(ctx.app.id) ? dock.unpin(ctx.app.id) : dock.pin(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)) }] : []),
]} />
)}
</View>
diff --git a/themes/default/components/Menu.jsx b/themes/default/components/Menu.jsx
index 3de0ca5..b7a9b24 100644
--- a/themes/default/components/Menu.jsx
+++ b/themes/default/components/Menu.jsx
@@ -1,33 +1,38 @@
-// Drop-down / context menu. Closes when clicking outside.
-import { View, Text, addListener, useTheme, screen, direction } from '@lordos/sdk';
+// 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 { useEffect, useRef, useState } from 'react';
+const ROW = 24, SEP_H = 9, HEAD_H = 22;
const inside = (inst, ref) => {
for (let n = inst; n; n = n.parent) if (n === ref?.current) return true;
return false;
};
+const rowH = (it) => (it === '-' ? SEP_H : it?.header ? HEAD_H : ROW);
+const selectable = (it) => it && it !== '-' && !it.header && !it.disabled;
-function Item({ item, onClose, onSub }) {
+function Item({ item, onClose, onSub, active, onHover }) {
const t = useTheme();
- const [hover, setHover] = useState(false);
const self = useRef(null);
if (item === '-') return <View style={{ height: 1, marginVertical: 4, marginHorizontal: 8, backgroundColor: t.separator }} />;
- if (item.header) return <Text style={{ height: 22, paddingHorizontal: 15, paddingTop: 5, fontSize: 11, fontWeight: 600, color: t.textDim }}>{item.header}</Text>;
+ if (item.header) return <Text style={{ height: HEAD_H, paddingHorizontal: 15, paddingTop: 5, fontSize: 11, fontWeight: 600, color: t.textDim }}>{item.header}</Text>;
const off = item.disabled;
+ const lit = active && !off;
const enter = () => {
- setHover(true);
+ onHover();
if (item.submenu && self.current) { const [x, y, w] = lord.getLayout(self.current.id); onSub({ items: item.submenu, x: x + w - 4, y: y - 5 }); }
else onSub(null);
};
return (
- <View ref={self} onMouseEnter={enter} onMouseLeave={() => setHover(false)}
+ <View ref={self} onMouseEnter={enter}
onClick={() => { if (!off && !item.submenu) { onClose(); item.onClick?.(); } }}
- style={{ height: 24, paddingHorizontal: 10, marginHorizontal: 5, borderRadius: 5, flexDirection: 'row', alignItems: 'center',
- backgroundColor: hover && !off ? t.accent : 'transparent' }}>
- <Text style={{ width: 16, fontSize: 12, color: hover && !off ? '#fff' : t.text }}>{item.checked ? '✓' : ''}</Text>
- <Text style={{ flex: 1, fontSize: 13, color: hover && !off ? '#fff' : off ? t.textDim : t.text, whiteSpace: 'nowrap' }}>{item.label}</Text>
- {item.hint ? <Text style={{ fontSize: 12, color: hover && !off ? '#fff' : t.textDim }}>{item.hint}</Text> : null}
- {item.submenu ? <Text style={{ fontSize: 12, color: hover ? '#fff' : t.textDim }}>›</Text> : null}
+ style={{ height: ROW, paddingHorizontal: 10, marginHorizontal: 5, borderRadius: 5, flexDirection: 'row', alignItems: 'center',
+ backgroundColor: lit ? t.accent : 'transparent' }}>
+ <Text style={{ width: 16, fontSize: 12, color: lit ? '#fff' : t.text }}>{item.checked ? '✓' : ''}</Text>
+ <Text style={{ flex: 1, fontSize: 13, color: lit ? '#fff' : off ? t.textDim : item.danger ? '#ff453a' : t.text, whiteSpace: 'nowrap' }}>{item.label}</Text>
+ {item.hint ? <Text style={{ fontSize: 12, color: lit ? '#fff' : t.textDim }}>{item.hint}</Text> : null}
+ {item.submenu ? <Text style={{ fontSize: 12, color: lit ? '#fff' : t.textDim }}>›</Text> : null}
</View>
);
}
@@ -37,7 +42,7 @@ function fitWidth(items, min) {
let w = min;
for (const it of items) {
if (it === '-' || !it?.label) continue;
- const need = 10 + 16 + lord.measureText(it.label, 13, 400) + (it.hint ? 18 + lord.measureText(it.hint, 12, 400) : 0) + 10 + 10;
+ const need = 10 + 16 + lord.measureText(it.label, 13, 400) + (it.hint ? 18 + lord.measureText(it.hint, 12, 400) : 0) + 10 + 10 + (it.submenu ? 14 : 0);
if (need > w) w = need;
}
return Math.min(Math.ceil(w), screen.width - 8);
@@ -46,37 +51,95 @@ function fitWidth(items, min) {
// above: y is the bottom edge of the menu (it opens upwards, as from the Dock).
// 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.
-export function Menu({ x, y, items, onClose, anchor, width: minWidth = 220, above = false, sub = false, nodeRef, side = null, centered = false }) {
+// keys: this menu has the keyboard (a submenu takes it while it is open; onBack gives it back).
+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);
const ref = nodeRef || own;
const subRef = useRef(null);
- const [subMenu, setSubMenu] = useState(null);
+ const scrollRef = useRef(null);
+ const [subMenu, setSubMenu] = useState(null); // { items, x, y, keys }
+ const [active, setActive] = useState(-1);
const width = fitWidth(items, minWidth);
// In Arabic/Hebrew x is the right edge: the menu opens to the left.
if (side ? side === 'left' : direction() === 'rtl') x -= width;
- // Always inside the screen.
- const height = items.reduce((h, it) => h + (it === '-' ? 9 : it?.header ? 22 : 24), 10);
+ // Always inside the screen; taller than it: it scrolls.
+ const full = items.reduce((h, it) => h + rowH(it), 10);
+ const height = Math.min(full, screen.height - 8);
if (above) y -= height;
else if (centered) y -= height / 2;
x = Math.max(4, Math.min(x, screen.width - width - 4));
y = Math.max(4, Math.min(y, screen.height - height - 4));
+ const scrolls = full > height;
+
+ // the keyboard
+ const st = useRef({});
+ st.current = { items, active, subMenu, onClose, onBack };
+ const rowTop = (i) => items.slice(0, i).reduce((h, it) => h + rowH(it), 5);
+ const openSub = (i) => {
+ const it = items[i];
+ if (!it?.submenu) return;
+ setSubMenu({ items: it.submenu, x: x + width - 4, y: y + rowTop(i) - 5 - (scrollRef.current?.offset?.() || 0), keys: true });
+ };
+ const reveal = (top) => {
+ const sv = scrollRef.current;
+ if (!sv) return;
+ const o = sv.offset();
+ if (top < o) sv.scrollTo(top - 5);
+ else if (top + ROW > o + height) sv.scrollTo(top + ROW - height + 5);
+ };
+ const move = (dir) => {
+ const { items: list, active: a } = st.current;
+ const n = list.length;
+ for (let k = 1; k <= n; k++) {
+ const i = ((a < 0 ? (dir > 0 ? -1 : 0) : a) + dir * k + n * 2) % n;
+ if (selectable(list[i])) { setActive(i); reveal(rowTop(i)); return; }
+ }
+ };
+ useEffect(() => {
+ if (subMenu?.keys) return undefined; // the submenu has the keyboard
+ const prev = focusToken();
+ const tok = {};
+ const onKey = (e) => {
+ const { items: list, active: a, onClose: close, onBack: back } = st.current;
+ const k = e.key;
+ if (k === 'ArrowDown') move(1);
+ else if (k === 'ArrowUp') move(-1);
+ else if (k === 'Home') { setActive(-1); setTimeout(() => move(1), 0); }
+ else if (k === 'End') { setActive(0); setTimeout(() => move(-1), 0); }
+ else if (k === 'ArrowRight' && list[a]?.submenu) openSub(a);
+ else if (k === 'ArrowLeft' && back) back();
+ else if ((k === 'Enter' || k === ' ' || k === 'Space') && selectable(list[a])) {
+ if (list[a].submenu) openSub(a);
+ else { close(); list[a].onClick?.(); }
+ }
+ };
+ takeTextFocus(tok, onKey);
+ return () => { releaseTextFocus(tok); if (!sub) restoreFocus(prev); };
+ }, [!!subMenu?.keys]);
useEffect(() => {
if (sub) return undefined; // the submenu is closed by its parent menu
const offPtr = addListener('pointerdown', (e) => { if (!inside(e.target, ref) && !inside(e.target, subRef) && !inside(e.target, anchor)) onClose(); });
const offKey = addListener('keydown', (e) => { if (e.key === 'Escape') onClose(); });
return () => { offPtr(); offKey(); };
}, [onClose]);
+ const rows = items.map((it, i) => (
+ <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 (
<>
<View ref={ref} style={{
- position: 'absolute', left: x, top: y, width, paddingVertical: 5, borderRadius: 9,
+ position: 'absolute', left: x, top: y, width, height: scrolls ? height : undefined, paddingVertical: scrolls ? 0 : 5, borderRadius: 9,
backgroundColor: t.panelBg, backdropFilter: `blur(${t.blur}px)`, border: `1px solid ${t.windowBorder}`,
- boxShadow: '0 12px 32px rgba(0,0,0,0.35)',
+ boxShadow: '0 12px 32px rgba(0,0,0,0.35)', overflow: 'hidden',
}}>
- {items.map((it, i) => <Item key={i} item={it} onClose={onClose} onSub={setSubMenu} />)}
+ {scrolls
+ ? <ScrollView scrollRef={scrollRef} style={{ height }}><View style={{ paddingVertical: 5 }}>{rows}</View></ScrollView>
+ : rows}
</View>
- {subMenu && <Menu sub nodeRef={subRef} x={subMenu.x} y={subMenu.y} items={subMenu.items} onClose={onClose} width={160} />}
+ {subMenu && <Menu sub nodeRef={subRef} x={subMenu.x} y={subMenu.y} items={subMenu.items} onClose={onClose} width={160}
+ onBack={subMenu.keys ? () => setSubMenu(null) : undefined} />}
</>
);
}
diff --git a/themes/default/index.jsx b/themes/default/index.jsx
index 7b106d6..10e28c0 100644
--- a/themes/default/index.jsx
+++ b/themes/default/index.jsx
@@ -3,7 +3,8 @@
// window frames. Apps come from apps/ through the SDK.
import {
startShell, View, Text, Image, screen, ThemeProvider, useSettings, useWindows, configureWindows, getApp, wm, addListener, t as tr,
- useLauncherApps, launchApp, useDockEntries, dockActivate, dockMenu, dock, dockPrefs,
+ useLauncherApps, launchApp, useDockEntries, dockActivate, dockMenu, dockPrefs, DOCK_LAUNCHER,
+ useTrash, openTrash, emptyTrash, trashMenu, ConfirmDialog,
DesktopWidgets, registerGestureActions, screenDisplays, mainDisplay, settings,
} from '@lordos/sdk';
import { apps } from '@lordos/apps';
@@ -17,7 +18,8 @@ import { ControlCenter } from './components/ControlCenter.jsx';
import { Menu } from './components/Menu.jsx';
const MENU_H = 28;
-const DOCK_ORDER = ['files', 'terminal', 'calculator', 'settings', 'about'];
+// Files is always first and the Trash always last (sdk/dockmodel.js); the app launcher follows Files.
+const DOCK_ORDER = ['files', DOCK_LAUNCHER, 'terminal', 'calculator', 'settings', 'about'];
// Area for windows: below the menu bar and without the Dock's side (unless it auto-hides),
// so maximized and new windows don't end up under the Dock.
@@ -40,7 +42,7 @@ configureWindows({ apps, workArea: areaFn, chrome: { w: 2, h: 43 } });
wm.open('files');
wm.open('about');
-// Pinned by default (the user changes the Dock with «Keep in Dock»: settings.dockPinned).
+// Pinned by default (the user changes the Dock by dragging and with «Keep in Dock»: settings.dockPinned).
const DOCK_DEFAULT = [...DOCK_ORDER, ...apps.filter((a) => a.dock && !DOCK_ORDER.includes(a.id)).map((a) => a.id)];
// Minimize effect: a window that was just minimized stays drawn for MIN_MS, shrinking towards the
@@ -72,6 +74,13 @@ function useMinimizing(windows) {
.filter((x) => x.win && x.win.minimized);
}
+// The Dock's right-click menus open toward the inside of the screen, next to the icon.
+function DockMenu({ pos, at, items, onClose }) {
+ return pos === 'bottom'
+ ? <Menu above side="right" x={at.x - 110} y={at.y} onClose={onClose} items={items} />
+ : <Menu centered side={pos === 'left' ? 'right' : 'left'} x={at.x} y={at.y} onClose={onClose} items={items} />;
+}
+
function App() {
const [s] = useSettings();
const t = makeTheme(s);
@@ -81,6 +90,9 @@ function App() {
const [control, setControl] = useState(null); // the display whose menu bar opened it
const [context, setContext] = useState(null);
const [dockCtx, setDockCtx] = useState(null);
+ const [trashCtx, setTrashCtx] = useState(null); // where the Trash's menu opens
+ const [askEmpty, setAskEmpty] = useState(false);
+ const trash = useTrash();
const launcherApps = useLauncherApps();
const dp = dockPrefs(s);
// the work area follows the Dock live (position, size, auto-hide, another screen)
@@ -111,9 +123,9 @@ function App() {
useEffect(() => registerGestureActions({ up: () => setLaunchpad(true), down: () => setLaunchpad(false) }), []);
const wallpaper = t.wallpapers.find((w) => w.id === s.wallpaper) || t.wallpapers[0];
- const launchpadEntry = { id: 'launchpad', name: tr('shell.menu.apps'), Icon: LaunchpadIcon };
- // Pinned and open apps; windows of the same app (Linux too) share a single icon.
- const entries = useDockEntries(DOCK_DEFAULT, { recents: dp.dockRecents ? 3 : 0 });
+ // Pinned and open apps; windows of the same app (Linux too) share a single icon. The app launcher
+ // is a Dock item too (it moves, but can't be removed).
+ const entries = useDockEntries(DOCK_DEFAULT, { recents: dp.dockRecents ? 3 : 0, launcher: { Icon: LaunchpadIcon, onOpen: () => setLaunchpad(true) } });
const byId = new Map(entries.map((e) => [e.id, e]));
return (
@@ -132,16 +144,19 @@ function App() {
<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))} />
))}
- <Dock t={t} items={[launchpadEntry, ...entries]} running={entries.filter((e) => e.running).map((e) => e.id)}
- onOpen={(id) => (id === 'launchpad' ? setLaunchpad(true) : byId.has(id) && dockActivate(byId.get(id)))}
+ <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 })}
- onDropApp={(id, index) => dock.pin(id, Math.max(0, index - 1))}
+ 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} area={main} />
- {dockCtx && (dp.dockPosition === 'bottom'
- ? <Menu above side="right" x={dockCtx.at.x - 110} y={dockCtx.at.y} onClose={() => setDockCtx(null)} items={dockMenu(byId.get(dockCtx.entry.id) || dockCtx.entry)} />
- : <Menu centered side={dp.dockPosition === 'left' ? 'right' : 'left'} x={dockCtx.at.x} y={dockCtx.at.y} onClose={() => setDockCtx(null)}
- items={dockMenu(byId.get(dockCtx.entry.id) || dockCtx.entry)} />)}
+ autohide={dp.dockAutohide} top={MENU_H} keepOpen={!!dockCtx || !!trashCtx} area={main} />
+ {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(); }} />
+ )}
{control && <ControlCenter t={t} top={MENU_H} area={control} onClose={() => setControl(null)} />}
{context && (
<Menu x={context.x} y={context.y} onClose={() => setContext(null)} items={[