From 4811a056e9dfedcb13b25470d9612b4827fbb328 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 20:16:07 -0700 Subject: [PATCH] refactor(kde): Minimize, Close and DebugWindow are methods with the macOS names The inline router arms become minimize_foreground_window, close_foreground_window and debug_window(window_id, reply) with the bodies they had, so that the three arms are the same text as macOS's (the bodies differ by the platform: the backend and Window::from here, the foreground element and the Accessibility window list there). Pure move, no behaviour change. Verified: KDE cargo check --all-targets and lib tests PASS; tools/format-all --apply --tree kde ran. --- .../komorebi/src/process_command.rs | 68 ++++++++++++------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/komorebi-for-kde/komorebi/src/process_command.rs b/komorebi-for-kde/komorebi/src/process_command.rs index fc38bd9e..1d660b58 100644 --- a/komorebi-for-kde/komorebi/src/process_command.rs +++ b/komorebi-for-kde/komorebi/src/process_command.rs @@ -1330,18 +1330,8 @@ impl WindowManager { SocketMessage::ResizeWindowAxis(axis, sizing) => { self.resize_window_axis(axis, sizing)? } - SocketMessage::Minimize => { - let foreground_window = backend() - .foreground_window() - .ok_or_eyre("there is no foreground window")?; - Window::from(foreground_window).minimize()?; - } - SocketMessage::Close => { - let foreground_window = backend() - .foreground_window() - .ok_or_eyre("there is no foreground window")?; - Window::from(foreground_window).close()?; - } + SocketMessage::Minimize => self.minimize_foreground_window()?, + SocketMessage::Close => self.close_foreground_window()?, SocketMessage::ManageFocusedWindow => { self.manage_focused_window()?; } @@ -1819,19 +1809,7 @@ impl WindowManager { workspace.resize_dimensions = resize; self.update_focused_workspace(false, false)?; } - SocketMessage::DebugWindow(window_id) => { - // an id that is not a u32 is not a window - let window = u32::try_from(window_id).map(Window::from); - if let Ok(window) = window - && window.is_valid() - { - let mut rule_debug = RuleDebug::default(); - let _ = window.should_manage(None, &mut rule_debug); - let schema = serde_json::to_string_pretty(&rule_debug)?; - - reply.write_all(schema.as_bytes())?; - } - } + SocketMessage::DebugWindow(window_id) => self.debug_window(window_id, &mut reply)?, SocketMessage::Border(enable) => { border_manager::BORDER_ENABLED.store(enable, Ordering::SeqCst); if !enable { @@ -1994,6 +1972,46 @@ pub fn read_commands_uds(wm: &Arc>, stream: UnixStream) -> komorebi_transport::read_commands::(wm, stream, &NoPolicy) } +impl WindowManager { + /// Minimizes the window that has the focus + pub fn minimize_foreground_window(&mut self) -> eyre::Result<()> { + let foreground_window = backend() + .foreground_window() + .ok_or_eyre("there is no foreground window")?; + Window::from(foreground_window).minimize()?; + Ok(()) + } + + /// Closes the window that has the focus + pub fn close_foreground_window(&mut self) -> eyre::Result<()> { + let foreground_window = backend() + .foreground_window() + .ok_or_eyre("there is no foreground window")?; + Window::from(foreground_window).close()?; + Ok(()) + } + + /// Answers with why the window of this id is, or is not, managed + pub fn debug_window( + &self, + window_id: i64, + reply: &mut impl std::io::Write, + ) -> eyre::Result<()> { + // an id that is not a u32 is not a window + let window = u32::try_from(window_id).map(Window::from); + if let Ok(window) = window + && window.is_valid() + { + let mut rule_debug = RuleDebug::default(); + let _ = window.should_manage(None, &mut rule_debug); + let schema = serde_json::to_string_pretty(&rule_debug)?; + + reply.write_all(schema.as_bytes())?; + } + Ok(()) + } +} + /// The window manager as the shared commands of `komorebi_core::command` see it impl komorebi_core::CommandHost for WindowManager { type P = crate::workspace::KdePlatform;