Skip to content

Commit

Permalink
fix(wm): use focus fn in komorebi ffm
Browse files Browse the repository at this point in the history
This commit swaps out the old "raise" fn for the more up-to-date and
tested "focus" fn when raising a window for focus when the "komorebi"
implementation of focus follows mouse is enabled.
  • Loading branch information
LGUG2Z committed Mar 16, 2024
1 parent 69573c3 commit bc46f65
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 52 deletions.
2 changes: 1 addition & 1 deletion komorebi/src/process_event.rs
Expand Up @@ -147,7 +147,7 @@ impl WindowManager {

match event {
WindowManagerEvent::Raise(window) => {
window.raise();
window.focus(false)?;
self.has_pending_raise_op = false;
}
WindowManagerEvent::Destroy(_, window) | WindowManagerEvent::Unmanage(window) => {
Expand Down
51 changes: 0 additions & 51 deletions komorebi/src/window.rs
Expand Up @@ -215,57 +215,6 @@ impl Window {
WindowsApi::unmaximize_window(self.hwnd());
}

pub fn raise(self) {
// Attach komorebi thread to Window thread
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
let current_thread_id = WindowsApi::current_thread_id();

// This can be allowed to fail if a window doesn't have a message queue or if a journal record
// hook has been installed
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-attachthreadinput#remarks
match WindowsApi::attach_thread_input(current_thread_id, window_thread_id, true) {
Ok(()) => {}
Err(error) => {
tracing::error!(
"could not attach to window thread input processing mechanism, but continuing execution of raise(): {}",
error
);
}
};

// Raise Window to foreground
match WindowsApi::set_foreground_window(self.hwnd()) {
Ok(()) => {}
Err(error) => {
tracing::error!(
"could not set as foreground window, but continuing execution of raise(): {}",
error
);
}
};

// This isn't really needed when the above command works as expected via AHK
match WindowsApi::set_focus(self.hwnd()) {
Ok(()) => {}
Err(error) => {
tracing::error!(
"could not set focus, but continuing execution of raise(): {}",
error
);
}
};

match WindowsApi::attach_thread_input(current_thread_id, window_thread_id, false) {
Ok(()) => {}
Err(error) => {
tracing::error!(
"could not detach from window thread input processing mechanism, but continuing execution of raise(): {}",
error
);
}
};
}

pub fn focus(self, mouse_follows_focus: bool) -> Result<()> {
// Attach komorebi thread to Window thread
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
Expand Down

0 comments on commit bc46f65

Please sign in to comment.