diff --git a/Cargo.lock b/Cargo.lock index 995920fb..f730c248 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3091,7 +3091,7 @@ dependencies = [ [[package]] name = "komorebi-layouts" version = "0.1.40" -source = "git+https://github.com/LGUG2Z/komorebi?rev=98122bd9d4aabbff927a29228acf6c8a0246c509#98122bd9d4aabbff927a29228acf6c8a0246c509" +source = "git+https://github.com/LGUG2Z/komorebi?rev=c165172b5a636f383739a99dc51a35fe4a3a77ef#c165172b5a636f383739a99dc51a35fe4a3a77ef" dependencies = [ "clap", "color-eyre", diff --git a/Cargo.toml b/Cargo.toml index c72dbe2d..b3938aae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" [workspace.dependencies] komorebi-themes = { git = "https://github.com/LGUG2Z/komorebi", rev = "98122bd9d4aabbff927a29228acf6c8a0246c509" } -komorebi-layouts = { git = "https://github.com/LGUG2Z/komorebi", rev = "98122bd9d4aabbff927a29228acf6c8a0246c509", features = [ +komorebi-layouts = { git = "https://github.com/LGUG2Z/komorebi", rev = "c165172b5a636f383739a99dc51a35fe4a3a77ef", features = [ "darwin", "schemars", ] } diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index ef3d0ff9..b8d6d56c 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -30,6 +30,7 @@ pub use komorebi_layouts::OperationDirection; pub use komorebi_layouts::Rect; pub use komorebi_layouts::ScrollingLayoutOptions; pub use komorebi_layouts::Sizing; +pub use komorebi_layouts::validate_ratios; // Keep local modules that aren't in komorebi-layouts pub mod animation; @@ -315,6 +316,7 @@ pub enum SocketMessage { ChangeLayout(DefaultLayout), CycleLayout(CycleDirection), ScrollingLayoutColumns(NonZeroUsize), + LayoutRatios(Option>, Option>), // ChangeLayoutCustom(#[serde_as(as = "ResolvedPathBuf")] PathBuf), FlipLayout(Axis), ToggleWorkspaceWindowContainerBehaviour, diff --git a/komorebi/src/core/rect_ext.rs b/komorebi/src/core/rect_ext.rs new file mode 100644 index 00000000..3b2c5ad2 --- /dev/null +++ b/komorebi/src/core/rect_ext.rs @@ -0,0 +1,29 @@ +use crate::core::Rect; +use crate::core_graphics::CoreGraphicsApi; +use crate::window::WindowBounds; +use objc2_core_foundation::CGRect; + +/// Mac-specific extensions for the Rect type from komorebi-layouts +pub trait RectExt { + /// Check if this rectangle contains another rectangle + fn contains(&self, other: &Rect) -> bool; +} + +impl RectExt for Rect { + fn contains(&self, other: &Rect) -> bool { + let self_cg: CGRect = self.into(); + let other_cg: CGRect = other.into(); + CoreGraphicsApi::contains_rect(other_cg, self_cg) + } +} + +impl From for Rect { + fn from(value: WindowBounds) -> Self { + Self { + left: value.x as i32, + top: value.y as i32, + right: value.width as i32, + bottom: value.height as i32, + } + } +} diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 3d4d9943..4281751f 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -36,6 +36,7 @@ use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::core::config_generation::WorkspaceMatchingRule; + use crate::core_graphics::CoreGraphicsApi; use crate::current_space_id; use crate::macos_api::MacosApi; @@ -1521,6 +1522,29 @@ impl WindowManager { focused_workspace.layout_options = Some(options); self.update_focused_workspace(false, false)?; } + SocketMessage::LayoutRatios(ref columns, ref rows) => { + use crate::core::validate_ratios; + + let focused_workspace = self.focused_workspace_mut()?; + + let mut options = focused_workspace.layout_options.unwrap_or(LayoutOptions { + scrolling: None, + grid: None, + column_ratios: None, + row_ratios: None, + }); + + if let Some(cols) = columns { + options.column_ratios = Some(validate_ratios(cols)); + } + + if let Some(rws) = rows { + options.row_ratios = Some(validate_ratios(rws)); + } + + focused_workspace.layout_options = Some(options); + self.update_focused_workspace(false, false)?; + } SocketMessage::NamedWorkspaceLayoutRule(ref workspace, at_container_count, layout) => { if let Some((monitor_idx, workspace_idx)) = self.monitor_workspace_index_by_name(workspace) diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 8090822e..5f39e413 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -621,6 +621,16 @@ struct ScrollingLayoutColumns { count: NonZeroUsize, } +#[derive(Parser)] +struct LayoutRatios { + /// Column width ratios (space-separated values between 0.1 and 0.9) + #[clap(short, long, num_args = 1..)] + columns: Option>, + /// Row height ratios (space-separated values between 0.1 and 0.9) + #[clap(short, long, num_args = 1..)] + rows: Option>, +} + #[derive(Parser)] struct Border { #[clap(value_enum)] @@ -969,6 +979,8 @@ enum SubCommand { /// Set the number of visible columns for the Scrolling layout on the focused workspace #[clap(arg_required_else_help = true)] ScrollingLayoutColumns(ScrollingLayoutColumns), + /// Set the layout column and row ratios for the focused workspace + LayoutRatios(LayoutRatios), // /// Load a custom layout from file for the focused workspace // #[clap(hide = true)] // #[clap(arg_required_else_help = true)] @@ -2337,6 +2349,15 @@ exit 1 SubCommand::ScrollingLayoutColumns(args) => { send_message(&SocketMessage::ScrollingLayoutColumns(args.count))?; } + SubCommand::LayoutRatios(args) => { + if args.columns.is_none() && args.rows.is_none() { + println!( + "No ratios provided, nothing to change. Use --columns or --rows to specify ratios." + ); + } else { + send_message(&SocketMessage::LayoutRatios(args.columns, args.rows))?; + } + } SubCommand::ClearWorkspaceLayoutRules(args) => { send_message(&SocketMessage::ClearWorkspaceLayoutRules( args.monitor, diff --git a/nix/komorebi-bar-options.nix b/nix/komorebi-bar-options.nix index eeef511f..730623e6 100644 --- a/nix/komorebi-bar-options.nix +++ b/nix/komorebi-bar-options.nix @@ -976,6 +976,17 @@ in ); default = null; }; + accent = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; colours = lib.mkOption { type = ( lib.types.nullOr ( @@ -1051,28 +1062,6 @@ in ); default = null; }; - auto_select_fill = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - accent = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; name = lib.mkOption { type = ( lib.types.nullOr ( @@ -1359,6 +1348,17 @@ in ); default = null; }; + auto_select_fill = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; }; } ) diff --git a/nix/komorebi-options.nix b/nix/komorebi-options.nix index dc2e4062..940d2a86 100644 --- a/nix/komorebi-options.nix +++ b/nix/komorebi-options.nix @@ -788,17 +788,6 @@ in ] ); }; - floating_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; name = lib.mkOption { type = ( lib.types.nullOr ( @@ -1107,50 +1096,6 @@ in ); default = null; }; - monocle_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - unfocused_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - unfocused_locked_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - bar_accent = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; colours = lib.mkOption { type = ( lib.types.nullOr ( @@ -1226,6 +1171,61 @@ in ); default = null; }; + floating_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + monocle_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + bar_accent = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + unfocused_locked_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + unfocused_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; }; } )