Stop ctrl W from closing the window (now on windows
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
// deno desktop has no setting for chromium's command line, but its linux launcher passes its arguments on to chromium.
|
||||
// so this moves the launcher to bworld-bin and puts a script in its place that starts it with the switches webgpu
|
||||
// needs on some linux setups. run it on the app folder after deno desktop builds it; running it again does nothing
|
||||
|
||||
if (Deno.build.os !== "linux") {
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
const SWITCHES = [
|
||||
"--enable-unsafe-webgpu",
|
||||
"--ozone-platform=x11",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// on windows the app takes chromium's reserved shortcuts (see shortcuts.ts) as hotkeys, through user32. a hotkey takes
|
||||
// the key press before any window gets it, its release still reaches chromium. hotkeys are for the whole system, so
|
||||
// they're only registered while the app's window has focus. holding the key repeats the hotkey
|
||||
// they're only registered while the app's window is in front. holding the key repeats the hotkey
|
||||
import { KEYS, send_key } from "./shortcuts.ts";
|
||||
|
||||
const MOD_CONTROL = 0x2;
|
||||
@@ -11,13 +11,15 @@ const PM_REMOVE = 0x1;
|
||||
const MSG_SIZE = 48;
|
||||
const MSG_MESSAGE = 8;
|
||||
const MSG_LPARAM = 24;
|
||||
// how often it looks for hotkeys, in milliseconds
|
||||
// how often it looks for hotkeys and which window is in front, in milliseconds
|
||||
const POLL_MS = 4;
|
||||
|
||||
const USER32 = {
|
||||
RegisterHotKey: { parameters: ["pointer", "i32", "u32", "u32"], result: "i32" },
|
||||
UnregisterHotKey: { parameters: ["pointer", "i32"], result: "i32" },
|
||||
PeekMessageW: { parameters: ["buffer", "pointer", "u32", "u32", "u32"], result: "i32" },
|
||||
GetForegroundWindow: { parameters: [], result: "pointer" },
|
||||
GetWindowThreadProcessId: { parameters: ["pointer", "buffer"], result: "u32" },
|
||||
} as const;
|
||||
|
||||
export function guard_shortcuts_windows(win: Deno.BrowserWindow) {
|
||||
@@ -46,13 +48,24 @@ export function guard_shortcuts_windows(win: Deno.BrowserWindow) {
|
||||
hotkeys.forEach((_, id) => user32.UnregisterHotKey(null, id + 1));
|
||||
registered = false;
|
||||
};
|
||||
win.addEventListener("focus", register);
|
||||
win.addEventListener("blur", unregister);
|
||||
win.addEventListener("close", unregister);
|
||||
|
||||
// the cef backend never sends focus or blur on windows, so it checks whether the window in front is the app's.
|
||||
// chromium's windows are this process's own
|
||||
const owner = new Uint32Array(1);
|
||||
const in_front = () => {
|
||||
const window = user32.GetForegroundWindow();
|
||||
if (!window) return false;
|
||||
owner[0] = 0;
|
||||
user32.GetWindowThreadProcessId(window, owner);
|
||||
return owner[0] === Deno.pid;
|
||||
};
|
||||
|
||||
const msg = new Uint8Array(MSG_SIZE);
|
||||
const view = new DataView(msg.buffer);
|
||||
setInterval(() => {
|
||||
if (in_front()) register();
|
||||
else unregister();
|
||||
while (user32.PeekMessageW(msg, null, WM_HOTKEY, WM_HOTKEY, PM_REMOVE)) {
|
||||
if (view.getUint32(MSG_MESSAGE, true) !== WM_HOTKEY) continue;
|
||||
const lparam = view.getUint32(MSG_LPARAM, true);
|
||||
|
||||
Reference in New Issue
Block a user