Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(shortcuts): merge window summon and close into one toggle key

vastsae0c460123d6f
diff --git a/apps/desktop/electron/main/application-menu.ts b/apps/desktop/electron/main/application-menu.ts
index 3c3857b59..e99372a89 100644
--- a/apps/desktop/electron/main/application-menu.ts
+++ b/apps/desktop/electron/main/application-menu.ts
@@ -117,24 +117,18 @@ export function buildApplicationMenuTemplate({
dispatch,
accelerator("openSettings"),
),
- // Symmetrical counterpart to closeWindow: bring a hidden
- // or minimized-to-tray main window back into focus
- // (D384). The label is locale-resolved at render time.
- {
- label: labels.menu.summonWindow,
- accelerator: accelerator("summonWindow"),
- click: () => dispatchNative("restoreMainWindow"),
- },
] satisfies MenuItemConstructorOptions[])
: []),
{ type: "separator" },
- nativeAction(
- labels.menu.closeWindow,
- "close",
- "close",
- accelerator("closeWindow"),
- dispatchNative,
- ),
+ // One window-visibility key (D438): `Mod+W` hides the window the user
+ // is looking at and brings a hidden or tray-minimized window back. The
+ // retired `Mod+Shift+W` summon item is gone; the label is
+ // locale-resolved at render time.
+ {
+ label: labels.menu.toggleWindow,
+ accelerator: accelerator("toggleWindow"),
+ click: () => dispatchNative("toggleMainWindow"),
+ },
],
},
{
diff --git a/apps/desktop/electron/main/bootstrap/app-lifecycle.ts b/apps/desktop/electron/main/bootstrap/app-lifecycle.ts
index fb4bdbf02..685ef4a99 100644
--- a/apps/desktop/electron/main/bootstrap/app-lifecycle.ts
+++ b/apps/desktop/electron/main/bootstrap/app-lifecycle.ts
@@ -6,6 +6,7 @@ import {
APP_NAME,
IPC,
isThemeColorScheme,
+ migrateKeybindingOverrides,
type AppMenuCommand,
type CloseBehavior,
type KeybindingOverrides,
@@ -14,6 +15,7 @@ import {
import { catalogs, resolveLocale } from "@pi-desktop/i18n";
import { installApplicationMenu } from "../application-menu";
import { createWindow, type WindowLifecycleState } from "./window";
+import { windowToggleAction } from "./window-visibility";
import type { BrowserPane } from "../browser-view";
import type { Logger } from "../logger";
import type { PluginRuntime } from "../plugin-runtime";
@@ -64,7 +66,7 @@ export type ApplicationLifecycleDependencies = {
logger: Pick<Logger, "app">;
refreshReleaseNotes: () => void;
applyPluginLauncherShortcut: (keybindings?: KeybindingOverrides) => void;
- applySummonWindowShortcut: (keybindings?: KeybindingOverrides) => void;
+ applyToggleWindowShortcut: (keybindings?: KeybindingOverrides) => void;
broadcastPluginPanelEvent: (event: string, payload: unknown) => void;
getHost: () => HostProcess | null;
};
@@ -97,7 +99,7 @@ export function createApplicationLifecycle({
logger,
refreshReleaseNotes,
applyPluginLauncherShortcut,
- applySummonWindowShortcut,
+ applyToggleWindowShortcut,
broadcastPluginPanelEvent,
getHost,
}: ApplicationLifecycleDependencies) {
@@ -153,6 +155,21 @@ export function createApplicationLifecycle({
});
}
+ /**
+ * One press of the merged window shortcut (D438): hide the window the user is
+ * looking at, otherwise bring it back. Hiding is `Window.hide()` and never
+ * the close path, so it raises no close-behaviour prompt, destroys no window,
+ * and quits nothing — the tray (or the same key again) is the way back.
+ */
+ function toggleMainWindow() {
+ const window = state.mainWindow;
+ if (window && !window.isDestroyed() && windowToggleAction(window) === "hide") {
+ window.hide();
+ return;
+ }
+ restoreMainWindow();
+ }
+
function updateTrayMenu(locale = app.getLocale()) {
if (!state.tray) return;
const labels = catalogs[resolveLocale(locale)].tray;
@@ -307,8 +324,9 @@ export function createApplicationLifecycle({
action: NativeMenuAction,
target: BrowserWindow | null = state.mainWindow,
) {
- if (action === "restoreMainWindow") {
- restoreMainWindow();
+ if (action === "restoreMainWindow" || action === "toggleMainWindow") {
+ if (action === "restoreMainWindow") restoreMainWindow();
+ else toggleMainWindow();
const window = state.mainWindow;
return {
maximized: Boolean(window && !window.isDestroyed() && window.isMaximized()),
@@ -472,12 +490,16 @@ export function createApplicationLifecycle({
.catch(() => {});
}
applyAppThemePreference(settings?.theme);
- const keybindings =
+ // Persisted keybindings can still carry the retired window ids (D438); the
+ // main process is the only reader when the window never opens, so it folds
+ // them itself instead of relying on a renderer write-back.
+ const keybindings = migrateKeybindingOverrides(
settings?.keybindings && typeof settings.keybindings === "object"
? (settings.keybindings as KeybindingOverrides)
- : undefined;
+ : undefined,
+ );
applyPluginLauncherShortcut(keybindings);
- applySummonWindowShortcut(keybindings);
+ applyToggleWindowShortcut(keybindings);
const devMode = settings?.developerMode === true;
const signature = JSON.stringify({ locale, keybindings, devMode });
if (appState.appliedMenuSettings === signature) return;
@@ -542,6 +564,7 @@ export function createApplicationLifecycle({
applyDevelopmentBranding,
hasVisibleWindow,
restoreMainWindow,
+ toggleMainWindow,
updateTrayMenu,
createTray,
resetMenuRendererReady,
diff --git a/apps/desktop/electron/main/bootstrap/launcher.ts b/apps/desktop/electron/main/bootstrap/launcher.ts
index 8e0448748..3fb8a1213 100644
--- a/apps/desktop/electron/main/bootstrap/launcher.ts
+++ b/apps/desktop/electron/main/bootstrap/launcher.ts
@@ -16,7 +16,7 @@ import type { WindowLifecycleState } from "./window";
export type LauncherState = {
creationPromise: Promise<BrowserWindow> | null;
pluginLauncherAccelerator: string | null;
- summonWindowAccelerator: string | null;
+ toggleWindowAccelerator: string | null;
};
export type LauncherDependencies = {
@@ -26,7 +26,7 @@ export type LauncherDependencies = {
getHost: () => HostProcess | null;
logger: Pick<Logger, "app">;
safeOpenExternal: (rawUrl: unknown) => Promise<void>;
- restoreMainWindow: () => void;
+ toggleMainWindow: () => void;
};
/**
@@ -54,7 +54,7 @@ export function createLauncher({
getHost,
logger,
safeOpenExternal,
- restoreMainWindow,
+ toggleMainWindow,
}: LauncherDependencies) {
const PLUGIN_LAUNCHER_WIDTH = 620;
@@ -256,13 +256,14 @@ export function createLauncher({
}
/**
- * Register the summon-window shortcut (D384). The default `Mod+Shift+W`
- * brings a hidden/minimized-to-tray window back into focus; this is the
- * symmetrical counterpart to `closeWindow` (`Mod+W`).
+ * Register the merged window toggle (D438). The default `Mod+W` runs the same
+ * toggle the menu item and the renderer run: it hides the window the user is
+ * looking at, or brings a hidden/minimized-to-tray window back into focus.
+ * The retired `Mod+Shift+W` summon binding is no longer registered.
*/
- function applySummonWindowShortcut(keybindings?: KeybindingOverrides) {
+ function applyToggleWindowShortcut(keybindings?: KeybindingOverrides) {
const shortcut = KEYBOARD_SHORTCUTS.find(
- (candidate) => candidate.id === "summonWindow",
+ (candidate) => candidate.id === "toggleWindow",
);
if (!shortcut || !app.isReady()) return;
const platform: ShortcutPlatform =
@@ -273,21 +274,21 @@ export function createLauncher({
: "linux";
const binding = resolveKeybinding(shortcut, keybindings, platform);
const accelerator = keybindingToElectronAccelerator(binding, platform);
- recordHostGlobalBinding("summonWindow", binding);
+ recordHostGlobalBinding("toggleWindow", binding);
- if (launcherState.summonWindowAccelerator && launcherState.summonWindowAccelerator !== accelerator) {
- globalShortcut.unregister(launcherState.summonWindowAccelerator);
- launcherState.summonWindowAccelerator = null;
+ if (launcherState.toggleWindowAccelerator && launcherState.toggleWindowAccelerator !== accelerator) {
+ globalShortcut.unregister(launcherState.toggleWindowAccelerator);
+ launcherState.toggleWindowAccelerator = null;
}
- if (!accelerator || accelerator === launcherState.summonWindowAccelerator) return;
+ if (!accelerator || accelerator === launcherState.toggleWindowAccelerator) return;
const registered = globalShortcut.register(accelerator, () => {
- restoreMainWindow();
+ toggleMainWindow();
});
if (registered) {
- launcherState.summonWindowAccelerator = accelerator;
+ launcherState.toggleWindowAccelerator = accelerator;
} else {
- logger.app("diagnostics", "warn", "summon window shortcut unavailable", {
+ logger.app("diagnostics", "warn", "window toggle shortcut unavailable", {
data: { accelerator, platform: process.platform },
});
}
@@ -301,6 +302,6 @@ export function createLauncher({
showPluginLauncher,
togglePluginLauncher,
applyPluginLauncherShortcut,
- applySummonWindowShortcut,
+ applyToggleWindowShortcut,
};
}
diff --git a/apps/desktop/electron/main/bootstrap/shutdown.ts b/apps/desktop/electron/main/bootstrap/shutdown.ts
index d39df9f80..14e7bb944 100644
--- a/apps/desktop/electron/main/bootstrap/shutdown.ts
+++ b/apps/desktop/electron/main/bootstrap/shutdown.ts
@@ -23,7 +23,7 @@ export type ShutdownState = {
closeBehavior: CloseBehavior;
tray: Tray | null;
pluginLauncherAccelerator: string | null;
- summonWindowAccelerator: string | null;
+ toggleWindowAccelerator: string | null;
};
export type ShutdownDependencies = {
@@ -120,9 +120,9 @@ export function registerShutdownHandlers({
globalShortcut.unregister(state.pluginLauncherAccelerator);
state.pluginLauncherAccelerator = null;
}
- if (state.summonWindowAccelerator) {
- globalShortcut.unregister(state.summonWindowAccelerator);
- state.summonWindowAccelerator = null;
+ if (state.toggleWindowAccelerator) {
+ globalShortcut.unregister(state.toggleWindowAccelerator);
+ state.toggleWindowAccelerator = null;
}
state.shutdownPromise = (async () => {
// Replies still streaming are stopped through the sidecar first so their
diff --git a/apps/desktop/electron/main/bootstrap/startup.ts b/apps/desktop/electron/main/bootstrap/startup.ts
index d620746c8..004348e73 100644
--- a/apps/desktop/electron/main/bootstrap/startup.ts
+++ b/apps/desktop/electron/main/bootstrap/startup.ts
@@ -78,7 +78,7 @@ export type StartupDependencies = {
} | null) => void;
applyDeveloperMode: (settings?: { developerMode?: unknown } | null) => void;
applyPluginLauncherShortcut: (keybindings?: KeybindingOverrides) => void;
- applySummonWindowShortcut: (keybindings?: KeybindingOverrides) => void;
+ applyToggleWindowShortcut: (keybindings?: KeybindingOverrides) => void;
ensureWindow: () => Promise<boolean>;
bootHostStatus: (bootError: unknown) => unknown;
flushPendingApplicationMenuCommands: () => void;
@@ -121,7 +121,7 @@ export function registerApplicationStartup(deps: StartupDependencies): void {
applyApplicationMenuSettings,
applyDeveloperMode,
applyPluginLauncherShortcut,
- applySummonWindowShortcut,
+ applyToggleWindowShortcut,
ensureWindow,
bootHostStatus,
flushPendingApplicationMenuCommands,
@@ -221,12 +221,13 @@ export function registerApplicationStartup(deps: StartupDependencies): void {
// Keep the OS-locale menu until settings can be read again, while
// retaining the historical default launcher fallback for this failure.
applyPluginLauncherShortcut();
- applySummonWindowShortcut();
+ applyPluginLauncherShortcut();
+ applyToggleWindowShortcut();
}
} else {
// If the backend never started, retain the default focused/global path.
applyPluginLauncherShortcut();
- applySummonWindowShortcut();
+ applyToggleWindowShortcut();
}
await ensureWindow();
if (process.env.PI_DESKTOP_MCP_CONTROL === "1") {
diff --git a/apps/desktop/electron/main/bootstrap/window-visibility.ts b/apps/desktop/electron/main/bootstrap/window-visibility.ts
new file mode 100644
index 000000000..43caf635b
--- /dev/null
+++ b/apps/desktop/electron/main/bootstrap/window-visibility.ts
@@ -0,0 +1,25 @@
+/**
+ * The one decision behind the window toggle (D438): the merged
+ * `toggleWindow` shortcut and its menu item either hide the window the user is
+ * looking at, or bring the window back.
+ *
+ * Split out of `bootstrap/app-lifecycle.ts` because the choice is the rule; the
+ * lifecycle module only supplies the live `BrowserWindow`. The counterpart of
+ * `hide` is deliberately `Window.hide()` rather than `Window.close()`: hiding
+ * must not enter the close path, which on Windows/Linux can raise the
+ * close-behaviour prompt and can quit the app.
+ */
+export type WindowVisibilitySnapshot = {
+ isVisible(): boolean;
+ isMinimized(): boolean;
+ isFocused(): boolean;
+};
+
+/** `hide` for a window the user is looking at, `show` for anything else. */
+export function windowToggleAction(
+ window: WindowVisibilitySnapshot,
+): "hide" | "show" {
+ return window.isVisible() && !window.isMinimized() && window.isFocused()
+ ? "hide"
+ : "show";
+}
diff --git a/apps/desktop/electron/main/index.ts b/apps/desktop/electron/main/index.ts
index 41cc3aa4b..36c9085e4 100644
--- a/apps/desktop/electron/main/index.ts
+++ b/apps/desktop/electron/main/index.ts
@@ -221,7 +221,7 @@ let pluginLauncherWindow: BrowserWindow | null = null;
let pluginLauncherCreationPromise: Promise<BrowserWindow> | null = null;
let pluginLauncherAccelerator: string | null = null;
let pluginLauncherBinding: string | null = null;
-let summonWindowAccelerator: string | null = null;
+let toggleWindowAccelerator: string | null = null;
const launcherState: LauncherState = {
get creationPromise() {
return pluginLauncherCreationPromise;
@@ -235,11 +235,11 @@ const launcherState: LauncherState = {
set pluginLauncherAccelerator(value) {
pluginLauncherAccelerator = value;
},
- get summonWindowAccelerator() {
- return summonWindowAccelerator;
+ get toggleWindowAccelerator() {
+ return toggleWindowAccelerator;
},
- set summonWindowAccelerator(value) {
- summonWindowAccelerator = value;
+ set toggleWindowAccelerator(value) {
+ toggleWindowAccelerator = value;
},
};
let windowCreationPromise: Promise<void> | null = null;
@@ -474,10 +474,10 @@ const applyPluginLauncherShortcutForLifecycle = (
) => {
launcherRuntime?.applyPluginLauncherShortcut(keybindings);
};
-const applySummonWindowShortcutForLifecycle = (
+const applyToggleWindowShortcutForLifecycle = (
keybindings?: KeybindingOverrides,
) => {
- launcherRuntime?.applySummonWindowShortcut(keybindings);
+ launcherRuntime?.applyToggleWindowShortcut(keybindings);
};
const applyCloseBehaviorForLifecycle = (next: CloseBehavior) => {
if (!closeBehaviorRuntime) {
@@ -928,7 +928,7 @@ applicationLifecycle = createApplicationLifecycle({
logger,
refreshReleaseNotes: () => updater.refreshReleaseNotes(),
applyPluginLauncherShortcut: applyPluginLauncherShortcutForLifecycle,
- applySummonWindowShortcut: applySummonWindowShortcutForLifecycle,
+ applyToggleWindowShortcut: applyToggleWindowShortcutForLifecycle,
broadcastPluginPanelEvent,
getHost: () => host,
});
@@ -936,6 +936,7 @@ const {
applyDevelopmentBranding,
hasVisibleWindow,
restoreMainWindow,
+ toggleMainWindow,
updateTrayMenu,
createTray,
resetMenuRendererReady,
@@ -982,7 +983,7 @@ const createdLauncher = createLauncher({
getHost: () => host,
logger,
safeOpenExternal,
- restoreMainWindow,
+ toggleMainWindow,
});
launcherRuntime = createdLauncher;
const {
@@ -990,7 +991,7 @@ const {
showPluginLauncher,
togglePluginLauncher,
applyPluginLauncherShortcut,
- applySummonWindowShortcut,
+ applyToggleWindowShortcut,
} = createdLauncher;
/** sessionId → open host turn id, for turn bookkeeping across agent events. */
@@ -1404,7 +1405,7 @@ registerApplicationStartup({
applyApplicationMenuSettings,
applyDeveloperMode,
applyPluginLauncherShortcut,
- applySummonWindowShortcut,
+ applyToggleWindowShortcut,
ensureWindow,
bootHostStatus,
flushPendingApplicationMenuCommands,
@@ -1459,11 +1460,11 @@ const shutdownState: ShutdownState = {
set pluginLauncherAccelerator(value) {
pluginLauncherAccelerator = value;
},
- get summonWindowAccelerator() {
- return summonWindowAccelerator;
+ get toggleWindowAccelerator() {
+ return toggleWindowAccelerator;
},
- set summonWindowAccelerator(value) {
- summonWindowAccelerator = value;
+ set toggleWindowAccelerator(value) {
+ toggleWindowAccelerator = value;
},
};
diff --git a/apps/desktop/electron/main/plugin-shortcut-registry.ts b/apps/desktop/electron/main/plugin-shortcut-registry.ts
index 6c7b6a4d7..0cd5b8985 100644
--- a/apps/desktop/electron/main/plugin-shortcut-registry.ts
+++ b/apps/desktop/electron/main/plugin-shortcut-registry.ts
@@ -33,7 +33,7 @@ export const MAX_PLUGIN_GLOBAL_SHORTCUTS = 8;
* `bootstrap/launcher.ts`); everything else in `KEYBOARD_SHORTCUTS` is
* renderer-scoped and cannot conflict with a system-wide binding.
*/
-const HOST_GLOBAL_SHORTCUT_IDS = ["openPluginLauncher", "summonWindow"] as const;
+const HOST_GLOBAL_SHORTCUT_IDS = ["openPluginLauncher", "toggleWindow"] as const;
export type PluginShortcutErrorCode =
| "INVALID_ACCELERATOR"
diff --git a/apps/desktop/src/features/app/useAppShellRuntime.tsx b/apps/desktop/src/features/app/useAppShellRuntime.tsx
index f2e3fc6d9..6b730905e 100644
--- a/apps/desktop/src/features/app/useAppShellRuntime.tsx
+++ b/apps/desktop/src/features/app/useAppShellRuntime.tsx
@@ -729,8 +729,11 @@ export function useAppShellRuntime() {
case "abort":
void abort();
break;
- case "closeWindow":
- void api.windowControl("close");
+ case "toggleWindow":
+ // The same native action the menu item runs (D438): hide the window
+ // the user is looking at, or bring it back. The window's own close
+ // button stays the only path into the close behaviour.
+ void api.nativeMenuAction("toggleMainWindow");
break;
case "resetZoom":
case "zoomIn":
diff --git a/apps/desktop/src/stores/app-store.ts b/apps/desktop/src/stores/app-store.ts
index a1db40214..c983892e7 100644
--- a/apps/desktop/src/stores/app-store.ts
+++ b/apps/desktop/src/stores/app-store.ts
@@ -37,6 +37,7 @@ import {
ErrorCodes as SharedErrorCodes,
initialThinkingLevelForBinding,
modeForProposalKind,
+ migrateKeybindingOverrides,
modelIdsMatch,
normalizeMode,
normalizeProposalKind,
@@ -539,6 +540,10 @@ export const useAppStore = create<AppState>((set, get) => {
defaultMode: normalizeMode(
(settingsRaw as { defaultMode?: unknown }).defaultMode,
),
+ // Persisted keybindings can still name the retired window ids
+ // (D438); every renderer reader sees the folded map, and the next
+ // shortcut save writes that shape back.
+ keybindings: migrateKeybindingOverrides(settingsRaw.keybindings),
}
: settingsRaw;
// First-run default per D003: Agent. Never force-rewrite an existing
diff --git a/apps/desktop/test/plugin-shortcuts.test.mjs b/apps/desktop/test/plugin-shortcuts.test.mjs
index 7c2225687..3fb25f712 100644
--- a/apps/desktop/test/plugin-shortcuts.test.mjs
+++ b/apps/desktop/test/plugin-shortcuts.test.mjs
@@ -225,7 +225,9 @@ test("a system-reserved binding is refused", () => {
test("without a live source the app's shipped defaults are refused", () => {
for (const platform of ["linux", "darwin"]) {
const { registry, calls } = fakePlatform({ platform });
- for (const accelerator of ["Alt+Space", "Mod+Shift+W"]) {
+ // D438: the app spends `Mod+W` on the window toggle, and the retired
+ // `Mod+Shift+W` summon chord is free again.
+ for (const accelerator of ["Alt+Space", "Mod+W"]) {
refusal(
() =>
registry.register({
@@ -243,29 +245,30 @@ test("without a live source the app's shipped defaults are refused", () => {
});
test("the live host bindings decide, not the shipped defaults", () => {
- // The user rebound the summon-window shortcut, so its old default is free
- // again while whatever the app now holds is refused instead.
+ // The user rebound the window toggle, so `Mod+W` is free again while
+ // whatever the app now holds is refused instead.
const { registry, calls } = fakePlatform({ hostBindings: () => ["Mod+Shift+W"] });
const freedDefault = registry.register({
pluginId: PLUGIN_ID,
id: "voice.pushToTalk",
- accelerator: "Alt+Space",
+ accelerator: "Mod+W",
command: VOICE_COMMAND,
});
- assert.equal(freedDefault.accelerator, "Alt+Space");
+ assert.equal(freedDefault.accelerator, "Mod+W");
refusal(
() =>
registry.register({
pluginId: PLUGIN_ID,
- id: "voice.summon",
+ id: "voice.toggle",
accelerator: "Mod+Shift+W",
command: VOICE_COMMAND,
}),
"SHORTCUT_CONFLICT",
);
- assert.deepEqual(calls.registered, ["Alt+Space"]);
+ // `register` receives Electron's platform spelling of the canonical binding.
+ assert.deepEqual(calls.registered, ["Control+W"]);
});
test("an empty live report still falls back to the shipped defaults", () => {
diff --git a/apps/desktop/test/settings-keyboard-shortcuts.test.mjs b/apps/desktop/test/settings-keyboard-shortcuts.test.mjs
index 19921f239..cc7b04feb 100644
--- a/apps/desktop/test/settings-keyboard-shortcuts.test.mjs
+++ b/apps/desktop/test/settings-keyboard-shortcuts.test.mjs
@@ -44,7 +44,7 @@ test("shared shortcut map drives renderer dispatch and native menu accelerators"
"openWorkPanel",
"openPluginLauncher",
"abort",
- "closeWindow",
+ "toggleWindow",
"resetZoom",
"zoomIn",
"zoomOut",
diff --git a/apps/desktop/test/window-menu.test.mjs b/apps/desktop/test/window-menu.test.mjs
index 7fa91eb4b..705193bc7 100644
--- a/apps/desktop/test/window-menu.test.mjs
+++ b/apps/desktop/test/window-menu.test.mjs
@@ -95,7 +95,17 @@ test("macOS application menu routes shell commands and preserves native roles",
assert.match(menuSource, new RegExp(`role: "${role}"`));
}
assert.match(menuSource, /function nativeAction\(/);
- for (const action of ["close", "resetZoom", "zoomIn", "zoomOut", "toggleFullScreen"]) {
+ // The File menu's window item is the merged visibility toggle (D438): its
+ // accelerator is the toggle's `Mod+W` and its click is that native action.
+ assert.match(menuSource, /accelerator\("toggleWindow"\)/);
+ assert.match(menuSource, /labels\.menu\.toggleWindow/);
+ for (const action of [
+ "toggleMainWindow",
+ "resetZoom",
+ "zoomIn",
+ "zoomOut",
+ "toggleFullScreen",
+ ]) {
assert.match(menuSource, new RegExp(`"${action}"`));
}
assert.match(menuSource, /A plain item keeps the command clickable/);
diff --git a/apps/desktop/test/window-toggle-shortcut.test.mjs b/apps/desktop/test/window-toggle-shortcut.test.mjs
new file mode 100644
index 000000000..3248285da
--- /dev/null
+++ b/apps/desktop/test/window-toggle-shortcut.test.mjs
@@ -0,0 +1,188 @@
+/**
+ * The merged window toggle (D438).
+ *
+ * Behavioral: `windowToggleAction` turns the live window flags into the one
+ * decision a press makes, so "visible and focused hides, anything else comes
+ * back" is asserted without Electron.
+ *
+ * Contract: the catalog ships exactly one window-visibility key, the launcher
+ * registers it and nothing else, the toggle path hides instead of closing, both
+ * processes fold stored legacy overrides, and every locale and the settings map
+ * show the merged row.
+ */
+import assert from "node:assert/strict";
+import test from "node:test";
+import { readFile } from "node:fs/promises";
+import { register } from "node:module";
+import { dirname, join } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
+import {
+ readAppSource,
+ readMainModule,
+ readMainSource,
+ readSettingsSource,
+ readStoreSource,
+} from "./helpers/source-contracts.mjs";
+
+const here = dirname(fileURLToPath(import.meta.url));
+register(pathToFileURL(join(here, "helpers/ts-import-hooks.mjs")));
+
+const { windowToggleAction } = await import(
+ "../electron/main/bootstrap/window-visibility.ts"
+);
+const { KEYBOARD_SHORTCUTS, KEYBOARD_SHORTCUT_IDS, migrateKeybindingOverrides } =
+ await import("../../../packages/shared/src/keyboard-shortcuts.ts");
+const { catalogs, flattenCatalog } = await import(
+ "../../../packages/i18n/src/index.ts"
+);
+
+const mainSource = await readMainSource();
+const launcherSource = await readMainModule("bootstrap/launcher.ts");
+const lifecycleSource = await readMainModule("bootstrap/app-lifecycle.ts");
+const shutdownSource = await readMainModule("bootstrap/shutdown.ts");
+const registrySource = await readMainModule("plugin-shortcut-registry.ts");
+const menuSource = await readMainModule("application-menu.ts");
+const protocolSource = await readFile(
+ new URL("../../../packages/shared/src/protocol.ts", import.meta.url),
+ "utf8",
+);
+const windowControlsSource = await readFile(
+ new URL("../src/components/WindowControls.tsx", import.meta.url),
+ "utf8",
+);
+const appSource = await readAppSource();
+const storeSource = await readStoreSource();
+const settingsSource = await readSettingsSource();
+const sectionSource = await readFile(
+ new URL("../src/components/settings/KeyboardShortcutsSection.tsx", import.meta.url),
+ "utf8",
+);
+
+function toggleActionFor({ visible, minimized, focused }) {
+ return windowToggleAction({
+ isVisible: () => visible,
+ isMinimized: () => minimized,
+ isFocused: () => focused,
+ });
+}
+
+test("the catalog ships one window toggle on Mod+W, with no summon chord", () => {
+ assert.ok(KEYBOARD_SHORTCUT_IDS.includes("toggleWindow"));
+ assert.equal(KEYBOARD_SHORTCUT_IDS.includes("summonWindow"), false);
+ assert.equal(KEYBOARD_SHORTCUT_IDS.includes("closeWindow"), false);
+
+ const windowGroup = KEYBOARD_SHORTCUTS.filter((shortcut) => shortcut.group === "window");
+ assert.equal(
+ KEYBOARD_SHORTCUTS.some((shortcut) => shortcut.defaultBinding === "Mod+Shift+W"),
+ false,
+ );
+ assert.deepEqual(
+ windowGroup.map((shortcut) => shortcut.id),
+ ["toggleWindow", "resetZoom", "zoomIn", "zoomOut", "toggleFullScreen"],
+ );
+});
+
+test("a visible, focused window hides; anything else comes back", () => {
+ assert.equal(toggleActionFor({ visible: true, minimized: false, focused: true }), "hide");
+ // Hidden in the tray, minimized to the taskbar, or behind another
+ // application: every one of those comes back and takes focus.
+ assert.equal(toggleActionFor({ visible: false, minimized: false, focused: false }), "show");
+ assert.equal(toggleActionFor({ visible: true, minimized: true, focused: true }), "show");
+ assert.equal(toggleActionFor({ visible: true, minimized: false, focused: false }), "show");
+});
+
+test("the toggle hides the window instead of entering the close path", () => {
+ const toggleBlock = lifecycleSource.slice(
+ lifecycleSource.indexOf("function toggleMainWindow()"),
+ lifecycleSource.indexOf("function updateTrayMenu"),
+ );
+ assert.match(toggleBlock, /windowToggleAction\(window\) === "hide"/);
+ assert.match(toggleBlock, /window\.hide\(\)/);
+ assert.match(toggleBlock, /restoreMainWindow\(\)/);
+ // Hiding must not raise the close-behaviour prompt, destroy the window, or
+ // quit: `Window.hide()` is the whole hide path.
+ assert.doesNotMatch(toggleBlock, /\.close\(\)|\.destroy\(\)|app\.quit\(|quitConfirmed/);
+ assert.match(lifecycleSource, /function restoreMainWindow\(\)/);
+});
+
+test("the launcher registers the toggle accelerator and nothing else", () => {
+ assert.match(launcherSource, /applyToggleWindowShortcut/);
+ assert.match(launcherSource, /candidate\.id === "toggleWindow"/);
+ assert.match(launcherSource, /recordHostGlobalBinding\("toggleWindow", binding\)/);
+ assert.match(
+ launcherSource,
+ /globalShortcut\.register\(accelerator, \(\) => \{\s*toggleMainWindow\(\);\s*\}\)/,
+ );
+ assert.match(launcherSource, /toggleWindowAccelerator/);
+ assert.match(lifecycleSource, /applyToggleWindowShortcut\(keybindings\)/);
+ assert.match(shutdownSource, /state\.toggleWindowAccelerator/);
+ // Only the plugin launcher and the window toggle are process-wide
+ // accelerators: the retired summon id is registered by nothing.
+ assert.deepEqual(
+ [...launcherSource.matchAll(/recordHostGlobalBinding\("([A-Za-z]+)"/g)]
+ .map((match) => match[1])
+ .sort(),
+ ["openPluginLauncher", "toggleWindow"],
+ );
+ // The plugin registry refuses what the app now holds: `Alt+Space` and the
+ // `Mod+W` toggle.
+ assert.match(
+ registrySource,
+ /HOST_GLOBAL_SHORTCUT_IDS = \["openPluginLauncher", "toggleWindow"\] as const/,
+ );
+});
+
+test("the shell key, the menu item, and the accelerator run one action", () => {
+ assert.match(appSource, /case "toggleWindow":/);
+ assert.match(appSource, /api\.nativeMenuAction\("toggleMainWindow"\)/);
+ assert.match(protocolSource, /"restoreMainWindow",\s*\n\s*"toggleMainWindow",/);
+ assert.match(lifecycleSource, /action === "restoreMainWindow" \|\| action === "toggleMainWindow"/);
+ assert.match(menuSource, /labels\.menu\.toggleWindow/);
+ assert.match(windowControlsSource, /api\.windowControl\("close"\)/);
+ assert.match(menuSource, /dispatchNative\("toggleMainWindow"\)/);
+ assert.doesNotMatch(menuSource, /summonWindow|closeWindow/);
+});
+
+test("stored legacy overrides are folded where each process reads them", () => {
+ assert.match(lifecycleSource, /migrateKeybindingOverrides\(/);
+ assert.match(storeSource, /migrateKeybindingOverrides\(settingsRaw\.keybindings\)/);
+ // The two cases the migration exists for: a user who customized the old close
+ // key, and one who customized the old summon key.
+ assert.deepEqual(migrateKeybindingOverrides({ closeWindow: "Mod+Shift+Q" }), {
+ toggleWindow: "Mod+Shift+Q",
+ });
+ assert.deepEqual(migrateKeybindingOverrides({ summonWindow: "Alt+Shift+W" }), {
+ toggleWindow: "Alt+Shift+W",
+ });
+ assert.deepEqual(migrateKeybindingOverrides({}), undefined);
+});
+
+test("settings lists one toggle row and formats it from the shared catalog", () => {
+ assert.match(sectionSource, /KEYBOARD_SHORTCUTS\.filter\(\(shortcut\) => shortcut\.group === group\)/);
+ assert.match(sectionSource, /resolveKeybinding\(shortcut, settings\.keybindings, platform\)/);
+ assert.doesNotMatch(sectionSource, /closeWindow|summonWindow/);
+ assert.match(settingsSource, /<KeyboardShortcutsSection/);
+ assert.doesNotMatch(settingsSource, /closeWindow|summonWindow/);
+});
+
+test("every locale labels the merged row in both surfaces", () => {
+ for (const [id, catalog] of Object.entries(catalogs)) {
+ const flat = flattenCatalog(catalog);
+ assert.notEqual(flat["menu.toggleWindow"], undefined, id);
+ for (const shortcutId of KEYBOARD_SHORTCUT_IDS) {
+ assert.notEqual(
+ flat[`settings.shortcutAction.${shortcutId}`],
+ undefined,
+ `${id} settings.shortcutAction.${shortcutId}`,
+ );
+ }
+ for (const retired of [
+ "menu.closeWindow",
+ "menu.summonWindow",
+ "settings.shortcutAction.closeWindow",
+ "settings.shortcutAction.summonWindow",
+ ]) {
+ assert.equal(flat[retired], undefined, `${id} ${retired}`);
+ }
+ }
+});
diff --git a/docs/adr/0211-plan-safe-plugin-actions.md b/docs/adr/0211-plan-safe-plugin-actions.md
index 4d87512a0..f69b5a83e 100644
--- a/docs/adr/0211-plan-safe-plugin-actions.md
+++ b/docs/adr/0211-plan-safe-plugin-actions.md
@@ -3,7 +3,10 @@
- Status: Accepted
- Date: 2026-09-10
- Deciders: PI-Desktop core
-- Related: ADR 0052, ADR 0053, ADR 0170, E2E-PLAN-005
+ - Amended by: D438 (the window-summon shortcut in §7 becomes one
+ window-visibility toggle on `Mod+W`; the plan-safe plugin-action opt-in is
+ unchanged)
+ - Related: ADR 0052, ADR 0053, ADR 0170, E2E-PLAN-005
## Context
@@ -105,6 +108,12 @@ is the symmetrical counterpart to `closeWindow`: closing a window hides
it to the tray or minimizes it; summoning brings the same window back to
focus.
+*(Amended by D438: the catalog now ships one `toggleWindow` id on `Mod+W`
+instead of the `summonWindow` / `closeWindow` pair, the retired `Mod+Shift+W`
+chord is registered by nothing, and stored overrides for the two retired ids
+are folded into the toggle on read. Hiding is `Window.hide()` and never the
+close path.)*
+
## Consequences
- Plan and Goal modes can inspect external resources through any plugin
@@ -121,7 +130,8 @@ focus.
plugin rejects it itself.
- The `Mod+Shift+W` summon shortcut pairs with `Mod+W` close, so users
on Windows/Linux with a tray-residing window have one shortcut to
- hide and one to bring back.
+ hide and one to bring back. *(Amended by D438: those two keys are one
+ `Mod+W` toggle.)*
## Alternatives
@@ -164,7 +174,7 @@ current focus. The `Mod+Shift+W` binding is symmetrical with
- `docs/spec/03-runtime/03-tools-and-permissions.md`
- `docs/spec/06-delivery/04-e2e-test-plan.md` E2E-PLAN-005
-- `docs/spec/08-meta/decisions-log.md` D384
+ - `docs/spec/08-meta/decisions-log.md` D384, D438
- `packages/plugin-sdk/src/index.ts`
- `packages/agent-runtime/src/runtime.ts`
- `packages/agent-runtime/src/mode-prompts.ts`
diff --git a/docs/spec/03-runtime/01-ipc-protocol.md b/docs/spec/03-runtime/01-ipc-protocol.md
index d889d383a..923884750 100644
--- a/docs/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/spec/03-runtime/01-ipc-protocol.md
@@ -1689,7 +1689,8 @@ a generic main-process command surface:
type NativeMenuAction =
| "undo" | "redo" | "cut" | "copy" | "paste" | "selectAll"
| "reload" | "zoomIn" | "zoomOut" | "resetZoom"
- | "toggleFullScreen" | "minimize" | "toggleMaximize" | "close";
+ | "toggleFullScreen" | "minimize" | "toggleMaximize" | "close"
+ | "restoreMainWindow" | "toggleMainWindow";
menu/nativeAction({ action: NativeMenuAction })
-> { maximized: boolean; fullScreen: boolean }
diff --git a/docs/spec/04-ux/06-settings-ia.md b/docs/spec/04-ux/06-settings-ia.md
index 7e5b3f0a7..1d6e94c59 100644
--- a/docs/spec/04-ux/06-settings-ia.md
+++ b/docs/spec/04-ux/06-settings-ia.md
@@ -183,6 +183,11 @@ a usage tab.
on Windows/Linux; its native global registration follows the same override.
An unbound launcher disables Electron registration, the Windows host hook,
and the focused-window fallback
+ - the window-visibility row is one toggle on `Cmd/Ctrl + W`: it hides a
+ visible, focused window to the tray and brings a hidden or minimized window
+ back. It is the only window key — the retired `Cmd/Ctrl + Shift + W` summon
+ row is gone — and a stored `closeWindow`/`summonWindow` override is folded
+ into it when the map is read (D438)
### Model configuration (`agent` tab)
- **Defaults** card: a compact settings row shows the provider name and exact
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index d93ad1420..110ef6280 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -15,7 +15,7 @@
| `Cmd/Ctrl + Shift + P` | Open command palette | Global (D014) |
| `Cmd/Ctrl + N` | New chat/session | Global |
| `Cmd/Ctrl + O` | Open project | Global |
-| `Cmd/Ctrl + W` | Close window | Global |
+| `Cmd/Ctrl + W` | Show or hide the window (toggle) | Global (D438); hides to the tray, never quits |
| `Cmd/Ctrl + ,` | Open settings | Global |
| `Cmd/Ctrl + B` | Toggle sidebar | Global |
| `Cmd/Ctrl + J` | Toggle work panel | Global; active session |
@@ -74,6 +74,13 @@
the panel's normal activation instead of issuing a second application
activation or window-stack move. The launcher always opens on the display
nearest the pointer.
+- The window visibility key is one toggle (`Cmd/Ctrl + W`): a visible, focused
+ window hides to the tray, and anything else — hidden, minimized, or behind
+ another application — is shown and focused. Hiding never enters the close
+ path, so it raises no close-behaviour prompt, destroys nothing, and never
+ quits the app. The retired `Cmd/Ctrl + Shift + W` summon chord is not
+ registered, and stored `closeWindow`/`summonWindow` overrides are folded into
+ the toggle when the map is read (D438).
### 1.5 Plugin launcher shortcuts
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 168cb6182..3f7b46de5 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -4382,6 +4382,14 @@ identify the platform validation still needed.
old global binding, focused fallback, and Alt+Space host fallback are all
inactive. 11) Press and release Ctrl/Command alone, confirm an IME candidate,
and hold the back/forward chord long enough to generate repeats.
+ 12) With the main window focused, press the window-visibility chord
+ `Cmd/Ctrl + W` and confirm the window hides to the tray with no
+ close-behaviour prompt and with the app still running; from another
+ application, press it again and confirm the window returns and focuses.
+ 13) Seed one profile with a stored customized `closeWindow` binding and one
+ with a customized `summonWindow` binding; confirm each profile keeps that
+ binding on the single toggle row after restart and that `Cmd/Ctrl + Shift +
+ W` registers nothing.
- **Expected**: Actions are grouped as Navigation, Agent, and Window with
platform-native key labels; recording has visible focus and `Escape` cancels;
the custom Search chord takes effect immediately, replaces the old chord,
@@ -4392,13 +4400,19 @@ identify the platform validation still needed.
macOS accelerator, and disables the Windows launcher fallback layers;
individual and global reset restore the shared defaults; Keyboard shortcuts is
its own Settings destination. Modifier-only and IME keydowns dispatch nothing,
- and a held history chord traverses only once per physical press.
+ and a held history chord traverses only once per physical press. The
+ window-visibility key is one toggle on `Cmd/Ctrl + W` — a visible, focused
+ window hides to the tray, anything else shows and focuses — and it never
+ enters the close path, so it raises no close-behaviour prompt and never quits;
+ the retired `Cmd/Ctrl + Shift + W` chord registers nothing, and a stored
+ `closeWindow`/`summonWindow` override folds into the toggle (D438).
- **Specs linked**: `04-ux/06-settings-ia.md`, `04-ux/07-ui-design-system.md`,
`03-runtime/01-ipc-protocol.md`
- **Acceptance**: F (settings persistence), Quality (keyboard accessibility)
- **Milestone**: M5
- **Status**: Unit-covered (`keyboard-shortcuts.test.ts`,
- `settings-keyboard-shortcuts.test.mjs`, host settings RPC test); rendered scenario Draft
+ `settings-keyboard-shortcuts.test.mjs`, `window-toggle-shortcut.test.mjs`,
+ host settings RPC test); rendered scenario Draft
#### E2E-073a: Developer mode gates the developer-tools console
@@ -7321,14 +7335,14 @@ identify the platform validation still needed.
`Alt+Shift+V` and inspect the answer. 5) Disable and uninstall A and confirm
the accelerator becomes free and B can take it; repeat after terminating A's
runtime (crash) and while A's panel is closed. 6) Attempt the app's own
- launcher accelerator `Alt+Space`, the `Mod+Shift+W` summon binding, a
+ launcher accelerator `Alt+Space`, the `Mod+W` window toggle, a
reserved binding such as `Mod+C`, an invalid accelerator, and a ninth
shortcut for one plugin.
- **Expected**: Only A's own command runs for the accelerator; a shortcut whose
`command` is not registered by the plugin is refused with `INVALID_ARGUMENT`.
B receives a refusal (`registered: false`, code `SHORTCUT_CONFLICT`) and keeps
no accelerator while A holds it. The host's own `Alt+Space` launcher and
- `Mod+Shift+W` summon shortcuts and OS-reserved bindings are refused with
+ `Mod+W` window-toggle shortcuts and OS-reserved bindings are refused with
`SHORTCUT_CONFLICT` or `SHORTCUT_UNAVAILABLE`; an invalid accelerator is
refused with `INVALID_ACCELERATOR` and the ninth per-plugin shortcut with
`LIMIT_EXCEEDED`. Disabling, unloading, or crashing a plugin releases every
diff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.md
index 975cd9c2d..332f5ce30 100644
--- a/docs/spec/07-plugins/03-plugin-api.md
+++ b/docs/spec/07-plugins/03-plugin-api.md
@@ -804,7 +804,7 @@ command belonging to that plugin.
`command` must already be registered by the calling plugin; anything else fails
`INVALID_ARGUMENT`. An accelerator reserved by the operating system, one
PI-Desktop itself currently spends (by default `Alt+Space` opens the plugin
-launcher and `Mod+Shift+W` summons the window; once the user rebinds one of
+launcher and `Mod+W` shows or hides the window; once the user rebinds one of
them, the freed accelerator is available again), or one held by another plugin
is refused rather than taken over, and a refused re-registration leaves the
previous binding in place.
diff --git a/docs/spec/07-plugins/04-plugin-security.md b/docs/spec/07-plugins/04-plugin-security.md
index 3c4f512b8..cce193b74 100644
--- a/docs/spec/07-plugins/04-plugin-security.md
+++ b/docs/spec/07-plugins/04-plugin-security.md
@@ -396,8 +396,8 @@ receives a keyboard hook, `before-input-event`, raw input device, or key event
stream, so there is no keylogger-shaped surface and no way to see the keys the
user types. A plugin may only map an accelerator to one of its own registered
commands, and an accelerator the OS reserves, that PI-Desktop itself currently
-spends (the plugin-launcher and summon-window bindings, `Alt+Space` and
-`Mod+Shift+W` by default; a user rebinding one frees it for plugins), or that
+spends (the plugin-launcher and window-toggle bindings, `Alt+Space` and
+`Mod+W` by default; a user rebinding one frees it for plugins), or that
another plugin holds is refused with
`LIMIT_EXCEEDED` (at most 8 per plugin) instead of being taken over. A trigger
runs exactly that one command. Register, unregister, and trigger are audited
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index 580fc0f7b..7cee8dde7 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -4569,6 +4569,9 @@ D193, and D194.
## 2026-09-10 — Plan-safe plugin actions and summon-window shortcut (D384)
+*(superseded by D438 for the summon-window shortcut; the plan-safe plugin
+action opt-in below stays)*
+
- Plan and Goal modes could not invoke plugin tools at all, even for
read-only actions like fetching a URL through the bundled Browser
plugin, and the keyboard shortcut catalog only exposed a close-window
@@ -4582,6 +4585,55 @@ D193, and D194.
declares `["navigate", "snapshot", "screenshot", "console"]`; the
mutating actions stay Agent-only. The shortcut catalog gains
`summonWindow` (`Mod+Shift+W`) in the `window` group, paired with
+
+## 2026-09-17 — One window toggle replaces the summon/close pair (#360, D438)
+
+- Issue #360 item 3 asks for the summon-window and hide/close-window global
+ shortcuts to become one key. D384 shipped the opposite arrangement —
+ `summonWindow` (`Mod+Shift+W`) as the "symmetrical counterpart" of
+ `closeWindow` (`Mod+W`), mirrored by `04-ux/09-interaction-patterns.md` §1.1 —
+ so D438 supersedes exactly that half of D384; the plan-safe plugin-action
+ opt-in from the same decision is untouched. The numbering skips D435 and D437,
+ which other in-flight work already claims.
+- The catalog ships one `toggleWindow` id in the `window` group, default
+ `Mod+W` on every platform. `closeWindow` and `summonWindow` leave
+ `KEYBOARD_SHORTCUT_IDS`, so the retired `Mod+Shift+W` chord is spent on
+ nothing: it is not a shipped default, not registered with `globalShortcut`,
+ not a settings row, and not a menu accelerator. The plugin shortcut registry
+ therefore now refuses `Alt+Space` and `Mod+W`, and the freed `Mod+Shift+W`
+ becomes available to plugins.
+- Pressing the key is a decision, not a close. `windowToggleAction` hides a
+ visible, focused window through `Window.hide()` and otherwise shows and
+ focuses it (hidden, minimized, or behind another application all count as
+ "not visible"). `Window.hide()` is the whole hide path, so the Windows/Linux
+ close-behaviour prompt, its `Quit` choice, `window-all-closed`, and
+ `before-quit` are never reached, no window is destroyed, and the app keeps
+ running; the tray icon, the same key, or macOS application activation brings
+ the window back. `windowControl("close")` remains the window's own close
+ button, which is still the only way into the close behaviour.
+- Persisted `settings.keybindings` can still name the two retired ids, and the
+ same rule applies in both processes: `migrateKeybindingOverrides` folds the
+ map as it is read — in Electron main before it registers accelerators or
+ builds the menu, and in the renderer store before any consumer sees it — so
+ no surface can act on the retired ids. The rules are ordered and idempotent:
+ an existing `toggleWindow` override wins unchanged; otherwise the first
+ retired entry that carries a *binding* wins, `closeWindow` first because
+ `Mod+W` is the key the toggle keeps; a retired entry that is only `null` is
+ honoured when no binding competes, so an explicit unbind is never replaced by
+ a shipped default; and a stored value equal to its own retired default carries
+ no intent (the settings UI deletes overrides that match a shipped default), so
+ `Mod+W`/`Mod+Shift+W` values are dropped rather than resurrected. Nothing is
+ rewritten in storage: the folded map is what the next shortcut save persists,
+ and an older release reading a newer map simply ignores the unknown id.
+- The window-visibility key is a supported global shortcut on macOS, Windows,
+ and Linux, so it is documented as one: menu label and settings row are
+ localized in all eight catalogs, and the settings card shows a single Window
+ row instead of two contradictory ones.
+- See ADR 0211 (amended), `04-ux/09-interaction-patterns.md` §1.1 and §1.4,
+ `04-ux/06-settings-ia.md` (shortcuts tab), `07-plugins/03-plugin-api.md`,
+ `07-plugins/04-plugin-security.md`, `03-runtime/01-ipc-protocol.md`
+ (`NATIVE_MENU_ACTIONS`), E2E-072, and
+ `apps/desktop/test/window-toggle-shortcut.test.mjs`.
`closeWindow` (`Mod+W`), and the desktop main process registers it
through `globalShortcut` and the native menu. See ADR 0211 and
E2E-PLAN-005.
diff --git a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
index 5582debed..8b94214ac 100644
--- a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
@@ -1366,7 +1366,8 @@ menu/rendererReady() -> { ready: true }
type NativeMenuAction =
| "undo" | "redo" | "cut" | "copy" | "paste" | "selectAll"
| "reload" | "zoomIn" | "zoomOut" | "resetZoom"
- | "toggleFullScreen" | "minimize" | "toggleMaximize" | "close";
+ | "toggleFullScreen" | "minimize" | "toggleMaximize" | "close"
+ | "restoreMainWindow" | "toggleMainWindow";
menu/nativeAction({ action: NativeMenuAction })
-> { maximized: boolean; fullScreen: boolean }
diff --git a/docs/zh-CN/spec/04-ux/06-settings-ia.md b/docs/zh-CN/spec/04-ux/06-settings-ia.md
index e4c074db2..89986a485 100644
--- a/docs/zh-CN/spec/04-ux/06-settings-ia.md
+++ b/docs/zh-CN/spec/04-ux/06-settings-ia.md
@@ -121,6 +121,10 @@ Token 用量**不是设置目的地**(D335 / ADR 0173)。已完成回合历
- 插件启动器在 macOS 默认为 `Option + Space`,在 Windows/Linux 默认为
`Alt + Space`;本机全局注册遵循相同覆盖。未绑定时会同时关闭 Electron 注册、
Windows host hook 和聚焦窗口后备
+ - 窗口可见性只有一行、一个开关键 `Cmd/Ctrl + W`:把可见且在前台的窗口隐藏到
+ 托盘,把已隐藏或已最小化的窗口调回来。它是唯一的窗口键 —— 已弃用的
+ `Cmd/Ctrl + Shift + W` 呼出组合键已移除 —— 读取配置映射时,已存储的
+ `closeWindow` / `summonWindow` 覆盖项会并入它(D438)
### 模型配置(`agent` 选项卡)
- **Studio Hero**:提供商计数、就绪计数和当前默认 provider/model 摘要
diff --git a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
index d15d43277..5e27ea53f 100644
--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
@@ -18,7 +18,7 @@
| `Cmd/Ctrl + Shift + P` | 打开命令面板 | 全球 (D014) |
| `Cmd/Ctrl + N` | 新 chat/session | 全球 |
| `Cmd/Ctrl + O` | 打开项目 | 全球 |
-| `Cmd/Ctrl + W` | 关闭窗口 | 全球 |
+| `Cmd/Ctrl + W` | 呼出或隐藏窗口(切换) | 全局(D438);隐藏到托盘,绝不退出 |
| `Cmd/Ctrl + ,` | 打开设置 | 全球 |
| `Cmd/Ctrl + B` | 切换侧边栏 | 全球 |
| `Cmd/Ctrl + J` | 打开工作面板 | 全球;活动会话 |
@@ -70,6 +70,11 @@
专注。如果钩子无法被安装,聚焦窗口后备仍然可用。未绑定时会同时关闭钩子和
聚焦窗口后备。自定义绑定继续使用 Electron 的全局快捷方式 API。
启动器始终在最靠近指针的显示屏上打开。
+- 窗口可见性只有一个开关键(`Cmd/Ctrl + W`):可见且在前台的窗口隐藏到托盘,
+ 其余情况 —— 已隐藏、已最小化或被其它应用挡在后面 —— 显示并获得焦点。隐藏
+ 不走关闭路径,因此不会弹出关闭行为询问、不会销毁窗口,也绝不会退出应用。
+ 已弃用的 `Cmd/Ctrl + Shift + W` 呼出组合键不再注册;读取配置映射时,
+ 已存储的 `closeWindow` / `summonWindow` 覆盖项会并入该开关键(D438)。
### 1. 5 插件启动器快捷方式
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 4ed8889af..c606e27df 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -2923,13 +2923,18 @@ PI-Desktop 图标;两个表面都不会暴露库存 Electron 名称或图标
macOS 菜单;重复、无修饰符和保留组合以内联错误拒绝;“未绑定”是明确的本地化
状态,不参与冲突、不响应旧或默认组合、可跨重启保存,并会移除 macOS 加速器和
Windows 启动器后备层;单项和全局恢复都返回共享默认值。仅修饰符和 IME 按键不
- 会发送命令,长按历史组合每次物理按压只遍历一次。
+ 会发送命令,长按历史组合每次物理按压只遍历一次。窗口可见性只有一个开关键
+ `Cmd/Ctrl + W` —— 可见且在前台的窗口隐藏到托盘,其余情况显示并获得焦点 ——
+ 且绝不走关闭路径,因此不会弹出关闭行为询问、也不会退出应用;已弃用的
+ `Cmd/Ctrl + Shift + W` 组合键不再注册,已存储的 `closeWindow` / `summonWindow`
+ 覆盖项会并入该开关键(D438)。
- **链接规格**:`04-ux/06-settings-ia.md`、`04-ux/07-ui-design-system.md`、
`03-runtime/01-ipc-protocol.md`
- **接受**:F(设置持久性)、质量(键盘可访问性)
- **里程碑**:M5
- **状态**:单位覆盖(`keyboard-shortcuts.test.ts`、
- `settings-keyboard-shortcuts.test.mjs`、host 设置 RPC 测试);渲染场景草稿
+ `settings-keyboard-shortcuts.test.mjs`、`window-toggle-shortcut.test.mjs`、
+ host 设置 RPC 测试);渲染场景草稿
#### E2E-073a:开发者模式控制开发者工具控制台
diff --git a/docs/zh-CN/spec/07-plugins/03-plugin-api.md b/docs/zh-CN/spec/07-plugins/03-plugin-api.md
index a721fca3c..60d34bdcf 100644
--- a/docs/zh-CN/spec/07-plugins/03-plugin-api.md
+++ b/docs/zh-CN/spec/07-plugins/03-plugin-api.md
@@ -660,7 +660,7 @@ type PluginGlobalShortcut = {
`command` 必须已经由调用插件注册;否则以 `INVALID_ARGUMENT` 失败。被操作
系统保留、被 PI-Desktop 自己当前占用(默认 `Alt+Space` 打开插件启动器、
-`Mod+Shift+W` 唤起窗口;用户改绑后释放出来的加速键可以再次被插件使用)或
+`Mod+W` 呼出或隐藏窗口;用户改绑后释放出来的加速键可以再次被插件使用)或
已被另一个插件持有的加速键会被拒绝而不是被抢走,被拒绝的重新注册会保留原来
的绑定。拒绝是返回的结果,不是抛出的异常:
`registerGlobalShortcut` 以 `registered: false` 解析,并带 `error` 为
diff --git a/docs/zh-CN/spec/07-plugins/04-plugin-security.md b/docs/zh-CN/spec/07-plugins/04-plugin-security.md
index c75b14e7a..309d811f8 100644
--- a/docs/zh-CN/spec/07-plugins/04-plugin-security.md
+++ b/docs/zh-CN/spec/07-plugins/04-plugin-security.md
@@ -318,7 +318,7 @@ MCP 调用相同的 IPC 校验、生命周期检查、完成事件和审计条
Electron 的 `globalShortcut`;插件永远拿不到键盘钩子、`before-input-event`、
原始输入设备或按键事件流,所以不存在键盘记录器形状的表面,也无法看到用户
按下的键。插件只能把加速键映射到自己已注册的一条命令;被操作系统保留、被
-PI-Desktop 自己当前占用(默认是 `Alt+Space` 与 `Mod+Shift+W`;用户改绑后
+PI-Desktop 自己当前占用(默认是 `Alt+Space` 与 `Mod+W`;用户改绑后
即可释放给插件)或已被另一个插件持有的
加速键会被拒绝,返回 `SHORTCUT_CONFLICT` / `SHORTCUT_UNAVAILABLE` /
`INVALID_ACCELERATOR` / `LIMIT_EXCEEDED`(每个插件最多 8 条),而不是被抢走。
diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.md
index 23e8411f4..66747538f 100644
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@ -4286,3 +4286,39 @@ that amendment are retired by ADR 0268; the upstream work-panel lifecycle stays.
- `.composer-stack > .asktool-card` 现在绘制那块板:`--ds-bg-composer` 加 `--ds-shadow-composer`(浅色 `#ffffff`,深色 `color-mix(in oklab, #212121 96%, transparent)` 配合 composer 阴影)。
- 它的控件移到该板的内嵌层 —— 也就是 `.plan-approval-split` 在同一块板上已经使用的层:`.asktool-option` 与 `.asktool-custom-input` 去掉 `--ds-raised` 与 `--ds-raised-shadow`,改用 `--ds-tile-deep`,悬停/选中混合也以 `--ds-tile-deep` 为基底。不做这次翻转,浅色主题下选项行会白上加白,因为该调色板里 `--ds-raised` 与 `--ds-bg-composer` 都是 `#ffffff`。15 px 的选项标记保留 `--ds-tile-deep` —— 与侧边栏复选框同一枚标记 —— 它与内嵌行之间的对比,和它与侧边栏之间的对比完全一致。
- 仅渲染层:无协议、存储、宿主、权限、迁移或偏好改动,也没有新增默认值。两层在两种调色板里都是既有 token,因此贡献主题可以分别用 `--ds-bg-composer` / `--ds-tile-deep` 移动板与行。见 `04-ux/11-asktool-question-card.md`、`04-ux/07-ui-design-system.md` §6.4 与 E2E-078。
+
+## 2026-09-17 —— 呼出与隐藏窗口合并为一个开关键(#360,D438)
+
+- issue #360 第 3 项要求把「呼出窗口」与「隐藏/关闭窗口」两个全局快捷键合并成一个键。
+ D384 当年给的恰好是相反的安排 —— `summonWindow`(`Mod+Shift+W`)作为
+ `closeWindow`(`Mod+W`)的「对称键」,并由 `04-ux/09-interaction-patterns.md` §1.1
+ 记载 —— 因此 D438 取代 D384 的这一半;同一条决策里的插件 Plan 安全动作选项不受影响。
+ 编号跳过 D435 与 D437,因为其它在途工作已先占用。
+- 快捷键目录现在只保留 `window` 组里的一个 `toggleWindow`,各平台默认值都是 `Mod+W`。
+ `closeWindow` 与 `summonWindow` 已从 `KEYBOARD_SHORTCUT_IDS` 移除,因此被弃用的
+ `Mod+Shift+W` 不再被任何东西占用:它既不是随应用发布的默认值,也不会注册到
+ `globalShortcut`,既不是设置行,也不是菜单加速键。插件快捷键注册表因此改为拒绝
+ `Alt+Space` 与 `Mod+W`,而被释放出来的 `Mod+Shift+W` 可以交给插件使用。
+- 按下这个键是一次判定,而不是一次关闭。`windowToggleAction` 对可见且在前台的窗口执行
+ `Window.hide()`,其余情况显示并获得焦点(已隐藏、已最小化、被其它应用挡在后面都算
+ 「不可见」)。`Window.hide()` 就是隐藏的全部路径,所以 Windows/Linux 的关闭行为询问、
+ 其中的「退出」选项、`window-all-closed` 与 `before-quit` 都不会被触达,没有窗口被销毁,
+ 应用继续运行;托盘图标、同一个键或 macOS 的应用激活都能把窗口调回来。
+ `windowControl("close")` 仍是窗口自己的关闭按钮,依旧走关闭行为。
+- 已持久化的 `settings.keybindings` 仍可能写着这两个已退役的 id,两个进程遵循同一条规则:
+ `migrateKeybindingOverrides` 在读取时就折叠映射 —— Electron 主进程在注册加速键和构建
+ 菜单之前,渲染层 store 在任何消费方看到它之前 —— 因此没有任何表面会按退役 id 行事。
+ 规则有序且幂等:已存在的 `toggleWindow` 覆盖原样胜出;否则第一个带*绑定值*的退役项胜出,
+ `closeWindow` 优先,因为 `Mod+W` 正是开关键保留的那个键;只有在没有绑定值竞争时,
+ 仅写入 `null` 的退役项才被尊重,所以明确的「未绑定」不会被随应用发布的默认值顶替;
+ 与自身退役默认值相同的存储值不携带任何意图(设置界面会删除等于发布默认值的覆盖项),
+ 因此 `Mod+W`/`Mod+Shift+W` 这类值会被丢弃而不是被复活。存储本身不做改写:折叠后的映射
+ 由下一次快捷键保存写入,旧版本读到新映射时只是忽略不认识的 id。
+- 窗口可见性键在 macOS、Windows 与 Linux 上都是受支持的全局快捷键,因此按一个键来记录:
+ 菜单标签与设置行在全部八套语言包里本地化,快捷键卡片显示唯一的一行「窗口」,
+ 而不是两行互相矛盾的行。
+- 见 ADR 0211(已修订)、`04-ux/09-interaction-patterns.md` §1.1 与 §1.4、
+ `04-ux/06-settings-ia.md`(快捷键选项卡)、`07-plugins/03-plugin-api.md`、
+ `07-plugins/04-plugin-security.md`、`03-runtime/01-ipc-protocol.md`
+ (`NATIVE_MENU_ACTIONS`)、E2E-072 与
+ `apps/desktop/test/window-toggle-shortcut.test.mjs`。
diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.ts
index abe0e5357..aac353bbb 100644
--- a/packages/i18n/src/locales/de/index.ts
+++ b/packages/i18n/src/locales/de/index.ts
@@ -69,8 +69,7 @@ export const de = {
"newTask": "Neue Aufgabe",
"openProject": "Projekt öffnen…",
"settings": "Einstellungen…",
- "closeWindow": "Fenster schließen",
- "summonWindow": "Fenster in den Vordergrund",
+ "toggleWindow": "Fenster zeigen/verbergen",
"refreshMarket": "Marktplatz aktualisieren",
"search": "Suchen…",
"toggleSidebar": "Seitenleiste",
@@ -631,8 +630,7 @@ sklm: {
"toggleSidebar": "Seitenleiste um-/ausblenden",
"openWorkPanel": "Seitenpanel umschalten",
"abort": "Aktive Aufgabe stoppen",
- "closeWindow": "Fenster schließen",
- "summonWindow": "Fenster in den Vordergrund holen",
+ "toggleWindow": "Fenster zeigen oder verbergen",
"resetZoom": "Zoom zurücksetzen",
"zoomIn": "Vergrößern",
"zoomOut": "Verkleinern",
diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.ts
index 9ecfce98f..a00e9031b 100644
--- a/packages/i18n/src/locales/en/index.ts
+++ b/packages/i18n/src/locales/en/index.ts
@@ -76,8 +76,7 @@ export const en = {
newTask: "New Task",
openProject: "Open Project…",
settings: "Settings…",
- closeWindow: "Close Window",
- summonWindow: "Summon Window",
+ toggleWindow: "Show/Hide Window",
refreshMarket: "Refresh marketplace",
search: "Search…",
toggleSidebar: "Sidebar",
@@ -638,8 +637,7 @@ sklm: {
toggleSidebar: "Toggle sidebar",
openWorkPanel: "Toggle side panel",
abort: "Stop active task",
- closeWindow: "Close window",
- summonWindow: "Bring window to front",
+ toggleWindow: "Show or hide the window",
resetZoom: "Reset zoom",
zoomIn: "Zoom in",
zoomOut: "Zoom out",
diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.ts
index cfccb4d81..ed1b91e0c 100644
--- a/packages/i18n/src/locales/es/index.ts
+++ b/packages/i18n/src/locales/es/index.ts
@@ -69,8 +69,7 @@ export const es = {
"newTask": "Nueva tarea",
"openProject": "Abrir proyecto…",
"settings": "Configuración…",
- "closeWindow": "Cerrar ventana",
- "summonWindow": "Traer ventana al frente",
+ "toggleWindow": "Mostrar/Ocultar ventana",
"refreshMarket": "Actualizar mercado",
"search": "Buscar…",
"toggleSidebar": "Barra lateral",
@@ -631,8 +630,7 @@ sklm: {
"toggleSidebar": "Alternar barra lateral",
"openWorkPanel": "Alternar panel lateral",
"abort": "Detener tarea activa",
- "closeWindow": "Cerrar ventana",
- "summonWindow": "Traer ventana al frente",
+ "toggleWindow": "Mostrar u ocultar la ventana",
"resetZoom": "Restablecer zoom",
"zoomIn": "Acercar",
"zoomOut": "Zoom out",
diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.ts
index 85cedac5d..6697256a5 100644
--- a/packages/i18n/src/locales/fr/index.ts
+++ b/packages/i18n/src/locales/fr/index.ts
@@ -69,8 +69,7 @@ export const fr = {
"newTask": "Nouvelle tâche",
"openProject": "Ouvrir le projet…",
"settings": "Paramètres…",
- "closeWindow": "Fermer la fenêtre",
- "summonWindow": "Ramener la fenêtre au premier plan",
+ "toggleWindow": "Afficher/Masquer la fenêtre",
"refreshMarket": "Actualiser la place de marché",
"search": "Recherche…",
"toggleSidebar": "Barre latérale",
@@ -631,8 +630,7 @@ sklm: {
"toggleSidebar": "Basculer la barre latérale",
"openWorkPanel": "Basculer le panneau latéral",
"abort": "Arrêter la tâche active",
- "closeWindow": "Fermer la fenêtre",
- "summonWindow": "Ramener la fenêtre au premier plan",
+ "toggleWindow": "Afficher ou masquer la fenêtre",
"resetZoom": "Réinitialiser le zoom",
"zoomIn": "Zoom avant",
"zoomOut": "Zoom arrière",
diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.ts
index d334df6c8..9b72755cb 100644
--- a/packages/i18n/src/locales/ko/index.ts
+++ b/packages/i18n/src/locales/ko/index.ts
@@ -78,8 +78,7 @@ export const ko = {
newTask: "새 작업",
openProject: "프로젝트 열기…",
settings: "설정…",
- closeWindow: "창 닫기",
- summonWindow: "창 불러오기",
+ toggleWindow: "창 표시/숨기기",
refreshMarket: "마켓플레이스 새로 고침",
search: "검색…",
toggleSidebar: "사이드바",
@@ -639,8 +638,7 @@ sklm: {
toggleSidebar: "사이드바 전환",
openWorkPanel: "사이드 패널 전환",
abort: "활성 작업 중지",
- closeWindow: "창 닫기",
- summonWindow: "창을 앞으로 가져오기",
+ toggleWindow: "창 표시 또는 숨기기",
resetZoom: "확대/축소 초기화",
zoomIn: "확대",
zoomOut: "축소",
diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.ts
index c3ec41dbb..7ed3ec66e 100644
--- a/packages/i18n/src/locales/tr/index.ts
+++ b/packages/i18n/src/locales/tr/index.ts
@@ -78,8 +78,7 @@ export const tr = {
newTask: "Yeni görev",
openProject: "Proje aç…",
settings: "Ayarlar…",
- closeWindow: "Pencereyi kapat",
- summonWindow: "Pencereyi öne getir",
+ toggleWindow: "Pencereyi göster/gizle",
refreshMarket: "Mağazayı yenile",
search: "Ara…",
toggleSidebar: "Kenar çubuğu",
@@ -639,8 +638,7 @@ sklm: {
toggleSidebar: "Kenar çubuğunu aç/kapat",
openWorkPanel: "Yan paneli aç/kapat",
abort: "Aktif görevi durdur",
- closeWindow: "Pencereyi kapat",
- summonWindow: "Pencereyi öne getir",
+ toggleWindow: "Pencereyi göster veya gizle",
resetZoom: "Yakınlaştırmayı sıfırla",
zoomIn: "Yakınlaştır",
zoomOut: "Uzaklaştır",
diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.ts
index 9ecf66072..02c99db06 100644
--- a/packages/i18n/src/locales/zh-CN/index.ts
+++ b/packages/i18n/src/locales/zh-CN/index.ts
@@ -71,8 +71,7 @@ export const zhCN = {
newTask: "新建任务",
openProject: "打开项目…",
settings: "设置…",
- closeWindow: "关闭窗口",
- summonWindow: "呼出窗口",
+ toggleWindow: "呼出 / 隐藏窗口",
refreshMarket: "刷新插件市场",
search: "搜索…",
toggleSidebar: "侧边栏",
@@ -632,8 +631,7 @@ sklm: {
toggleSidebar: "切换侧边栏",
openWorkPanel: "切换侧边面板",
abort: "停止当前任务",
- closeWindow: "关闭窗口",
- summonWindow: "将窗口带到前台",
+ toggleWindow: "呼出或隐藏窗口",
resetZoom: "重置缩放",
zoomIn: "放大",
zoomOut: "缩小",
diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.ts
index 8c4fecea1..88f8817eb 100644
--- a/packages/i18n/src/locales/zh-TW/index.ts
+++ b/packages/i18n/src/locales/zh-TW/index.ts
@@ -71,8 +71,7 @@ export const zhTW = {
newTask: "新建任務",
openProject: "開啟專案…",
settings: "設定…",
- closeWindow: "關閉視窗",
- summonWindow: "喚出視窗",
+ toggleWindow: "喚出 / 隱藏視窗",
refreshMarket: "重新整理外掛市場",
search: "搜尋…",
toggleSidebar: "側邊欄",
@@ -632,8 +631,7 @@ sklm: {
toggleSidebar: "切換側邊欄",
openWorkPanel: "切換側邊面板",
abort: "停止當前任務",
- closeWindow: "關閉視窗",
- summonWindow: "將視窗帶到最前",
+ toggleWindow: "喚出或隱藏視窗",
resetZoom: "重置縮放",
zoomIn: "放大",
zoomOut: "縮小",
diff --git a/packages/shared/src/keyboard-shortcuts.test.ts b/packages/shared/src/keyboard-shortcuts.test.ts
index 0827f602d..7a4ebe53e 100644
--- a/packages/shared/src/keyboard-shortcuts.test.ts
+++ b/packages/shared/src/keyboard-shortcuts.test.ts
@@ -9,25 +9,39 @@ import {
keybindingMatchesEvent,
keybindingToElectronAccelerator,
keybindingsConflict,
+ migrateKeybindingOverrides,
normalizeKeybinding,
resolveKeybinding,
} from "./keyboard-shortcuts.js";
describe("keyboard shortcut mapping", () => {
- it("declares summonWindow in the window group with Mod+Shift+W default", () => {
- expect(KEYBOARD_SHORTCUT_IDS).toContain("summonWindow");
- const summon = KEYBOARD_SHORTCUTS.find(
- (shortcut) => shortcut.id === "summonWindow",
+ it("declares one window toggle in the window group with a Mod+W default", () => {
+ expect(KEYBOARD_SHORTCUT_IDS).toContain("toggleWindow");
+ // D438: the summon/close pair is gone from the catalog, so nothing can
+ // register the retired `Mod+Shift+W` chord any more.
+ expect(KEYBOARD_SHORTCUT_IDS).not.toContain("summonWindow");
+ expect(KEYBOARD_SHORTCUT_IDS).not.toContain("closeWindow");
+ const toggle = KEYBOARD_SHORTCUTS.find(
+ (shortcut) => shortcut.id === "toggleWindow",
);
- expect(summon).toBeDefined();
- expect(summon!.group).toBe("window");
- expect(summon!.defaultBinding).toBe("Mod+Shift+W");
- expect(resolveKeybinding(summon!, undefined, "darwin")).toBe("Mod+Shift+W");
- expect(resolveKeybinding(summon!, undefined, "win32")).toBe("Mod+Shift+W");
- // The default summonWindow binding must not collide with closeWindow.
- const close = KEYBOARD_SHORTCUTS.find((s) => s.id === "closeWindow")!;
- expect(
- keybindingsConflict(summon!.defaultBinding, close.defaultBinding),
+ expect(toggle).toBeDefined();
+ expect(toggle!.group).toBe("window");
+ expect(toggle!.defaultBinding).toBe("Mod+W");
+ expect(resolveKeybinding(toggle!, undefined, "darwin")).toBe("Mod+W");
+ expect(resolveKeybinding(toggle!, undefined, "win32")).toBe("Mod+W");
+ expect(resolveKeybinding(toggle!, undefined, "linux")).toBe("Mod+W");
+ // One key, one binding: no shipped default may collide with it.
+ for (const shortcut of KEYBOARD_SHORTCUTS) {
+ if (shortcut.id === "toggleWindow") continue;
+ expect(
+ keybindingsConflict(
+ toggle!.defaultBinding,
+ resolveKeybinding(shortcut, undefined, "linux"),
+ ),
+ ).toBe(false);
+ }
+ expect(
+ KEYBOARD_SHORTCUTS.some((shortcut) => shortcut.defaultBinding === "Mod+Shift+W"),
).toBe(false);
});
@@ -184,3 +198,79 @@ describe("keyboard shortcut mapping", () => {
expect(keybindingDisplayParts("Mod+Comma", "win32")).toEqual(["Ctrl", ","]);
});
});
+
+describe("retired window keybindings migrate into the toggle (D438)", () => {
+ it("leaves users who never customized a window key on the new default", () => {
+ expect(migrateKeybindingOverrides(undefined)).toBeUndefined();
+ expect(migrateKeybindingOverrides(null)).toBeUndefined();
+ expect(migrateKeybindingOverrides({})).toBeUndefined();
+ const toggle = KEYBOARD_SHORTCUTS.find((s) => s.id === "toggleWindow")!;
+ expect(
+ resolveKeybinding(toggle, migrateKeybindingOverrides({}), "darwin"),
+ ).toBe("Mod+W");
+ });
+
+ it("carries a customized close binding onto the toggle key", () => {
+ const migrated = migrateKeybindingOverrides({
+ closeWindow: "Mod+Shift+Q",
+ openSearch: "Mod+Shift+K",
+ });
+ expect(migrated).toEqual({
+ toggleWindow: "Mod+Shift+Q",
+ openSearch: "Mod+Shift+K",
+ });
+ expect(migrated).not.toHaveProperty("closeWindow");
+ expect(migrated).not.toHaveProperty("summonWindow");
+ });
+
+ it("merges a customized summon binding into the toggle", () => {
+ expect(
+ migrateKeybindingOverrides({ summonWindow: "Alt+Shift+W" }),
+ ).toEqual({ toggleWindow: "Alt+Shift+W" });
+ });
+
+ it("prefers the close entry when both retired keys were customized", () => {
+ expect(
+ migrateKeybindingOverrides({
+ closeWindow: "Mod+Shift+Q",
+ summonWindow: "Alt+Shift+W",
+ }),
+ ).toEqual({ toggleWindow: "Mod+Shift+Q" });
+ });
+
+ it("does not resurrect a shipped default behind an explicit unbind", () => {
+ expect(migrateKeybindingOverrides({ closeWindow: null })).toEqual({
+ toggleWindow: null,
+ });
+ // A live binding still wins over a retired unbind.
+ expect(
+ migrateKeybindingOverrides({ closeWindow: null, summonWindow: "Alt+Shift+W" }),
+ ).toEqual({ toggleWindow: "Alt+Shift+W" });
+ });
+
+ it("ignores stored values that only repeat a retired default", () => {
+ expect(migrateKeybindingOverrides({ closeWindow: "Mod+W" })).toBeUndefined();
+ expect(
+ migrateKeybindingOverrides({ summonWindow: "Mod+Shift+W" }),
+ ).toBeUndefined();
+ // The retired chord therefore never comes back, even from hand-written
+ // storage.
+ expect(
+ migrateKeybindingOverrides({ summonWindow: "Shift+Mod+W" }),
+ ).toBeUndefined();
+ });
+
+ it("is idempotent and never rewrites a later rebind", () => {
+ const once = migrateKeybindingOverrides({
+ closeWindow: "Mod+Shift+Q",
+ toggleWindow: "Mod+Shift+T",
+ });
+ expect(once).toEqual({ toggleWindow: "Mod+Shift+T" });
+ expect(migrateKeybindingOverrides(once)).toEqual(once);
+ expect(
+ migrateKeybindingOverrides(migrateKeybindingOverrides({
+ summonWindow: "Alt+Shift+W",
+ })),
+ ).toEqual({ toggleWindow: "Alt+Shift+W" });
+ });
+});
diff --git a/packages/shared/src/keyboard-shortcuts.ts b/packages/shared/src/keyboard-shortcuts.ts
index 38a05be81..fd8d61d2e 100644
--- a/packages/shared/src/keyboard-shortcuts.ts
+++ b/packages/shared/src/keyboard-shortcuts.ts
@@ -10,8 +10,7 @@ export const KEYBOARD_SHORTCUT_IDS = [
"toggleSidebar",
"openWorkPanel",
"abort",
- "summonWindow",
- "closeWindow",
+ "toggleWindow",
"resetZoom",
"zoomIn",
"zoomOut",
@@ -54,8 +53,7 @@ export const KEYBOARD_SHORTCUTS: readonly KeyboardShortcutDefinition[] = [
{ id: "toggleSidebar", group: "navigation", defaultBinding: "Mod+B" },
{ id: "openWorkPanel", group: "navigation", defaultBinding: "Mod+J" },
{ id: "abort", group: "agent", defaultBinding: "Mod+Period" },
- { id: "summonWindow", group: "window", defaultBinding: "Mod+Shift+W" },
- { id: "closeWindow", group: "window", defaultBinding: "Mod+W" },
+ { id: "toggleWindow", group: "window", defaultBinding: "Mod+W" },
{ id: "resetZoom", group: "window", defaultBinding: "Mod+0" },
{ id: "zoomIn", group: "window", defaultBinding: "Mod+Equal" },
{ id: "zoomOut", group: "window", defaultBinding: "Mod+Minus" },
@@ -67,6 +65,89 @@ export const KEYBOARD_SHORTCUTS: readonly KeyboardShortcutDefinition[] = [
},
] as const;
+/**
+ * A keybinding map as it comes back from storage: it may still name ids an
+ * older release shipped, so it is deliberately wider than
+ * `KeybindingOverrides`.
+ */
+export type PersistedKeybindingOverrides = Record<
+ string,
+ string | null | undefined
+>;
+
+/**
+ * Shortcut ids that the window toggle replaced (D438). Their stored overrides
+ * are folded into `toggleWindow` by `migrateKeybindingOverrides`.
+ */
+const RETIRED_WINDOW_SHORTCUTS = [
+ // The key the toggle keeps: `Mod+W` was the binding that hid the window, and
+ // it stays the binding that hides it.
+ { id: "closeWindow", defaultBinding: "Mod+W" },
+ // Retired outright: nothing summons the window with `Mod+Shift+W` any more.
+ { id: "summonWindow", defaultBinding: "Mod+Shift+W" },
+] as const;
+
+/**
+ * Fold the retired `closeWindow` / `summonWindow` overrides into the single
+ * `toggleWindow` entry (D438), for a persisted `settings.keybindings` map.
+ *
+ * Rules, in order:
+ *
+ * - an existing `toggleWindow` override wins as it is, so the migration is
+ * idempotent and never rewrites a later rebind;
+ * - otherwise the first retired entry that carries a *binding* wins, in the
+ * order above. `closeWindow` comes first because `Mod+W` is the key the
+ * toggle keeps;
+ * - a retired entry that is only `null` (the user unbound it) is honoured after
+ * that: the toggle stays unbound instead of resurrecting a shipped default;
+ * - a stored value equal to its retired default carries no intent (the
+ * settings UI deletes overrides that match the shipped default), so it is
+ * ignored and the new default applies.
+ */
+export function migrateKeybindingOverrides(
+ overrides:
+ | KeybindingOverrides
+ | PersistedKeybindingOverrides
+ | null
+ | undefined,
+): KeybindingOverrides | undefined {
+ if (!overrides || typeof overrides !== "object") return undefined;
+ const legacy = overrides as PersistedKeybindingOverrides;
+ const migrated: Record<string, string | null> = {};
+ for (const [id, binding] of Object.entries(overrides)) {
+ // A key stored without a value is not an override; JSON cannot hold one
+ // either, so it never reaches the migrated map.
+ if (binding === undefined) continue;
+ if (RETIRED_WINDOW_SHORTCUTS.some((retired) => retired.id === id)) continue;
+ migrated[id] = binding;
+ }
+ if (!Object.prototype.hasOwnProperty.call(migrated, "toggleWindow")) {
+ const inherited = inheritedToggleBinding(legacy);
+ if (inherited !== undefined) migrated.toggleWindow = inherited;
+ }
+ return Object.keys(migrated).length > 0
+ ? (migrated as KeybindingOverrides)
+ : undefined;
+}
+
+function inheritedToggleBinding(
+ legacy: Record<string, string | null | undefined>,
+): string | null | undefined {
+ let unbound = false;
+ for (const { id, defaultBinding } of RETIRED_WINDOW_SHORTCUTS) {
+ if (!Object.prototype.hasOwnProperty.call(legacy, id)) continue;
+ const value = legacy[id];
+ if (value === null) {
+ unbound = true;
+ continue;
+ }
+ const binding = normalizeKeybinding(value);
+ if (!binding || binding === defaultBinding) continue;
+ return binding;
+ }
+ return unbound ? null : undefined;
+}
+
const MODIFIER_ORDER = ["Mod", "Ctrl", "Alt", "Shift"] as const;
const MODIFIERS = new Set<string>(MODIFIER_ORDER);
const MODIFIER_KEY_VALUES = new Set(["Alt", "AltGraph", "Control", "Meta", "Shift"]);
diff --git a/packages/shared/src/protocol.ts b/packages/shared/src/protocol.ts
index 85211764e..668081d2e 100644
--- a/packages/shared/src/protocol.ts
+++ b/packages/shared/src/protocol.ts
@@ -34,6 +34,7 @@ export const NATIVE_MENU_ACTIONS = [
"toggleMaximize",
"close",
"restoreMainWindow",
+ "toggleMainWindow",
] as const;
export type NativeMenuAction = (typeof NATIVE_MENU_ACTIONS)[number];