mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 01:58:51 +02:00
refactor(wm): use from trait to construct windows
This commit is contained in:
@@ -219,16 +219,10 @@ impl WindowManager {
|
|||||||
WindowsApi::left_click();
|
WindowsApi::left_click();
|
||||||
}
|
}
|
||||||
SocketMessage::Close => {
|
SocketMessage::Close => {
|
||||||
Window {
|
Window::from(WindowsApi::foreground_window()?).close()?;
|
||||||
hwnd: WindowsApi::foreground_window()?,
|
|
||||||
}
|
|
||||||
.close()?;
|
|
||||||
}
|
}
|
||||||
SocketMessage::Minimize => {
|
SocketMessage::Minimize => {
|
||||||
Window {
|
Window::from(WindowsApi::foreground_window()?).minimize();
|
||||||
hwnd: WindowsApi::foreground_window()?,
|
|
||||||
}
|
|
||||||
.minimize();
|
|
||||||
}
|
}
|
||||||
SocketMessage::ToggleFloat => self.toggle_float()?,
|
SocketMessage::ToggleFloat => self.toggle_float()?,
|
||||||
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
||||||
@@ -1342,7 +1336,7 @@ impl WindowManager {
|
|||||||
self.update_focused_workspace(false, false)?;
|
self.update_focused_workspace(false, false)?;
|
||||||
}
|
}
|
||||||
SocketMessage::DebugWindow(hwnd) => {
|
SocketMessage::DebugWindow(hwnd) => {
|
||||||
let window = Window { hwnd };
|
let window = Window::from(hwnd);
|
||||||
let mut rule_debug = RuleDebug::default();
|
let mut rule_debug = RuleDebug::default();
|
||||||
let _ = window.should_manage(None, &mut rule_debug);
|
let _ = window.should_manage(None, &mut rule_debug);
|
||||||
let schema = serde_json::to_string_pretty(&rule_debug)?;
|
let schema = serde_json::to_string_pretty(&rule_debug)?;
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ impl From<isize> for Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<HWND> for Window {
|
||||||
|
fn from(value: HWND) -> Self {
|
||||||
|
Self { hwnd: value.0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::module_name_repetitions)]
|
#[allow(clippy::module_name_repetitions)]
|
||||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||||
pub struct WindowDetails {
|
pub struct WindowDetails {
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ impl WindowManager {
|
|||||||
|
|
||||||
// Hide the window we are about to remove if it is on the currently focused workspace
|
// Hide the window we are about to remove if it is on the currently focused workspace
|
||||||
if op.is_origin(focused_monitor_idx, focused_workspace_idx) {
|
if op.is_origin(focused_monitor_idx, focused_workspace_idx) {
|
||||||
Window { hwnd: op.hwnd }.hide();
|
Window::from(op.hwnd).hide();
|
||||||
should_update_focused_workspace = true;
|
should_update_focused_workspace = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,7 +550,7 @@ impl WindowManager {
|
|||||||
.get_mut(op.target_workspace_idx)
|
.get_mut(op.target_workspace_idx)
|
||||||
.ok_or_else(|| anyhow!("there is no workspace with that index"))?;
|
.ok_or_else(|| anyhow!("there is no workspace with that index"))?;
|
||||||
|
|
||||||
target_workspace.new_container_for_window(Window { hwnd: op.hwnd });
|
target_workspace.new_container_for_window(Window::from(op.hwnd));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only re-tile the focused workspace if we need to
|
// Only re-tile the focused workspace if we need to
|
||||||
@@ -598,14 +598,14 @@ impl WindowManager {
|
|||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn manage_focused_window(&mut self) -> Result<()> {
|
pub fn manage_focused_window(&mut self) -> Result<()> {
|
||||||
let hwnd = WindowsApi::foreground_window()?;
|
let hwnd = WindowsApi::foreground_window()?;
|
||||||
let event = WindowManagerEvent::Manage(Window { hwnd });
|
let event = WindowManagerEvent::Manage(Window::from(hwnd));
|
||||||
Ok(winevent_listener::event_tx().send(event)?)
|
Ok(winevent_listener::event_tx().send(event)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn unmanage_focused_window(&mut self) -> Result<()> {
|
pub fn unmanage_focused_window(&mut self) -> Result<()> {
|
||||||
let hwnd = WindowsApi::foreground_window()?;
|
let hwnd = WindowsApi::foreground_window()?;
|
||||||
let event = WindowManagerEvent::Unmanage(Window { hwnd });
|
let event = WindowManagerEvent::Unmanage(Window::from(hwnd));
|
||||||
Ok(winevent_listener::event_tx().send(event)?)
|
Ok(winevent_listener::event_tx().send(event)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,15 +633,13 @@ impl WindowManager {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let event = WindowManagerEvent::Raise(Window { hwnd });
|
let event = WindowManagerEvent::Raise(Window::from(hwnd));
|
||||||
self.has_pending_raise_op = true;
|
self.has_pending_raise_op = true;
|
||||||
winevent_listener::event_tx().send(event)?;
|
winevent_listener::event_tx().send(event)?;
|
||||||
} else {
|
} else {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
"not raising unknown window: {}",
|
"not raising unknown window: {}",
|
||||||
Window {
|
Window::from(WindowsApi::window_at_cursor_pos()?)
|
||||||
hwnd: WindowsApi::window_at_cursor_pos()?
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,9 +763,7 @@ impl WindowManager {
|
|||||||
window.focus(self.mouse_follows_focus)?;
|
window.focus(self.mouse_follows_focus)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let desktop_window = Window {
|
let desktop_window = Window::from(WindowsApi::desktop_window()?);
|
||||||
hwnd: WindowsApi::desktop_window()?,
|
|
||||||
};
|
|
||||||
|
|
||||||
let rect = self.focused_monitor_size()?;
|
let rect = self.focused_monitor_size()?;
|
||||||
WindowsApi::center_cursor_in_rect(&rect)?;
|
WindowsApi::center_cursor_in_rect(&rect)?;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
|||||||
let is_maximized = WindowsApi::is_zoomed(hwnd);
|
let is_maximized = WindowsApi::is_zoomed(hwnd);
|
||||||
|
|
||||||
if is_visible && is_window && !is_minimized {
|
if is_visible && is_window && !is_minimized {
|
||||||
let window = Window { hwnd: hwnd.0 };
|
let window = Window::from(hwnd);
|
||||||
|
|
||||||
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
|
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
|
||||||
if should_manage {
|
if should_manage {
|
||||||
@@ -48,7 +48,7 @@ pub extern "system" fn alt_tab_windows(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
|||||||
let is_minimized = WindowsApi::is_iconic(hwnd);
|
let is_minimized = WindowsApi::is_iconic(hwnd);
|
||||||
|
|
||||||
if is_visible && is_window && !is_minimized {
|
if is_visible && is_window && !is_minimized {
|
||||||
let window = Window { hwnd: hwnd.0 };
|
let window = Window::from(hwnd);
|
||||||
|
|
||||||
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
|
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
|
||||||
if should_manage {
|
if should_manage {
|
||||||
@@ -74,7 +74,7 @@ pub extern "system" fn win_event_hook(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let window = Window { hwnd: hwnd.0 };
|
let window = Window::from(hwnd);
|
||||||
|
|
||||||
let winevent = match WinEvent::try_from(event) {
|
let winevent = match WinEvent::try_from(event) {
|
||||||
Ok(event) => event,
|
Ok(event) => event,
|
||||||
|
|||||||
Reference in New Issue
Block a user