дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +02:00
Refs #6029. On Windows and Linux (X11) the frameless title bar keeps its caption buttons and drag region in full screen. Full screen is restored on start (window-state's `FULLSCREEN` flag) and the IntelliJ Windows keymap binds no key to Toggle Full Screen, so a window that comes back in full screen covers the taskbar with no obvious way out. There: - **Maximize** called `toggleMaximize()`, which only flipped the maximized flag under the full-screen frame: the icon changed to Restore Down and nothing else happened. - **Dragging** the title bar (Tauri's drag-region script) moved a full-screen window, and a **double click** toggled maximize, leaving the window in a broken frame (a thin strip, the page not resized). Changes: - In full screen the caption button shows Restore Down and leaves full screen (`window_toggle_fullscreen`). - `installFullscreenDragGuard`: while the window is in full screen, presses on a `data-tauri-drag-region` stop in the capture phase before Tauri's drag script sees them. Installed on Windows and Linux only; macOS keeps its own drag handling. Tests: `WindowControls.test.tsx` (full screen → Restore Down leaves full screen; otherwise maximize), `window-drag.test.ts` (guard on/off), `src/workbench` vitest, `pnpm typecheck`. **Not run on Windows or Linux** (macOS uses native title bar buttons, so none of this runs there). Needs a real-machine check on Windows: 1. Open a project, run Toggle Full Screen (Ctrl+Shift+A → Toggle Full Screen). 2. The maximize caption shows Restore Down; clicking it returns to the previous (maximized or normal) window with the taskbar visible. 3. In full screen, dragging or double-clicking the empty title bar does nothing. 4. Outside full screen: maximize / restore / drag / double-click behave as before.
112 рядки
3.5 KiB
TypeScript
112 рядки
3.5 KiB
TypeScript
/**
|
|
* Caption buttons (minimise, maximise / restore, close) for the frameless
|
|
* title bar, on each side as the desktop lays them out (GTK's decoration
|
|
* layout on Linux). Dialog windows (Settings) only have close, as in IDEA.
|
|
*/
|
|
import { type ComponentType, useEffect, useState } from "react";
|
|
import clsx from "clsx";
|
|
import { t } from "@/platform/i18n";
|
|
import { call, commands, type WindowButton } from "@/platform/ipc";
|
|
import { usePlatform } from "@/platform/platformInfo";
|
|
import { Icon } from "@/ui";
|
|
import styles from "./TitleBar.module.css";
|
|
import { captionButtons, type Side } from "./windowButtons";
|
|
|
|
type AppWindow = import("@tauri-apps/api/window").Window;
|
|
|
|
function withWindow(run: (w: AppWindow) => unknown) {
|
|
void import("@tauri-apps/api/window").then(({ getCurrentWindow }) => run(getCurrentWindow()));
|
|
}
|
|
|
|
function CloseButton() {
|
|
return (
|
|
<button
|
|
type="button"
|
|
className={clsx(styles.caption, styles.captionClose)}
|
|
aria-label={t("window.caption.close")}
|
|
title={t("window.caption.close")}
|
|
onClick={() => withWindow((w) => w.close())}
|
|
>
|
|
<Icon name="window-close" size={16} />
|
|
</button>
|
|
);
|
|
}
|
|
|
|
function MinimizeButton() {
|
|
return (
|
|
<button
|
|
type="button"
|
|
className={styles.caption}
|
|
aria-label={t("window.caption.minimize")}
|
|
title={t("window.caption.minimize")}
|
|
onClick={() => withWindow((w) => w.minimize())}
|
|
>
|
|
<Icon name="window-minimize" size={16} />
|
|
</button>
|
|
);
|
|
}
|
|
|
|
function MaximizeButton() {
|
|
const [state, setState] = useState<"normal" | "maximized" | "fullscreen">("normal");
|
|
|
|
useEffect(() => {
|
|
let disposed = false;
|
|
let unlisten: (() => void) | undefined;
|
|
withWindow(async (w) => {
|
|
const sync = () =>
|
|
void Promise.all([w.isMaximized(), w.isFullscreen()]).then(
|
|
([maximized, fullscreen]) =>
|
|
!disposed && setState(fullscreen ? "fullscreen" : maximized ? "maximized" : "normal"),
|
|
);
|
|
sync();
|
|
const off = await w.onResized(sync);
|
|
if (disposed) off();
|
|
else unlisten = off;
|
|
});
|
|
return () => {
|
|
disposed = true;
|
|
unlisten?.();
|
|
};
|
|
}, []);
|
|
|
|
// In full screen the button restores the window: maximizing under the full-screen frame did
|
|
// nothing visible and left the window broken once it was dragged (#6029).
|
|
const restore = state !== "normal";
|
|
const label = restore ? t("window.caption.restore") : t("window.caption.maximize");
|
|
return (
|
|
<button
|
|
type="button"
|
|
className={styles.caption}
|
|
aria-label={label}
|
|
title={label}
|
|
onClick={() =>
|
|
state === "fullscreen"
|
|
? void call(commands.windowToggleFullscreen()).catch((e) => console.warn("cannot leave full screen", e))
|
|
: withWindow((w) => w.toggleMaximize())
|
|
}
|
|
>
|
|
<Icon name={restore ? "window-restore" : "window-maximize"} size={16} />
|
|
</button>
|
|
);
|
|
}
|
|
|
|
const BUTTONS: Record<WindowButton, ComponentType> = {
|
|
minimize: MinimizeButton,
|
|
maximize: MaximizeButton,
|
|
close: CloseButton,
|
|
};
|
|
|
|
export function WindowControls({ side, dialog = false }: { side: Side; dialog?: boolean }) {
|
|
const layout = usePlatform((s) => s.windowButtons);
|
|
const buttons = captionButtons(layout, side, dialog);
|
|
if (buttons.length === 0) return null;
|
|
return (
|
|
<div className={clsx(styles.captions, side === "left" && styles.captionsLeft)}>
|
|
{buttons.map((button) => {
|
|
const Button = BUTTONS[button];
|
|
return <Button key={button} />;
|
|
})}
|
|
</div>
|
|
);
|
|
}
|