diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 1214a751..77e7006e 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -68,7 +68,7 @@ jobs: args: "--locked --release" - run: | cargo install cargo-wix - cargo wix --no-build -p komorebi-windows --nocapture -I .\wix\main.wxs --target ${{ matrix.platform.target }} + cargo wix --no-build -p komorebi --nocapture -I .\wix\main.wxs --target ${{ matrix.platform.target }} - uses: actions/upload-artifact@v7 with: name: komorebi-${{ matrix.platform.target }}-${{ github.sha }} diff --git a/Cargo.lock b/Cargo.lock index 7efffda4..b3b7ce90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3383,6 +3383,17 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" +[[package]] +name = "komorebi" +version = "0.1.42" +dependencies = [ + "color-eyre", + "komorebi-linux", + "komorebi-macos", + "komorebi-windows", + "serde_json_lenient", +] + [[package]] name = "komorebi-backend" version = "0.1.42" diff --git a/Cargo.toml b/Cargo.toml index f48d405d..6288f854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "komorebi-layouts", "komorebi-scrolling", "komorebic", + "komorebi-daemon", "komorebic-no-console", "crates/komorebic-core", "komorebi-bar", @@ -48,6 +49,7 @@ default-members = [ "komorebi-layouts", "komorebi-scrolling", "komorebic", + "komorebi-daemon", "komorebic-no-console", "crates/komorebic-core", "komorebi-bar", diff --git a/deny.toml b/deny.toml index e9675ed5..61f56194 100644 --- a/deny.toml +++ b/deny.toml @@ -42,6 +42,11 @@ allow = [ ] confidence-threshold = 0.8 +[[licenses.clarify]] +crate = "komorebi" +expression = "LicenseRef-Komorebi-2.0" +license-files = [] + [[licenses.clarify]] crate = "komorebi-windows" expression = "LicenseRef-Komorebi-2.0" diff --git a/flake.nix b/flake.nix index e3a4727b..3a9c4fbe 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)_)|-bar/src/macos)[^/]*.*" path != null) + && !(builtins.match ".*/komorebi(c/(src/(linux|macos)|tests/(linux|macos)_)|-client/(src/(linux|macos)\\.rs|tests/(linux|macos)_)|-bar/src/macos|-daemon/tests/(linux|macos)_)[^/]*.*" path != null) && ( (craneLib.filterCargoSources path type) || (pkgs.lib.hasInfix "/docs/" path) diff --git a/justfile b/justfile index 3296b7dd..8353731e 100644 --- a/justfile +++ b/justfile @@ -86,7 +86,7 @@ jsonschema: cargo run --package komorebic -- application-specific-configuration-schema > schema.asc.json cargo run --package komorebi-bar -- --schema > schema.bar.json -version := `cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "komorebi-windows") | .version'` +version := `cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "komorebi") | .version'` schemapub: rm -Force komorebi-schema diff --git a/komorebi-daemon/Cargo.toml b/komorebi-daemon/Cargo.toml new file mode 100644 index 00000000..af3e0063 --- /dev/null +++ b/komorebi-daemon/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "komorebi" +version = "0.1.42" +description = "A tiling window manager for Windows, KDE Plasma and macOS" +repository = "https://github.com/LGUG2Z/komorebi" +edition = "2024" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +# The daemon of each platform is a library (`komorebi-windows`, `komorebi-linux`, `komorebi-macos`) with a +# `daemon::run` that is the old main; this package is the one `komorebi` binary and calls the one of the +# target OS. A dependency key has one path, so each library has a key of its own. + +[dependencies] +color-eyre = { workspace = true } + +[target.'cfg(windows)'.dependencies] +komorebi-windows = { package = "komorebi-windows", path = "../komorebi", default-features = false } + +[target.'cfg(target_os = "linux")'.dependencies] +komorebi-linux = { package = "komorebi-linux", path = "../komorebi-for-kde/komorebi", default-features = false } + +[target.'cfg(target_os = "macos")'.dependencies] +komorebi-macos = { package = "komorebi-macos", path = "../komorebi-for-mac/komorebi", default-features = false } + +[features] +default = ["schemars"] +deadlock_detection = ["komorebi-windows/deadlock_detection", "komorebi-linux/deadlock_detection", "komorebi-macos/deadlock_detection"] +schemars = ["komorebi-windows/schemars", "komorebi-linux/schemars", "komorebi-macos/schemars"] + +[target.'cfg(target_os = "linux")'.dev-dependencies] +serde_json = { workspace = true } diff --git a/komorebi-daemon/src/main.rs b/komorebi-daemon/src/main.rs new file mode 100644 index 00000000..e79d9c7a --- /dev/null +++ b/komorebi-daemon/src/main.rs @@ -0,0 +1,10 @@ +//! `komorebi`, the tiling window manager daemon, for Windows, KDE Plasma and macOS: the daemon of the target +//! OS is a library of its own and this binary runs it. + +fn main() -> color_eyre::eyre::Result<()> { + cfg_select! { + target_os = "windows" => komorebi_windows::daemon::run(), + target_os = "linux" => komorebi_linux::daemon::run(), + target_os = "macos" => komorebi_macos::daemon::run(), + } +} diff --git a/komorebi-for-kde/komorebi/tests/hot_reload.rs b/komorebi-daemon/tests/linux_hot_reload.rs similarity index 99% rename from komorebi-for-kde/komorebi/tests/hot_reload.rs rename to komorebi-daemon/tests/linux_hot_reload.rs index b2a3310f..2cdad023 100644 --- a/komorebi-for-kde/komorebi/tests/hot_reload.rs +++ b/komorebi-daemon/tests/linux_hot_reload.rs @@ -1,3 +1,4 @@ +#![cfg(target_os = "linux")] //! The daemon and its `komorebi.json`: `komorebi --fake-backend` finds the file in the config home //! or is given it with `--config`, is configured by it, and applies it again when the file changes. //! diff --git a/komorebi-for-kde/komorebi/tests/no_kwin.rs b/komorebi-daemon/tests/linux_no_kwin.rs similarity index 99% rename from komorebi-for-kde/komorebi/tests/no_kwin.rs rename to komorebi-daemon/tests/linux_no_kwin.rs index 417c68a3..b3ade6f0 100644 --- a/komorebi-for-kde/komorebi/tests/no_kwin.rs +++ b/komorebi-daemon/tests/linux_no_kwin.rs @@ -1,3 +1,4 @@ +#![cfg(target_os = "linux")] //! `komorebi` connects to KWin unless it is told to run against the in-memory desktop, says //! what went wrong when it cannot, and then leaves the socket of a komorebi that is running //! alone. diff --git a/komorebi-for-kde/komorebi/tests/socket.rs b/komorebi-daemon/tests/linux_socket.rs similarity index 99% rename from komorebi-for-kde/komorebi/tests/socket.rs rename to komorebi-daemon/tests/linux_socket.rs index 42f4c6d5..9cd834f8 100644 --- a/komorebi-for-kde/komorebi/tests/socket.rs +++ b/komorebi-daemon/tests/linux_socket.rs @@ -1,3 +1,4 @@ +#![cfg(target_os = "linux")] //! The daemon over its socket: `komorebi --fake-backend` answers on `komorebi.sock` in its //! runtime directory, and stops when it is sent `Stop`. diff --git a/komorebi-daemon/tests/linux_version.rs b/komorebi-daemon/tests/linux_version.rs new file mode 100644 index 00000000..fd627c96 --- /dev/null +++ b/komorebi-daemon/tests/linux_version.rs @@ -0,0 +1,27 @@ +#![cfg(target_os = "linux")] +//! `komorebi --version` reports the workspace version. + +use std::process::Command; + +#[test] +fn reports_the_package_version() { + let output = Command::new(env!("CARGO_BIN_EXE_komorebi")) + .arg("--version") + .output() + .expect("komorebi runs"); + + assert!(output.status.success()); + + let stdout = String::from_utf8(output.stdout).expect("utf-8 output"); + // the version the KDE daemon reports is that of the KDE `version` crate (the workspace version of + // komorebi for KDE), not of this package, which is shared with the other platforms + let manifest = include_str!("../../komorebi-for-kde/version/Cargo.toml"); + let version = manifest + .lines() + .find_map(|line| line.strip_prefix("version = \"")) + .and_then(|rest| rest.strip_suffix('"')) + .expect("the version crate has a version"); + let expected = format!("komorebi {version}"); + + assert_eq!(stdout.lines().next(), Some(expected.as_str())); +} diff --git a/komorebi-for-kde/deny.toml b/komorebi-for-kde/deny.toml index 4439b6a0..eab867dd 100644 --- a/komorebi-for-kde/deny.toml +++ b/komorebi-for-kde/deny.toml @@ -38,6 +38,11 @@ allow = [ ] confidence-threshold = 0.8 +[[licenses.clarify]] +crate = "komorebi" +expression = "LicenseRef-Komorebi-2.0" +license-files = [] + [[licenses.clarify]] crate = "komorebi-linux" expression = "LicenseRef-Komorebi-2.0" diff --git a/komorebi-for-kde/flake.nix b/komorebi-for-kde/flake.nix index f60290e3..ea310c93 100644 --- a/komorebi-for-kde/flake.nix +++ b/komorebi-for-kde/flake.nix @@ -97,8 +97,19 @@ "komorebi-client/tests" ] || pkgs.lib.hasPrefix "komorebi-client/tests/linux_" relative; + + # the one komorebi binary package: its manifest, main.rs and tests + komorebiDaemon = + builtins.elem relative [ + "komorebi-daemon" + "komorebi-daemon/Cargo.toml" + "komorebi-daemon/src" + "komorebi-daemon/src/main.rs" + "komorebi-daemon/tests" + ] + || pkgs.lib.hasPrefix "komorebi-daemon/tests/linux_" relative; in - ((rootCrate || rootCrateParent || komorebic || komorebiClient) && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || relative == "Cargo.lock" || inTree) + ((rootCrate || rootCrateParent || komorebic || komorebiClient || komorebiDaemon) && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || relative == "Cargo.lock" || inTree) && # the VM tests (their library, scripts and the states they keep) are not built, so # editing one does not change the source the daemon is built from @@ -131,9 +142,10 @@ pkgs.lib.hasPrefix "${platformDir}/" member || member == "komorebic" || member == "komorebi-client" + || member == "komorebi-daemon" || builtins.any (crate: member == crate || pkgs.lib.hasPrefix "${crate}/" member) rootCrates; }; - packages = "-p komorebi-linux -p komorebic -p komorebi-client -p komorebi-hotkeys"; + packages = "-p komorebi -p komorebi-linux -p komorebic -p komorebi-client -p komorebi-hotkeys"; workspaceArgs = { pname = "komorebi-workspace"; version = (builtins.fromTOML (builtins.readFile ./komorebi/Cargo.toml)).package.version; diff --git a/komorebi-for-kde/komorebi/Cargo.toml b/komorebi-for-kde/komorebi/Cargo.toml index 747623b3..1d8d0bb1 100644 --- a/komorebi-for-kde/komorebi/Cargo.toml +++ b/komorebi-for-kde/komorebi/Cargo.toml @@ -61,7 +61,3 @@ schemars = ["dep:schemars", "komorebi-collections/schemars", "komorebi-core/sche [lib] name = "komorebi" - -[[bin]] -name = "komorebi" -path = "src/main.rs" diff --git a/komorebi-for-kde/komorebi/src/main.rs b/komorebi-for-kde/komorebi/src/daemon.rs similarity index 91% rename from komorebi-for-kde/komorebi/src/main.rs rename to komorebi-for-kde/komorebi/src/daemon.rs index d20b4692..5d896b06 100644 --- a/komorebi-for-kde/komorebi/src/main.rs +++ b/komorebi-for-kde/komorebi/src/daemon.rs @@ -3,15 +3,15 @@ //! The daemon owns the layout of every window and asks the compositor, through a backend, to //! put each one where the layout says. //! -//! The backend is KWin's ([`komorebi::kwin`]): the daemon connects to the session bus, loads its +//! The backend is KWin's ([`crate::kwin`]): the daemon connects to the session bus, loads its //! script into KWin and waits for the script to report the desktop. `--fake-backend` replaces it //! with an in-memory desktop with one monitor and no windows, for development and testing. //! //! The daemon starts from `komorebi.json`: the file `--config` names, or else the one in -//! [`struct@HOME_DIR`] when there is one ([`komorebi::static_config`]), which it reloads whenever +//! [`struct@HOME_DIR`] when there is one ([`crate::static_config`]), which it reloads whenever //! it changes. Without a file it runs on its defaults. It loads the monitors and the windows //! that are open, gives each monitor the configuration the file has for it, asks for the borders -//! it draws ([`komorebi::border_manager`]), tiles the windows, listens for messages on +//! it draws ([`crate::border_manager`]), tiles the windows, listens for messages on //! `komorebi.sock` in [`struct@DATA_DIR`], handles the events the backend reports and the changes //! of the monitors on threads of their own, and runs until it is stopped, with `SIGINT`, //! `SIGTERM` or a `Stop` message. @@ -19,7 +19,7 @@ //! With a key binding file (`--keybindings`, or the first of `skhdrc`, `whkdrc` and `sxhkdrc` in //! [`struct@HOME_DIR`]), the daemon also runs the engine of [`komorebi_hotkeys`]: it registers the //! keys of the bindings that are not static shortcuts with KWin's global shortcut daemon and runs -//! their commands ([`komorebi::kwin::hotkeys::load`]). A file that cannot be read is logged, and +//! their commands ([`crate::kwin::hotkeys::load`]). A file that cannot be read is logged, and //! the window manager runs without keys. The bindings it takes are the engine's part of the file's //! plan in `--keybindings-mode`, the mode `komorebic hotkeys compile --mode` wrote the static //! shortcuts in. `--chord-timeout` is how long the next key of a chord chain is waited for, and @@ -36,21 +36,21 @@ use clap::Parser; use clap::ValueEnum; use color_eyre::eyre; -use komorebi::DATA_DIR; -use komorebi::HOME_DIR; -use komorebi::LOG_DIR; -use komorebi::backend; -use komorebi::backend::fake::FakeBackend; -use komorebi::border_manager; -use komorebi::core::pathext::replace_env_in_path; -use komorebi::kwin::hotkeys::Keybindings; -use komorebi::monitor_reconciliator; -use komorebi::process_command::listen_for_commands; -use komorebi::process_event::listen_for_events; -use komorebi::static_config::StaticConfig; -use komorebi::static_config::StaticConfigExt; -use komorebi::window_manager::WindowManager; -use komorebi::window_manager_event_listener; +use crate::DATA_DIR; +use crate::HOME_DIR; +use crate::LOG_DIR; +use crate::backend; +use crate::backend::fake::FakeBackend; +use crate::border_manager; +use crate::core::pathext::replace_env_in_path; +use crate::kwin::hotkeys::Keybindings; +use crate::monitor_reconciliator; +use crate::process_command::listen_for_commands; +use crate::process_event::listen_for_events; +use crate::static_config::StaticConfig; +use crate::static_config::StaticConfigExt; +use crate::window_manager::WindowManager; +use crate::window_manager_event_listener; use komorebi_hotkeys::Format; use komorebi_hotkeys::engine::EngineOptions; use komorebi_hotkeys::plan::PlanMode; @@ -269,7 +269,7 @@ fn app_alias(value: &str) -> Result<(String, Vec), String> { Ok((name.trim().to_string(), aliases)) } -fn main() -> eyre::Result<()> { +pub fn run() -> eyre::Result<()> { let opts: Opts = Opts::parse(); let (_guard, _color_guard) = setup(opts.log_level.clone())?; @@ -282,7 +282,7 @@ fn main() -> eyre::Result<()> { backend::set_backend(Arc::new(FakeBackend::with_one_monitor())); } else { tracing::info!("connecting to KWin"); - backend::set_backend(komorebi::kwin::connect()?); + backend::set_backend(crate::kwin::connect()?); } #[cfg(feature = "deadlock_detection")] @@ -339,7 +339,7 @@ fn main() -> eyre::Result<()> { { let mut wm = wm.lock(); border_manager::update_colours(&wm); - komorebi::transparency_manager::apply(&mut wm); + crate::transparency_manager::apply(&mut wm); } monitor_reconciliator::listen_for_notifications(wm.clone())?; @@ -365,7 +365,7 @@ fn main() -> eyre::Result<()> { app_aliases, }, }; - if let Err(error) = komorebi::kwin::hotkeys::load(keybindings) { + if let Err(error) = crate::kwin::hotkeys::load(keybindings) { tracing::error!("the key bindings are not active: {error}"); } } @@ -383,11 +383,11 @@ fn main() -> eyre::Result<()> { { let mut wm = wm.lock(); wm.restore_all_windows(false)?; - komorebi::transparency_manager::restore(&mut wm); + crate::transparency_manager::restore(&mut wm); } backend::backend().shutdown(); - let sockets = komorebi::SUBSCRIPTION_SOCKETS.lock(); + let sockets = crate::SUBSCRIPTION_SOCKETS.lock(); for path in (*sockets).values() { if let Ok(stream) = UnixStream::connect(path) { stream.shutdown(Shutdown::Both)?; diff --git a/komorebi-for-kde/komorebi/src/lib.rs b/komorebi-for-kde/komorebi/src/lib.rs index 20064658..e9c2c80d 100644 --- a/komorebi-for-kde/komorebi/src/lib.rs +++ b/komorebi-for-kde/komorebi/src/lib.rs @@ -64,6 +64,7 @@ extern crate komorebi_collections; pub use komorebi_collections::ring; +pub mod daemon; pub mod animation; pub mod backend; pub mod border_manager; diff --git a/komorebi-for-kde/komorebi/tests/version.rs b/komorebi-for-kde/komorebi/tests/version.rs deleted file mode 100644 index e5d7e05e..00000000 --- a/komorebi-for-kde/komorebi/tests/version.rs +++ /dev/null @@ -1,18 +0,0 @@ -//! `komorebi --version` reports the workspace version. - -use std::process::Command; - -#[test] -fn reports_the_package_version() { - let output = Command::new(env!("CARGO_BIN_EXE_komorebi")) - .arg("--version") - .output() - .expect("komorebi runs"); - - assert!(output.status.success()); - - let stdout = String::from_utf8(output.stdout).expect("utf-8 output"); - let expected = format!("komorebi {}", env!("CARGO_PKG_VERSION")); - - assert_eq!(stdout.lines().next(), Some(expected.as_str())); -} diff --git a/komorebi-for-mac/deny.toml b/komorebi-for-mac/deny.toml index 8377debc..ff68c08a 100644 --- a/komorebi-for-mac/deny.toml +++ b/komorebi-for-mac/deny.toml @@ -43,6 +43,11 @@ allow = [ ] confidence-threshold = 0.8 +[[licenses.clarify]] +crate = "komorebi" +expression = "LicenseRef-Komorebi-2.0" +license-files = [] + [[licenses.clarify]] crate = "komorebi-macos" expression = "LicenseRef-Komorebi-2.0" diff --git a/komorebi-for-mac/flake.nix b/komorebi-for-mac/flake.nix index 92054bcc..7dbe4ab2 100644 --- a/komorebi-for-mac/flake.nix +++ b/komorebi-for-mac/flake.nix @@ -93,8 +93,18 @@ "komorebi-bar/src/main.rs" ] || pkgs.lib.hasPrefix "komorebi-bar/src/macos" relative; + + # the one komorebi binary package: its manifest, main.rs and tests + komorebiDaemon = + builtins.elem relative [ + "komorebi-daemon" + "komorebi-daemon/Cargo.toml" + "komorebi-daemon/src" + "komorebi-daemon/src/main.rs" + "komorebi-daemon/tests" + ]; in - ((rootCrate || komorebic || komorebiClient || komorebiBar) && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || relative == "Cargo.lock" || inTree) + ((rootCrate || komorebic || komorebiClient || komorebiBar || komorebiDaemon) && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || relative == "Cargo.lock" || inTree) && ( (craneLib.filterCargoSources path type) || (pkgs.lib.hasInfix "/docs/" path) @@ -113,10 +123,11 @@ pkgs.lib.hasPrefix "${platformDir}/" member || member == "komorebic" || member == "komorebi-client" + || member == "komorebi-daemon" || 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"; + packages = "-p komorebi -p komorebi-macos -p komorebic -p komorebi-client -p komorebi-bar"; workspaceArgs = { pname = "komorebi-workspace"; inherit version; diff --git a/komorebi-for-mac/komorebi/Cargo.toml b/komorebi-for-mac/komorebi/Cargo.toml index 0e984dc8..bfb1ca57 100644 --- a/komorebi-for-mac/komorebi/Cargo.toml +++ b/komorebi-for-mac/komorebi/Cargo.toml @@ -138,7 +138,3 @@ schemars = ["dep:schemars", "komorebi-collections/schemars", "komorebi-core/sche [lib] name = "komorebi" - -[[bin]] -name = "komorebi" -path = "src/main.rs" diff --git a/komorebi-for-mac/komorebi/src/main.rs b/komorebi-for-mac/komorebi/src/daemon.rs similarity index 92% rename from komorebi-for-mac/komorebi/src/main.rs rename to komorebi-for-mac/komorebi/src/daemon.rs index 5b5ad65c..fc1505b5 100644 --- a/komorebi-for-mac/komorebi/src/main.rs +++ b/komorebi-for-mac/komorebi/src/daemon.rs @@ -4,26 +4,26 @@ use clap::Parser; use clap::ValueEnum; use color_eyre::eyre; use color_eyre::eyre::OptionExt; -use komorebi::CoreFoundationRunLoop; -use komorebi::DATA_DIR; -use komorebi::HOME_DIR; -use komorebi::border_manager; -use komorebi::core::pathext::replace_env_in_path; -use komorebi::display_reconfiguration_listener::DisplayReconfigurationListener; -use komorebi::input_event_listener; -use komorebi::input_event_listener::InputEventListener; -use komorebi::monitor_reconciliator; -use komorebi::notification_center_listener::NotificationCenterListener; -use komorebi::process_command::listen_for_commands; -use komorebi::process_event::listen_for_events; -use komorebi::reaper; -use komorebi::settle; -use komorebi::static_config::StaticConfig; -use komorebi::static_config::StaticConfigExt; -use komorebi::theme_manager; -use komorebi::window_manager::WindowManager; -use komorebi::window_manager_event_listener; -use komorebi::workspace_reconciliator; +use crate::CoreFoundationRunLoop; +use crate::DATA_DIR; +use crate::HOME_DIR; +use crate::border_manager; +use crate::core::pathext::replace_env_in_path; +use crate::display_reconfiguration_listener::DisplayReconfigurationListener; +use crate::input_event_listener; +use crate::input_event_listener::InputEventListener; +use crate::monitor_reconciliator; +use crate::notification_center_listener::NotificationCenterListener; +use crate::process_command::listen_for_commands; +use crate::process_event::listen_for_events; +use crate::reaper; +use crate::settle; +use crate::static_config::StaticConfig; +use crate::static_config::StaticConfigExt; +use crate::theme_manager; +use crate::window_manager::WindowManager; +use crate::window_manager_event_listener; +use crate::workspace_reconciliator; use objc2::MainThreadMarker; use objc2::rc::autoreleasepool; use objc2_app_kit::NSApplication; @@ -200,7 +200,7 @@ struct Opts { log_level: LogLevel, } -fn main() -> eyre::Result<()> { +pub fn run() -> eyre::Result<()> { let opts: Opts = Opts::parse(); let (_guard, _color_guard) = setup(opts.log_level)?; @@ -350,11 +350,11 @@ fn main() -> eyre::Result<()> { } // nothing may move a window once they have all been put back where they were found - komorebi::animation::animator::shutdown(); + crate::animation::animator::shutdown(); wm.lock().restore_all_windows(false)?; - let sockets = komorebi::SUBSCRIPTION_SOCKETS.lock(); + let sockets = crate::SUBSCRIPTION_SOCKETS.lock(); for path in (*sockets).values() { if let Ok(stream) = UnixStream::connect(path) { stream.shutdown(Shutdown::Both)?; diff --git a/komorebi-for-mac/komorebi/src/lib.rs b/komorebi-for-mac/komorebi/src/lib.rs index d69b65ea..df046e82 100644 --- a/komorebi-for-mac/komorebi/src/lib.rs +++ b/komorebi-for-mac/komorebi/src/lib.rs @@ -43,6 +43,7 @@ extern crate komorebi_collections; pub use komorebi_collections::ring; +pub mod daemon; pub mod accessibility; pub mod animation; pub mod app_kit_notification_constants; diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index d2bde6ff..0db869c1 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -83,7 +83,3 @@ schemars = [ [lib] name = "komorebi" - -[[bin]] -name = "komorebi" -path = "src/main.rs" diff --git a/komorebi/src/main.rs b/komorebi/src/daemon.rs similarity index 90% rename from komorebi/src/main.rs rename to komorebi/src/daemon.rs index 76d858ce..2cca1181 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/daemon.rs @@ -20,10 +20,10 @@ use clap::ValueEnum; use color_eyre::eyre; use color_eyre::eyre::bail; use crossbeam_utils::Backoff; -use komorebi::animation::ANIMATION_ENABLED_GLOBAL; -use komorebi::animation::ANIMATION_ENABLED_PER_ANIMATION; -use komorebi::animation::AnimationEngine; -use komorebi::replace_env_in_path; +use crate::animation::ANIMATION_ENABLED_GLOBAL; +use crate::animation::ANIMATION_ENABLED_PER_ANIMATION; +use crate::animation::AnimationEngine; +use crate::replace_env_in_path; use parking_lot::Mutex; #[cfg(feature = "deadlock_detection")] use parking_lot::deadlock; @@ -35,29 +35,29 @@ use tracing_subscriber::EnvFilter; use tracing_subscriber::layer::SubscriberExt; use uds_windows::UnixStream; -use komorebi::CUSTOM_FFM; -use komorebi::DATA_DIR; -use komorebi::HOME_DIR; -use komorebi::INITIAL_CONFIGURATION_LOADED; -use komorebi::SESSION_ID; -use komorebi::border_manager; -use komorebi::focus_manager; -use komorebi::load_configuration; -use komorebi::monitor_reconciliator; -use komorebi::process_command::listen_for_commands; -use komorebi::process_command::listen_for_commands_tcp; -use komorebi::process_event::listen_for_events; -use komorebi::process_movement::listen_for_movements; -use komorebi::reaper; -use komorebi::stackbar_manager; -use komorebi::state::State; -use komorebi::static_config::StaticConfig; -use komorebi::static_config::StaticConfigExt; -use komorebi::theme_manager; -use komorebi::transparency_manager; -use komorebi::window_manager::WindowManager; -use komorebi::windows_api::WindowsApi; -use komorebi::winevent_listener; +use crate::CUSTOM_FFM; +use crate::DATA_DIR; +use crate::HOME_DIR; +use crate::INITIAL_CONFIGURATION_LOADED; +use crate::SESSION_ID; +use crate::border_manager; +use crate::focus_manager; +use crate::load_configuration; +use crate::monitor_reconciliator; +use crate::process_command::listen_for_commands; +use crate::process_command::listen_for_commands_tcp; +use crate::process_event::listen_for_events; +use crate::process_movement::listen_for_movements; +use crate::reaper; +use crate::stackbar_manager; +use crate::state::State; +use crate::static_config::StaticConfig; +use crate::static_config::StaticConfigExt; +use crate::theme_manager; +use crate::transparency_manager; +use crate::window_manager::WindowManager; +use crate::windows_api::WindowsApi; +use crate::winevent_listener; fn setup(log_level: LogLevel) -> eyre::Result<(WorkerGuard, WorkerGuard)> { if std::env::var("RUST_LIB_BACKTRACE").is_err() { @@ -172,7 +172,7 @@ enum LogLevel { } #[derive(Parser)] -#[clap(name = "komorebi", author, about, version = komorebi::build::CLAP_LONG_VERSION)] +#[clap(name = "komorebi", author, about, version = crate::build::CLAP_LONG_VERSION)] struct Opts { /// Allow the use of komorebi's custom focus-follows-mouse implementation #[clap(short, long = "ffm")] @@ -197,7 +197,7 @@ struct Opts { #[tracing::instrument] #[allow(clippy::cognitive_complexity)] -fn main() -> eyre::Result<()> { +pub fn run() -> eyre::Result<()> { let opts: Opts = Opts::parse(); CUSTOM_FFM.store(opts.focus_follows_mouse, Ordering::SeqCst); @@ -342,7 +342,7 @@ fn main() -> eyre::Result<()> { } listen_for_events(wm.clone()); - komorebi::live_resize::listen_for_steps(wm.clone()); + crate::live_resize::listen_for_steps(wm.clone()); if CUSTOM_FFM.load(Ordering::SeqCst) { listen_for_movements(wm.clone()); @@ -373,7 +373,7 @@ fn main() -> eyre::Result<()> { WindowsApi::disable_focus_follows_mouse()?; } - let sockets = komorebi::SUBSCRIPTION_SOCKETS.lock(); + let sockets = crate::SUBSCRIPTION_SOCKETS.lock(); for path in (*sockets).values() { if let Ok(stream) = UnixStream::connect(path) { stream.shutdown(Shutdown::Both)?; diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 24dc4f33..65e0daa2 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -3,6 +3,7 @@ #[macro_use] extern crate komorebi_collections; +pub mod daemon; pub mod animation; pub mod border_manager; pub mod cloaked;