Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix open with zed not focusing window (#35645)

localcc844ea3d1ab4c
diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rs
index 4043001a352..32a6da23915 100644
--- a/crates/gpui/src/platform/windows/window.rs
+++ b/crates/gpui/src/platform/windows/window.rs
@@ -677,6 +677,36 @@ impl PlatformWindow for WindowsWindow {
this.set_window_placement().log_err();
unsafe { SetActiveWindow(hwnd).log_err() };
unsafe { SetFocus(Some(hwnd)).log_err() };
+
+ // premium ragebait by windows, this is needed because the window
+ // must have received an input event to be able to set itself to foreground
+ // so let's just simulate user input as that seems to be the most reliable way
+ // some more info: https://gist.github.com/Aetopia/1581b40f00cc0cadc93a0e8ccb65dc8c
+ // bonus: this bug also doesn't manifest if you have vs attached to the process
+ let inputs = [
+ INPUT {
+ r#type: INPUT_KEYBOARD,
+ Anonymous: INPUT_0 {
+ ki: KEYBDINPUT {
+ wVk: VK_MENU,
+ dwFlags: KEYBD_EVENT_FLAGS(0),
+ ..Default::default()
+ },
+ },
+ },
+ INPUT {
+ r#type: INPUT_KEYBOARD,
+ Anonymous: INPUT_0 {
+ ki: KEYBDINPUT {
+ wVk: VK_MENU,
+ dwFlags: KEYEVENTF_KEYUP,
+ ..Default::default()
+ },
+ },
+ },
+ ];
+ unsafe { SendInput(&inputs, std::mem::size_of::<INPUT>() as i32) };
+
// todo(windows)
// crate `windows 0.56` reports true as Err
unsafe { SetForegroundWindow(hwnd).as_bool() };