diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 35d34e9c..ea0114c4 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -248,7 +248,7 @@ pub enum SocketMessage { SwapWorkspacesToMonitorNumber(usize), // ForceFocus, // Close, - // Minimize, + Minimize, Promote, PromoteFocus, PromoteWindow(OperationDirection), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 0f74b17f..2262530f 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -240,6 +240,11 @@ impl WindowManager { } self.focus_container_window(idx)?; } + SocketMessage::Minimize => { + let foreground_window = + MacosApi::foreground_window().ok_or_eyre("there is no foreground window")?; + AdhocWindow::minimize(&foreground_window)?; + } SocketMessage::LockMonitorWorkspaceContainer( monitor_idx, workspace_idx, diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 28bc8e40..ed6a4ca7 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -752,6 +752,12 @@ impl AdhocWindow { .map(|s| s.to_string()) } + pub fn minimize(element: &CFRetained) -> Result<(), AccessibilityError> { + let cf_boolean = CFBoolean::new(true); + let value = &**cf_boolean; + AccessibilityApi::set_attribute_cf_value(element, kAXMinimizedAttribute, value) + } + #[tracing::instrument(skip_all)] pub fn hide(id: u32, element: &CFRetained) -> Result<(), AccessibilityError> { let mut window_restore_positions = WINDOW_RESTORE_POSITIONS.lock(); diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 29caf8fe..80d6dcdb 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -660,8 +660,8 @@ enum SubCommand { /// Move the focused window in the specified direction #[clap(arg_required_else_help = true)] Move(Move), - // /// Minimize the focused window - // Minimize, + /// Minimize the focused window + Minimize, // /// Close the focused window // Close, // /// Forcibly focus the window at the cursor with a left mouse click @@ -1307,6 +1307,9 @@ fn main() -> eyre::Result<()> { SubCommand::Retile => { send_message(&SocketMessage::Retile)?; } + SubCommand::Minimize => { + send_message(&SocketMessage::Minimize)?; + } SubCommand::Promote => { send_message(&SocketMessage::Promote)?; }