diff --git a/plugins/topbar/src/main.rs b/plugins/topbar/src/main.rs index e1efe5e..e7befe1 100644 --- a/plugins/topbar/src/main.rs +++ b/plugins/topbar/src/main.rs @@ -2113,6 +2113,15 @@ unsafe fn keys(vks: &[u16]) { vks.iter().rev().for_each(|&v| send(v, true)); } +/// Releases `vk` alone: a swallowed key-up handed back to the shell as a synthetic one (see `run::kb_hook`). +unsafe fn key_up(vk: u16) { + let mut i: INPUT = zeroed(); + i.r#type = INPUT_KEYBOARD; + i.Anonymous.ki.wVk = vk; + i.Anonymous.ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(1, &i, size_of::() as i32); +} + /// WM_CLOSE. A window of an elevated app ignores it from our normal-rights process (UIPI), so then /// ask for admin once (UAC) and let an elevated taskkill send the close request. unsafe fn close_window(w: HWND) { diff --git a/plugins/topbar/src/run.rs b/plugins/topbar/src/run.rs index 63a27c3..b2582c8 100644 --- a/plugins/topbar/src/run.rs +++ b/plugins/topbar/src/run.rs @@ -153,8 +153,16 @@ pub(crate) unsafe extern "system" fn kb_hook(n: i32, w: WPARAM, l: LPARAM) -> LR if down { WIN_ALONE.store(true, Relaxed); } else if WIN_ALONE.swap(false, Relaxed) { - keys(&[0xE8]); // an unassigned key between press and release: Windows no longer opens its own Start + // A lone Win *release* is what opens Windows' own Start. An E8 sent from here used to be queued behind + // the release already being dispatched, so the shell sometimes saw no other key in time and opened its + // Start on top of ours. Swallow the real release and hand the shell an E8 and then a synthetic Win-up: + // it sees a key between down and up (so no Start), and the synthetic up still clears the Win key for + // everything else (our own hook skips it: injected). A Win+key chord never reaches here: the key down + // clears WIN_ALONE before the release. + keys(&[0xE8]); + key_up(k.vkCode as u16); PostMessageW(BAR.load(Relaxed) as HWND, WIN_START, 0, 0); + return 1; } } else if down { WIN_ALONE.store(false, Relaxed); // Win+something else: a shortcut, not a Start press