Skip to content

Commit

Permalink
fix: fix focus_follows_cursor on touchpads (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger authored Dec 2, 2024
1 parent 6c98c41 commit 8e5591f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 9 additions & 5 deletions packages/wm/src/common/platform/event_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ use windows::Win32::{
use super::{
KeyboardHook, MouseMoveEvent, Platform, PlatformEvent, WindowEventHook,
};
use crate::{common::Point, user_config::KeybindingConfig};
use crate::{
common::{platform::FOREGROUND_INPUT_IDENTIFIER, Point},
user_config::KeybindingConfig,
};

/// Global instance of sender for platform events.
///
Expand Down Expand Up @@ -266,13 +269,14 @@ fn handle_input_msg(
)
};

// Ignore if data is invalid or not a mouse event. The `hDevice` check
// ignores programmatic mouse inputs via `SendInput` (this caused issues
// since `NativeWindow::set_foreground` simulates a mouse input).
// Ignore if data is invalid or not a mouse event. Inputs from our own
// process are ignored, which would cause issues since
// `NativeWindow::set_foreground` simulates a mouse input.
if res_size == 0
|| raw_input_size == u32::MAX
|| raw_input.header.dwType != RIM_TYPEMOUSE.0
|| raw_input.header.hDevice.is_invalid()
|| unsafe { raw_input.data.mouse.ulExtraInformation }
== FOREGROUND_INPUT_IDENTIFIER
{
return Ok(());
}
Expand Down
14 changes: 13 additions & 1 deletion packages/wm/src/common/platform/native_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use windows::{
},
},
UI::{
Input::KeyboardAndMouse::{SendInput, INPUT, INPUT_MOUSE},
Input::KeyboardAndMouse::{
SendInput, INPUT, INPUT_0, INPUT_MOUSE, MOUSEINPUT,
},
Shell::{ITaskbarList, TaskbarList},
WindowsAndMessaging::{
EnumWindows, GetClassNameW, GetWindow, GetWindowLongPtrW,
Expand All @@ -45,6 +47,10 @@ use crate::{
windows::WindowState,
};

/// Magic number used to identify programmatic mouse inputs from our own
/// process.
pub const FOREGROUND_INPUT_IDENTIFIER: u32 = 6379;

#[derive(Debug, Clone)]
pub struct NativeWindow {
pub handle: isize,
Expand Down Expand Up @@ -288,6 +294,12 @@ impl NativeWindow {
pub fn set_foreground(&self) -> anyhow::Result<()> {
let input = [INPUT {
r#type: INPUT_MOUSE,
Anonymous: INPUT_0 {
mi: MOUSEINPUT {
dwExtraInfo: FOREGROUND_INPUT_IDENTIFIER as usize,
..Default::default()
},
},
..Default::default()
}];

Expand Down

0 comments on commit 8e5591f

Please sign in to comment.