mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 10:08:33 +02:00
refactor(windows_callbacks): push logic further up
The win_event_hook was still just a messy copy-paste from the yatta days. This commit pushes the logic around deciding if we should emit a WindowManagerEvent::Show from a WinEvent::ObjectNameChange up to the WindowManagerEvent::from_win_event method. Now, the win_event_hook is just calling other functions that decide what to do with the window and passing on the results.
This commit is contained in:
@@ -3,6 +3,7 @@ use std::fmt::Formatter;
|
|||||||
|
|
||||||
use crate::window::Window;
|
use crate::window::Window;
|
||||||
use crate::winevent::WinEvent;
|
use crate::winevent::WinEvent;
|
||||||
|
use crate::OBJECT_NAME_CHANGE_ON_LAUNCH;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum WindowManagerEvent {
|
pub enum WindowManagerEvent {
|
||||||
@@ -68,24 +69,42 @@ impl WindowManagerEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn from_win_event(winevent: WinEvent, window: Window) -> Option<Self> {
|
pub fn from_win_event(winevent: WinEvent, window: Window) -> Option<Self> {
|
||||||
match winevent {
|
match winevent {
|
||||||
WinEvent::ObjectDestroy => Some(Self::Destroy(winevent, window)),
|
WinEvent::ObjectDestroy => Option::from(Self::Destroy(winevent, window)),
|
||||||
|
|
||||||
WinEvent::ObjectCloaked | WinEvent::ObjectHide => Some(Self::Hide(winevent, window)),
|
WinEvent::ObjectCloaked | WinEvent::ObjectHide => {
|
||||||
|
Option::from(Self::Hide(winevent, window))
|
||||||
|
}
|
||||||
|
|
||||||
WinEvent::SystemMinimizeStart => Some(Self::Minimize(winevent, window)),
|
WinEvent::SystemMinimizeStart => Option::from(Self::Minimize(winevent, window)),
|
||||||
|
|
||||||
WinEvent::ObjectShow | WinEvent::ObjectUncloaked | WinEvent::SystemMinimizeEnd => {
|
WinEvent::ObjectShow | WinEvent::ObjectUncloaked | WinEvent::SystemMinimizeEnd => {
|
||||||
Some(Self::Show(winevent, window))
|
Option::from(Self::Show(winevent, window))
|
||||||
}
|
}
|
||||||
|
|
||||||
WinEvent::ObjectFocus | WinEvent::SystemForeground => {
|
WinEvent::ObjectFocus | WinEvent::SystemForeground => {
|
||||||
Some(Self::FocusChange(winevent, window))
|
Option::from(Self::FocusChange(winevent, window))
|
||||||
}
|
}
|
||||||
WinEvent::SystemMoveSizeEnd => Some(Self::MoveResizeEnd(winevent, window)),
|
WinEvent::SystemMoveSizeEnd => Option::from(Self::MoveResizeEnd(winevent, window)),
|
||||||
WinEvent::SystemCaptureStart | WinEvent::SystemCaptureEnd => {
|
WinEvent::SystemCaptureStart | WinEvent::SystemCaptureEnd => {
|
||||||
Some(Self::MouseCapture(winevent, window))
|
Option::from(Self::MouseCapture(winevent, window))
|
||||||
|
}
|
||||||
|
WinEvent::ObjectNameChange => {
|
||||||
|
// Some apps like Firefox don't send ObjectCreate or ObjectShow on launch
|
||||||
|
// This spams the message queue, but I don't know what else to do. On launch
|
||||||
|
// it only sends the following WinEvents :/
|
||||||
|
//
|
||||||
|
// [yatta\src\windows_event.rs:110] event = 32780 ObjectNameChange
|
||||||
|
// [yatta\src\windows_event.rs:110] event = 32779 ObjectLocationChange
|
||||||
|
|
||||||
|
let object_name_change_on_launch = OBJECT_NAME_CHANGE_ON_LAUNCH.lock();
|
||||||
|
|
||||||
|
if object_name_change_on_launch.contains(&window.exe().ok()?) {
|
||||||
|
Option::from(Self::Show(winevent, window))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ use crate::ring::Ring;
|
|||||||
use crate::window::Window;
|
use crate::window::Window;
|
||||||
use crate::window_manager_event::WindowManagerEvent;
|
use crate::window_manager_event::WindowManagerEvent;
|
||||||
use crate::windows_api::WindowsApi;
|
use crate::windows_api::WindowsApi;
|
||||||
use crate::winevent::WinEvent;
|
|
||||||
use crate::winevent_listener::WINEVENT_CALLBACK_CHANNEL;
|
use crate::winevent_listener::WINEVENT_CALLBACK_CHANNEL;
|
||||||
use crate::OBJECT_NAME_CHANGE_ON_LAUNCH;
|
|
||||||
|
|
||||||
pub extern "system" fn enum_display_monitor(
|
pub extern "system" fn enum_display_monitor(
|
||||||
hmonitor: HMONITOR,
|
hmonitor: HMONITOR,
|
||||||
@@ -71,30 +69,9 @@ pub extern "system" fn win_event_hook(
|
|||||||
let window = Window { hwnd: hwnd.0 };
|
let window = Window { hwnd: hwnd.0 };
|
||||||
|
|
||||||
let winevent = unsafe { ::std::mem::transmute(event) };
|
let winevent = unsafe { ::std::mem::transmute(event) };
|
||||||
let event_type = if let Some(event) = WindowManagerEvent::from_win_event(winevent, window) {
|
let event_type = match WindowManagerEvent::from_win_event(winevent, window) {
|
||||||
event
|
None => return,
|
||||||
} else {
|
Some(event) => event,
|
||||||
// Some apps like Firefox don't send ObjectCreate or ObjectShow on launch
|
|
||||||
// This spams the message queue, but I don't know what else to do. On launch
|
|
||||||
// it only sends the following WinEvents :/
|
|
||||||
//
|
|
||||||
// [yatta\src\windows_event.rs:110] event = 32780 ObjectNameChange
|
|
||||||
// [yatta\src\windows_event.rs:110] event = 32779 ObjectLocationChange
|
|
||||||
let object_name_change_on_launch = OBJECT_NAME_CHANGE_ON_LAUNCH.lock();
|
|
||||||
|
|
||||||
if let Ok(exe) = window.exe() {
|
|
||||||
if winevent == WinEvent::ObjectNameChange {
|
|
||||||
if object_name_change_on_launch.contains(&exe) {
|
|
||||||
WindowManagerEvent::Show(winevent, window)
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(should_manage) = window.should_manage(Option::from(event_type)) {
|
if let Ok(should_manage) = window.should_manage(Option::from(event_type)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user