mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 01:58:51 +02:00
fix(wm): detach thread inputs explicitly
This commit ensures that any calls to AttachThreadInput which are used to allow the focusing or raising of a window are paired with a closing call to detach the thread input. Although undocumented, it seems that when attaching the input thread of a window to an admin/sudo process, this prevents that window from handling inputs from any unelevated processes (including regular keyboard and mouse inputs), until the input thread is detached. fix #86
This commit is contained in:
@@ -311,6 +311,11 @@ Run, komorebic.exe float-rule exe "TranslucentTB.exe", , Hide
|
|||||||
; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
|
; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
|
||||||
Run, komorebic.exe identify-tray-application exe "TranslucentTB.exe", , Hide
|
Run, komorebic.exe identify-tray-application exe "TranslucentTB.exe", , Hide
|
||||||
|
|
||||||
|
; Unreal Editor
|
||||||
|
Run, komorebic.exe identify-border-overflow-application exe "UnrealEditor.exe", , Hide
|
||||||
|
; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line
|
||||||
|
Run, komorebic.exe identify-tray-application exe "UnrealEditor.exe", , Hide
|
||||||
|
|
||||||
; Visual Studio Code
|
; Visual Studio Code
|
||||||
Run, komorebic.exe identify-border-overflow-application exe "Code.exe", , Hide
|
Run, komorebic.exe identify-border-overflow-application exe "Code.exe", , Hide
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
WindowManagerEvent::Raise(window) => {
|
WindowManagerEvent::Raise(window) => {
|
||||||
window.raise()?;
|
window.raise();
|
||||||
self.has_pending_raise_op = false;
|
self.has_pending_raise_op = false;
|
||||||
}
|
}
|
||||||
WindowManagerEvent::Destroy(_, window) | WindowManagerEvent::Unmanage(window) => {
|
WindowManagerEvent::Destroy(_, window) | WindowManagerEvent::Unmanage(window) => {
|
||||||
|
|||||||
@@ -187,25 +187,55 @@ impl Window {
|
|||||||
WindowsApi::unmaximize_window(self.hwnd());
|
WindowsApi::unmaximize_window(self.hwnd());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raise(self) -> Result<()> {
|
pub fn raise(self) {
|
||||||
// Attach komorebi thread to Window thread
|
// Attach komorebi thread to Window thread
|
||||||
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
|
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
|
||||||
let current_thread_id = WindowsApi::current_thread_id();
|
let current_thread_id = WindowsApi::current_thread_id();
|
||||||
WindowsApi::attach_thread_input(current_thread_id, window_thread_id, true)?;
|
|
||||||
|
// 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
|
// Raise Window to foreground
|
||||||
match WindowsApi::set_foreground_window(self.hwnd()) {
|
match WindowsApi::set_foreground_window(self.hwnd()) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"could not set as foreground window, but continuing execution of focus(): {}",
|
"could not set as foreground window, but continuing execution of raise(): {}",
|
||||||
error
|
error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This isn't really needed when the above command works as expected via AHK
|
// This isn't really needed when the above command works as expected via AHK
|
||||||
WindowsApi::set_focus(self.hwnd())
|
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<()> {
|
pub fn focus(self, mouse_follows_focus: bool) -> Result<()> {
|
||||||
@@ -253,6 +283,16 @@ impl Window {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 focus(): {}",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user