mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Merge open app switcher ordering
# Conflicts: # app/ui/shell/shell.ts # docs/validation-launcher-layout.md
This commit is contained in:
5 files changed
+212
-8
No files matched your search
+49
-2
@@ -336,7 +336,7 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
||||
*/
|
||||
keepWindowFocus = false;
|
||||
|
||||
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void) {
|
||||
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void, title = "System") {
|
||||
// Aligned to the min-height window band (like the sidebar), wherever the
|
||||
// vertical position setting currently puts it; centered over the
|
||||
// application area, i.e. the part of the screen beside a side strip
|
||||
@@ -344,7 +344,7 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
||||
// the strip overlays).
|
||||
const width = 272;
|
||||
const area = appViewportRect("min");
|
||||
super("System", items, {
|
||||
super(title, items, {
|
||||
x: area.x + (((area.width - width) / 2) | 0),
|
||||
y: area.y + 8,
|
||||
width,
|
||||
@@ -1336,6 +1336,43 @@ class Shell {
|
||||
return hidden ? this.windows.filter((window) => window !== hidden) : this.windows;
|
||||
}
|
||||
|
||||
/** Reorder visible app windows while keeping pinned/temporary slots and foreground stable. */
|
||||
private moveSwitcherWindow(windowId: string, targetId: string): boolean {
|
||||
const movable = this.switcherWindows().filter(window => window.closeable);
|
||||
const from = movable.findIndex(window => window.windowId === windowId);
|
||||
const to = movable.findIndex(window => window.windowId === targetId);
|
||||
if (from < 0 || to < 0 || from === to) return false;
|
||||
const foreground = this.foregroundWindow();
|
||||
const ids = new Set(movable.map(window => window.windowId));
|
||||
const [moved] = movable.splice(from, 1);
|
||||
movable.splice(to, 0, moved!);
|
||||
let index = 0;
|
||||
this.windows = this.windows.map(window => ids.has(window.windowId) ? movable[index++]! : window);
|
||||
if (foreground) this.selectedIndex = this.windows.indexOf(foreground);
|
||||
this.config.onWindowsChanged?.();
|
||||
this.config.requestShellRender();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Capture window IDs: changing titles or closing windows cannot redirect a pending move. */
|
||||
private openSwitcherMoveMenu(windowId: string): void {
|
||||
if (!this.screenOn || this.activeVoiceLayer || !this.stack.isAtBase()) return;
|
||||
const movable = this.switcherWindows().filter(window => window.closeable);
|
||||
const selected = movable.findIndex(window => window.windowId === windowId);
|
||||
if (selected < 0 || movable.length < 2) return;
|
||||
const items: MenuItem[] = movable.map((window, index) => ({
|
||||
label: `${index + 1}. ${window.title}`,
|
||||
onSelect: ctx => {
|
||||
ctx.stack.pop();
|
||||
this.moveSwitcherWindow(windowId, window.windowId);
|
||||
},
|
||||
}));
|
||||
const layer = new ShellOverlayMenuLayer(items, undefined, () => this.yieldFocusToSidebar(), "Move app to position");
|
||||
layer.selectItem(selected);
|
||||
this.stack.push(layer);
|
||||
this.config.requestShellRender();
|
||||
}
|
||||
|
||||
/**
|
||||
* The status bar items the switcher's selection can move onto, in order:
|
||||
* with a bottom switcher (the selection reaches them past the last
|
||||
@@ -2022,6 +2059,16 @@ class Shell {
|
||||
},
|
||||
}));
|
||||
}
|
||||
if (foreground.closeable && this.switcherWindows().filter(window => window.closeable).length > 1) {
|
||||
items.push({
|
||||
label: "Move in app switcher",
|
||||
description: "Choose this open window's position in the app switcher.",
|
||||
onSelect: ctx => {
|
||||
ctx.stack.pop();
|
||||
this.openSwitcherMoveMenu(foreground.windowId);
|
||||
},
|
||||
});
|
||||
}
|
||||
if (brightnessSetting.get() !== "auto") {
|
||||
items.push({
|
||||
label: "Brightness",
|
||||
|
||||
@@ -13,3 +13,13 @@ Hardware validation remains pending: ring row/item selection, watch directional
|
||||
Independent branch validation: 1073 JavaScript tests passed, 2 skipped, 0 failed; TypeScript and changed-source lint passed.
|
||||
|
||||
Combined validation on build/all-features: 1117 JavaScript tests passed, 2 skipped, 0 failed; TypeScript and changed-source lint passed. The launcher test fixture loads the real transcription-language data when the independent Whisper feature is present.
|
||||
|
||||
## Open app switcher order
|
||||
|
||||
The system menu adds Move in app switcher when the selected window can be moved and at least two app windows are open. Its numbered position picker shows the currently open app windows in switcher order, preselects the current position, and uses window IDs internally to distinguish windows with identical titles. Choose a destination to move there, or double tap to cancel.
|
||||
|
||||
This arranges existing open windows independently of the launcher's Alphabetical/Custom preference. Pinned windows keep their slots and temporary status-item windows do not participate. Reordering retains the same foreground window, attention state and most-recently-used history; closing a window still returns to the most recently viewed one. New windows append as before. Open-window order lasts for those windows' lifetime; reopening the app does not restore previously closed windows or write ephemeral window IDs to settings.
|
||||
|
||||
Software tests cover both directions, menu integration, duplicate titles, captured source IDs, cancellation, removed source/destination, temporary and pinned windows, appending/replacing windows, foreground identity and MRU close behavior. Hardware checks remain pending for ring/watch navigation in the position picker and left/right/bottom/popup switcher placements.
|
||||
|
||||
Independent branch after adding open-window ordering: 1080 JavaScript tests passed, 2 skipped; TypeScript and changed-source lint passed.
|
||||
@@ -9,7 +9,7 @@ function fixture(options = {}) {
|
||||
const source = ts.createSourceFile('shell.ts', fs.readFileSync(path.join(__dirname, '../app/ui/shell/shell.ts'), 'utf8'), ts.ScriptTarget.Latest, true);
|
||||
const shellClass = source.statements.find(node => ts.isClassDeclaration(node) && node.name.text === 'Shell');
|
||||
const names = new Set(['routeInput', 'openEscapeMenu', 'closeAllWindows', 'closeWindow', 'removeWindow',
|
||||
'foregroundWindow', 'noteWindowVisible', 'mostRecentWindowIndex', 'yieldFocusToSidebar', 'applyScreenTimeout']);
|
||||
'foregroundWindow', 'switcherWindows', 'noteWindowVisible', 'mostRecentWindowIndex', 'yieldFocusToSidebar', 'applyScreenTimeout']);
|
||||
const methods = shellClass.members.filter(node => names.has(node.name?.getText(source)));
|
||||
assert.equal(methods.length, names.size);
|
||||
const overlay = source.statements.find(node => ts.isClassDeclaration(node) && node.name.text === 'ShellOverlayMenuLayer');
|
||||
|
||||
@@ -131,11 +131,7 @@ test('system menu hides brightness in Auto and opens its picker between Voice in
|
||||
opened = shell.stack.layers.at(-1);
|
||||
assert.deepEqual(Array.from(opened.items, (item) => item.label),
|
||||
['Close current app', 'Focus app switcher', 'Voice input', 'Close all apps', 'Enter full screen', 'Keep screen awake', 'Brightness', 'Debug']);
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'scroll-down' }));
|
||||
opened.selectItem(opened.items.findIndex(item => item.label === 'Brightness'));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'click', source: 'ring' }));
|
||||
assert.ok(shell.stack.topMatches((layer) => layer instanceof f.picker.BrightnessPickerLayer));
|
||||
await shell.stack.handleInput(gestures.makeInputEvent({ type: 'double-click', source: 'ring' }));
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
|
||||
function fixture() {
|
||||
const source = ts.createSourceFile('shell.ts', fs.readFileSync('app/ui/shell/shell.ts', 'utf8'), ts.ScriptTarget.Latest, true);
|
||||
const cls = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'Shell');
|
||||
const names = new Set(['moveSwitcherWindow', 'openSwitcherMoveMenu', 'switcherWindows', 'foregroundWindow',
|
||||
'openEscapeMenu', 'registerWindow', 'removeWindow', 'noteWindowVisible', 'mostRecentWindowIndex']);
|
||||
const methods = cls.members.filter(n => names.has(n.name?.getText(source)));
|
||||
assert.equal(methods.length, names.size);
|
||||
const overlay = source.statements.find(n => ts.isClassDeclaration(n) && n.name.text === 'ShellOverlayMenuLayer');
|
||||
class MenuLayer {
|
||||
constructor(title, items) { this.title = title; this.items = items; }
|
||||
selectItem(index) { this.selectedIndex = index; }
|
||||
}
|
||||
const context = { exports: {}, MenuLayer, appViewportRect: () => ({ x: 0, y: 0, width: 576 }),
|
||||
CONTEXT_MENU_DIM: 0.5, brightnessSetting: { get: () => 'auto' }, makeInputEvent: e => e,
|
||||
appFullscreenSetting: () => ({ get: () => false }), appKeepAwakeSetting: () => ({ label: 'Keep screen awake' }),
|
||||
toggleSettingMenuItem: setting => ({ label: setting.label }),
|
||||
swapMenuGesturesSetting: { get: () => false }, GESTURE_SHORT_THEN_LONG_PRESS: 'tap-hold',
|
||||
};
|
||||
vm.runInNewContext(ts.transpileModule(`${overlay.getText(source)}\nexport class Shell { ${methods.map(n => n.getText(source)).join('\n')} }`, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
const s = new context.exports.Shell();
|
||||
const foregroundCalls = [], closed = [], input = [];
|
||||
const window = (windowId, appId = windowId, closeable = true, title = windowId) => ({
|
||||
windowId, appId, closeable, title, requestRender() {},
|
||||
setForeground: value => foregroundCalls.push([windowId, value]),
|
||||
close: () => closed.push(windowId), handleInput: event => input.push([windowId, event.type]),
|
||||
});
|
||||
const launcher = window('launcher', 'launcher', false, 'Apps');
|
||||
const first = window('terminal:one', 'terminal', true, 'Terminal');
|
||||
const second = window('terminal:two', 'terminal', true, 'Terminal');
|
||||
const third = window('calendar', 'calendar', true, 'Calendar');
|
||||
const layers = [];
|
||||
let changed = 0, renders = 0;
|
||||
Object.assign(s, {
|
||||
windows: [launcher, first, second, third], selectedIndex: 1, focus: 'sidebar', screenOn: true,
|
||||
attention: new Map(), mruWindowIds: ['terminal:one', 'calendar', 'terminal:two', 'launcher'],
|
||||
config: { voiceInputEnabled: false, onWindowsChanged: () => changed++, requestShellRender: () => renders++ },
|
||||
yieldFocusToSidebar() { this.focus = 'sidebar'; },
|
||||
stack: { isAtBase: () => !layers.length, push: layer => layers.push(layer),
|
||||
pop: () => layers.pop()?.onRemoved?.() },
|
||||
});
|
||||
return { s, launcher, first, second, third, window, foregroundCalls, closed, input,
|
||||
ids: () => Array.from(s.windows, w => w.windowId), changed: () => changed, renders: () => renders,
|
||||
menu: () => layers.at(-1), choose(label) {
|
||||
const item = layers.at(-1).items.find(item => item.label === label);
|
||||
assert.ok(item, label); item.onSelect({ stack: s.stack });
|
||||
} };
|
||||
}
|
||||
|
||||
test('moving open windows in either direction keeps foreground, MRU and pinned launcher stable', () => {
|
||||
const h = fixture(); h.s.focus = 'window';
|
||||
const mru = Array.from(h.s.mruWindowIds);
|
||||
assert.equal(h.s.moveSwitcherWindow(h.first.windowId, h.third.windowId), true);
|
||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:two', 'calendar', 'terminal:one']);
|
||||
assert.equal(h.s.foregroundWindow(), h.first);
|
||||
assert.equal(h.s.selectedIndex, 3);
|
||||
assert.equal(h.s.focus, 'window');
|
||||
assert.deepEqual(Array.from(h.s.mruWindowIds), mru);
|
||||
assert.deepEqual(h.foregroundCalls, []);
|
||||
assert.deepEqual(h.closed, []);
|
||||
assert.equal(h.changed(), 1); assert.equal(h.renders(), 1);
|
||||
assert.equal(h.s.moveSwitcherWindow(h.first.windowId, h.second.windowId), true);
|
||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:one', 'terminal:two', 'calendar']);
|
||||
assert.equal(h.s.foregroundWindow(), h.first);
|
||||
});
|
||||
|
||||
test('system menu opens a numbered position picker and moves the captured window, even with duplicate titles', () => {
|
||||
const h = fixture();
|
||||
h.s.openEscapeMenu(); h.choose('Move in app switcher');
|
||||
assert.equal(h.menu().title, 'Move app to position');
|
||||
assert.deepEqual(Array.from(h.menu().items, item => item.label), ['1. Terminal', '2. Terminal', '3. Calendar']);
|
||||
assert.equal(h.menu().selectedIndex, 0);
|
||||
// A delayed focus change must not move a different app than the menu captured.
|
||||
h.s.selectedIndex = 2;
|
||||
h.choose('3. Calendar');
|
||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:two', 'calendar', 'terminal:one']);
|
||||
assert.equal(h.s.foregroundWindow(), h.second);
|
||||
assert.equal(h.menu(), undefined);
|
||||
assert.equal(h.s.focus, 'sidebar');
|
||||
});
|
||||
|
||||
test('cancelling the picker and choosing the current slot leave ordering unchanged', () => {
|
||||
const h = fixture(); const before = h.ids();
|
||||
h.s.openSwitcherMoveMenu(h.first.windowId); h.s.stack.pop();
|
||||
assert.deepEqual(h.ids(), before);
|
||||
h.s.openSwitcherMoveMenu(h.first.windowId); h.choose('1. Terminal');
|
||||
assert.deepEqual(h.ids(), before);
|
||||
assert.equal(h.changed(), 0);
|
||||
});
|
||||
|
||||
test('closing the pending source or destination prevents a stale move from affecting another window', () => {
|
||||
for (const removed of ['terminal:one', 'calendar']) {
|
||||
const h = fixture(); h.s.openSwitcherMoveMenu(h.first.windowId);
|
||||
h.s.removeWindow(removed);
|
||||
const afterClose = h.ids();
|
||||
h.choose('3. Calendar');
|
||||
assert.deepEqual(h.ids(), afterClose);
|
||||
assert.equal(h.menu(), undefined);
|
||||
}
|
||||
});
|
||||
|
||||
test('temporary status windows and pinned slots stay fixed, including selected status foreground', () => {
|
||||
const h = fixture();
|
||||
const hidden = h.window('notifications:temporary');
|
||||
const pinned = h.window('another-pinned', 'pinned', false);
|
||||
h.s.windows.splice(2, 0, hidden, pinned);
|
||||
h.s.selectedIndex = 2;
|
||||
h.s.selectedStatus = { transient: true, host: hidden, item: { key: 'notification' } };
|
||||
assert.equal(h.s.moveSwitcherWindow(hidden.windowId, h.first.windowId), false);
|
||||
h.s.moveSwitcherWindow(h.first.windowId, h.third.windowId);
|
||||
assert.deepEqual(h.ids(), ['launcher', 'terminal:two', 'notifications:temporary', 'another-pinned', 'calendar', 'terminal:one']);
|
||||
assert.equal(h.s.foregroundWindow(), hidden);
|
||||
assert.equal(h.s.selectedStatus.host, hidden);
|
||||
h.s.openSwitcherMoveMenu(h.first.windowId);
|
||||
assert.deepEqual(Array.from(h.menu().items, item => item.label), ['1. Terminal', '2. Calendar', '3. Terminal']);
|
||||
});
|
||||
|
||||
test('new windows append, replacements keep their slot, and closing uses unchanged recency after a move', () => {
|
||||
const h = fixture(); h.s.moveSwitcherWindow(h.first.windowId, h.third.windowId);
|
||||
h.s.registerWindow(h.window('new'));
|
||||
assert.equal(h.ids().at(-1), 'new');
|
||||
const replacement = h.window(h.second.windowId, 'terminal', true, 'Renamed session');
|
||||
h.s.registerWindow(replacement);
|
||||
assert.equal(h.s.windows[1], replacement);
|
||||
assert.equal(h.s.foregroundWindow(), h.first);
|
||||
h.s.removeWindow(h.first.windowId);
|
||||
assert.equal(h.s.foregroundWindow(), h.third);
|
||||
});
|
||||
|
||||
test('pinned, missing, single-window, screen-off and overlay cases cannot start a reorder', () => {
|
||||
const h = fixture(); const before = h.ids();
|
||||
for (const [from, to] of [['launcher', 'calendar'], ['calendar', 'launcher'], ['missing', 'calendar']]) {
|
||||
assert.equal(h.s.moveSwitcherWindow(from, to), false);
|
||||
}
|
||||
h.s.openSwitcherMoveMenu('missing'); assert.equal(h.menu(), undefined);
|
||||
h.s.screenOn = false; h.s.openSwitcherMoveMenu(h.first.windowId); assert.equal(h.menu(), undefined);
|
||||
h.s.screenOn = true; h.s.stack.push({});
|
||||
h.s.openSwitcherMoveMenu(h.first.windowId); assert.equal(h.menu().title, undefined); h.s.stack.pop();
|
||||
assert.deepEqual(h.ids(), before);
|
||||
h.s.selectedIndex = 0; h.s.openEscapeMenu();
|
||||
assert.ok(!h.menu().items.some(item => item.label === 'Move in app switcher')); h.s.stack.pop();
|
||||
h.s.windows = [h.launcher, h.first]; h.s.selectedIndex = 1; h.s.openEscapeMenu();
|
||||
assert.ok(!h.menu().items.some(item => item.label === 'Move in app switcher'));
|
||||
});
|
||||
Reference in new issue
Block a user