From c9d03e2ff43a66fb2e4d7d88fabd0ca569f32b51 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 23:27:52 -0700 Subject: [PATCH] refactor(bar-core): move the shared statics and Alignment into komorebi-bar-core Pure move of what every bar module reads and nothing in it depends on: the monitor and label statics of main.rs (MAX_LABEL_WIDTH, MONITOR_LEFT/TOP/RIGHT/INDEX, BAR_HEIGHT, DEFAULT_PADDING, AUTO_SELECT_FILL/TEXT_COLOUR, and the Windows WIDGET_CLICKED flag with its two functions) and the three-variant Alignment of bar.rs. Each bar re-exports them (pub use komorebi_bar_core::statics::*, pub use komorebi_bar_core::alignment::Alignment), so crate::MAX_LABEL_WIDTH and crate::bar::Alignment resolve as before. The only difference between the trees is that the macOS bar now also has the WIDGET_CLICKED flag and its two functions; nothing in the macOS bar calls them (only the Windows systray widget does), so there is no behaviour change. Verified: Windows cargo clippy --workspace --locked --all-targets -D warnings clean; macOS fake-CC cargo check --locked --workspace --all-targets finished, 0 errors; native cargo test -p komorebi-bar-core 2 passed, 0 failed. Not verified: rendering. --- crates/komorebi-bar-core/src/alignment.rs | 6 +++++ crates/komorebi-bar-core/src/lib.rs | 3 +++ crates/komorebi-bar-core/src/statics.rs | 30 +++++++++++++++++++++++ komorebi-bar/src/bar.rs | 7 +----- komorebi-bar/src/main.rs | 30 +---------------------- komorebi-for-mac/komorebi-bar/src/bar.rs | 7 +----- komorebi-for-mac/komorebi-bar/src/main.rs | 14 +---------- 7 files changed, 43 insertions(+), 54 deletions(-) create mode 100644 crates/komorebi-bar-core/src/alignment.rs create mode 100644 crates/komorebi-bar-core/src/statics.rs diff --git a/crates/komorebi-bar-core/src/alignment.rs b/crates/komorebi-bar-core/src/alignment.rs new file mode 100644 index 00000000..674e2fe8 --- /dev/null +++ b/crates/komorebi-bar-core/src/alignment.rs @@ -0,0 +1,6 @@ +#[derive(Copy, Clone)] +pub enum Alignment { + Left, + Center, + Right, +} diff --git a/crates/komorebi-bar-core/src/lib.rs b/crates/komorebi-bar-core/src/lib.rs index a679df2b..7a081016 100644 --- a/crates/komorebi-bar-core/src/lib.rs +++ b/crates/komorebi-bar-core/src/lib.rs @@ -7,3 +7,6 @@ pub mod selected_frame; pub mod ui; + +pub mod alignment; +pub mod statics; diff --git a/crates/komorebi-bar-core/src/statics.rs b/crates/komorebi-bar-core/src/statics.rs new file mode 100644 index 00000000..d5a66ff9 --- /dev/null +++ b/crates/komorebi-bar-core/src/statics.rs @@ -0,0 +1,30 @@ +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicI32; +use std::sync::atomic::AtomicU32; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; + +pub static MAX_LABEL_WIDTH: AtomicI32 = AtomicI32::new(400); +pub static MONITOR_LEFT: AtomicI32 = AtomicI32::new(0); +pub static MONITOR_TOP: AtomicI32 = AtomicI32::new(0); +pub static MONITOR_RIGHT: AtomicI32 = AtomicI32::new(0); +pub static MONITOR_INDEX: AtomicUsize = AtomicUsize::new(0); +pub static BAR_HEIGHT: f32 = 50.0; +pub static DEFAULT_PADDING: f32 = 10.0; + +/// Flag to indicate that a widget has consumed a click event this frame. +/// This prevents the bar's global mouse handler from also processing the click. +pub static WIDGET_CLICKED: AtomicBool = AtomicBool::new(false); + +/// Mark that a widget has consumed a click event this frame. +pub fn mark_widget_clicked() { + WIDGET_CLICKED.store(true, Ordering::SeqCst); +} + +/// Check if a widget has consumed a click event this frame and reset the flag. +pub fn take_widget_clicked() -> bool { + WIDGET_CLICKED.swap(false, Ordering::SeqCst) +} + +pub static AUTO_SELECT_FILL_COLOUR: AtomicU32 = AtomicU32::new(0); +pub static AUTO_SELECT_TEXT_COLOUR: AtomicU32 = AtomicU32::new(0); diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index 7b797ff8..f113e3e2 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -1332,12 +1332,7 @@ impl eframe::App for Komobar { } } -#[derive(Copy, Clone)] -pub enum Alignment { - Left, - Center, - Right, -} +pub use komorebi_bar_core::alignment::Alignment; #[allow(clippy::too_many_arguments)] fn handle_notification( diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index e01ed678..328c6df8 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -22,9 +22,6 @@ use komorebi_client::replace_env_in_path; use std::io::BufReader; use std::io::Read; use std::path::PathBuf; -use std::sync::atomic::AtomicI32; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::time::Duration; use tracing_subscriber::EnvFilter; @@ -38,32 +35,7 @@ use windows::Win32::UI::WindowsAndMessaging::EnumThreadWindows; use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId; use windows_core::BOOL; -use std::sync::atomic::AtomicBool; - -pub static MAX_LABEL_WIDTH: AtomicI32 = AtomicI32::new(400); -pub static MONITOR_LEFT: AtomicI32 = AtomicI32::new(0); -pub static MONITOR_TOP: AtomicI32 = AtomicI32::new(0); -pub static MONITOR_RIGHT: AtomicI32 = AtomicI32::new(0); -pub static MONITOR_INDEX: AtomicUsize = AtomicUsize::new(0); -pub static BAR_HEIGHT: f32 = 50.0; -pub static DEFAULT_PADDING: f32 = 10.0; - -/// Flag to indicate that a widget has consumed a click event this frame. -/// This prevents the bar's global mouse handler from also processing the click. -pub static WIDGET_CLICKED: AtomicBool = AtomicBool::new(false); - -/// Mark that a widget has consumed a click event this frame. -pub fn mark_widget_clicked() { - WIDGET_CLICKED.store(true, Ordering::SeqCst); -} - -/// Check if a widget has consumed a click event this frame and reset the flag. -pub fn take_widget_clicked() -> bool { - WIDGET_CLICKED.swap(false, Ordering::SeqCst) -} - -pub static AUTO_SELECT_FILL_COLOUR: AtomicU32 = AtomicU32::new(0); -pub static AUTO_SELECT_TEXT_COLOUR: AtomicU32 = AtomicU32::new(0); +pub use komorebi_bar_core::statics::*; #[derive(Parser)] #[clap(author, about, version)] diff --git a/komorebi-for-mac/komorebi-bar/src/bar.rs b/komorebi-for-mac/komorebi-bar/src/bar.rs index 896d29eb..7f6b53f1 100644 --- a/komorebi-for-mac/komorebi-bar/src/bar.rs +++ b/komorebi-for-mac/komorebi-bar/src/bar.rs @@ -1296,12 +1296,7 @@ impl eframe::App for Komobar { } } -#[derive(Copy, Clone)] -pub enum Alignment { - Left, - Center, - Right, -} +pub use komorebi_bar_core::alignment::Alignment; #[allow(clippy::too_many_arguments)] fn handle_notification( diff --git a/komorebi-for-mac/komorebi-bar/src/main.rs b/komorebi-for-mac/komorebi-bar/src/main.rs index c3b75b33..fcd1e080 100644 --- a/komorebi-for-mac/komorebi-bar/src/main.rs +++ b/komorebi-for-mac/komorebi-bar/src/main.rs @@ -29,23 +29,11 @@ use raw_window_handle::RawWindowHandle; use std::io::BufReader; use std::io::Read; use std::path::PathBuf; -use std::sync::atomic::AtomicI32; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::time::Duration; use tracing_subscriber::EnvFilter; -pub static MAX_LABEL_WIDTH: AtomicI32 = AtomicI32::new(400); -pub static MONITOR_LEFT: AtomicI32 = AtomicI32::new(0); -pub static MONITOR_TOP: AtomicI32 = AtomicI32::new(0); -pub static MONITOR_RIGHT: AtomicI32 = AtomicI32::new(0); -pub static MONITOR_INDEX: AtomicUsize = AtomicUsize::new(0); -pub static BAR_HEIGHT: f32 = 50.0; -pub static DEFAULT_PADDING: f32 = 10.0; - -pub static AUTO_SELECT_FILL_COLOUR: AtomicU32 = AtomicU32::new(0); -pub static AUTO_SELECT_TEXT_COLOUR: AtomicU32 = AtomicU32::new(0); +pub use komorebi_bar_core::statics::*; #[derive(Parser)] #[clap(author, about, version)]