Fix open with zed not focusing window (#35645)
This commit is contained in:
parent
f017ffdffc
commit
844ea3d1ab
1 changed files with 30 additions and 0 deletions
|
@ -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() };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue