feat(bar): make explicit monitor config optional

This commit makes the monitor configuration option for the komorebi-bar
optional, defaulting to index 0.
This commit is contained in:
LGUG2Z
2026-01-04 19:15:21 -08:00
parent 1219c3d118
commit 8805fafa99
5 changed files with 18 additions and 10 deletions

View File

@@ -1,6 +1,5 @@
{ {
"$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.40/schema.bar.json", "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.40/schema.bar.json",
"monitor": 0,
"font_family": "JetBrains Mono", "font_family": "JetBrains Mono",
"theme": { "theme": {
"palette": "Base16", "palette": "Base16",

View File

@@ -453,10 +453,11 @@ impl Komobar {
self.right_widgets = right_widgets; self.right_widgets = right_widgets;
let (usr_monitor_index, config_work_area_offset) = match &self.config.monitor { 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) (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| { let mapped_info = self.monitor_info.as_ref().map(|info| {
@@ -866,9 +867,13 @@ impl eframe::App for Komobar {
Ok(KomorebiEvent::Notification(notification)) => { Ok(KomorebiEvent::Notification(notification)) => {
let state = &notification.state; let state = &notification.state;
let usr_monitor_index = match &self.config.monitor { let usr_monitor_index = match &self.config.monitor {
MonitorConfigOrIndex::MonitorConfig(monitor_config) => monitor_config.index, Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => {
MonitorConfigOrIndex::Index(idx) => *idx, monitor_config.index
}
Some(MonitorConfigOrIndex::Index(idx)) => *idx,
None => 0,
}; };
let monitor_index = state.monitor_usr_idx_map.get(&usr_monitor_index).copied(); let monitor_index = state.monitor_usr_idx_map.get(&usr_monitor_index).copied();
self.monitor_index = monitor_index; self.monitor_index = monitor_index;
let mut should_apply_config = false; let mut should_apply_config = false;

View File

@@ -76,7 +76,8 @@ pub struct KomobarConfig {
/// Frame options (see: https://docs.rs/egui/latest/egui/containers/frame/struct.Frame.html) /// Frame options (see: https://docs.rs/egui/latest/egui/containers/frame/struct.Frame.html)
pub frame: Option<FrameConfig>, pub frame: Option<FrameConfig>,
/// The monitor index or the full monitor options /// The monitor index or the full monitor options
pub monitor: MonitorConfigOrIndex, #[cfg_attr(feature = "schemars", schemars(extend("default" = MonitorConfigOrIndex::Index(0))))]
pub monitor: Option<MonitorConfigOrIndex>,
/// Font family /// Font family
pub font_family: Option<String>, pub font_family: Option<String>,
/// Font size /// Font size

View File

@@ -216,11 +216,13 @@ fn main() -> color_eyre::Result<()> {
)?)?; )?)?;
let (usr_monitor_index, work_area_offset) = match &config.monitor { 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) (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 let monitor_index = state
.monitor_usr_idx_map .monitor_usr_idx_map
.get(&usr_monitor_index) .get(&usr_monitor_index)

View File

@@ -99,8 +99,9 @@ impl RenderExt for &KomobarConfig {
icon_font_id.size *= icon_scale.unwrap_or(1.4).clamp(1.0, 2.0); icon_font_id.size *= icon_scale.unwrap_or(1.4).clamp(1.0, 2.0);
let monitor_idx = match &self.monitor { let monitor_idx = match &self.monitor {
MonitorConfigOrIndex::MonitorConfig(monitor_config) => monitor_config.index, Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => monitor_config.index,
MonitorConfigOrIndex::Index(idx) => *idx, 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 // check if any of the alignments have a komorebi widget with the workspace set to show all icons