diff --git a/docs/komorebi.bar.example.json b/docs/komorebi.bar.example.json index 0176e313..e2181b66 100644 --- a/docs/komorebi.bar.example.json +++ b/docs/komorebi.bar.example.json @@ -1,6 +1,5 @@ { "$schema": "https://komorebi-for-mac.lgug2z.com/komorebi.bar.0.1.0.schema.json", - "monitor": 0, "font_family": "JetBrainsMono Nerd Font", "height": 40, "theme": { diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index 7e908265..f7230441 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -444,10 +444,11 @@ impl Komobar { self.right_widgets = right_widgets; let (usr_monitor_index, config_work_area_offset) = match &self.config.monitor { - MonitorConfigOrIndex::MonitorConfig(monitor_config) => { + Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => { (monitor_config.index, monitor_config.work_area_offset) } - MonitorConfigOrIndex::Index(idx) => (*idx, None), + Some(MonitorConfigOrIndex::Index(idx)) => (*idx, None), + None => (0, None), }; let mapped_info = self.monitor_info.as_ref().map(|info| { @@ -479,43 +480,50 @@ impl Komobar { } else { tracing::info!("work area offset applied to monitor: {}", monitor_index); } + } else if let Some(height) = self.config.height.or(Some(BAR_HEIGHT)) { + let mut should_adjust = true; + + // only want to send the work area offset on non-built-in displays + if let Some(monitor_info) = self.monitor_info.as_ref() + && monitor_info.borrow().device.contains("Built-in") + { + should_adjust = false; + } + + if should_adjust { + // We only add the `bottom_margin` to the work_area_offset since the top margin is + // already considered on the `size_rect.top` + let bottom_margin = self + .config + .margin + .as_ref() + .map_or(0, |v| v.to_individual(0.0).bottom as i32); + + let new_rect = komorebi_client::Rect { + left: 0, + top: (height as i32) + + (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst)) + + bottom_margin, + right: 0, + bottom: (height as i32) + + (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst)) + + bottom_margin, + }; + + if new_rect != self.work_area_offset { + self.work_area_offset = new_rect; + if let Err(error) = komorebi_client::send_message( + &SocketMessage::MonitorWorkAreaOffset(monitor_index, new_rect), + ) { + tracing::error!( + "error applying work area offset to monitor '{monitor_index}': {error}" + ); + } else { + tracing::info!("work area offset applied to monitor: {monitor_index}",); + } + } + } } - // TODO: Not sure if we need this now that we are drawing behind the notch - // TODO: Also need to figure out how this looks on external monitors - // TODO: Probably not going to support other positions on macOS - // else if let Some(height) = self.config.height.or(Some(BAR_HEIGHT)) { - // // We only add the `bottom_margin` to the work_area_offset since the top margin is - // // already considered on the `size_rect.top` - // let bottom_margin = self - // .config - // .margin - // .as_ref() - // .map_or(0, |v| v.to_individual(0.0).bottom as i32); - - // let new_rect = komorebi_client::Rect { - // left: 0, - // top: (height as i32) - // + (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst)) - // + bottom_margin, - // right: 0, - // bottom: (height as i32) - // + (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst)) - // + bottom_margin, - // }; - - // if new_rect != self.work_area_offset { - // self.work_area_offset = new_rect; - // if let Err(error) = komorebi_client::send_message( - // &SocketMessage::MonitorWorkAreaOffset(monitor_index, new_rect), - // ) { - // tracing::error!( - // "error applying work area offset to monitor '{monitor_index}': {error}" - // ); - // } else { - // tracing::info!("work area offset applied to monitor: {monitor_index}",); - // } - // } - // } } else if self.monitor_info.is_some() && !self.disabled { tracing::warn!( "couldn't find the monitor index of this bar! Disabling the bar until the monitor connects..." @@ -859,9 +867,13 @@ impl eframe::App for Komobar { Ok(KomorebiEvent::Notification(notification)) => { let state = ¬ification.state; let usr_monitor_index = match &self.config.monitor { - MonitorConfigOrIndex::MonitorConfig(monitor_config) => monitor_config.index, - MonitorConfigOrIndex::Index(idx) => *idx, + Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => { + monitor_config.index + } + Some(MonitorConfigOrIndex::Index(idx)) => *idx, + None => 0, }; + let monitor_index = state.monitor_usr_idx_map.get(&usr_monitor_index).copied(); self.monitor_index = monitor_index; let mut should_apply_config = false; diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index 8f8d2ce4..ab58ef35 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -76,7 +76,8 @@ pub struct KomobarConfig { /// Frame options (see: https://docs.rs/egui/latest/egui/containers/frame/struct.Frame.html) pub frame: Option, /// The monitor index or the full monitor options - pub monitor: MonitorConfigOrIndex, + #[cfg_attr(feature = "schemars", schemars(extend("default" = MonitorConfigOrIndex::Index(0))))] + pub monitor: Option, /// Font family pub font_family: Option, /// Font size diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index bfdcb2c2..3396239b 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -186,10 +186,11 @@ fn main() -> eyre::Result<()> { )?)?; let (usr_monitor_index, work_area_offset) = match &config.monitor { - MonitorConfigOrIndex::MonitorConfig(monitor_config) => { + Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => { (monitor_config.index, monitor_config.work_area_offset) } - MonitorConfigOrIndex::Index(idx) => (*idx, None), + Some(MonitorConfigOrIndex::Index(idx)) => (*idx, None), + None => (0, None), }; let monitor_index = state .monitor_usr_idx_map diff --git a/komorebi-bar/src/render.rs b/komorebi-bar/src/render.rs index 36c67eb9..6634a346 100644 --- a/komorebi-bar/src/render.rs +++ b/komorebi-bar/src/render.rs @@ -98,8 +98,9 @@ impl RenderExt for &KomobarConfig { icon_font_id.size *= icon_scale.unwrap_or(1.4).clamp(1.0, 2.0); let monitor_idx = match &self.monitor { - MonitorConfigOrIndex::MonitorConfig(monitor_config) => monitor_config.index, - MonitorConfigOrIndex::Index(idx) => *idx, + Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => monitor_config.index, + Some(MonitorConfigOrIndex::Index(idx)) => *idx, + None => 0, }; // check if any of the alignments have a komorebi widget with the workspace set to show all icons diff --git a/komorebi-bar/src/widgets/komorebi.rs b/komorebi-bar/src/widgets/komorebi.rs index 4b97fbd4..84deafd1 100644 --- a/komorebi-bar/src/widgets/komorebi.rs +++ b/komorebi-bar/src/widgets/komorebi.rs @@ -762,6 +762,7 @@ impl LockedContainerBar { /// Updated whenever Komorebi state changes. #[derive(Clone, Debug)] pub struct MonitorInfo { + pub device: String, pub workspaces: Vec, pub layout: KomorebiLayout, pub mouse_follows_focus: bool, @@ -776,6 +777,7 @@ pub struct MonitorInfo { impl Default for MonitorInfo { fn default() -> Self { Self { + device: String::default(), workspaces: Vec::new(), layout: KomorebiLayout::Default(komorebi_client::DefaultLayout::BSP), mouse_follows_focus: true, @@ -829,6 +831,7 @@ impl MonitorInfo { let monitor = &state.monitors.elements()[self.monitor_index]; self.work_area_offset = monitor.work_area_offset; self.focused_workspace_idx = Some(monitor.focused_workspace_idx()); + self.device = monitor.device.clone(); // Layout let focused_ws = &monitor.workspaces()[monitor.focused_workspace_idx()]; diff --git a/nix/komorebi-bar-options.nix b/nix/komorebi-bar-options.nix index 69a10842..38a1bc7c 100644 --- a/nix/komorebi-bar-options.nix +++ b/nix/komorebi-bar-options.nix @@ -875,46 +875,49 @@ in }; monitor = lib.mkOption { type = ( - lib.types.oneOf [ - lib.types.int - (lib.types.submodule { - options = { - index = lib.mkOption { - type = lib.types.int; - description = "Komorebi monitor index of the monitor on which to render the bar"; + lib.types.nullOr ( + lib.types.oneOf [ + lib.types.int + (lib.types.submodule { + options = { + index = lib.mkOption { + type = lib.types.int; + description = "Komorebi monitor index of the monitor on which to render the bar"; + }; + work_area_offset = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.submodule { + options = { + bottom = lib.mkOption { + type = lib.types.int; + description = "Height of the rectangle (from the top point)"; + }; + left = lib.mkOption { + type = lib.types.int; + description = "Left point of the rectangle"; + }; + right = lib.mkOption { + type = lib.types.int; + description = "Width of the recentangle (from the left point)"; + }; + top = lib.mkOption { + type = lib.types.int; + description = "Top point of the rectangle"; + }; + }; + } + ) + ); + default = null; + description = "Automatically apply a work area offset for this monitor to accommodate the bar"; + }; }; - work_area_offset = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.submodule { - options = { - bottom = lib.mkOption { - type = lib.types.int; - description = "Height of the rectangle (from the top point)"; - }; - left = lib.mkOption { - type = lib.types.int; - description = "Left point of the rectangle"; - }; - right = lib.mkOption { - type = lib.types.int; - description = "Width of the recentangle (from the left point)"; - }; - top = lib.mkOption { - type = lib.types.int; - description = "Top point of the rectangle"; - }; - }; - } - ) - ); - default = null; - description = "Automatically apply a work area offset for this monitor to accommodate the bar"; - }; - }; - }) - ] + }) + ] + ) ); + default = 0; description = "The monitor index or the full monitor options"; }; padding = lib.mkOption { @@ -962,17 +965,6 @@ in ] ); }; - auto_select_text = 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 ( @@ -1259,7 +1251,18 @@ in ); default = null; }; - accent = lib.mkOption { + auto_select_text = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + auto_select_fill = lib.mkOption { type = ( lib.types.nullOr ( lib.types.oneOf [ @@ -1345,7 +1348,7 @@ in ); default = null; }; - auto_select_fill = lib.mkOption { + accent = lib.mkOption { type = ( lib.types.nullOr ( lib.types.oneOf [ diff --git a/nix/komorebi-options.nix b/nix/komorebi-options.nix index 2afd533a..fbf0b177 100644 --- a/nix/komorebi-options.nix +++ b/nix/komorebi-options.nix @@ -778,50 +778,6 @@ in ] ); }; - 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; - }; - unfocused_locked_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - stack_border = 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 ( @@ -897,6 +853,50 @@ in ); default = null; }; + stack_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; + }; + single_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 ( @@ -1183,17 +1183,6 @@ in ); default = null; }; - single_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 ( @@ -1205,7 +1194,18 @@ in ); default = null; }; - unfocused_border = lib.mkOption { + monocle_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + floating_border = lib.mkOption { type = ( lib.types.nullOr ( lib.types.oneOf [ diff --git a/schema.bar.json b/schema.bar.json index 5ca0a0e4..97478101 100644 --- a/schema.bar.json +++ b/schema.bar.json @@ -99,7 +99,15 @@ }, "monitor": { "description": "The monitor index or the full monitor options", - "$ref": "#/$defs/MonitorConfigOrIndex" + "anyOf": [ + { + "$ref": "#/$defs/MonitorConfigOrIndex" + }, + { + "type": "null" + } + ], + "default": 0 }, "padding": { "description": "Bar padding. Use one value for all sides or use a grouped padding for horizontal and/or\nvertical definition which can each take a single value for a symmetric padding or two\nvalues for each side, i.e.:\n```json\n\"padding\": {\n \"horizontal\": 10.0\n}\n```\nor:\n```json\n\"padding\": {\n \"horizontal\": [left, right]\n}\n```\nYou can also set individual padding on each side like this:\n```json\n\"padding\": {\n \"top\": 10.0,\n \"bottom\": 10.0,\n \"left\": 10.0,\n \"right\": 10.0\n}\n```", @@ -163,7 +171,6 @@ } }, "required": [ - "monitor", "left_widgets", "right_widgets" ],