From 7d4ea893cc74a4b0ec781b52aa3e579064ad4ca8 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 12:41:55 -0700 Subject: [PATCH] refactor(bar): one komorebi-bar package with a module per platform The macOS bar module moves from komorebi-for-mac/komorebi-bar/src/macos to komorebi-bar/src/macos (the include_str! path follows), komorebi-bar/src/main.rs is a cfg_select! over target_os that runs windows::main or macos::main, and komorebi-bar/Cargo.toml has what both share in [dependencies] and the rest in per-target tables (Windows: windows, windows-core, windows-icons x2, systray-util, tokio, regex, which, egui_extras, netdev 0.46, sysinfo 0.39, komorebi-themes without default features; macOS: objc2, objc2-app-kit, icns, raw-window-handle, netdev 0.40, sysinfo 0.38, komorebi-themes with defaults), so each platform keeps the versions it had. The old komorebi-bar-macos package stays as a shim that includes the moved module. The macOS flake builds -p komorebi-bar and its source filter takes the unified package's manifest, main.rs and src/macos; the Windows filter leaves src/macos out. The bar does not build for Linux (no arm of the cfg_select), as before. Gates run: Windows clippy --all-targets -D warnings PASS; macOS fake-CC check --locked --all-targets of -p komorebi-bar and -p komorebi-bar-macos PASS (type check only); bar-core schema oracle (3 + 6) PASS; the S/bar2 harness regenerates schema.bar.json for Windows (9091 lines) and macOS (3774) byte-identical to the checked-in files; tools/kde-closure-check ok; CLI docs oracle identical x3; nix evaluation PASS and by evaluation an edit of komorebi-bar/src/windows changes the Windows derivations only (the macOS side cannot be evaluated on this Linux host). Not run: nix builds, any bar run (Windows screenshot gate and the Mac hand check are owed). --- Cargo.lock | 6 ++++ flake.nix | 2 +- komorebi-bar/Cargo.toml | 32 +++++++++++++++---- .../src/macos/bar.rs | 0 .../src/macos/config.rs | 0 .../src/macos/mod.rs | 4 +-- .../src/macos/os.rs | 0 .../src/macos/widgets/komorebi.rs | 0 .../src/macos/widgets/mod.rs | 0 .../src/macos/widgets/network.rs | 0 .../src/macos/widgets/widget.rs | 0 komorebi-bar/src/main.rs | 16 ++++++++-- komorebi-for-mac/flake.nix | 16 ++++++++-- komorebi-for-mac/komorebi-bar/src/main.rs | 4 ++- 14 files changed, 64 insertions(+), 16 deletions(-) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/bar.rs (100%) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/config.rs (100%) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/mod.rs (98%) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/os.rs (100%) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/widgets/komorebi.rs (100%) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/widgets/mod.rs (100%) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/widgets/network.rs (100%) rename {komorebi-for-mac/komorebi-bar => komorebi-bar}/src/macos/widgets/widget.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 2ba9f61d..73359e9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3406,22 +3406,28 @@ dependencies = [ "egui_extras", "font-loader", "hotwatch", + "icns", "image 0.25.10", "komorebi-bar-core", "komorebi-client", "komorebi-themes", "lazy_static", + "netdev 0.40.1", "netdev 0.46.3", "num", "num-derive", "num-traits", + "objc2 0.6.5", + "objc2-app-kit 0.3.2", "parking_lot 0.12.5", "random_word", + "raw-window-handle", "regex", "reqwest", "schemars 1.2.3", "serde", "serde_json_lenient", + "sysinfo 0.38.4", "sysinfo 0.39.6", "systray-util", "tokio", diff --git a/flake.nix b/flake.nix index 9cfdf58f..e3a4727b 100644 --- a/flake.nix +++ b/flake.nix @@ -224,7 +224,7 @@ # the other platforms' crates are added as stubs below !(pkgs.lib.hasInfix "/komorebi-for-kde" path || pkgs.lib.hasInfix "/komorebi-for-mac" path) # the Linux and macOS files of komorebic are not read when building for Windows - && !(builtins.match ".*/komorebi(c/(src/(linux|macos)|tests/(linux|macos)_)|-client/(src/(linux|macos)\\.rs|tests/(linux|macos)_))[^/]*.*" path != null) + && !(builtins.match ".*/komorebi(c/(src/(linux|macos)|tests/(linux|macos)_)|-client/(src/(linux|macos)\\.rs|tests/(linux|macos)_)|-bar/src/macos)[^/]*.*" path != null) && ( (craneLib.filterCargoSources path type) || (pkgs.lib.hasInfix "/docs/" path) diff --git a/komorebi-bar/Cargo.toml b/komorebi-bar/Cargo.toml index f75831f4..74b6b1da 100644 --- a/komorebi-bar/Cargo.toml +++ b/komorebi-bar/Cargo.toml @@ -5,10 +5,12 @@ edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +# What both platforms use is in [dependencies]; what only one uses, or uses in another version or with other +# features, is in the table of its target OS, so that a build for one compiles nothing of the other. + [dependencies] komorebi-bar-core = { path = "../crates/komorebi-bar-core", default-features = false } komorebi-client = { path = "../komorebi-client", default-features = false } -komorebi-themes = { path = "../komorebi-themes", default-features = false } chrono-tz = { workspace = true } chrono = { workspace = true } @@ -19,33 +21,51 @@ dirs = { workspace = true } dunce = { workspace = true } eframe = { workspace = true } egui-phosphor = { git = "https://github.com/amPerl/egui-phosphor", rev = "d13688738478ecd12b426e3e74c59d6577a85b59" } -egui_extras = { workspace = true } font-loader = "0.11" hotwatch = { workspace = true } image = "0.25" lazy_static = { workspace = true } -netdev = "0.46" num = "0.4" num-derive = "0.4" num-traits = "0.2" parking_lot = { workspace = true } -regex = "1" random_word = { version = "0.5", features = ["en"] } reqwest = { version = "0.12", features = ["blocking"] } schemars = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } + +[target.'cfg(windows)'.dependencies] +komorebi-themes = { path = "../komorebi-themes", default-features = false } +egui_extras = { workspace = true } +netdev = "0.46" +regex = "1" sysinfo = { workspace = true } systray-util = "0.2.0" tokio = { version = "1", features = ["rt", "sync", "time"] } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } which = { workspace = true } windows = { workspace = true } windows-core = { workspace = true } windows-icons = { git = "https://github.com/LGUG2Z/windows-icons", rev = "0c9d7ee1b807347c507d3a9862dd007b4d3f4354" } windows-icons-fallback = { package = "windows-icons", git = "https://github.com/LGUG2Z/windows-icons", rev = "d67cc9920aa9b4883393e411fb4fa2ddd4c498b5" } +[target.'cfg(target_os = "macos")'.dependencies] +komorebi-themes = { path = "../komorebi-themes" } +icns = "0.4" +netdev = "0.40" +objc2 = { version = "0.6", default-features = false, features = ["std"] } +objc2-app-kit = { version = "0.3", default-features = false, features = [ + "std", + "NSApplication", + "NSResponder", + "NSView", + "NSWindow", +] } +raw-window-handle = "0.6" +sysinfo = "0.38" + [features] default = ["schemars"] schemars = [ diff --git a/komorebi-for-mac/komorebi-bar/src/macos/bar.rs b/komorebi-bar/src/macos/bar.rs similarity index 100% rename from komorebi-for-mac/komorebi-bar/src/macos/bar.rs rename to komorebi-bar/src/macos/bar.rs diff --git a/komorebi-for-mac/komorebi-bar/src/macos/config.rs b/komorebi-bar/src/macos/config.rs similarity index 100% rename from komorebi-for-mac/komorebi-bar/src/macos/config.rs rename to komorebi-bar/src/macos/config.rs diff --git a/komorebi-for-mac/komorebi-bar/src/macos/mod.rs b/komorebi-bar/src/macos/mod.rs similarity index 98% rename from komorebi-for-mac/komorebi-bar/src/macos/mod.rs rename to komorebi-bar/src/macos/mod.rs index 0c89b083..8808d49d 100644 --- a/komorebi-for-mac/komorebi-bar/src/macos/mod.rs +++ b/komorebi-bar/src/macos/mod.rs @@ -127,7 +127,7 @@ pub fn main() -> eyre::Result<()> { ); if opts.quickstart { - let komorebi_bar_json = include_str!("../../../docs/komorebi.bar.example.json").to_string(); + let komorebi_bar_json = include_str!("../../../komorebi-for-mac/docs/komorebi.bar.example.json").to_string(); std::fs::write(home_dir.join("komorebi.bar.json"), komorebi_bar_json)?; println!( "Example komorebi.bar.json file written to {}", @@ -148,7 +148,7 @@ pub fn main() -> eyre::Result<()> { let mut config = match config_path { None => { let komorebi_bar_json = - include_str!("../../../docs/komorebi.bar.example.json").to_string(); + include_str!("../../../komorebi-for-mac/docs/komorebi.bar.example.json").to_string(); std::fs::write(&default_config_path, komorebi_bar_json)?; tracing::info!( diff --git a/komorebi-for-mac/komorebi-bar/src/macos/os.rs b/komorebi-bar/src/macos/os.rs similarity index 100% rename from komorebi-for-mac/komorebi-bar/src/macos/os.rs rename to komorebi-bar/src/macos/os.rs diff --git a/komorebi-for-mac/komorebi-bar/src/macos/widgets/komorebi.rs b/komorebi-bar/src/macos/widgets/komorebi.rs similarity index 100% rename from komorebi-for-mac/komorebi-bar/src/macos/widgets/komorebi.rs rename to komorebi-bar/src/macos/widgets/komorebi.rs diff --git a/komorebi-for-mac/komorebi-bar/src/macos/widgets/mod.rs b/komorebi-bar/src/macos/widgets/mod.rs similarity index 100% rename from komorebi-for-mac/komorebi-bar/src/macos/widgets/mod.rs rename to komorebi-bar/src/macos/widgets/mod.rs diff --git a/komorebi-for-mac/komorebi-bar/src/macos/widgets/network.rs b/komorebi-bar/src/macos/widgets/network.rs similarity index 100% rename from komorebi-for-mac/komorebi-bar/src/macos/widgets/network.rs rename to komorebi-bar/src/macos/widgets/network.rs diff --git a/komorebi-for-mac/komorebi-bar/src/macos/widgets/widget.rs b/komorebi-bar/src/macos/widgets/widget.rs similarity index 100% rename from komorebi-for-mac/komorebi-bar/src/macos/widgets/widget.rs rename to komorebi-bar/src/macos/widgets/widget.rs diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index ab7f5e0e..0a906cc0 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -1,7 +1,17 @@ -//! `komorebi-bar`, the status bar of komorebi. The code of each platform is in a module of its own. +//! `komorebi-bar`, the status bar of komorebi, for Windows and macOS: the module of the target OS is +//! the bar, the code both share is in `komorebi-bar-core`. -mod windows; +cfg_select! { + target_os = "windows" => { + mod windows; + use windows as platform; + } + target_os = "macos" => { + mod macos; + use macos as platform; + } +} fn main() -> color_eyre::Result<()> { - windows::main() + platform::main() } diff --git a/komorebi-for-mac/flake.nix b/komorebi-for-mac/flake.nix index 6e40b085..92054bcc 100644 --- a/komorebi-for-mac/flake.nix +++ b/komorebi-for-mac/flake.nix @@ -83,8 +83,18 @@ "komorebi-client/src/macos.rs" "komorebi-client/tests" ]; + + # the unified komorebi-bar package: its manifest, main.rs and the macOS module + komorebiBar = + builtins.elem relative [ + "komorebi-bar" + "komorebi-bar/Cargo.toml" + "komorebi-bar/src" + "komorebi-bar/src/main.rs" + ] + || pkgs.lib.hasPrefix "komorebi-bar/src/macos" relative; in - ((rootCrate || komorebic || komorebiClient) && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || relative == "Cargo.lock" || inTree) + ((rootCrate || komorebic || komorebiClient || komorebiBar) && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || relative == "Cargo.lock" || inTree) && ( (craneLib.filterCargoSources path type) || (pkgs.lib.hasInfix "/docs/" path) @@ -103,9 +113,10 @@ pkgs.lib.hasPrefix "${platformDir}/" member || member == "komorebic" || member == "komorebi-client" + || member == "komorebi-bar" || builtins.any (crate: member == crate || pkgs.lib.hasPrefix "${crate}/" member) rootCrates; }; - packages = "-p komorebi-macos -p komorebic -p komorebi-client -p komorebi-bar-macos"; + packages = "-p komorebi-macos -p komorebic -p komorebi-client -p komorebi-bar"; workspaceArgs = { pname = "komorebi-workspace"; inherit version; @@ -253,7 +264,6 @@ "komorebi-windows" "komorebi-gui" "komorebic-no-console" - "komorebi-bar" "komorebi-shortcuts" "komorebi-e2e-agent" "komorebi-testwin" diff --git a/komorebi-for-mac/komorebi-bar/src/main.rs b/komorebi-for-mac/komorebi-bar/src/main.rs index 0aa802b4..c8fe1a9a 100644 --- a/komorebi-for-mac/komorebi-bar/src/main.rs +++ b/komorebi-for-mac/komorebi-bar/src/main.rs @@ -1,5 +1,7 @@ -//! `komorebi-bar` for macOS. The code is in the `macos` module. +//! `komorebi-bar-macos`: the macOS bar of the unified `komorebi-bar` package, kept under its old package +//! name until the cutover. The code is in `komorebi-bar/src/macos`. +#[path = "../../../komorebi-bar/src/macos/mod.rs"] mod macos; fn main() -> color_eyre::Result<()> {