mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-20 07:31:39 +01:00
chore(repo): merge kfde's core line into the package migration
Merge of wip-u-core (kfde: komorebi-core with Container, Workspace<P>, Monitor<P>) and wip-u-pkg-mig3. Conflicts and how they were resolved: - komorebi-for-kde/Cargo.toml, komorebi-for-kde/Cargo.lock: deleted, as in the migration (one root workspace); kfde's only edit there, the komorebi-core workspace dependency, is applied as a path dependency in the crate manifest. - komorebi-for-kde/komorebi/Cargo.toml: the migration's manifest (inlined dependencies, package name komorebi-linux, [lib]/[[bin]]) plus kfde's komorebi-core dependency and the komorebi-core/schemars feature. - Cargo.lock: the migration's lock re-resolved with cargo metadata --offline: the only change is the new komorebi-core 0.1.42 entry; no version of any other package moved (compared by name/version with both parents; kfde's Windows lock differs only by the komorebi -> komorebi-windows rename). - komorebi-bar/src/widgets/komorebi.rs: deleted (the Windows bar moved to komorebi-bar/src/windows/); kfde's one-line edit (title: value.title() instead of value.title().ok()) applied to komorebi-bar/src/windows/widgets/komorebi.rs. - komorebi-for-kde/nix/root-crates.json: crates/komorebi-core added (tools/kde-closure-check now ok with 11 root crates). Gates run: tools/fast-check --since wip-u-pkg-mig3: native tests, Windows clippy -D warnings, KDE check+lib+schemas, macOS fake-CC check, nix evaluation (root and both nested flakes) PASS; KDE cargo test -p komorebi-linux -p komorebic -p komorebi-client -p komorebi-hotkeys -p komorebi-core: 902 passed, 0 failed; CLI docs oracle identical x3; bar schema harness byte-identical for both bars (its Window::title stub now returns Option); bar-core tests 3+6; kde-closure-check ok; by evaluation an edit of the Windows bar or daemon leaves the kfde derivations unchanged, a KDE edit leaves Windows unchanged, and an edit of crates/komorebi-core changes Windows and kfde but not macOS. Not run: nix builds, VM, e2e (the Windows daemon changed: kfde's e2e gate applies), any Mac run.
This commit is contained in:
commit
b937a3d716
142 files changed
+13935
-23088
No files matched your search
File renamed without changes.
@@ -68,7 +68,7 @@ jobs:
|
||||
args: "--locked --release"
|
||||
- run: |
|
||||
cargo install cargo-wix
|
||||
cargo wix --no-build -p komorebi --nocapture -I .\wix\main.wxs --target ${{ matrix.platform.target }}
|
||||
cargo wix --no-build -p komorebi-windows --nocapture -I .\wix\main.wxs --target ${{ matrix.platform.target }}
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: komorebi-${{ matrix.platform.target }}-${{ github.sha }}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
CHANGELOG.md
|
||||
dummy.go
|
||||
komorebic/applications.yaml
|
||||
komorebic/applications.json
|
||||
/.vs
|
||||
/bar-schema
|
||||
/komorebi-schema
|
||||
|
||||
Generated
+711
-97
File diff suppressed because it is too large.
Load diff
+36
@@ -9,6 +9,42 @@ members = [
|
||||
"crates/komorebi-collections",
|
||||
"crates/komorebi-core",
|
||||
"crates/komorebi-config",
|
||||
"crates/komorebi-settings",
|
||||
"komorebi-layouts",
|
||||
"komorebi-scrolling",
|
||||
"komorebic",
|
||||
"komorebic-no-console",
|
||||
"crates/komorebic-core",
|
||||
"komorebi-bar",
|
||||
"komorebi-themes",
|
||||
"crates/komorebi-protocol",
|
||||
"crates/komorebi-transport",
|
||||
"crates/komorebi-bar-core",
|
||||
"komorebi-shortcuts",
|
||||
"e2e/guest/agent",
|
||||
"e2e/guest/testwin",
|
||||
# komorebi for KDE Plasma (Linux) and komorebi for macOS: built only on their own platform, selected
|
||||
# with -p; `default-members` below is the Windows set that a bare cargo command builds
|
||||
"komorebi-for-kde/komorebi",
|
||||
"komorebi-for-kde/komorebic",
|
||||
"komorebi-for-kde/komorebi-client",
|
||||
"komorebi-for-kde/komorebi-hotkeys",
|
||||
"komorebi-for-kde/version",
|
||||
"komorebi-for-mac/komorebi",
|
||||
"komorebi-for-mac/komorebic",
|
||||
"komorebi-for-mac/komorebi-client",
|
||||
"komorebi-for-mac/komorebi-bar",
|
||||
"komorebi-for-mac/version",
|
||||
]
|
||||
|
||||
default-members = [
|
||||
"komorebi",
|
||||
"komorebi-client",
|
||||
"komorebi-gui",
|
||||
"crates/komorebi-backend",
|
||||
"crates/komorebi-collections",
|
||||
"crates/komorebi-config",
|
||||
"crates/komorebi-settings",
|
||||
"komorebi-layouts",
|
||||
"komorebi-scrolling",
|
||||
"komorebic",
|
||||
|
||||
@@ -31,6 +31,7 @@ mod error;
|
||||
pub mod fake;
|
||||
mod id;
|
||||
mod info;
|
||||
mod registry;
|
||||
|
||||
pub use backend::Backend;
|
||||
pub use backend::Batch;
|
||||
@@ -41,4 +42,5 @@ pub use id::MonitorId;
|
||||
pub use id::WindowId;
|
||||
pub use info::MonitorInfo;
|
||||
pub use info::WindowInfo;
|
||||
pub use registry::Registry;
|
||||
pub use komorebi_layouts::Rect;
|
||||
@@ -0,0 +1,312 @@
|
||||
//! A thread-safe table from a [`WindowId`] to whatever a platform needs in order to act on that
|
||||
//! window from nothing but the id.
|
||||
//!
|
||||
//! macOS is the platform that needs it: a window there is an Accessibility element with the pid
|
||||
//! of its application and the observer that reports its events, and nothing can be done to a
|
||||
//! window without them. The table is generic over the handle (`H`) so that its rules can be
|
||||
//! tested on any host with a stand-in handle; macOS instantiates it with its Accessibility types.
|
||||
//!
|
||||
//! # Rules
|
||||
//!
|
||||
//! 1. **Thread-safe.** Any thread may call any method.
|
||||
//! 2. **Nothing of the platform runs under the lock.** [`Registry::get`] clones the handle (the
|
||||
//! handle must be cheap to clone: a retained reference) and returns; the caller acts on the
|
||||
//! clone with the lock released. A method that removes an entry hands the removed handle back
|
||||
//! to the caller instead of dropping it inside, because dropping a macOS handle can make an
|
||||
//! Accessibility round trip. This is what keeps a registry call from ever waiting on the main
|
||||
//! queue, or on an application, while holding the lock (`docs/dev/seam.md` section 3.3).
|
||||
//! 3. **A stale id is an error, not a panic.** Looking up an id that was never registered, was
|
||||
//! removed, or was removed with its application answers [`Error::WindowGone`].
|
||||
//! 4. **Entries end** when the window is destroyed ([`Registry::remove`]), when its application
|
||||
//! quits ([`Registry::remove_pid`]), and when a call on the window shows that it is gone. An
|
||||
//! entry that nobody removes is a leak of a retained element; the platform removes at every
|
||||
//! place it learns of a death.
|
||||
//! 5. **Re-registering an id replaces the entry** and returns the old handle (a tab that is
|
||||
//! now shown by another element keeps the window id).
|
||||
//!
|
||||
//! ```
|
||||
//! use komorebi_backend::Registry;
|
||||
//! use komorebi_backend::WindowId;
|
||||
//!
|
||||
//! let registry: Registry<&'static str> = Registry::new();
|
||||
//! let id = WindowId::from_u32(7);
|
||||
//! registry.insert(id, 100, "element");
|
||||
//! assert_eq!(registry.get(id).unwrap(), "element");
|
||||
//!
|
||||
//! registry.remove(id);
|
||||
//! assert!(registry.get(id).unwrap_err().is_window_gone());
|
||||
//! ```
|
||||
|
||||
use crate::Error;
|
||||
use crate::Result;
|
||||
use crate::WindowId;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::MutexGuard;
|
||||
|
||||
struct Entry<H> {
|
||||
pid: i32,
|
||||
handle: H,
|
||||
}
|
||||
|
||||
/// The table. See the [module documentation](self) for its rules.
|
||||
pub struct Registry<H> {
|
||||
entries: Mutex<HashMap<WindowId, Entry<H>>>,
|
||||
}
|
||||
|
||||
impl<H> Default for Registry<H> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<H> Registry<H> {
|
||||
/// Returns an empty registry.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
entries: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// a thread that panicked while holding the lock cannot have left an entry half written (every
|
||||
// method is a single map operation), so a poisoned lock is still good
|
||||
fn lock(&self) -> MutexGuard<'_, HashMap<WindowId, Entry<H>>> {
|
||||
self.entries.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
/// Registers the window, owned by the process `pid`. Returns the handle that this replaces,
|
||||
/// if the id was registered: the caller drops it, with no lock held.
|
||||
#[must_use = "drop the replaced handle yourself: it is not dropped under the lock"]
|
||||
pub fn insert(&self, id: WindowId, pid: i32, handle: H) -> Option<H> {
|
||||
self.lock().insert(id, Entry { pid, handle }).map(|e| e.handle)
|
||||
}
|
||||
|
||||
/// Replaces the handle of a window that is registered, keeping its pid. Returns the old
|
||||
/// handle, or [`Error::WindowGone`] (and registers nothing) if the id is not registered.
|
||||
pub fn replace(&self, id: WindowId, handle: H) -> Result<H> {
|
||||
match self.lock().get_mut(&id) {
|
||||
Some(entry) => Ok(std::mem::replace(&mut entry.handle, handle)),
|
||||
None => Err(Error::WindowGone(id)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Forgets the window. Returns its handle (for the caller to drop with no lock held), or
|
||||
/// `None` if it was not registered, which is not an error: a death is usually seen twice.
|
||||
#[must_use = "drop the removed handle yourself: it is not dropped under the lock"]
|
||||
pub fn remove(&self, id: WindowId) -> Option<H> {
|
||||
self.lock().remove(&id).map(|e| e.handle)
|
||||
}
|
||||
|
||||
/// Forgets every window of the process, as when its application quits. Returns the ids and
|
||||
/// handles removed, sorted by id.
|
||||
#[must_use = "drop the removed handles yourself: they are not dropped under the lock"]
|
||||
pub fn remove_pid(&self, pid: i32) -> Vec<(WindowId, H)> {
|
||||
let mut entries = self.lock();
|
||||
let ids: Vec<WindowId> = entries
|
||||
.iter()
|
||||
.filter(|(_, e)| e.pid == pid)
|
||||
.map(|(id, _)| *id)
|
||||
.collect();
|
||||
let mut removed: Vec<(WindowId, H)> = ids
|
||||
.into_iter()
|
||||
.filter_map(|id| entries.remove(&id).map(|e| (id, e.handle)))
|
||||
.collect();
|
||||
drop(entries);
|
||||
removed.sort_by_key(|(id, _)| *id);
|
||||
removed
|
||||
}
|
||||
|
||||
/// Whether the id is registered.
|
||||
pub fn contains(&self, id: WindowId) -> bool {
|
||||
self.lock().contains_key(&id)
|
||||
}
|
||||
|
||||
/// The pid of the registered window, or [`Error::WindowGone`].
|
||||
pub fn pid(&self, id: WindowId) -> Result<i32> {
|
||||
self.lock()
|
||||
.get(&id)
|
||||
.map(|e| e.pid)
|
||||
.ok_or(Error::WindowGone(id))
|
||||
}
|
||||
|
||||
/// How many windows are registered.
|
||||
pub fn len(&self) -> usize {
|
||||
self.lock().len()
|
||||
}
|
||||
|
||||
/// Whether nothing is registered.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.lock().is_empty()
|
||||
}
|
||||
|
||||
/// The registered ids, sorted.
|
||||
pub fn ids(&self) -> Vec<WindowId> {
|
||||
let mut ids: Vec<_> = self.lock().keys().copied().collect();
|
||||
ids.sort();
|
||||
ids
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: Clone> Registry<H> {
|
||||
/// A clone of the handle of the window, or [`Error::WindowGone`] for an id that is not
|
||||
/// registered. The lock is released before this returns.
|
||||
pub fn get(&self, id: WindowId) -> Result<H> {
|
||||
self.lock()
|
||||
.get(&id)
|
||||
.map(|e| e.handle.clone())
|
||||
.ok_or(Error::WindowGone(id))
|
||||
}
|
||||
|
||||
/// Clones of every handle with their ids, sorted by id.
|
||||
pub fn snapshot(&self) -> Vec<(WindowId, H)> {
|
||||
let mut all: Vec<_> = self
|
||||
.lock()
|
||||
.iter()
|
||||
.map(|(id, e)| (*id, e.handle.clone()))
|
||||
.collect();
|
||||
all.sort_by_key(|(id, _)| *id);
|
||||
all
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
fn id(n: u32) -> WindowId {
|
||||
WindowId::from_u32(n)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_registered_window_is_found_by_its_id() {
|
||||
let r = Registry::new();
|
||||
assert!(r.insert(id(1), 10, "a").is_none());
|
||||
assert!(matches!(r.get(id(1)), Ok("a")));
|
||||
assert!(matches!(r.pid(id(1)), Ok(10)));
|
||||
assert!(r.contains(id(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_id_is_window_gone_and_not_a_panic() {
|
||||
let r: Registry<&str> = Registry::new();
|
||||
assert!(matches!(r.get(id(9)), Err(Error::WindowGone(w)) if w == id(9)));
|
||||
assert!(matches!(r.pid(id(9)), Err(Error::WindowGone(_))));
|
||||
assert!(r.get(id(9)).unwrap_err().is_window_gone());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_removed_window_is_stale() {
|
||||
let r = Registry::new();
|
||||
let _ = r.insert(id(1), 10, "a");
|
||||
assert_eq!(r.remove(id(1)), Some("a"));
|
||||
assert!(r.get(id(1)).unwrap_err().is_window_gone());
|
||||
// a death seen twice is not an error
|
||||
assert_eq!(r.remove(id(1)), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reinserting_replaces_and_hands_back_the_old_handle() {
|
||||
let r = Registry::new();
|
||||
let _ = r.insert(id(1), 10, "tab one");
|
||||
assert_eq!(r.insert(id(1), 10, "tab two"), Some("tab one"));
|
||||
assert!(matches!(r.get(id(1)), Ok("tab two")));
|
||||
assert_eq!(r.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_keeps_the_pid_and_refuses_a_stale_id() {
|
||||
let r = Registry::new();
|
||||
let _ = r.insert(id(1), 10, "a");
|
||||
assert!(matches!(r.replace(id(1), "b"), Ok("a")));
|
||||
assert!(matches!(r.pid(id(1)), Ok(10)));
|
||||
assert!(r.replace(id(2), "c").unwrap_err().is_window_gone());
|
||||
assert!(!r.contains(id(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_application_quitting_takes_all_its_windows_and_only_them() {
|
||||
let r = Registry::new();
|
||||
let _ = r.insert(id(3), 10, "c");
|
||||
let _ = r.insert(id(1), 10, "a");
|
||||
let _ = r.insert(id(2), 20, "b");
|
||||
|
||||
assert_eq!(r.remove_pid(10), vec![(id(1), "a"), (id(3), "c")]);
|
||||
assert_eq!(r.ids(), vec![id(2)]);
|
||||
assert!(r.get(id(1)).unwrap_err().is_window_gone());
|
||||
assert_eq!(r.remove_pid(10), vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_is_sorted_and_independent_of_later_changes() {
|
||||
let r = Registry::new();
|
||||
let _ = r.insert(id(2), 1, "b");
|
||||
let _ = r.insert(id(1), 1, "a");
|
||||
let snap = r.snapshot();
|
||||
let _ = r.remove(id(1));
|
||||
assert_eq!(snap, vec![(id(1), "a"), (id(2), "b")]);
|
||||
}
|
||||
|
||||
/// A handle whose drop would, on macOS, make a round trip: it must not run under the lock.
|
||||
struct Probe {
|
||||
registry: Arc<Registry<Arc<Probe>>>,
|
||||
drops: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl Drop for Probe {
|
||||
fn drop(&mut self) {
|
||||
// would deadlock if the registry dropped the handle while holding its lock
|
||||
let _ = self.registry.len();
|
||||
self.drops.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handles_are_never_dropped_under_the_lock() {
|
||||
let registry = Arc::new(Registry::new());
|
||||
let drops = Arc::new(AtomicUsize::new(0));
|
||||
let probe = |_: u32| {
|
||||
Arc::new(Probe {
|
||||
registry: registry.clone(),
|
||||
drops: drops.clone(),
|
||||
})
|
||||
};
|
||||
|
||||
let _ = registry.insert(id(1), 10, probe(1));
|
||||
// the replaced and the removed handles come back to us, so their drop runs here
|
||||
drop(registry.insert(id(1), 10, probe(2)));
|
||||
drop(registry.remove(id(1)));
|
||||
let _ = registry.insert(id(2), 10, probe(3));
|
||||
drop(registry.remove_pid(10));
|
||||
|
||||
assert_eq!(drops.load(Ordering::SeqCst), 3);
|
||||
assert!(registry.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_threads_can_register_look_up_and_remove() {
|
||||
let r = Arc::new(Registry::new());
|
||||
let threads: Vec<_> = (0..8u32)
|
||||
.map(|t| {
|
||||
let r = r.clone();
|
||||
std::thread::spawn(move || {
|
||||
for n in 0..200u32 {
|
||||
let wid = id(t * 1000 + n);
|
||||
let _ = r.insert(wid, t as i32, n);
|
||||
assert!(matches!(r.get(wid), Ok(v) if v == n));
|
||||
assert_eq!(r.remove(wid), Some(n));
|
||||
assert!(r.get(wid).unwrap_err().is_window_gone());
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
for t in threads {
|
||||
t.join().unwrap();
|
||||
}
|
||||
|
||||
assert!(r.is_empty());
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,23 @@ chrono = { workspace = true }
|
||||
chrono-tz = { workspace = true }
|
||||
eframe = { workspace = true }
|
||||
egui-phosphor = { git = "https://github.com/amPerl/egui-phosphor", rev = "d13688738478ecd12b426e3e74c59d6577a85b59" }
|
||||
lazy_static = { workspace = true }
|
||||
image = "0.25"
|
||||
komorebi-config = { path = "../komorebi-config", default-features = false }
|
||||
reqwest = { version = "0.12", features = ["blocking"] }
|
||||
komorebi-layouts = { path = "../../komorebi-layouts" }
|
||||
komorebi-themes = { path = "../../komorebi-themes", default-features = false }
|
||||
komorebi-protocol = { path = "../komorebi-protocol", default-features = false }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
color-eyre = { workspace = true }
|
||||
serde_json = { workspace = true, features = ["preserve_order"] }
|
||||
starship-battery = "0.11"
|
||||
sysinfo = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
||||
# Optional dependencies
|
||||
schemars = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
default = ["schemars"]
|
||||
schemars = ["dep:schemars"]
|
||||
schemars = ["dep:schemars", "komorebi-config/schemars", "komorebi-layouts/schemars", "komorebi-themes/schemars", "komorebi-protocol/schemars"]
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::DEFAULT_PADDING;
|
||||
use crate::bar::exec_powershell;
|
||||
use crate::config::types::*;
|
||||
use crate::statics::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::statics::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::statics::DEFAULT_PADDING;
|
||||
use crate::platform::platform;
|
||||
use crate::render::Grouping;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::render::RenderExt;
|
||||
@@ -11,9 +12,9 @@ use eframe::egui::Context;
|
||||
use eframe::egui::FontId;
|
||||
use eframe::egui::TextBuffer;
|
||||
use eframe::egui::TextStyle;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::Rect;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_protocol::pathext::PathExt;
|
||||
use komorebi_layouts::Rect;
|
||||
use komorebi_protocol::message::SocketMessage;
|
||||
use komorebi_themes::colour::Colour;
|
||||
use komorebi_themes::colour::Rgb;
|
||||
use serde::Deserialize;
|
||||
@@ -424,7 +425,7 @@ pub struct KomorebiMouseMessage {
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = true)))]
|
||||
pub ignore_mouse_follows_focus: Option<bool>,
|
||||
/// The message to send to the komorebi client
|
||||
pub message: komorebi_client::SocketMessage,
|
||||
pub message: komorebi_protocol::message::SocketMessage,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
@@ -497,7 +498,7 @@ impl MouseMessage {
|
||||
|
||||
tracing::debug!("Sending messages: {messages:?}");
|
||||
|
||||
if komorebi_client::send_batch(messages).is_err() {
|
||||
if platform().send_komorebi_batch(messages).is_err() {
|
||||
tracing::error!("could not send commands");
|
||||
}
|
||||
}
|
||||
@@ -506,7 +507,10 @@ impl MouseMessage {
|
||||
|
||||
let cmd_no_env = cmd.replace_env();
|
||||
|
||||
if exec_powershell(cmd_no_env.to_str().expect("Invalid command")).is_err() {
|
||||
if platform()
|
||||
.exec_shell_command(cmd_no_env.to_str().expect("Invalid command"))
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("Failed to execute '{}'", cmd);
|
||||
}
|
||||
}
|
||||
@@ -522,6 +526,18 @@ impl KomobarConfig {
|
||||
_ => panic!("unsupported format"),
|
||||
};
|
||||
|
||||
crate::widgets::widget::warn_unsupported(
|
||||
value
|
||||
.left_widgets
|
||||
.iter()
|
||||
.chain(value.center_widgets.iter().flatten())
|
||||
.chain(value.right_widgets.iter()),
|
||||
);
|
||||
|
||||
if value.mouse.is_some() && !cfg!(target_os = "windows") {
|
||||
tracing::warn!("the `mouse` options are not supported on this platform and are ignored");
|
||||
}
|
||||
|
||||
if value.frame.is_none() {
|
||||
value.frame = Some(FrameConfig {
|
||||
inner_margin: Position {
|
||||
@@ -586,5 +602,4 @@ impl RenderExt for &KomobarConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub use komorebi_bar_core::config::types::*;
|
||||
pub use komorebi_themes::KomobarTheme;
|
||||
@@ -1,3 +1,5 @@
|
||||
pub mod komobar;
|
||||
pub mod types;
|
||||
|
||||
pub use komobar::*;
|
||||
pub use types::*;
|
||||
@@ -18,3 +18,5 @@ pub mod render;
|
||||
pub mod widgets;
|
||||
|
||||
pub mod platform;
|
||||
|
||||
pub mod schema;
|
||||
@@ -3,6 +3,8 @@
|
||||
//! A shell implements [`BarPlatform`] and calls [`install`] first thing in `main`; the widgets
|
||||
//! reach it through [`platform`] when they are built or clicked.
|
||||
|
||||
use crate::widgets::icons::ImageIcon;
|
||||
use komorebi_protocol::message::SocketMessage;
|
||||
use std::io;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
@@ -17,6 +19,9 @@ pub enum SystemTool {
|
||||
NetworkSettings,
|
||||
/// A URL, in the default browser
|
||||
Url(String),
|
||||
/// The location a storage widget label names (the label text, as shown: the platform
|
||||
/// knows how its labels are built), in the file manager
|
||||
StorageLocation(String),
|
||||
}
|
||||
|
||||
pub trait BarPlatform: Send + Sync {
|
||||
@@ -26,6 +31,19 @@ pub trait BarPlatform: Send + Sync {
|
||||
/// The GitHub API URL that says which release of this platform's komorebi is the latest.
|
||||
fn latest_release_api_url(&self) -> &'static str;
|
||||
|
||||
/// The icon of the program a command string would start (Windows: the executable's icon;
|
||||
/// macOS: none).
|
||||
fn command_icon(&self, command: &str) -> Option<ImageIcon>;
|
||||
|
||||
/// Runs a command line in the bar's shell session (Windows: its PowerShell session).
|
||||
fn exec_shell_command(&self, command: &str) -> color_eyre::Result<()>;
|
||||
|
||||
/// Sends one message to the komorebi daemon.
|
||||
fn send_komorebi_message(&self, message: &SocketMessage) -> io::Result<()>;
|
||||
|
||||
/// Sends messages to the komorebi daemon as one batch.
|
||||
fn send_komorebi_batch(&self, messages: Vec<SocketMessage>) -> io::Result<()>;
|
||||
|
||||
/// The glyph the date widget shows as its calendar icon.
|
||||
fn calendar_icon(&self) -> &'static str;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
//! What the macOS bar's schema says differently from the union, as data.
|
||||
//!
|
||||
//! The union is written once: it is the Windows text of `schema.bar.json` (every widget, the
|
||||
//! mouse options, Windows' spelling of the documentation). The macOS view removes what the macOS
|
||||
//! bar does not have (the keyboard, media and systray widgets, the mouse options and their
|
||||
//! definitions, which pruning of the unreachable definitions finishes) and sets the text and the
|
||||
//! defaults that read differently. Each entry is a convergence candidate: dropping one changes
|
||||
//! one line of `komorebi-for-mac/schema.bar.json` and of `nix/komorebi-bar-options.nix`.
|
||||
//!
|
||||
//! Generated from the difference between the two checked-in files; `tests/schema_oracle.rs`
|
||||
//! proves that the view of the Windows file is byte-identical to the macOS file.
|
||||
|
||||
/// One change of a view
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Change {
|
||||
/// Replace the value at the JSON pointer with this JSON text
|
||||
Set(&'static str),
|
||||
/// Remove the key at the JSON pointer
|
||||
Remove,
|
||||
/// Remove the elements of the array at the JSON pointer whose `title` is this
|
||||
RemoveTitled(&'static str),
|
||||
}
|
||||
|
||||
/// The changes of the macOS view, in order.
|
||||
pub const MACOS: &[(&str, Change)] = &[
|
||||
(
|
||||
"/description",
|
||||
Change::Set(
|
||||
r####""The `komorebi.bar.json` static configuration file reference for komorebi for Mac `v0.1.0`\n\n`\"$schema\": \"https://komorebi-for-mac.lgug2z.com/komorebi.bar.0.1.0.schema.json\"`""####,
|
||||
),
|
||||
),
|
||||
(
|
||||
"/properties/height",
|
||||
Change::Set(
|
||||
r####"{"description":"Bar height","type":["number","null"],"format":"float","default":50.0}"####,
|
||||
),
|
||||
),
|
||||
(
|
||||
"/properties/margin",
|
||||
Change::Set(
|
||||
r####"{"description":"Bar margin. Use one value for all sides or use a grouped margin for horizontal and/or\nvertical definition which can each take a single value for a symmetric margin or two\nvalues for each side, i.e.:\n```json\n\"margin\": {\n \"horizontal\": 10.0\n}\n```\nor:\n```json\n\"margin\": {\n \"vertical\": [top, bottom]\n}\n```\nYou can also set individual margin on each side like this:\n```json\n\"margin\": {\n \"top\": 10.0,\n \"bottom\": 10.0,\n \"left\": 10.0,\n \"right\": 10.0\n}\n```","anyOf":[{"$ref":"#/$defs/SpacingKind"},{"type":"null"}]}"####,
|
||||
),
|
||||
),
|
||||
(
|
||||
"/properties/padding",
|
||||
Change::Set(
|
||||
r####"{"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```","anyOf":[{"$ref":"#/$defs/SpacingKind"},{"type":"null"}]}"####,
|
||||
),
|
||||
),
|
||||
("/properties/mouse", Change::Remove),
|
||||
(
|
||||
"/$defs/KomorebiFocusedContainerConfig/properties/show_icon",
|
||||
Change::Set(
|
||||
r####"{"description":"DEPRECATED: use 'display' instead (Show the icon of the currently focused container)","type":["boolean","null"]}"####,
|
||||
),
|
||||
),
|
||||
(
|
||||
"/$defs/KomorebiLayout",
|
||||
Change::Set(
|
||||
r####"{"description":"Komorebi layout kind","oneOf":[{"title":"Default","description":"Predefined layout","type":"object","properties":{"Default":{"$ref":"#/$defs/DefaultLayout"}},"additionalProperties":false,"required":["Default"]},{"description":"Monocle mode","type":"string","const":"Monocle"},{"description":"Floating layer","type":"string","const":"Floating"},{"description":"Paused","type":"string","const":"Paused"},{"description":"Custom layout","type":"string","const":"Custom"}]}"####,
|
||||
),
|
||||
),
|
||||
(
|
||||
"/$defs/NetworkConfig/properties/default_interface_options",
|
||||
Change::Remove,
|
||||
),
|
||||
(
|
||||
"/$defs/StorageDisplayName/oneOf/0/description",
|
||||
Change::Set(r####""Display label as mount point eg. /""####),
|
||||
),
|
||||
(
|
||||
"/$defs/StorageDisplayName/oneOf/1/description",
|
||||
Change::Set(r####""Display label as name eg. Macintosh HD""####),
|
||||
),
|
||||
(
|
||||
"/$defs/StorageDisplayName/oneOf/2/description",
|
||||
Change::Set(r####""Display label as mount then name eg. / Macintosh HD""####),
|
||||
),
|
||||
(
|
||||
"/$defs/StorageDisplayName/oneOf/3/description",
|
||||
Change::Set(r####""Display label as name then mount eg. Macintosh HD /""####),
|
||||
),
|
||||
(
|
||||
"/$defs/TimeConfig/properties/changing_icon",
|
||||
Change::Set(
|
||||
r####"{"description":"Change the icon depending on the time. The default icon is used between 8:30 and 12:00","type":["boolean","null"],"default":false}"####,
|
||||
),
|
||||
),
|
||||
(
|
||||
"/$defs/TimeFormat/oneOf/6/title",
|
||||
Change::Set(r####""Default""####),
|
||||
),
|
||||
(
|
||||
"/$defs/WidgetConfig/oneOf",
|
||||
Change::RemoveTitled("Keyboard"),
|
||||
),
|
||||
("/$defs/WidgetConfig/oneOf", Change::RemoveTitled("Media")),
|
||||
("/$defs/WidgetConfig/oneOf", Change::RemoveTitled("Systray")),
|
||||
];
|
||||
@@ -0,0 +1,128 @@
|
||||
//! The JSON Schema of `komorebi.bar.json`, one per platform, as views of one union.
|
||||
//!
|
||||
//! The union is the Windows schema: every widget and option any bar reads, in Windows' spelling.
|
||||
//! [`view_of`] turns it into the schema a platform checks in: it applies the platform's
|
||||
//! [`changes`] and removes the definitions nothing refers to any more. The Windows view is the
|
||||
//! union itself.
|
||||
//!
|
||||
//! The changes are idempotent (setting text that is already there, or removing what is not
|
||||
//! there, does nothing), so a bar can print its own generated schema through its view.
|
||||
|
||||
pub mod changes;
|
||||
|
||||
use changes::Change;
|
||||
use serde_json::Map;
|
||||
use serde_json::Value;
|
||||
|
||||
/// A platform that has a bar
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum SchemaPlatform {
|
||||
Windows,
|
||||
MacOs,
|
||||
}
|
||||
|
||||
/// The changes a platform's view applies, in order
|
||||
#[must_use]
|
||||
pub const fn changes_of(platform: SchemaPlatform) -> &'static [(&'static str, Change)] {
|
||||
match platform {
|
||||
SchemaPlatform::Windows => &[],
|
||||
SchemaPlatform::MacOs => changes::MACOS,
|
||||
}
|
||||
}
|
||||
|
||||
/// The text a bar prints for `--schema`: pretty JSON followed by a newline, of the view of the
|
||||
/// union of the bar configuration.
|
||||
#[must_use]
|
||||
pub fn view_text(union: Value, platform: SchemaPlatform) -> String {
|
||||
let mut text =
|
||||
serde_json::to_string_pretty(&view_of(union, platform)).expect("a schema is JSON");
|
||||
text.push('\n');
|
||||
text
|
||||
}
|
||||
|
||||
/// The view of `schema` for `platform`.
|
||||
#[must_use]
|
||||
pub fn view_of(mut schema: Value, platform: SchemaPlatform) -> Value {
|
||||
for (pointer, change) in changes_of(platform) {
|
||||
apply(&mut schema, pointer, *change);
|
||||
}
|
||||
prune_unreachable(&mut schema);
|
||||
schema
|
||||
}
|
||||
|
||||
fn apply(schema: &mut Value, pointer: &str, change: Change) {
|
||||
match change {
|
||||
Change::Set(json) => {
|
||||
if let Some(target) = schema.pointer_mut(pointer) {
|
||||
*target = serde_json::from_str(json).expect("a change is JSON");
|
||||
}
|
||||
}
|
||||
Change::Remove => {
|
||||
if let Some((parent, key)) = pointer.rsplit_once('/')
|
||||
&& let Some(Value::Object(map)) = schema.pointer_mut(parent)
|
||||
{
|
||||
map.retain(|k, _| k != key);
|
||||
}
|
||||
}
|
||||
Change::RemoveTitled(title) => {
|
||||
if let Some(Value::Array(items)) = schema.pointer_mut(pointer) {
|
||||
items.retain(|item| item.get("title").and_then(Value::as_str) != Some(title));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep the definitions that the schema refers to, directly or through another definition.
|
||||
fn prune_unreachable(schema: &mut Value) {
|
||||
let mut reachable = Vec::new();
|
||||
collect_refs(schema, &mut reachable);
|
||||
let Some(defs) = schema.get("$defs").and_then(Value::as_object).cloned() else {
|
||||
return;
|
||||
};
|
||||
let mut next = 0;
|
||||
while next < reachable.len() {
|
||||
if let Some(def) = defs.get(&reachable[next]) {
|
||||
let mut found = Vec::new();
|
||||
collect_refs(def, &mut found);
|
||||
for name in found {
|
||||
if !reachable.contains(&name) {
|
||||
reachable.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
next += 1;
|
||||
}
|
||||
let kept: Map<String, Value> = defs
|
||||
.into_iter()
|
||||
.filter(|(name, _)| reachable.contains(name))
|
||||
.collect();
|
||||
schema["$defs"] = Value::Object(kept);
|
||||
}
|
||||
|
||||
fn collect_refs(value: &Value, found: &mut Vec<String>) {
|
||||
match value {
|
||||
Value::Object(map) => {
|
||||
if let Some(Value::String(target)) = map.get("$ref")
|
||||
&& let Some(name) = target.strip_prefix("#/$defs/")
|
||||
&& !found.iter().any(|n| n == name)
|
||||
{
|
||||
found.push(name.to_string());
|
||||
}
|
||||
for (key, child) in map {
|
||||
if key != "$defs" {
|
||||
collect_refs(child, found);
|
||||
}
|
||||
}
|
||||
}
|
||||
Value::Array(items) => items.iter().for_each(|item| collect_refs(item, found)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// The text `--schema` prints for the bar configuration type `T`, as `platform` checks it in.
|
||||
#[cfg(feature = "schemars")]
|
||||
#[must_use]
|
||||
pub fn generated_text<T: schemars::JsonSchema>(platform: SchemaPlatform) -> String {
|
||||
let union = serde_json::to_value(schemars::schema_for!(T)).expect("a schema is JSON");
|
||||
view_text(union, platform)
|
||||
}
|
||||
+4
-34
@@ -1,4 +1,5 @@
|
||||
use super::ImageIcon;
|
||||
use super::icons::ImageIcon;
|
||||
use crate::platform::platform;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
@@ -17,17 +18,14 @@ use eframe::egui::StrokeKind;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::vec2;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_protocol::pathext::PathExt;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::borrow::Cow;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use tracing;
|
||||
use which::which;
|
||||
|
||||
/// Minimum interval between consecutive application launches to prevent accidental spamming.
|
||||
const MIN_LAUNCH_INTERVAL: Duration = Duration::from_millis(800);
|
||||
@@ -273,13 +271,7 @@ impl Icon {
|
||||
/// - Returns `None` if the executable path is unavailable or icon extraction fails.
|
||||
#[inline]
|
||||
pub fn try_from_command(command: &UserCommand) -> Option<Self> {
|
||||
let path = command.get_executable()?;
|
||||
let image_icon = ImageIcon::try_load(path.as_ref(), || {
|
||||
let path_str = path.to_str()?;
|
||||
windows_icons::get_icon_by_path(path_str)
|
||||
.or_else(|| windows_icons_fallback::get_icon_by_path(path_str))
|
||||
})?;
|
||||
Some(Icon::Image(image_icon))
|
||||
platform().command_icon(&command.command).map(Icon::Image)
|
||||
}
|
||||
|
||||
/// Renders the icon in the given [`Ui`] using the provided [`IconConfig`].
|
||||
@@ -364,28 +356,6 @@ impl UserCommand {
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to resolve the executable path from the command string.
|
||||
///
|
||||
/// Resolution logic:
|
||||
/// - Splits the command by ".exe" and checks if the first part is an existing file.
|
||||
/// - If not, attempts to locate the binary using [`which`] on this name.
|
||||
/// - If still unresolved, takes the first word (separated by whitespace) and attempts
|
||||
/// to find it in the system `PATH` using [`which`].
|
||||
///
|
||||
/// Returns `None` if no executable path can be determined.
|
||||
#[inline]
|
||||
pub fn get_executable(&self) -> Option<Cow<'_, Path>> {
|
||||
if let Some(binary) = self.command.split(".exe").next().map(Path::new) {
|
||||
if binary.is_file() {
|
||||
return Some(Cow::Borrowed(binary));
|
||||
} else if let Ok(binary) = which(binary) {
|
||||
return Some(Cow::Owned(binary));
|
||||
}
|
||||
}
|
||||
|
||||
which(self.command.split(' ').next()?).ok().map(Cow::Owned)
|
||||
}
|
||||
|
||||
/// Attempts to launch the specified command in a separate thread if enough time has passed
|
||||
/// since the last launch. This prevents repeated launches from rapid consecutive clicks.
|
||||
///
|
||||
@@ -9,23 +9,6 @@ use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::RwLock;
|
||||
|
||||
pub mod applications;
|
||||
pub use komorebi_bar_core::widgets::battery;
|
||||
pub use komorebi_bar_core::widgets::cpu;
|
||||
pub use komorebi_bar_core::widgets::date;
|
||||
pub mod keyboard;
|
||||
pub mod komorebi;
|
||||
mod komorebi_layout;
|
||||
pub mod media;
|
||||
pub use komorebi_bar_core::widgets::memory;
|
||||
pub mod network;
|
||||
pub mod storage;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub mod systray;
|
||||
pub mod time;
|
||||
pub use komorebi_bar_core::widgets::update;
|
||||
pub mod widget;
|
||||
|
||||
/// Global cache for icon images and their associated GPU textures.
|
||||
pub static ICONS_CACHE: IconsCache = IconsCache::new();
|
||||
|
||||
@@ -103,7 +86,7 @@ impl IconsCache {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn rgba_to_color_image(rgba_image: &RgbaImage) -> ColorImage {
|
||||
pub fn rgba_to_color_image(rgba_image: &RgbaImage) -> ColorImage {
|
||||
let size = [rgba_image.width() as usize, rgba_image.height() as usize];
|
||||
let pixels = rgba_image.as_flat_samples();
|
||||
ColorImage::from_rgba_unmultiplied(size, pixels.as_slice())
|
||||
@@ -166,6 +149,8 @@ pub enum ImageIconId {
|
||||
Hwnd(isize),
|
||||
/// System tray icon identifier.
|
||||
SystrayIcon(String),
|
||||
/// macOS window ID.
|
||||
WindowId(u32),
|
||||
}
|
||||
|
||||
impl From<&Path> for ImageIconId {
|
||||
@@ -181,3 +166,16 @@ impl From<isize> for ImageIconId {
|
||||
Self::Hwnd(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for ImageIconId {
|
||||
#[inline]
|
||||
fn from(value: u32) -> Self {
|
||||
Self::WindowId(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for IconsCache {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
//! The configuration of the komorebi widgets (workspaces, layout, focused container, ...) and
|
||||
//! the layout kind the layout widget shows: data only, shared by both bars.
|
||||
|
||||
use crate::config::DisplayFormat;
|
||||
use crate::config::WorkspacesDisplayFormat;
|
||||
use color_eyre::eyre;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::de::Error;
|
||||
use serde_json::from_str;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget configuration
|
||||
pub struct KomorebiConfig {
|
||||
/// Configure the Workspaces widget
|
||||
pub workspaces: Option<KomorebiWorkspacesConfig>,
|
||||
/// Configure the Layout widget
|
||||
pub layout: Option<KomorebiLayoutConfig>,
|
||||
/// Configure the Workspace Layer widget
|
||||
pub workspace_layer: Option<KomorebiWorkspaceLayerConfig>,
|
||||
/// Configure the Focused Container widget
|
||||
#[serde(alias = "focused_window")]
|
||||
pub focused_container: Option<KomorebiFocusedContainerConfig>,
|
||||
/// Configure the Locked Container widget
|
||||
pub locked_container: Option<KomorebiLockedContainerConfig>,
|
||||
/// Configure the Configuration Switcher widget
|
||||
pub configuration_switcher: Option<KomorebiConfigurationSwitcherConfig>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget workspaces configuration
|
||||
pub struct KomorebiWorkspacesConfig {
|
||||
/// Enable the Komorebi Workspaces widget
|
||||
pub enable: bool,
|
||||
/// Hide workspaces without any windows
|
||||
pub hide_empty_workspaces: bool,
|
||||
/// Display format of the workspace
|
||||
pub display: Option<WorkspacesDisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget layout configuration
|
||||
pub struct KomorebiLayoutConfig {
|
||||
/// Enable the Komorebi Layout widget
|
||||
pub enable: bool,
|
||||
/// List of layout options
|
||||
pub options: Option<Vec<KomorebiLayout>>,
|
||||
/// Display format of the current layout
|
||||
pub display: Option<DisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget workspace layer configuration
|
||||
pub struct KomorebiWorkspaceLayerConfig {
|
||||
/// Enable the Komorebi Workspace Layer widget
|
||||
pub enable: bool,
|
||||
/// Display format of the current layer
|
||||
pub display: Option<DisplayFormat>,
|
||||
/// Show the widget event if the layer is Tiling
|
||||
pub show_when_tiling: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget focused container configuration
|
||||
pub struct KomorebiFocusedContainerConfig {
|
||||
/// Enable the Komorebi Focused Container widget
|
||||
pub enable: bool,
|
||||
/// DEPRECATED: use `display` instead (Show the icon of the currently focused container)
|
||||
#[deprecated(note = "Use `display` instead")]
|
||||
pub show_icon: Option<bool>,
|
||||
/// Display format of the currently focused container
|
||||
pub display: Option<DisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget locked container configuration
|
||||
pub struct KomorebiLockedContainerConfig {
|
||||
/// Enable the Komorebi Locked Container widget
|
||||
pub enable: bool,
|
||||
/// Display format of the current locked state
|
||||
pub display: Option<DisplayFormat>,
|
||||
/// Show the widget event if the layer is unlocked
|
||||
pub show_when_unlocked: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget configuration switcher configuration
|
||||
pub struct KomorebiConfigurationSwitcherConfig {
|
||||
/// Enable the Komorebi Configurations widget
|
||||
pub enable: bool,
|
||||
/// A map of display friendly name => path to configuration.json
|
||||
pub configurations: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// Komorebi layout kind
|
||||
pub enum KomorebiLayout {
|
||||
/// Predefined layout
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Default"))]
|
||||
Default(komorebi_layouts::DefaultLayout),
|
||||
/// Monocle mode
|
||||
Monocle,
|
||||
/// Floating layer
|
||||
Floating,
|
||||
/// Paused
|
||||
Paused,
|
||||
/// Custom layout
|
||||
Custom,
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for KomorebiLayout {
|
||||
fn deserialize<D>(deserializer: D) -> eyre::Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s: String = String::deserialize(deserializer)?;
|
||||
|
||||
// Attempt to deserialize the string as a DefaultLayout
|
||||
if let Ok(default_layout) = from_str::<komorebi_layouts::DefaultLayout>(&format!("\"{s}\""))
|
||||
{
|
||||
return Ok(KomorebiLayout::Default(default_layout));
|
||||
}
|
||||
|
||||
// Handle other cases
|
||||
match s.as_str() {
|
||||
"Monocle" => Ok(KomorebiLayout::Monocle),
|
||||
"Floating" => Ok(KomorebiLayout::Floating),
|
||||
"Paused" => Ok(KomorebiLayout::Paused),
|
||||
"Custom" => Ok(KomorebiLayout::Custom),
|
||||
_ => Err(Error::custom(format!("Invalid layout: {s}"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for KomorebiLayout {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
KomorebiLayout::Default(layout) => write!(f, "{layout}"),
|
||||
KomorebiLayout::Monocle => write!(f, "Monocle"),
|
||||
KomorebiLayout::Floating => write!(f, "Floating"),
|
||||
KomorebiLayout::Paused => write!(f, "Paused"),
|
||||
KomorebiLayout::Custom => write!(f, "Custom"),
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
-85
@@ -1,8 +1,9 @@
|
||||
use crate::config::DisplayFormat;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::komorebi::KomorebiLayoutConfig;
|
||||
use color_eyre::eyre;
|
||||
use crate::platform::platform;
|
||||
use crate::widgets::komorebi_config::KomorebiLayout;
|
||||
use crate::widgets::komorebi_config::KomorebiLayoutConfig;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::CornerRadius;
|
||||
use eframe::egui::FontId;
|
||||
@@ -14,70 +15,30 @@ use eframe::egui::StrokeKind;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::vec2;
|
||||
use komorebi_client::SocketMessage;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::de::Error;
|
||||
use serde_json::from_str;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
use komorebi_protocol::message::SocketMessage;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// Komorebi layout kind
|
||||
pub enum KomorebiLayout {
|
||||
/// Predefined layout
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Default"))]
|
||||
Default(komorebi_client::DefaultLayout),
|
||||
/// Monocle mode
|
||||
Monocle,
|
||||
/// Floating layer
|
||||
Floating,
|
||||
/// Paused
|
||||
Paused,
|
||||
/// Custom layout
|
||||
Custom,
|
||||
/// What the layout widget does with a layout kind (the kind itself lives in the core).
|
||||
pub trait KomorebiLayoutExt {
|
||||
fn is_default(&mut self) -> bool;
|
||||
fn on_click(
|
||||
&mut self,
|
||||
show_options: &bool,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: Option<usize>,
|
||||
) -> bool;
|
||||
fn on_click_option(&mut self, monitor_idx: usize, workspace_idx: Option<usize>);
|
||||
fn show_icon(&mut self, is_selected: bool, font_id: FontId, ctx: &Context, ui: &mut Ui);
|
||||
fn show(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
render_config: &mut RenderConfig,
|
||||
layout_config: &KomorebiLayoutConfig,
|
||||
workspace_idx: Option<usize>,
|
||||
);
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for KomorebiLayout {
|
||||
fn deserialize<D>(deserializer: D) -> eyre::Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s: String = String::deserialize(deserializer)?;
|
||||
|
||||
// Attempt to deserialize the string as a DefaultLayout
|
||||
if let Ok(default_layout) = from_str::<komorebi_client::DefaultLayout>(&format!("\"{s}\""))
|
||||
{
|
||||
return Ok(KomorebiLayout::Default(default_layout));
|
||||
}
|
||||
|
||||
// Handle other cases
|
||||
match s.as_str() {
|
||||
"Monocle" => Ok(KomorebiLayout::Monocle),
|
||||
"Floating" => Ok(KomorebiLayout::Floating),
|
||||
"Paused" => Ok(KomorebiLayout::Paused),
|
||||
"Custom" => Ok(KomorebiLayout::Custom),
|
||||
_ => Err(Error::custom(format!("Invalid layout: {s}"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for KomorebiLayout {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
KomorebiLayout::Default(layout) => write!(f, "{layout}"),
|
||||
KomorebiLayout::Monocle => write!(f, "Monocle"),
|
||||
KomorebiLayout::Floating => write!(f, "Floating"),
|
||||
KomorebiLayout::Paused => write!(f, "Paused"),
|
||||
KomorebiLayout::Custom => write!(f, "Custom"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KomorebiLayout {
|
||||
impl KomorebiLayoutExt for KomorebiLayout {
|
||||
fn is_default(&mut self) -> bool {
|
||||
matches!(self, KomorebiLayout::Default(_))
|
||||
}
|
||||
@@ -100,7 +61,7 @@ impl KomorebiLayout {
|
||||
match self {
|
||||
KomorebiLayout::Default(option) => {
|
||||
if let Some(ws_idx) = workspace_idx
|
||||
&& komorebi_client::send_message(&SocketMessage::WorkspaceLayout(
|
||||
&& platform().send_komorebi_message(&SocketMessage::WorkspaceLayout(
|
||||
monitor_idx,
|
||||
ws_idx,
|
||||
*option,
|
||||
@@ -111,7 +72,7 @@ impl KomorebiLayout {
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Monocle => {
|
||||
if komorebi_client::send_batch([
|
||||
if platform().send_komorebi_batch(vec![
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleMonocle,
|
||||
])
|
||||
@@ -121,7 +82,7 @@ impl KomorebiLayout {
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Floating => {
|
||||
if komorebi_client::send_batch([
|
||||
if platform().send_komorebi_batch(vec![
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleTiling,
|
||||
])
|
||||
@@ -131,7 +92,7 @@ impl KomorebiLayout {
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Paused => {
|
||||
if komorebi_client::send_message(&SocketMessage::TogglePause).is_err() {
|
||||
if platform().send_komorebi_message(&SocketMessage::TogglePause).is_err() {
|
||||
tracing::error!("could not send message to komorebi: TogglePause");
|
||||
}
|
||||
}
|
||||
@@ -158,44 +119,44 @@ impl KomorebiLayout {
|
||||
|
||||
match self {
|
||||
KomorebiLayout::Default(layout) => match layout {
|
||||
komorebi_client::DefaultLayout::BSP => {
|
||||
komorebi_layouts::DefaultLayout::BSP => {
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c, c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c + vec2(r / 2.0, 0.0), c + vec2(r / 2.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::Columns => {
|
||||
komorebi_layouts::DefaultLayout::Columns => {
|
||||
painter.line_segment([c - vec2(r / 2.0, r), c + vec2(-r / 2.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(-r / 2.0, r), c + vec2(r / 2.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::Rows => {
|
||||
komorebi_layouts::DefaultLayout::Rows => {
|
||||
painter.line_segment([c - vec2(r, r / 2.0), c + vec2(r, -r / 2.0)], stroke);
|
||||
painter.line_segment([c - vec2(r, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c - vec2(r, -r / 2.0), c + vec2(r, r / 2.0)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::VerticalStack => {
|
||||
komorebi_layouts::DefaultLayout::VerticalStack => {
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c, c + vec2(r, 0.0)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::RightMainVerticalStack => {
|
||||
komorebi_layouts::DefaultLayout::RightMainVerticalStack => {
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(r, 0.0), c], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::HorizontalStack => {
|
||||
komorebi_layouts::DefaultLayout::HorizontalStack => {
|
||||
painter.line_segment([c - vec2(r, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c, c + vec2(0.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::UltrawideVerticalStack => {
|
||||
komorebi_layouts::DefaultLayout::UltrawideVerticalStack => {
|
||||
painter.line_segment([c - vec2(r / 2.0, r), c + vec2(-r / 2.0, r)], stroke);
|
||||
painter.line_segment([c + vec2(r / 2.0, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c - vec2(-r / 2.0, r), c + vec2(r / 2.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::Grid => {
|
||||
komorebi_layouts::DefaultLayout::Grid => {
|
||||
painter.line_segment([c - vec2(r, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
}
|
||||
// TODO: @CtByte can you think of a nice icon to draw here?
|
||||
komorebi_client::DefaultLayout::Scrolling => {
|
||||
komorebi_layouts::DefaultLayout::Scrolling => {
|
||||
painter.line_segment([c - vec2(r / 2.0, r), c + vec2(-r / 2.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(-r / 2.0, r), c + vec2(r / 2.0, r)], stroke);
|
||||
@@ -242,7 +203,7 @@ impl KomorebiLayout {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show(
|
||||
fn show(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
@@ -284,18 +245,18 @@ impl KomorebiLayout {
|
||||
);
|
||||
|
||||
let mut layout_options = layout_config.options.clone().unwrap_or(vec![
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::BSP),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::Columns),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::Rows),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::VerticalStack),
|
||||
KomorebiLayout::Default(komorebi_layouts::DefaultLayout::BSP),
|
||||
KomorebiLayout::Default(komorebi_layouts::DefaultLayout::Columns),
|
||||
KomorebiLayout::Default(komorebi_layouts::DefaultLayout::Rows),
|
||||
KomorebiLayout::Default(komorebi_layouts::DefaultLayout::VerticalStack),
|
||||
KomorebiLayout::Default(
|
||||
komorebi_client::DefaultLayout::RightMainVerticalStack,
|
||||
komorebi_layouts::DefaultLayout::RightMainVerticalStack,
|
||||
),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::HorizontalStack),
|
||||
KomorebiLayout::Default(komorebi_layouts::DefaultLayout::HorizontalStack),
|
||||
KomorebiLayout::Default(
|
||||
komorebi_client::DefaultLayout::UltrawideVerticalStack,
|
||||
komorebi_layouts::DefaultLayout::UltrawideVerticalStack,
|
||||
),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::Grid),
|
||||
KomorebiLayout::Default(komorebi_layouts::DefaultLayout::Grid),
|
||||
//KomorebiLayout::Custom,
|
||||
KomorebiLayout::Monocle,
|
||||
KomorebiLayout::Floating,
|
||||
@@ -1,6 +1,14 @@
|
||||
pub mod applications;
|
||||
pub mod battery;
|
||||
pub mod cpu;
|
||||
pub mod date;
|
||||
pub mod icons;
|
||||
pub mod komorebi_config;
|
||||
pub mod komorebi_layout;
|
||||
pub mod memory;
|
||||
pub mod network_config;
|
||||
pub mod platform_config;
|
||||
pub mod storage;
|
||||
pub mod time;
|
||||
pub mod update;
|
||||
pub mod widget;
|
||||
@@ -0,0 +1,66 @@
|
||||
//! The configuration of the network widget: data only, shared by both bars. The Windows bar
|
||||
//! reads `default_interface_options`; the macOS bar accepts the key and ignores it.
|
||||
|
||||
use crate::config::LabelPrefix;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Network widget configuration
|
||||
pub struct NetworkConfig {
|
||||
/// Enable the Network widget
|
||||
pub enable: bool,
|
||||
/// Show total received and transmitted activity
|
||||
#[serde(alias = "show_total_data_transmitted")]
|
||||
pub show_total_activity: bool,
|
||||
/// Show received and transmitted activity
|
||||
#[serde(alias = "show_network_activity")]
|
||||
pub show_activity: bool,
|
||||
/// Show default interface
|
||||
pub show_default_interface: Option<bool>,
|
||||
/// Default interface options: whether to show the friendly name, IPv4 or IPv6 address
|
||||
pub default_interface_options: Option<DefaultInterfaceConfig>,
|
||||
/// Characters to reserve for received and transmitted activity
|
||||
#[serde(alias = "network_activity_fill_characters")]
|
||||
pub activity_left_padding: Option<usize>,
|
||||
/// Data refresh interval in seconds
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||
pub data_refresh_interval: Option<u64>,
|
||||
/// Display label prefix
|
||||
pub label_prefix: Option<LabelPrefix>,
|
||||
/// Select when the value is over a limit (1MiB is 1048576 bytes (1024*1024))
|
||||
pub auto_select: Option<NetworkSelectConfig>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Network select configuration
|
||||
pub struct NetworkSelectConfig {
|
||||
/// Select the total received data when it's over this value
|
||||
pub total_received_over: Option<u64>,
|
||||
/// Select the total transmitted data when it's over this value
|
||||
pub total_transmitted_over: Option<u64>,
|
||||
/// Select the received data when it's over this value
|
||||
pub received_over: Option<u64>,
|
||||
/// Select the transmitted data when it's over this value
|
||||
pub transmitted_over: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Which IP address to show for the default interface
|
||||
pub enum InterfaceDisplayType {
|
||||
#[default]
|
||||
FriendlyName,
|
||||
Ipv4,
|
||||
Ipv6,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Default interface configuration
|
||||
pub struct DefaultInterfaceConfig {
|
||||
#[serde(default)]
|
||||
pub display_type: InterfaceDisplayType,
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
//! The configuration types of the widgets only the Windows bar runs (keyboard, media, system
|
||||
//! tray). They are data without any platform code, so that `WidgetConfig` can name every widget
|
||||
//! and the schema is one union that each platform's view prunes (see `schema`).
|
||||
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::config::MediaDisplayFormat;
|
||||
use komorebi_config::matching::MatchingStrategy;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Keyboard widget configuration
|
||||
pub struct KeyboardConfig {
|
||||
/// Enable the Input widget
|
||||
pub enable: bool,
|
||||
/// Data refresh interval
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||
pub data_refresh_interval: Option<u64>,
|
||||
/// Display label prefix
|
||||
pub label_prefix: Option<LabelPrefix>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Media widget configuration
|
||||
pub struct MediaConfig {
|
||||
/// Enable the Media widget
|
||||
pub enable: bool,
|
||||
/// Display format of the media widget (defaults to IconAndText)
|
||||
pub display: Option<MediaDisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Position of the overflow toggle button
|
||||
pub enum OverflowTogglePosition {
|
||||
/// Toggle button appears on the left side (before visible icons)
|
||||
Left,
|
||||
/// Toggle button appears on the right side (after visible icons)
|
||||
#[default]
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Where to place a systray button (refresh, info, shortcuts, etc.)
|
||||
pub enum ButtonPosition {
|
||||
/// Show in the main visible area
|
||||
Visible,
|
||||
/// Show in the overflow/hidden section
|
||||
Overflow,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// A field value with an optional matching strategy.
|
||||
///
|
||||
/// A plain string uses exact (case-insensitive) matching.
|
||||
/// An object with `value` and `matching_strategy` uses the specified strategy.
|
||||
pub enum FieldMatch {
|
||||
/// Exact case-insensitive match
|
||||
Exact(String),
|
||||
/// Match using a specific strategy
|
||||
WithStrategy {
|
||||
/// The value to match against
|
||||
value: String,
|
||||
/// How to match (Equals, StartsWith, EndsWith, Contains, Regex, etc.)
|
||||
matching_strategy: MatchingStrategy,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// Rule for matching a systray icon to hide
|
||||
///
|
||||
/// A plain string matches the exe name (backward compatible).
|
||||
/// An object with optional `exe`, `tooltip`, and/or `guid` fields
|
||||
/// uses AND logic: all specified fields must match.
|
||||
/// Each field can be a plain string (exact match) or an object with
|
||||
/// `value` and `matching_strategy` for advanced matching.
|
||||
pub enum HiddenIconRule {
|
||||
/// Match by exe name (case-insensitive, exact)
|
||||
Exe(String),
|
||||
/// Match by one or more properties (all specified fields must match)
|
||||
Match {
|
||||
/// Exe name to match
|
||||
exe: Option<FieldMatch>,
|
||||
/// Tooltip text to match
|
||||
tooltip: Option<FieldMatch>,
|
||||
/// Icon GUID to match (most stable identifier across restarts)
|
||||
guid: Option<FieldMatch>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// System tray widget configuration
|
||||
pub struct SystrayConfig {
|
||||
/// Enable the System Tray widget
|
||||
pub enable: bool,
|
||||
/// A list of rules for icons to hide from the system tray
|
||||
///
|
||||
/// Each entry can be a plain string (matches exe name, case-insensitive)
|
||||
/// or an object with optional `exe`, `tooltip`, and/or `guid` fields
|
||||
/// (all specified fields must match, AND logic, case-insensitive).
|
||||
///
|
||||
/// Run komorebi-bar with RUST_LOG=info to see the properties of all
|
||||
/// systray icons in the log output.
|
||||
pub hidden_icons: Option<Vec<HiddenIconRule>>,
|
||||
/// Position of the overflow toggle button (default: Right)
|
||||
pub overflow_toggle_position: Option<OverflowTogglePosition>,
|
||||
/// Show an info button that opens a floating panel listing all systray icons
|
||||
/// with their exe, tooltip, and GUID. Set to "Visible" to show it in the main
|
||||
/// area, or "Overflow" to show it in the hidden/overflow section.
|
||||
pub info_button: Option<ButtonPosition>,
|
||||
/// Interval in seconds to automatically check for and remove stale icons
|
||||
/// whose owning process has exited. Clamped between 30 and 600 seconds.
|
||||
/// Defaults to 60. Set to 0 to disable.
|
||||
pub stale_icons_check_interval: Option<u64>,
|
||||
/// Show a refresh button that manually triggers stale icon cleanup.
|
||||
/// Set to "Visible" to show it in the main area, or "Overflow" to
|
||||
/// show it in the hidden/overflow section.
|
||||
pub refresh_button: Option<ButtonPosition>,
|
||||
/// Show a button that toggles komorebi-shortcuts (kills the process if
|
||||
/// running, starts it otherwise). Set to "Visible" to show it in the main
|
||||
/// area, or "Overflow" to show it in the hidden/overflow section.
|
||||
pub shortcuts_button: Option<ButtonPosition>,
|
||||
}
|
||||
+5
-9
@@ -1,4 +1,4 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::alignment::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
@@ -11,7 +11,8 @@ use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::process::Command;
|
||||
use crate::platform::SystemTool;
|
||||
use crate::platform::platform;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Disks;
|
||||
@@ -190,13 +191,8 @@ impl BarWidget for Storage {
|
||||
if SelectableFrame::new_auto(output.selected, auto_focus_fill)
|
||||
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
|
||||
.clicked()
|
||||
&& let Err(error) = Command::new("cmd.exe")
|
||||
.args([
|
||||
"/C",
|
||||
"explorer.exe",
|
||||
output.label.split(' ').collect::<Vec<&str>>()[0],
|
||||
])
|
||||
.spawn()
|
||||
&& let Err(error) = platform()
|
||||
.open_system_tool(SystemTool::StorageLocation(output.label.clone()))
|
||||
{
|
||||
eprintln!("{error}")
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::alignment::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
@@ -1,7 +1,132 @@
|
||||
use crate::render::RenderConfig;
|
||||
use crate::widgets::applications::ApplicationsConfig;
|
||||
use crate::widgets::battery::BatteryConfig;
|
||||
use crate::widgets::cpu::CpuConfig;
|
||||
use crate::widgets::date::DateConfig;
|
||||
use crate::widgets::komorebi_config::KomorebiConfig;
|
||||
use crate::widgets::memory::MemoryConfig;
|
||||
use crate::widgets::network_config::NetworkConfig;
|
||||
use crate::widgets::platform_config::KeyboardConfig;
|
||||
use crate::widgets::platform_config::MediaConfig;
|
||||
use crate::widgets::platform_config::SystrayConfig;
|
||||
use crate::widgets::storage::StorageConfig;
|
||||
use crate::widgets::time::TimeConfig;
|
||||
use crate::widgets::update::UpdateConfig;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::Ui;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
pub trait BarWidget {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig);
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Widget configuration
|
||||
pub enum WidgetConfig {
|
||||
/// Applications widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Applications"))]
|
||||
Applications(ApplicationsConfig),
|
||||
/// Battery widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Battery"))]
|
||||
Battery(BatteryConfig),
|
||||
/// CPU widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Cpu"))]
|
||||
Cpu(CpuConfig),
|
||||
/// Date widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Date"))]
|
||||
Date(DateConfig),
|
||||
/// Keyboard widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Keyboard"))]
|
||||
Keyboard(KeyboardConfig),
|
||||
/// Komorebi widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Komorebi"))]
|
||||
Komorebi(KomorebiConfig),
|
||||
/// Media widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Media"))]
|
||||
Media(MediaConfig),
|
||||
/// Memory widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Memory"))]
|
||||
Memory(MemoryConfig),
|
||||
/// Network widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Network"))]
|
||||
Network(NetworkConfig),
|
||||
/// Storage widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Storage"))]
|
||||
Storage(StorageConfig),
|
||||
/// System Tray widget configuration (Windows only)
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Systray"))]
|
||||
Systray(SystrayConfig),
|
||||
/// Time widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Time"))]
|
||||
Time(TimeConfig),
|
||||
/// Update widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Update"))]
|
||||
Update(UpdateConfig),
|
||||
}
|
||||
|
||||
impl WidgetConfig {
|
||||
/// The widget a configuration key names, if the platform this bar runs on has it. The
|
||||
/// keyboard, media and system tray widgets exist on Windows only: elsewhere the key is
|
||||
/// accepted and skipped (see [`WidgetConfig::unsupported`]).
|
||||
#[must_use]
|
||||
pub const fn supported(&self) -> bool {
|
||||
!matches!(
|
||||
self,
|
||||
WidgetConfig::Keyboard(_) | WidgetConfig::Media(_) | WidgetConfig::Systray(_)
|
||||
) || cfg!(target_os = "windows")
|
||||
}
|
||||
|
||||
/// The name of this widget when the platform cannot run it.
|
||||
#[must_use]
|
||||
pub const fn unsupported(&self) -> Option<&'static str> {
|
||||
if self.supported() {
|
||||
return None;
|
||||
}
|
||||
|
||||
match self {
|
||||
WidgetConfig::Keyboard(_) => Some("Keyboard"),
|
||||
WidgetConfig::Media(_) => Some("Media"),
|
||||
WidgetConfig::Systray(_) => Some("Systray"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the widget is enabled and can run on this platform.
|
||||
#[must_use]
|
||||
pub fn enabled(&self) -> bool {
|
||||
self.supported()
|
||||
&& match self {
|
||||
WidgetConfig::Applications(config) => config.enable,
|
||||
WidgetConfig::Battery(config) => config.enable,
|
||||
WidgetConfig::Cpu(config) => config.enable,
|
||||
WidgetConfig::Date(config) => config.enable,
|
||||
WidgetConfig::Keyboard(config) => config.enable,
|
||||
WidgetConfig::Komorebi(config) => {
|
||||
config.workspaces.as_ref().is_some_and(|w| w.enable)
|
||||
|| config.layout.as_ref().is_some_and(|w| w.enable)
|
||||
|| config.focused_container.as_ref().is_some_and(|w| w.enable)
|
||||
|| config
|
||||
.configuration_switcher
|
||||
.as_ref()
|
||||
.is_some_and(|w| w.enable)
|
||||
}
|
||||
WidgetConfig::Media(config) => config.enable,
|
||||
WidgetConfig::Memory(config) => config.enable,
|
||||
WidgetConfig::Network(config) => config.enable,
|
||||
WidgetConfig::Storage(config) => config.enable,
|
||||
WidgetConfig::Systray(config) => config.enable,
|
||||
WidgetConfig::Time(config) => config.enable,
|
||||
WidgetConfig::Update(config) => config.enable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Logs a warning for every widget in `widgets` that this platform cannot run; they are accepted
|
||||
/// in the configuration and skipped.
|
||||
pub fn warn_unsupported<'a>(widgets: impl IntoIterator<Item = &'a WidgetConfig>) {
|
||||
for name in widgets.into_iter().filter_map(WidgetConfig::unsupported) {
|
||||
tracing::warn!("the {name} widget is not supported on this platform and is skipped");
|
||||
}
|
||||
}
|
||||
@@ -76,3 +76,73 @@ fn the_checked_in_bar_schemas_are_json_schemas_of_komobar_config() {
|
||||
assert!(text.ends_with("}\n"), "{}", pin.file);
|
||||
}
|
||||
}
|
||||
|
||||
mod views {
|
||||
use komorebi_bar_core::schema::SchemaPlatform;
|
||||
use komorebi_bar_core::schema::view_text;
|
||||
|
||||
fn text(file: &str) -> String {
|
||||
String::from_utf8(super::read(file)).expect("utf-8")
|
||||
}
|
||||
|
||||
/// The Windows file is the union; its Windows view is itself.
|
||||
#[test]
|
||||
fn the_windows_view_of_the_union_is_the_windows_file() {
|
||||
let union = serde_json::from_str(&text("schema.bar.json")).expect("json");
|
||||
assert!(view_text(union, SchemaPlatform::Windows) == text("schema.bar.json"));
|
||||
}
|
||||
|
||||
/// The macOS view of the union is the macOS file, byte for byte.
|
||||
#[test]
|
||||
fn the_macos_view_of_the_union_is_the_macos_file() {
|
||||
let union = serde_json::from_str(&text("schema.bar.json")).expect("json");
|
||||
let view = view_text(union, SchemaPlatform::MacOs);
|
||||
let file = text("komorebi-for-mac/schema.bar.json");
|
||||
if view != file {
|
||||
let first = view.lines().zip(file.lines()).position(|(a, b)| a != b);
|
||||
panic!(
|
||||
"the views differ, first at line {first:?} (view {} lines, file {})",
|
||||
view.lines().count(),
|
||||
file.lines().count()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A view applied to its own output changes nothing, so a bar can print its generated
|
||||
/// schema through it.
|
||||
#[test]
|
||||
fn a_view_is_idempotent() {
|
||||
let union = serde_json::from_str(&text("schema.bar.json")).expect("json");
|
||||
let once = view_text(union, SchemaPlatform::MacOs);
|
||||
let again = view_text(
|
||||
serde_json::from_str(&once).expect("json"),
|
||||
SchemaPlatform::MacOs,
|
||||
);
|
||||
assert!(once == again);
|
||||
}
|
||||
}
|
||||
|
||||
mod generated {
|
||||
use komorebi_bar_core::config::KomobarConfig;
|
||||
use komorebi_bar_core::schema::SchemaPlatform;
|
||||
use komorebi_bar_core::schema::generated_text;
|
||||
|
||||
/// The schema the core generates from its own types, through the macOS view, is the macOS
|
||||
/// file. (Not tested for Windows: three descriptions in komorebi-protocol and the themes
|
||||
/// crate read differently when compiled for Windows, which a Linux test host cannot do; the
|
||||
/// out-of-tree harness covers it.)
|
||||
#[test]
|
||||
fn the_generated_macos_view_is_the_macos_file() {
|
||||
let file =
|
||||
String::from_utf8(super::read("komorebi-for-mac/schema.bar.json")).expect("utf-8");
|
||||
let text = generated_text::<KomobarConfig>(SchemaPlatform::MacOs);
|
||||
if text != file {
|
||||
let first = text.lines().zip(file.lines()).position(|(a, b)| a != b);
|
||||
panic!(
|
||||
"differs, first at line {first:?} ({} lines, file {})",
|
||||
text.lines().count(),
|
||||
file.lines().count()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -617,7 +617,7 @@ impl StaticConfig {
|
||||
/// # Errors
|
||||
///
|
||||
/// The file cannot be read, or it is not a configuration.
|
||||
pub fn read(path: &PathBuf) -> color_eyre::Result<Self> {
|
||||
pub fn read(path: &std::path::Path) -> color_eyre::Result<Self> {
|
||||
let content = std::fs::read_to_string(path)?;
|
||||
serde_json::from_str(&content).map_err(Into::into)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "komorebi-settings"
|
||||
version = "0.1.42"
|
||||
edition = "2024"
|
||||
description = "The settings every komorebi daemon reads while it runs: one immutable snapshot, replaced as a whole, instead of process-wide statics"
|
||||
|
||||
[dependencies]
|
||||
komorebi-config = { path = "../komorebi-config", default-features = false }
|
||||
komorebi-layouts = { path = "../../komorebi-layouts" }
|
||||
komorebi-protocol = { path = "../komorebi-protocol", default-features = false }
|
||||
komorebi-themes = { path = "../../komorebi-themes", default-features = false }
|
||||
|
||||
parking_lot = "0.12"
|
||||
@@ -0,0 +1,263 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use crate::Settings;
|
||||
|
||||
/// The current [`Settings`] of a daemon.
|
||||
///
|
||||
/// Reading costs one uncontended read lock and an `Arc` clone; the lock is held for the clone
|
||||
/// only, never while the caller uses the snapshot. The representation (an `RwLock<Arc<_>>`) is
|
||||
/// private: it can become an `ArcSwap` later without touching a caller.
|
||||
pub struct Handle<P> {
|
||||
current: RwLock<Arc<Settings<P>>>,
|
||||
// Serialises writers. Readers never take it.
|
||||
writers: Mutex<()>,
|
||||
}
|
||||
|
||||
impl<P> Handle<P> {
|
||||
pub fn new(settings: Settings<P>) -> Self {
|
||||
Self {
|
||||
current: RwLock::new(Arc::new(settings)),
|
||||
writers: Mutex::new(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The settings as they are now. Take it once per unit of work (one border render, one
|
||||
/// layout pass, one rule check) and use it for all of it.
|
||||
pub fn snapshot(&self) -> Arc<Settings<P>> {
|
||||
Arc::clone(&self.current.read())
|
||||
}
|
||||
|
||||
/// Publish a whole new value. Readers that already hold a snapshot keep the old one.
|
||||
pub fn replace(&self, settings: Settings<P>) {
|
||||
let _writer = self.writers.lock();
|
||||
*self.current.write() = Arc::new(settings);
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Clone> Handle<P> {
|
||||
/// Copy the current value, let `edit` change the copy and publish it once.
|
||||
///
|
||||
/// Writers are serialised for the whole call, so an `update` never overwrites a change made by
|
||||
/// another `update` that ran at the same time. If `edit` panics nothing is published.
|
||||
pub fn update<R>(&self, edit: impl FnOnce(&mut Settings<P>) -> R) -> R {
|
||||
let _writer = self.writers.lock();
|
||||
let mut copy = (**self.current.read()).clone();
|
||||
let result = edit(&mut copy);
|
||||
*self.current.write() = Arc::new(copy);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Clone + 'static> Handle<P> {
|
||||
/// Set one field now and put its previous value back when the guard is dropped.
|
||||
///
|
||||
/// The previous value is restored only if the field still holds the value this call set. If a
|
||||
/// reload or a command changed the field meanwhile, that change wins. (The statics did the
|
||||
/// opposite: the saved value overwrote whatever had been written in between.)
|
||||
pub fn scoped<T>(&self, field: fn(&mut Settings<P>) -> &mut T, value: T) -> Scoped<'_, P, T>
|
||||
where
|
||||
T: Clone + PartialEq,
|
||||
{
|
||||
let previous = self.update(|settings| std::mem::replace(field(settings), value.clone()));
|
||||
|
||||
Scoped {
|
||||
handle: self,
|
||||
field,
|
||||
set: value,
|
||||
previous: Some(previous),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The guard returned by [`Handle::scoped`].
|
||||
#[must_use = "the previous value is put back when the guard is dropped"]
|
||||
pub struct Scoped<'a, P: Clone + 'static, T: Clone + PartialEq> {
|
||||
handle: &'a Handle<P>,
|
||||
field: fn(&mut Settings<P>) -> &mut T,
|
||||
set: T,
|
||||
previous: Option<T>,
|
||||
}
|
||||
|
||||
impl<P: Clone + 'static, T: Clone + PartialEq> Drop for Scoped<'_, P, T> {
|
||||
fn drop(&mut self) {
|
||||
if let Some(previous) = self.previous.take() {
|
||||
let field = self.field;
|
||||
let set = &self.set;
|
||||
self.handle.update(|settings| {
|
||||
let slot = field(settings);
|
||||
if slot == set {
|
||||
*slot = previous;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::shared::PlatformDefaults;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Default)]
|
||||
struct Platform {
|
||||
hiding: u8,
|
||||
flag: bool,
|
||||
}
|
||||
|
||||
fn handle() -> Handle<Platform> {
|
||||
Handle::new(Settings::new(
|
||||
crate::Shared::defaults_for(PlatformDefaults::KDE),
|
||||
Platform::default(),
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_snapshot_does_not_change_when_the_handle_does() {
|
||||
let handle = handle();
|
||||
let before = handle.snapshot();
|
||||
|
||||
handle.update(|s| s.shared.border.width = 99);
|
||||
|
||||
assert_eq!(before.shared.border.width, 10);
|
||||
assert_eq!(handle.snapshot().shared.border.width, 99);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_publishes_the_whole_value() {
|
||||
let handle = handle();
|
||||
let mut next = (*handle.snapshot()).clone();
|
||||
next.platform.hiding = 3;
|
||||
next.shared.border.enabled = false;
|
||||
|
||||
handle.replace(next);
|
||||
|
||||
let now = handle.snapshot();
|
||||
assert_eq!(now.platform.hiding, 3);
|
||||
assert!(!now.shared.border.enabled);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_panicking_edit_publishes_nothing() {
|
||||
let handle = handle();
|
||||
|
||||
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
handle.update(|s| {
|
||||
s.shared.border.width = 77;
|
||||
panic!("edit failed");
|
||||
});
|
||||
}));
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_eq!(handle.snapshot().shared.border.width, 10);
|
||||
// and the writer lock is free again
|
||||
handle.update(|s| s.shared.border.width = 5);
|
||||
assert_eq!(handle.snapshot().shared.border.width, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concurrent_updates_lose_nothing() {
|
||||
let handle = Arc::new(handle());
|
||||
let threads: Vec<_> = (0..8)
|
||||
.map(|_| {
|
||||
let handle = Arc::clone(&handle);
|
||||
std::thread::spawn(move || {
|
||||
for _ in 0..500 {
|
||||
handle.update(|s| s.shared.border.width += 1);
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
for thread in threads {
|
||||
thread.join().unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(handle.snapshot().shared.border.width, 10 + 8 * 500);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn readers_never_see_half_an_update() {
|
||||
// The writer keeps width and offset equal; a torn read would show them different.
|
||||
let handle = Arc::new(handle());
|
||||
handle.update(|s| {
|
||||
s.shared.border.width = 0;
|
||||
s.shared.border.offset = 0;
|
||||
});
|
||||
let stop = Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
|
||||
let writer = {
|
||||
let (handle, stop) = (Arc::clone(&handle), Arc::clone(&stop));
|
||||
std::thread::spawn(move || {
|
||||
let mut n = 0;
|
||||
while !stop.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
n += 1;
|
||||
handle.update(|s| {
|
||||
s.shared.border.width = n;
|
||||
s.shared.border.offset = n;
|
||||
});
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
for _ in 0..50_000 {
|
||||
let seen = handle.snapshot();
|
||||
assert_eq!(seen.shared.border.width, seen.shared.border.offset);
|
||||
}
|
||||
stop.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
writer.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scoped_puts_the_value_back() {
|
||||
let handle = handle();
|
||||
|
||||
{
|
||||
let _guard = handle.scoped(|s| &mut s.platform.hiding, 9);
|
||||
assert_eq!(handle.snapshot().platform.hiding, 9);
|
||||
}
|
||||
|
||||
assert_eq!(handle.snapshot().platform.hiding, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scoped_leaves_a_change_made_meanwhile() {
|
||||
let handle = handle();
|
||||
|
||||
{
|
||||
let _guard = handle.scoped(|s| &mut s.platform.hiding, 9);
|
||||
// a reload writes the field while the override is held
|
||||
handle.update(|s| s.platform.hiding = 4);
|
||||
}
|
||||
|
||||
assert_eq!(handle.snapshot().platform.hiding, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scoped_touches_only_its_own_field() {
|
||||
let handle = handle();
|
||||
|
||||
{
|
||||
let _guard = handle.scoped(|s| &mut s.platform.flag, true);
|
||||
handle.update(|s| s.shared.border.width = 31);
|
||||
}
|
||||
|
||||
let now = handle.snapshot();
|
||||
assert!(!now.platform.flag);
|
||||
assert_eq!(now.shared.border.width, 31);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_scopes_unwind_in_order() {
|
||||
let handle = handle();
|
||||
|
||||
let outer = handle.scoped(|s| &mut s.platform.hiding, 1);
|
||||
let inner = handle.scoped(|s| &mut s.platform.hiding, 2);
|
||||
assert_eq!(handle.snapshot().platform.hiding, 2);
|
||||
drop(inner);
|
||||
assert_eq!(handle.snapshot().platform.hiding, 1);
|
||||
drop(outer);
|
||||
assert_eq!(handle.snapshot().platform.hiding, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//! The settings a daemon reads while it runs.
|
||||
//!
|
||||
//! Today each daemon keeps them in dozens of process-wide statics that `apply_globals` and the
|
||||
//! `SocketMessage` handlers write one at a time while the border, animator and reaper threads
|
||||
//! read them (see `docs/dev/settings.md`). This crate holds the replacement and nothing else: no
|
||||
//! daemon uses it yet.
|
||||
//!
|
||||
//! * [`Settings`] is a value: a [`Shared`] part that is the same struct on every platform and a
|
||||
//! platform part `P` that each daemon defines for its own subsystems.
|
||||
//! * [`Handle`] holds the current value. A reader takes a [`Handle::snapshot`] once per unit of
|
||||
//! work and sees one consistent configuration for all of it. A writer uses [`Handle::update`],
|
||||
//! which serialises writers, so two writers never lose each other's change, and publishes the
|
||||
//! result once.
|
||||
//! * [`Handle::scoped`] replaces the "store a value, do work, store the old value back" pattern
|
||||
//! without clobbering a change made in between.
|
||||
#![warn(clippy::all)]
|
||||
#![allow(clippy::missing_errors_doc, clippy::use_self, clippy::doc_markdown)]
|
||||
|
||||
mod handle;
|
||||
pub mod shared;
|
||||
|
||||
pub use handle::Handle;
|
||||
pub use handle::Scoped;
|
||||
pub use shared::Shared;
|
||||
|
||||
/// Every setting of one running daemon.
|
||||
///
|
||||
/// `P` is the platform part: a plain type the daemon defines (the Windows stackbar and hiding
|
||||
/// behaviour, the macOS tabbed-application list, ...). Shared code never looks inside it, so it is
|
||||
/// a type parameter and not a trait; it needs to be `Clone` so that an update can copy the value.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Settings<P> {
|
||||
pub shared: Shared,
|
||||
pub platform: P,
|
||||
}
|
||||
|
||||
impl<P> Settings<P> {
|
||||
pub fn new(shared: Shared, platform: P) -> Self {
|
||||
Self { shared, platform }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,648 @@
|
||||
//! The part of the settings that is the same struct on every platform.
|
||||
//!
|
||||
//! Every field here has a counterpart static in each daemon (`docs/dev/settings.md`, section 2.1),
|
||||
//! and [`SharedDelta::apply`] reproduces what `StaticConfig::apply_globals` does with it, including
|
||||
//! which absent keys keep the old value and which are reset.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use komorebi_config::animation::PerAnimationPrefixConfig;
|
||||
use komorebi_config::aspect_ratio::AspectRatio;
|
||||
use komorebi_config::aspect_ratio::PredefinedAspectRatio;
|
||||
use komorebi_layouts::DefaultLayout;
|
||||
use komorebi_layouts::LayoutDefaultEntry;
|
||||
use komorebi_protocol::animation::AnimationStyle;
|
||||
use komorebi_protocol::animation::prefix::AnimationPrefix;
|
||||
use komorebi_themes::colour::Colour;
|
||||
use komorebi_themes::colour::Rgb;
|
||||
|
||||
/// What `ANIMATION_FPS` becomes when `animation` is configured without `fps`
|
||||
/// (`DEFAULT_ANIMATION_FPS` in each daemon).
|
||||
pub const DEFAULT_ANIMATION_FPS: u64 = 60;
|
||||
/// `DEFAULT_ANIMATION_ENABLED`, `DEFAULT_ANIMATION_STYLE` and `DEFAULT_ANIMATION_DURATION`.
|
||||
pub const DEFAULT_ANIMATION_ENABLED: bool = false;
|
||||
pub const DEFAULT_ANIMATION_STYLE: AnimationStyle = AnimationStyle::Linear;
|
||||
pub const DEFAULT_ANIMATION_DURATION: u64 = 250;
|
||||
/// `DEFAULT_RESIZE_DELTA` and `DEFAULT_MOUSE_FOLLOWS_FOCUS` (equal on all three platforms).
|
||||
pub const DEFAULT_RESIZE_DELTA: i32 = 50;
|
||||
pub const DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = true;
|
||||
|
||||
/// The defaults a daemon starts with. They differ per platform today (border width 8 / 10 / 10,
|
||||
/// padding 10 / 5 / 5, ...) and this step does not change any of them.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct PlatformDefaults {
|
||||
pub border_width: i32,
|
||||
pub border_offset: i32,
|
||||
pub border_radius: i32,
|
||||
pub container_padding: i32,
|
||||
pub workspace_padding: i32,
|
||||
}
|
||||
|
||||
impl PlatformDefaults {
|
||||
/// `komorebi/src/border_manager/mod.rs` and `komorebi/src/lib.rs`. Windows has no border
|
||||
/// radius setting; the unused value is the one the other platforms use.
|
||||
pub const WINDOWS: Self = Self {
|
||||
border_width: 8,
|
||||
border_offset: -1,
|
||||
border_radius: 10,
|
||||
container_padding: 10,
|
||||
workspace_padding: 10,
|
||||
};
|
||||
/// `komorebi-for-kde/komorebi/src/border_manager/mod.rs` and `.../lib.rs`
|
||||
pub const KDE: Self = Self {
|
||||
border_width: 10,
|
||||
border_offset: 0,
|
||||
border_radius: 10,
|
||||
container_padding: 5,
|
||||
workspace_padding: 5,
|
||||
};
|
||||
/// `komorebi-for-mac/komorebi/src/border_manager/mod.rs` and `.../lib.rs`
|
||||
pub const MACOS: Self = Self {
|
||||
border_width: 10,
|
||||
border_offset: 0,
|
||||
border_radius: 10,
|
||||
container_padding: 5,
|
||||
workspace_padding: 5,
|
||||
};
|
||||
}
|
||||
|
||||
/// Colours are `u32` exactly as the border statics hold them (`u32::from(Colour)`).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct BorderColours {
|
||||
pub single: u32,
|
||||
pub stack: u32,
|
||||
pub monocle: u32,
|
||||
pub floating: u32,
|
||||
pub unfocused: u32,
|
||||
pub unfocused_locked: u32,
|
||||
}
|
||||
|
||||
/// Whether and how the borders are drawn; the colours are the same on all three platforms.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Border {
|
||||
pub enabled: bool,
|
||||
pub width: i32,
|
||||
pub offset: i32,
|
||||
/// Used by KDE and macOS; Windows keeps it but never reads it.
|
||||
pub radius: i32,
|
||||
pub colours: BorderColours,
|
||||
}
|
||||
|
||||
/// The animation settings: a global value for each of enabled, style and duration, and a map of
|
||||
/// per-prefix values that wins over the global one.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Animation {
|
||||
pub enabled: bool,
|
||||
pub style: AnimationStyle,
|
||||
pub duration: u64,
|
||||
pub fps: u64,
|
||||
pub enabled_per_animation: HashMap<AnimationPrefix, bool>,
|
||||
pub style_per_animation: HashMap<AnimationPrefix, AnimationStyle>,
|
||||
pub duration_per_animation: HashMap<AnimationPrefix, u64>,
|
||||
}
|
||||
|
||||
/// How a window is moved for one kind of animation: the three values `motion_for` reads today as
|
||||
/// three separate statics.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Motion {
|
||||
pub duration_ms: u64,
|
||||
pub style: AnimationStyle,
|
||||
}
|
||||
|
||||
impl Animation {
|
||||
/// `None` if `prefix` is not animated, else how. The same rule as `motion_for` (without the
|
||||
/// suspension counter, which is runtime state and stays with the animation module), now read
|
||||
/// from one snapshot.
|
||||
pub fn motion_for(&self, prefix: AnimationPrefix) -> Option<Motion> {
|
||||
let enabled = self
|
||||
.enabled_per_animation
|
||||
.get(&prefix)
|
||||
.copied()
|
||||
.unwrap_or(self.enabled);
|
||||
|
||||
enabled.then(|| Motion {
|
||||
duration_ms: self
|
||||
.duration_per_animation
|
||||
.get(&prefix)
|
||||
.copied()
|
||||
.unwrap_or(self.duration),
|
||||
style: self
|
||||
.style_per_animation
|
||||
.get(&prefix)
|
||||
.copied()
|
||||
.unwrap_or(self.style),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Defaults {
|
||||
pub container_padding: i32,
|
||||
pub workspace_padding: i32,
|
||||
pub resize_delta: i32,
|
||||
pub mouse_follows_focus: bool,
|
||||
}
|
||||
|
||||
/// `transparency` and `transparency_alpha` (Windows and KDE; macOS never reads them).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Transparency {
|
||||
pub enabled: bool,
|
||||
pub alpha: u8,
|
||||
}
|
||||
|
||||
/// Every setting that is not tied to one platform.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Shared {
|
||||
pub border: Border,
|
||||
pub animation: Animation,
|
||||
pub defaults: Defaults,
|
||||
pub transparency: Transparency,
|
||||
pub floating_window_aspect_ratio: AspectRatio,
|
||||
pub layout_defaults: HashMap<DefaultLayout, LayoutDefaultEntry>,
|
||||
pub display_index_preferences: HashMap<usize, String>,
|
||||
}
|
||||
|
||||
impl Shared {
|
||||
/// The values the statics hold before any configuration is read.
|
||||
pub fn defaults_for(defaults: PlatformDefaults) -> Self {
|
||||
Self {
|
||||
border: Border {
|
||||
enabled: true,
|
||||
width: defaults.border_width,
|
||||
offset: defaults.border_offset,
|
||||
radius: defaults.border_radius,
|
||||
colours: BorderColours {
|
||||
single: rgb(66, 165, 245),
|
||||
stack: rgb(0, 165, 66),
|
||||
monocle: rgb(255, 51, 153),
|
||||
floating: rgb(245, 245, 165),
|
||||
unfocused: rgb(128, 128, 128),
|
||||
unfocused_locked: rgb(158, 8, 8),
|
||||
},
|
||||
},
|
||||
animation: Animation {
|
||||
enabled: DEFAULT_ANIMATION_ENABLED,
|
||||
style: DEFAULT_ANIMATION_STYLE,
|
||||
duration: DEFAULT_ANIMATION_DURATION,
|
||||
fps: DEFAULT_ANIMATION_FPS,
|
||||
enabled_per_animation: HashMap::new(),
|
||||
style_per_animation: HashMap::new(),
|
||||
duration_per_animation: HashMap::new(),
|
||||
},
|
||||
defaults: Defaults {
|
||||
container_padding: defaults.container_padding,
|
||||
workspace_padding: defaults.workspace_padding,
|
||||
resize_delta: DEFAULT_RESIZE_DELTA,
|
||||
mouse_follows_focus: DEFAULT_MOUSE_FOLLOWS_FOCUS,
|
||||
},
|
||||
transparency: Transparency {
|
||||
enabled: false,
|
||||
alpha: 200,
|
||||
},
|
||||
// The static starts at Widescreen; a load without the key writes Standard
|
||||
// (`unwrap_or`), see `SharedDelta::floating_window_aspect_ratio`.
|
||||
floating_window_aspect_ratio: AspectRatio::Predefined(
|
||||
PredefinedAspectRatio::Widescreen,
|
||||
),
|
||||
layout_defaults: HashMap::new(),
|
||||
display_index_preferences: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rgb(r: u32, g: u32, b: u32) -> u32 {
|
||||
u32::from(Colour::Rgb(Rgb::new(r, g, b)))
|
||||
}
|
||||
|
||||
/// The colours a configuration file or theme names; a missing one keeps the current value.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub struct BorderColoursDelta {
|
||||
pub single: Option<u32>,
|
||||
pub stack: Option<u32>,
|
||||
pub monocle: Option<u32>,
|
||||
pub floating: Option<u32>,
|
||||
pub unfocused: Option<u32>,
|
||||
pub unfocused_locked: Option<u32>,
|
||||
}
|
||||
|
||||
/// The animation block of a configuration file (`enabled` is required in the file, the rest is
|
||||
/// optional).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct AnimationDelta {
|
||||
pub enabled: PerAnimationPrefixConfig<bool>,
|
||||
pub style: Option<PerAnimationPrefixConfig<AnimationStyle>>,
|
||||
pub duration: Option<PerAnimationPrefixConfig<u64>>,
|
||||
pub fps: Option<u64>,
|
||||
}
|
||||
|
||||
/// What one configuration load says about the [`Shared`] settings. `None` means "the key is not in
|
||||
/// the file", and [`apply`](Self::apply) treats each `None` exactly as
|
||||
/// `StaticConfig::apply_globals` does.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct SharedDelta {
|
||||
pub border: Option<bool>,
|
||||
pub border_width: Option<i32>,
|
||||
pub border_offset: Option<i32>,
|
||||
pub border_radius: Option<i32>,
|
||||
pub border_colours: Option<BorderColoursDelta>,
|
||||
pub animation: Option<AnimationDelta>,
|
||||
pub default_container_padding: Option<i32>,
|
||||
pub default_workspace_padding: Option<i32>,
|
||||
pub transparency: Option<bool>,
|
||||
pub transparency_alpha: Option<u8>,
|
||||
pub floating_window_aspect_ratio: Option<AspectRatio>,
|
||||
pub layout_defaults: Option<HashMap<DefaultLayout, LayoutDefaultEntry>>,
|
||||
pub display_index_preferences: Option<HashMap<usize, String>>,
|
||||
}
|
||||
|
||||
impl SharedDelta {
|
||||
/// Merge this load into `shared`.
|
||||
///
|
||||
/// * Keeps the old value when the key is absent: the border (enabled, width, offset, radius,
|
||||
/// each colour), both paddings, transparency and its alpha, the display index preferences,
|
||||
/// and the animation block as a whole.
|
||||
/// * Resets when the key is absent: `floating_window_aspect_ratio` (to Standard, not to the
|
||||
/// initial Widescreen), `layout_defaults` (cleared), and, inside a present animation block,
|
||||
/// `fps` (to 60).
|
||||
/// * A global animation value clears that setting's per-prefix map; a per-prefix map replaces
|
||||
/// the whole map and leaves the global value alone.
|
||||
pub fn apply(&self, shared: &mut Shared) {
|
||||
shared.floating_window_aspect_ratio = self
|
||||
.floating_window_aspect_ratio
|
||||
.unwrap_or(AspectRatio::Predefined(PredefinedAspectRatio::Standard));
|
||||
|
||||
if let Some(preferences) = &self.display_index_preferences {
|
||||
shared.display_index_preferences.clone_from(preferences);
|
||||
}
|
||||
|
||||
if let Some(animation) = &self.animation {
|
||||
let target = &mut shared.animation;
|
||||
|
||||
match &animation.enabled {
|
||||
PerAnimationPrefixConfig::Prefix(enabled) => {
|
||||
target.enabled_per_animation.clone_from(enabled);
|
||||
}
|
||||
PerAnimationPrefixConfig::Global(enabled) => {
|
||||
target.enabled = *enabled;
|
||||
target.enabled_per_animation.clear();
|
||||
}
|
||||
}
|
||||
|
||||
match &animation.style {
|
||||
Some(PerAnimationPrefixConfig::Prefix(style)) => {
|
||||
target.style_per_animation.clone_from(style);
|
||||
}
|
||||
Some(PerAnimationPrefixConfig::Global(style)) => {
|
||||
target.style = *style;
|
||||
target.style_per_animation.clear();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
match &animation.duration {
|
||||
Some(PerAnimationPrefixConfig::Prefix(duration)) => {
|
||||
target.duration_per_animation.clone_from(duration);
|
||||
}
|
||||
Some(PerAnimationPrefixConfig::Global(duration)) => {
|
||||
target.duration = *duration;
|
||||
target.duration_per_animation.clear();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
target.fps = animation.fps.unwrap_or(DEFAULT_ANIMATION_FPS);
|
||||
}
|
||||
|
||||
if let Some(container) = self.default_container_padding {
|
||||
shared.defaults.container_padding = container;
|
||||
}
|
||||
|
||||
if let Some(workspace) = self.default_workspace_padding {
|
||||
shared.defaults.workspace_padding = workspace;
|
||||
}
|
||||
|
||||
match &self.layout_defaults {
|
||||
Some(defaults) => shared.layout_defaults.clone_from(defaults),
|
||||
None => shared.layout_defaults.clear(),
|
||||
}
|
||||
|
||||
if let Some(width) = self.border_width {
|
||||
shared.border.width = width;
|
||||
}
|
||||
|
||||
if let Some(offset) = self.border_offset {
|
||||
shared.border.offset = offset;
|
||||
}
|
||||
|
||||
if let Some(radius) = self.border_radius {
|
||||
shared.border.radius = radius;
|
||||
}
|
||||
|
||||
if let Some(enabled) = self.border {
|
||||
shared.border.enabled = enabled;
|
||||
}
|
||||
|
||||
if let Some(colours) = &self.border_colours {
|
||||
let target = &mut shared.border.colours;
|
||||
if let Some(colour) = colours.single {
|
||||
target.single = colour;
|
||||
}
|
||||
if let Some(colour) = colours.stack {
|
||||
target.stack = colour;
|
||||
}
|
||||
if let Some(colour) = colours.monocle {
|
||||
target.monocle = colour;
|
||||
}
|
||||
if let Some(colour) = colours.floating {
|
||||
target.floating = colour;
|
||||
}
|
||||
if let Some(colour) = colours.unfocused {
|
||||
target.unfocused = colour;
|
||||
}
|
||||
if let Some(colour) = colours.unfocused_locked {
|
||||
target.unfocused_locked = colour;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(enabled) = self.transparency {
|
||||
shared.transparency.enabled = enabled;
|
||||
}
|
||||
|
||||
if let Some(alpha) = self.transparency_alpha {
|
||||
shared.transparency.alpha = alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn shared() -> Shared {
|
||||
Shared::defaults_for(PlatformDefaults::KDE)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_platform_defaults_are_the_ones_the_statics_start_with() {
|
||||
let windows = Shared::defaults_for(PlatformDefaults::WINDOWS);
|
||||
assert_eq!(
|
||||
(windows.border.width, windows.border.offset),
|
||||
(8, -1),
|
||||
"komorebi/src/border_manager/mod.rs"
|
||||
);
|
||||
assert_eq!(windows.defaults.container_padding, 10);
|
||||
assert_eq!(windows.defaults.workspace_padding, 10);
|
||||
|
||||
for platform in [PlatformDefaults::KDE, PlatformDefaults::MACOS] {
|
||||
let other = Shared::defaults_for(platform);
|
||||
assert_eq!((other.border.width, other.border.offset), (10, 0));
|
||||
assert_eq!(other.defaults.container_padding, 5);
|
||||
assert_eq!(other.defaults.workspace_padding, 5);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_default_colours_are_the_theme_conversion_of_the_rgb_values() {
|
||||
// Rgb packs as r | g << 8 | b << 16 (komorebi-themes), e.g. FOCUSED = (66, 165, 245)
|
||||
let colours = shared().border.colours;
|
||||
assert_eq!(colours.single, 66 | (165 << 8) | (245 << 16));
|
||||
assert_eq!(colours.unfocused_locked, 158 | (8 << 8) | (8 << 16));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_load_keeps_everything_but_the_two_reset_keys() {
|
||||
let mut shared = shared();
|
||||
shared.border.width = 33;
|
||||
shared.defaults.container_padding = 7;
|
||||
shared.transparency.alpha = 12;
|
||||
shared.animation.fps = 144;
|
||||
shared
|
||||
.display_index_preferences
|
||||
.insert(0, String::from("serial"));
|
||||
shared.layout_defaults.insert(
|
||||
DefaultLayout::BSP,
|
||||
LayoutDefaultEntry {
|
||||
layout_options: None,
|
||||
layout_options_rules: None,
|
||||
},
|
||||
);
|
||||
let before = shared.clone();
|
||||
|
||||
SharedDelta::default().apply(&mut shared);
|
||||
|
||||
// kept
|
||||
assert_eq!(shared.border, before.border);
|
||||
assert_eq!(shared.defaults, before.defaults);
|
||||
assert_eq!(shared.transparency, before.transparency);
|
||||
assert_eq!(shared.animation, before.animation);
|
||||
assert_eq!(
|
||||
shared.display_index_preferences,
|
||||
before.display_index_preferences
|
||||
);
|
||||
// reset
|
||||
assert!(shared.layout_defaults.is_empty());
|
||||
assert_eq!(
|
||||
shared.floating_window_aspect_ratio,
|
||||
AspectRatio::Predefined(PredefinedAspectRatio::Standard),
|
||||
"absent key writes Standard, not the initial Widescreen"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn present_keys_replace_and_absent_colours_stay() {
|
||||
let mut shared = shared();
|
||||
let before = shared.border.colours;
|
||||
|
||||
SharedDelta {
|
||||
border: Some(false),
|
||||
border_width: Some(3),
|
||||
border_offset: Some(-2),
|
||||
border_radius: Some(0),
|
||||
border_colours: Some(BorderColoursDelta {
|
||||
single: Some(1),
|
||||
unfocused_locked: Some(2),
|
||||
..BorderColoursDelta::default()
|
||||
}),
|
||||
default_workspace_padding: Some(1),
|
||||
transparency: Some(true),
|
||||
transparency_alpha: Some(9),
|
||||
..SharedDelta::default()
|
||||
}
|
||||
.apply(&mut shared);
|
||||
|
||||
assert!(!shared.border.enabled);
|
||||
assert_eq!(
|
||||
(
|
||||
shared.border.width,
|
||||
shared.border.offset,
|
||||
shared.border.radius
|
||||
),
|
||||
(3, -2, 0)
|
||||
);
|
||||
assert_eq!(shared.border.colours.single, 1);
|
||||
assert_eq!(shared.border.colours.unfocused_locked, 2);
|
||||
assert_eq!(shared.border.colours.stack, before.stack);
|
||||
assert_eq!(shared.defaults.workspace_padding, 1);
|
||||
assert_eq!(shared.defaults.container_padding, 5, "absent: kept");
|
||||
assert_eq!(
|
||||
shared.transparency,
|
||||
Transparency {
|
||||
enabled: true,
|
||||
alpha: 9
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
fn block(
|
||||
enabled: PerAnimationPrefixConfig<bool>,
|
||||
style: Option<PerAnimationPrefixConfig<AnimationStyle>>,
|
||||
duration: Option<PerAnimationPrefixConfig<u64>>,
|
||||
fps: Option<u64>,
|
||||
) -> SharedDelta {
|
||||
SharedDelta {
|
||||
animation: Some(AnimationDelta {
|
||||
enabled,
|
||||
style,
|
||||
duration,
|
||||
fps,
|
||||
}),
|
||||
..SharedDelta::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_global_animation_value_clears_its_per_prefix_map_and_a_map_keeps_the_global() {
|
||||
let mut shared = shared();
|
||||
shared
|
||||
.animation
|
||||
.enabled_per_animation
|
||||
.insert(AnimationPrefix::Movement, true);
|
||||
shared
|
||||
.animation
|
||||
.duration_per_animation
|
||||
.insert(AnimationPrefix::Workspace, 50);
|
||||
|
||||
// global enabled clears the enabled map; style absent keeps; duration map replaces the
|
||||
// map and leaves the global duration alone
|
||||
block(
|
||||
PerAnimationPrefixConfig::Global(true),
|
||||
None,
|
||||
Some(PerAnimationPrefixConfig::Prefix(HashMap::from([(
|
||||
AnimationPrefix::Movement,
|
||||
10,
|
||||
)]))),
|
||||
Some(30),
|
||||
)
|
||||
.apply(&mut shared);
|
||||
|
||||
assert!(shared.animation.enabled);
|
||||
assert!(shared.animation.enabled_per_animation.is_empty());
|
||||
assert_eq!(shared.animation.style, DEFAULT_ANIMATION_STYLE);
|
||||
assert_eq!(shared.animation.duration, DEFAULT_ANIMATION_DURATION);
|
||||
assert_eq!(
|
||||
shared.animation.duration_per_animation,
|
||||
HashMap::from([(AnimationPrefix::Movement, 10)])
|
||||
);
|
||||
assert_eq!(shared.animation.fps, 30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_animation_block_without_fps_resets_fps_and_no_block_keeps_it() {
|
||||
let mut shared = shared();
|
||||
shared.animation.fps = 144;
|
||||
|
||||
SharedDelta::default().apply(&mut shared);
|
||||
assert_eq!(shared.animation.fps, 144);
|
||||
|
||||
block(PerAnimationPrefixConfig::Global(false), None, None, None).apply(&mut shared);
|
||||
assert_eq!(shared.animation.fps, DEFAULT_ANIMATION_FPS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn motion_for_reads_one_consistent_configuration() {
|
||||
let mut shared = shared();
|
||||
shared.animation.enabled = true;
|
||||
shared.animation.duration = 250;
|
||||
shared.animation.style = AnimationStyle::Linear;
|
||||
shared
|
||||
.animation
|
||||
.duration_per_animation
|
||||
.insert(AnimationPrefix::Workspace, 400);
|
||||
shared
|
||||
.animation
|
||||
.style_per_animation
|
||||
.insert(AnimationPrefix::Workspace, AnimationStyle::EaseInSine);
|
||||
shared
|
||||
.animation
|
||||
.enabled_per_animation
|
||||
.insert(AnimationPrefix::Transparency, false);
|
||||
|
||||
assert_eq!(
|
||||
shared.animation.motion_for(AnimationPrefix::Movement),
|
||||
Some(Motion {
|
||||
duration_ms: 250,
|
||||
style: AnimationStyle::Linear
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
shared.animation.motion_for(AnimationPrefix::Workspace),
|
||||
Some(Motion {
|
||||
duration_ms: 400,
|
||||
style: AnimationStyle::EaseInSine
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
shared.animation.motion_for(AnimationPrefix::Transparency),
|
||||
None,
|
||||
"a per-prefix false wins over a global true"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layout_defaults_are_replaced_when_given() {
|
||||
let mut shared = shared();
|
||||
let entry = LayoutDefaultEntry {
|
||||
layout_options: None,
|
||||
layout_options_rules: None,
|
||||
};
|
||||
|
||||
SharedDelta {
|
||||
layout_defaults: Some(HashMap::from([(DefaultLayout::BSP, entry.clone())])),
|
||||
..SharedDelta::default()
|
||||
}
|
||||
.apply(&mut shared);
|
||||
assert_eq!(
|
||||
shared.layout_defaults.get(&DefaultLayout::BSP),
|
||||
Some(&entry)
|
||||
);
|
||||
|
||||
SharedDelta {
|
||||
layout_defaults: Some(HashMap::new()),
|
||||
..SharedDelta::default()
|
||||
}
|
||||
.apply(&mut shared);
|
||||
assert!(shared.layout_defaults.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_index_preferences_are_replaced_not_merged() {
|
||||
let mut shared = shared();
|
||||
shared
|
||||
.display_index_preferences
|
||||
.insert(0, String::from("a"));
|
||||
shared
|
||||
.display_index_preferences
|
||||
.insert(1, String::from("b"));
|
||||
|
||||
SharedDelta {
|
||||
display_index_preferences: Some(HashMap::from([(2, String::from("c"))])),
|
||||
..SharedDelta::default()
|
||||
}
|
||||
.apply(&mut shared);
|
||||
|
||||
assert_eq!(
|
||||
shared.display_index_preferences,
|
||||
HashMap::from([(2, String::from("c"))])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ allow = [
|
||||
confidence-threshold = 0.8
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebi"
|
||||
crate = "komorebi-windows"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
# One `komorebi-bar` for Windows and macOS
|
||||
|
||||
Status at the revision that adds this file. Everything below was measured on this tree with
|
||||
`diff` (counts are lines that differ, `<`/`>` lines of `diff`, hunks in parentheses). Nothing
|
||||
here was rendered: the bars cannot run on Linux. Gates that did run are named; the ones that
|
||||
did not are listed at the end.
|
||||
|
||||
KDE has no bar: `komorebi-for-kde` has no `komorebi-bar` package and no `schema.bar.json`.
|
||||
The plan below is for two platforms; a KDE bar would add a third shell and a third schema view.
|
||||
|
||||
|
||||
## What exists
|
||||
|
||||
- `crates/komorebi-bar-core` (4,592 lines): the code both bars share, one copy each.
|
||||
`selected_frame`, `ui`, `statics`, `alignment`, `render`, `config` (the leaf types and the whole
|
||||
`KomobarConfig` with the mouse options), the widgets `applications`, `battery`, `cpu`, `date`,
|
||||
`memory`, `storage`, `time`, `update`, `komorebi_layout`, the icon cache (`widgets/icons.rs`),
|
||||
all widget configuration types (`komorebi_config`, `network_config`, `platform_config` for
|
||||
keyboard, media and systray), `WidgetConfig` with a variant for every widget, the `BarWidget`
|
||||
trait, `platform` (`BarPlatform`, `SystemTool`, a once-installed global) and `schema`
|
||||
(per-platform views, see below).
|
||||
- `BarPlatform` hooks: `open_system_tool`, `latest_release_api_url`, `calendar_icon`,
|
||||
`command_icon`, `exec_shell_command`, `send_komorebi_message`, `send_komorebi_batch`.
|
||||
- Two shells, `komorebi-bar` (Windows, root workspace, version 0.1.42) and
|
||||
`komorebi-for-mac/komorebi-bar` (own workspace, own `Cargo.lock`, own flake, version 0.1.1).
|
||||
Each keeps `main.rs`, `bar.rs`, `os.rs`, the one-line `config.rs`, and the widgets whose
|
||||
runtime differs: `komorebi.rs`, `network.rs`, and on Windows `keyboard.rs`, `media.rs`,
|
||||
`systray.rs`. `widgets/widget.rs` is only `WidgetConfigExt` (config -> widget).
|
||||
- The schema oracle regenerates the macOS file natively
|
||||
(`tests/schema_oracle.rs`, module `generated`); the Windows file is still checked by the
|
||||
out-of-tree harness because three descriptions read differently when compiled for Windows.
|
||||
|
||||
## Why one package is not possible yet (the structural blocker)
|
||||
|
||||
The two trees are two Cargo workspaces with two lockfiles and two flakes. A package belongs to
|
||||
one workspace, so a single `komorebi-bar` that builds on both platforms needs one workspace
|
||||
first: the Windows root `Cargo.toml` and `komorebi-for-mac/Cargo.toml` merged, one `Cargo.lock`,
|
||||
one version (0.1.42 vs 0.1.0), one `komorebi-client` (the two `lib.rs` differ in 150 lines:
|
||||
Windows re-exports the daemon crate and `State`/`Window`/`Workspace`, macOS has its own
|
||||
types) and `windows`/`objc2` dependencies under `[target.'cfg(...)'.dependencies]`. That is a
|
||||
repository-level cutover (the plan's "final naming of the outputs and the unified app/devShell
|
||||
is a cutover decision"), not a bar change. Until then the bars share the crate and converge,
|
||||
they do not merge. Everything in this stack is ordered so the merge later is a package move.
|
||||
|
||||
## The schema is solved: views of one union
|
||||
|
||||
`schema.bar.json` differs between the platforms in 40 hunks (5,381 lines of 9,091 / 3,774).
|
||||
Analysed by definition (`jq` over `$defs`):
|
||||
|
||||
- 42 definitions exist only on Windows: all reachable only through `MouseConfig` (which holds a
|
||||
`SocketMessage`, hence the closure) and the `Keyboard`/`Media`/`Systray` widgets. Removing the
|
||||
`mouse` property and the three widget variants and pruning unreachable definitions removes
|
||||
all 42.
|
||||
- 14 differences remain in the 55 shared definitions, all text or default: root description
|
||||
(macOS names its own schema URL), `height` default `50` vs `50.0`, the margin and padding
|
||||
examples (`10` vs `10.0`, a sentence about defaults, a trailing comma), `show_icon`
|
||||
(deprecated flag and backticks), `KomorebiLayout` (untagged `anyOf` on Windows, externally
|
||||
tagged `oneOf` on macOS), `NetworkConfig.default_interface_options` (Windows only),
|
||||
four storage descriptions (`C:\` vs `/`), `TimeConfig.changing_icon` (`default: false` only
|
||||
on macOS), `TimeFormat` title of `Custom` (macOS says `Default`, a mislabel), the
|
||||
`WidgetConfig` variants above.
|
||||
|
||||
`komorebi_bar_core::schema` holds this as data (`schema/changes.rs`, 16 changes) in the same
|
||||
design as `komorebi-config`: the union is the Windows text, `view_of` applies a platform's
|
||||
changes and prunes. `tests/schema_oracle.rs` proves that the macOS view of the checked-in Windows
|
||||
file is byte-identical to `komorebi-for-mac/schema.bar.json`, that the Windows view is the
|
||||
identity, and that views are idempotent. Both bars print `--schema` through their view
|
||||
(`schema::generated_text`), so the files and `nix/komorebi-bar-options.nix` do not change when
|
||||
code is converged onto the Windows spelling.
|
||||
|
||||
The out-of-tree harness (`S/bar2/regen.sh`, real bar sources over the real
|
||||
`komorebi-protocol`/`komorebi-config`) regenerates both files on Linux. Since `config.rs` moved, the
|
||||
in-repo oracle regenerates the macOS file itself (`generated` tests); only Windows needs the harness.
|
||||
|
||||
## What is still per platform (measured at this tip)
|
||||
|
||||
| file | win / mac lines | differing | what differs and why it is not moved |
|
||||
|---|---|---|---|
|
||||
| `widgets/komorebi.rs` | 940 / 986 | 136 (17) | Two things. (1) Real rendering differences: macOS wraps `show_label` and the "all icons" painter in a `Frame` with a margin and a minimum height (`bar.show_label(...)`, a method, vs an associated function on Windows), `1.0` vs `1.0_f32`. Taking either spelling is a visual change on the other platform: needs a screen. (2) The conversion from the daemon state: Windows uses `komorebi_client::{State, Window, Workspace, Container}` (`hwnd`, `title()`, `process_id()`, windows-icons), macOS its own client types (`details.title`, `details.icon_path`, `icns_to_rgba`, `device`, no `Layout::Custom`). A State-to-snapshot split (`WindowInfo`/`MonitorInfo` of `komorebi-backend` as the carrier) is not clean yet: the macOS and Windows `komorebi_client` `State` are different types, the bar subscribes to the daemons with different notification shapes, and I cannot test either subscription here. Not attempted. |
|
||||
| `widgets/network.rs` | 598 / 578 | 82 (19) | Windows reads `default_interface_options` (friendly name, IPv4, IPv6), macOS does not (the config type is shared and macOS logs a warning); `std::sync::Mutex` (poisoning handled) vs `parking_lot`; `netdev` 0.46 vs 0.40 and a different interface match key (friendly name vs `name`); `cmd.exe /C ncpa` vs `open x-apple...`. Functional on macOS: BEHAVIOUR, needs a Mac. Known difference, left as is. |
|
||||
| `bar.rs` | 1,399 / 1,105 | 444 (35) | Windows: PowerShell session (`exec_powershell`, behind the hook), `hwnd`, virtual-desktop restore/minimize, `position_bar` through `komorebi_client::Window`, CJK font fallbacks, `scale_factor`, the Windows mouse handling. macOS: unboxed notification type, window shadow and level. Not behaviour-preserving without a screen. |
|
||||
| `main.rs` | 402 / 388 | 92 (14) | `process_hwnd`/`enum_window`, DPI awareness, `set_read_timeout`; macOS activation policy and window level (AppKit), config dir `~/.config/komorebi`. Window and viewport setup belongs behind `BarPlatform` hooks (`init_process`, `viewport_builder`, `after_creation`), not written: it cannot be exercised here. |
|
||||
| `os.rs` | 83 / 60 | 71 (14) | the platform implementations themselves; stays per platform (`cfg(target_os)` modules after the merge). |
|
||||
| `widgets/widget.rs`, `widgets/mod.rs` | 41 / 49, 22 / 19 | 20, 5 | `WidgetConfigExt` (macOS builds a no-op `Unsupported` for the three Windows-only widgets) and the module lists. |
|
||||
|
||||
Windows-only and not shared: `widgets/keyboard.rs` (167), `media.rs` (322), `systray.rs` (1,205);
|
||||
their config types are in the core. The macOS copies of keyboard and media were dead and are deleted.
|
||||
|
||||
### Known macOS/Windows differences that were kept (D-coord-1)
|
||||
|
||||
- `network.rs`: see above. The macOS bar ignores `default_interface_options`.
|
||||
- Windows-only config keys are accepted on macOS and skipped with a logged warning (BEHAVIOUR on
|
||||
macOS, as for `StaticConfig`): `Keyboard`, `Media` and `Systray` widgets
|
||||
(`widgets::widget::warn_unsupported`), the `mouse` options and the network
|
||||
`default_interface_options`. Before, the first group failed to deserialize and rejected the whole
|
||||
config, the other two were ignored silently.
|
||||
- macOS commands that spawn programs that do not exist there are preserved, not fixed:
|
||||
`SystemTool::PowerSettings` (battery click) spawns `cmd.exe /C start ms-settings:...`,
|
||||
`SystemTool::Url` (update click) spawns `explorer.exe`, and `UserCommand::launch_if_ready` of the
|
||||
applications widget spawns `cmd /C <command>` in both bars. `update.rs` still has a second GitHub
|
||||
API URL for the Windows repository. The macOS spawns live in
|
||||
`komorebi-for-mac/komorebi-bar/src/os.rs`; the storage click is `SystemTool::StorageLocation` and
|
||||
each shell spawns what it spawned before.
|
||||
- `KomorebiLayout` is `#[serde(untagged)]` in both bars now (the macOS source converged; the macOS
|
||||
schema view restores the macOS text). Its `Deserialize` is hand-written and nothing in the bar
|
||||
serializes it, so this changes only the derived schema and `Serialize`. The coordinator said to
|
||||
leave it alone; it is a separate revision (`mac-bar: converge komorebi.rs config text and
|
||||
komorebi_layout.rs`) and can be dropped, at the price of keeping `KomorebiLayout` and its
|
||||
widget in the shells.
|
||||
|
||||
## The merged package layout (for the coordinator's workspace merge)
|
||||
|
||||
Not done and not prepared in the tree (no workspace or lockfile structure was changed). When the
|
||||
root workspace and `komorebi-for-mac` are merged the bar should look like this:
|
||||
|
||||
- Package `komorebi-bar` (one, in `komorebi-bar/`) plus `crates/komorebi-bar-core` as today.
|
||||
Version: the workspace version. The macOS tree's `komorebi-bar` 0.1.1 and the `v0.1.0` text in
|
||||
its schema description are a view concern (`schema/changes.rs`), not a package one.
|
||||
- `src/main.rs` (shared: the argument parsing, config read, `--schema`, the event loop shell)
|
||||
and `src/bar.rs` split into `src/bar/mod.rs` (shared `Komobar`) with
|
||||
`#[cfg(target_os = "windows")] mod windows;` and `#[cfg(target_os = "macos")] mod macos;`
|
||||
for the window handle, DPI, activation policy, window level, position and the PowerShell
|
||||
session. `src/os.rs` becomes `src/os/{windows,macos}.rs` (the `BarPlatform` implementations,
|
||||
selected by `cfg(target_os)` and installed first thing in `main`). Windows-only widgets
|
||||
(`keyboard`, `media`, `systray`) are `#[cfg(target_os = "windows")]` modules; `komorebi.rs` and
|
||||
`network.rs` stay two files (`komorebi/{windows,macos}.rs` behind one `widgets::komorebi`
|
||||
facade) until the snapshot split.
|
||||
- `Cargo.toml`: `windows`, `windows-core`, `windows-icons*`, `systray-util`, `font-loader` under
|
||||
`[target.'cfg(windows)'.dependencies]`; `objc2`, `objc2-app-kit`, `raw-window-handle`, `icns`
|
||||
under `[target.'cfg(target_os = "macos")'.dependencies]`; `netdev` has two versions (0.46,
|
||||
0.40): pick one when `network.rs` converges, until then a target-specific rename
|
||||
(`netdev-win`, `netdev-mac`). `komorebi-client`: one crate (the two differ in 150 lines).
|
||||
Features: `schemars` as now (it forwards to the core). No new feature per platform: the
|
||||
platform is `cfg(target_os)`.
|
||||
- Schema: the checked-in files stay (`schema.bar.json`, `komorebi-for-mac/schema.bar.json`, or one
|
||||
directory for both after the merge). `--schema` prints the view of the running platform
|
||||
(`SchemaPlatform` from `cfg(target_os)`); a `--schema-for <platform>` flag would let one host
|
||||
regenerate both, as the Windows union is the Windows text. Windows' three
|
||||
platform-dependent descriptions (protocol `PathBuf`, themes) need the Windows target to
|
||||
regenerate, so the Windows file is only verifiable on Windows or with the harness.
|
||||
- Lock files: the macOS `Cargo.lock` folds into the root one; the lines this stack added to both
|
||||
(`image`, `komorebi-config`, `komorebi-layouts`, `komorebi-protocol`, `komorebi-themes`,
|
||||
`tracing`, `lazy_static`, `color-eyre` for bar-core) are the same crates in both, so the merge
|
||||
adds no new versions beyond `netdev` and `starship-battery`/`sysinfo` (already unified here).
|
||||
- Nix: `komorebi-for-mac/nix/komorebi-bar-options.nix` is generated from the macOS file and does
|
||||
not change; the two flakes' `extractBinary "komorebi-bar"` become one derivation per system.
|
||||
|
||||
## The plan, in order
|
||||
|
||||
1. Done: schema views and oracle; storage, time, applications, komorebi layout widget, icon
|
||||
cache, all widget config types, `WidgetConfig`, `config.rs` moved; hooks for platform
|
||||
spawns, the shell session and the komorebi client.
|
||||
2. Not done, needs a screen or a Mac: `bar.rs`/`main.rs` window code behind `BarPlatform`
|
||||
(`init_process`, `viewport_builder`, `after_creation`, position/DPI/activation), then
|
||||
`Komobar<P>` and the shared `app` body into the core.
|
||||
3. Not done, needs the snapshot split: `komorebi.rs`. It needs `State`-to-snapshot conversion
|
||||
per platform and one renderer; the frame/margin difference must be decided by looking at both.
|
||||
4. Decision for `network.rs`: converge on the Windows widget (macOS gains friendly-name,
|
||||
IPv4/IPv6 and the `netdev` bump) or keep two.
|
||||
5. Workspace merge (above), then the two shells collapse into one package.
|
||||
6. The oracle then compares generated text with the files for both platforms.
|
||||
|
||||
## What to check by hand
|
||||
|
||||
Windows (coordinator, screenshot e2e): the bar starts; the storage, time, applications (icons
|
||||
from executables), komorebi layout (click opens the options, choosing one changes the layout,
|
||||
Monocle/Floating toggles, paused) and komorebi workspaces widgets render; a click on storage
|
||||
opens Explorer on the drive; a config with `mouse` options and a `Systray`/`Keyboard`/`Media`
|
||||
widget still works (this is the Windows path through the moved `config.rs`, `WidgetConfig` and
|
||||
the `exec_shell_command` hook: a `Command` mouse message must still reach the PowerShell session);
|
||||
`komorebi-bar --schema` equals `schema.bar.json`.
|
||||
|
||||
macOS (also in the section for `docs/dev/macos-handcheck.md`): the bar starts with your real
|
||||
config; the time widget renders (format variants, `changing_icon`); clicking a storage widget
|
||||
opens the mounted volume in Finder (`open <path>`); the komorebi layout widget click works as
|
||||
before; a config that contains a `Keyboard`, `Media` or `Systray` widget, a `mouse` block, or
|
||||
`default_interface_options` under `Network` starts the bar and logs one warning per item (before:
|
||||
the widget case failed to load the config); `komorebi-bar --schema` equals
|
||||
`komorebi-for-mac/schema.bar.json`; the battery and update clicks still fail the way they did
|
||||
(preserved, one-function fix in `os.rs`).
|
||||
@@ -0,0 +1,77 @@
|
||||
# macOS hand-check list
|
||||
|
||||
Status: written by the `kfm` agent for the user, 2026-10-31. Nothing here has been run: macOS cannot be built, linked or tested on the Linux host, only type-checked through a fake C compiler (`tools/fast-check`). Every revision below is `type-checks, not run`. Revision ids are jj change ids (stable) with the commit id they had when this was written (commit ids change when a revision is rewritten; use `jj log -r <change id>`).
|
||||
|
||||
How to use it: build the unified (or, until they exist, the per-tree) macOS `komorebi`, `komorebic` and `komorebi-bar`, run `cargo test --workspace` on the Mac first (the 399+ unit tests have never run against these changes), then walk the sections in order. For before/after capture use `komorebi-recorder` against a build of the baseline `wip-main` ancestor `ff3711dc` and the tip. A section is done when the "look for" column is true.
|
||||
|
||||
## Status of the Mini runs (2026-10-31)
|
||||
|
||||
The real-Mac runs so far (Mac Mini, rustc and clippy 1.93, tip a35573d8) are **compile and unit tests only**: `cargo test --workspace` in komorebi-for-mac passed (daemon 366 passed, 1 ignored; 368 total, 0 failed) and clippy `-D warnings` was clean apart from the two items fixed afterwards. Nothing was run as a daemon: no focus, tiling, borders, animations or bar rendering has been observed on the Mini. Every walk-through item below is still open.
|
||||
|
||||
## A. Revisions that change what the daemon does (BEHAVIOUR)
|
||||
|
||||
| Revision | What changed | Look for on a Mac |
|
||||
|---|---|---|
|
||||
| `ummqkuvp` 01b9cbed `fix(mac): take the rule-list locks in one order...` | `window_is_eligible` (window.rs) and `apply_globals` (static_config.rs) now lock floating, ignore, manage, regex in that order; before they locked regex, ignore, manage and ignore, regex, manage. The order is documented at the statics in lib.rs. Same fix as the KDE `ef1d3ef0`. | Run `komorebic reload-configuration` (and `komorebic replace-configuration`) in a loop of 50 while opening and closing windows (new Finder windows, Terminal tabs) at the same time. Before the fix this could hang the daemon (the command is never answered, new windows are not tiled). Expected: no hang, every reload answered. Also check that float rules, ignore rules and manage rules from the config and from `komorebic float-rule`/`ignore-rule`/`manage-rule` still apply to new windows. |
|
||||
| `nvwvptpv` 866b2840 `use the shared command listener` | The UDS command accept loop and per-client reader are the shared `komorebi-transport` code (`NoPolicy`: no read timeouts, as before); `WindowManager` is a `CommandTarget` (lock with `try_lock_for`). | Every `komorebic` command is answered; a command sent while the daemon is busy gets an answer or a clean error, not a hang; kill the daemon mid-command: the client returns. |
|
||||
| `ywwwwpwm` 587defe3 `use the shared pause filter` | `allowed_while_paused` lists the commands allowed while paused. | `komorebic toggle-pause`; while paused only `toggle-pause`, `state`, `global-state`, `stop` work, everything else is ignored (and the connection ends); unpause and check windows tile again. |
|
||||
| `kzynysto` b85827e6 `use the shared subscriber push` | Subscriber sockets are pushed to by the shared `notify_sockets`; the macOS override events are kept. | `komorebic subscribe-socket` (and `subscribe-socket-with-options`): events arrive for focus, move, workspace change, monitor change, theme and config reload; a subscriber that goes away is dropped without breaking the others. The bar is a subscriber, so the bar updating is the check. |
|
||||
| `ovsplvmn` 5cc38da6 `use EventChannel for the window events` | The window-event channel (capacity 20, try_send, drop warning, `ResizeStep` claim flag) is `komorebi_transport::EventChannel`. | Drag a window edge continuously (live resize) and pan with the trackpad: no stalls, no repeated drop warnings in the log, the layout follows. Move many windows at once (workspace switch with 10+ windows). |
|
||||
| `lrqkuuzq` a4996ac6 `use SocketMessage from komorebi-protocol` and `sowrttxs` 5c129ab5 `carry DebugWindow as i64` | One `SocketMessage` for all platforms; the wire format must be unchanged. `DebugWindow` takes an i64 (a negative id parses and matches nothing). | Every command of the `komorebic` help works against the daemon; `komorebic debug-window <id>` for a real id; `komorebic state` and `global-state` JSON parse. |
|
||||
| `qqwoptqt` 975f007a, `yptnnkxv` eb903bcc (animation prefix, Bezier doc) | `AnimationPrefix` gains `Transparency` (ignored by the daemon); schema.json changed the shape of per-prefix animation settings. | Config with `animation.style` / `duration` per prefix (movement, workspace) still loads; animations behave as before. Run `komorebic static-config-schema` and diff with `komorebi-for-mac/schema.json` (two description-level changes and the per-prefix shape are intended). |
|
||||
| `kvtvnouo` 93e4d511, `stxmqnop` dec91984 (StaticConfig from komorebi-config) | The config data types and their defaults come from `komorebi-config`; `komorebic static-config-schema` prints the macOS view. | A real `komorebi.json` of yours loads with no new warning and every key still takes effect (borders, padding, animations, scrolling, rules, workspaces); `komorebic static-config-schema` matches the checked-in `schema.json` up to the intended description lines. |
|
||||
| `qukywpss` c46320ea, `zwkwptox` 1e902542, `sxptsttt` 0345fccb (komorebic shares clap definitions, launcher, pan) | `komorebic start` and `stop` use the shared Launcher skeleton (the odd `--config` arguments are kept; "Waiting for komorebi to start..." is flushed); pan commands use the shared module. | `komorebic start --bar`, `start --await-configuration`, `stop`, `stop --bar`; `komorebic pan-*` commands; `komorebic --help` and a few `<command> --help` texts (about 15 help texts changed to the Windows wording). |
|
||||
| `oywqqkuy` f0b1a448 `register every Window in ax_registry and forget the dead` | `Window::new` registers the window in the id registry (`ax_registry`); entries are removed in `Window::drop` of a dead window, in `reap_window`, and (`forget_pid`) when an application terminates. No AX call is added; the table holds retained AX references and observers. | Open and close 50 windows (Finder, Terminal, Safari) and quit several apps, then check the daemon's memory in Activity Monitor does not climb and nothing behaves differently (focus, tiling, borders). If a quit app's windows were not forgotten the symptom is memory growth only. Run with `RUST_LOG=debug` and check no new errors at app quit. |
|
||||
| `oqnvyqvw` e0687167 `keep ax_registry in step when a native tab changes a window's id` | The two places that swap a window's id and element in place for native tabs also update the registry (`sync`). | A native-tabbed app (Terminal, Finder, Safari tabs): switch tabs, close the first tab, open a new tab, focus the window with `komorebic focus ...`, move and resize it. Must behave as on the baseline (no window lost, no stuck border). |
|
||||
| Bar: `nottqpms` 086833af, `zvuyspku` b8de056b, `uxzpkmnk` 7cd85bd4, `yopuwouu` 6da27dda (bar-core, platform hooks) | macOS now builds `sysinfo` 0.39 and `starship-battery` 0.11 (the Windows versions); cpu, battery, memory, date, update widgets are the shared code. | Bar renders; CPU %, memory, battery % and charging state show sane values; date and the calendar icon; clicking CPU, battery, network, update (see bug list D below: these click handlers are broken on macOS and stay broken). |
|
||||
|
||||
Revisions in section B change no behaviour on purpose (rename, move, route); they still need the sections C walk-through, because a mechanical mistake would show there.
|
||||
|
||||
## B. Mechanical macOS revisions of the `kfm` agent (Step 6 and 11(i))
|
||||
|
||||
| Revision | Change |
|
||||
|---|---|
|
||||
| `vzxkxzzy` 796c3832 | `Window::frame()` (renamed `window_rect` below) for the 28 sites that read a Window's frame through `MacosApi::window_rect(&w.element)` (window.rs, window_manager.rs, workspace.rs, process_event.rs, process_command.rs, settle.rs, macos_backend.rs) |
|
||||
| `oootynxk` 7c2e1bea | `Window::is_valid` renamed `Window::alive` |
|
||||
| `roxrxtru` 49a6dbda | `Window::set_position` renamed `Window::set_rect` (10 callers) |
|
||||
| `vmnnuzzu` 803a1410 | `Window::set_messaging_timeout` (settle.rs: 3 raw AX sites) |
|
||||
| `upylxxuw` ecaa3e15 | `Window::close` (the same close-button press as `AdhocWindow::close`) |
|
||||
| `tsymmvll` d30a3eb6 | step 11(i): `MacosBackend` calls only `Window` methods (new `Window::minimized`); still unused by the daemon |
|
||||
| `qsrxvsmv` 931b17d7 | `Window::frame` renamed `Window::window_rect` (the Backend and the Windows Window use that name) |
|
||||
| `xrtqmxkp` 4c9094d7 | native: `komorebi_backend::Registry` (the rules of the id registry; 9 unit and 1 doc test run on Linux) |
|
||||
| `tmmtuosy` 386c5a79 | `ax_registry` module; `MacosBackend` resolves ids through it (the adapter is still unused by the daemon) |
|
||||
| `kvkxkqnx` ba22e8dc | `ax_registry::identify`: the 7 sites that turn a system-handed element into a window id (input_event_listener, process_command, process_event x5, window_manager) |
|
||||
| `kpopuvoy` 01b3bd5c | live-resize step (window_manager.rs) reads the dragged window's frame through `Window::window_rect` |
|
||||
|
||||
Hand check: C below. If something breaks and is not the lock order, bisect among these seven first: they only rename and route, so a regression means a call was routed to the wrong receiver (type-check cannot tell a Window from another window of the same type).
|
||||
|
||||
## C. Walk-through (the list the plan names)
|
||||
|
||||
Do each with the baseline build and the tip build and compare (or record with `komorebi-recorder`).
|
||||
|
||||
1. **Focus**: `komorebic focus left|right|up|down`, `cycle-focus`, `focus-window <n>`; mouse-follows-focus on/off (the cursor centres in the window: uses the window frame query); focus a window of a tabbed app (Terminal, Finder): the focus uses `element_to_focus`, check the right tab.
|
||||
2. **Move and resize**: `move`, `resize-axis`, `resize-edge` and a manual drag of a window; after a drag the layout puts the window back (settle reads the frame with a timeout); live resize of one edge moves the neighbour. A window that refuses a width (a fixed size app) is read back and the neighbours adapt.
|
||||
3. **Stack**: `stack`, `unstack`, `cycle-stack`, `stack-all`; hidden stack members are parked off-screen (`hide`) and restored (`restore`) correctly; no window left at a hidden corner after unstack or quit.
|
||||
4. **Workspaces**: switch (`focus-workspace`), send a window (`send-to-workspace`), `move-to-workspace`, with 2 monitors if possible; windows of the workspace you left are hidden, those of the new one restored to where they were; workspace rules after a monitor change.
|
||||
5. **Scrolling layout**: the scrolling layout, `pan` commands, `scroll-*`; windows slide in from the edge (the arrival/slide code reads the frame).
|
||||
6. **Pan** (trackpad gesture) and **live resize**: `komorebic pan-*`, three-finger style gestures as you configured them.
|
||||
7. **Borders**: focused/unfocused/stack colours follow focus and follow animated windows; borders vanish and come back on workspace switch; no border left behind after closing a window (the window's close and borders share the observer code).
|
||||
8. **Animations**: movement and workspace animations on and off; the ghost images; cancel an animation by issuing a new command in the middle.
|
||||
9. **Display change**: plug or unplug a monitor or change the resolution: work areas update, workspaces go to the right monitors, workspace rules re-apply. (This is the thread that can deadlock, see bug list A.)
|
||||
10. **Sleep and wake**: close the lid or sleep, wake: windows are where they were, the daemon answers, the bar returns.
|
||||
11. **Minimize, unminimize, close**: `komorebic minimize`, `close` (the foreground window), un-minimize a window from the Dock; closing a window removes it from its container (the reaper uses `Window::alive`).
|
||||
12. **Reload the config** repeatedly (see section A, first row).
|
||||
|
||||
## D. Bugs noticed, not fixed here
|
||||
|
||||
A. **Possible deadlock, main queue against the window-manager lock** (`docs/dev/seam.md` section 3.3, by reading only, never reproduced). A thread holding the WM lock calls a blocking main-queue dispatch (`destroy_all_borders` at process_event.rs lines about 128/139, process_command.rs, `retile_all`; `hide_borders_on` in window_manager.rs; `activate_finder` in process_event.rs) while the monitor reconciliator has dispatched a closure to main that itself takes the WM lock (monitor_reconciliator.rs about 106 and 383). Then the event thread waits for main, main waits for the lock. `parking_lot`'s deadlock detector cannot see it (the dispatch is a semaphore). Window of exposure: a display change at the instant of one of those events. Structural fix: no closure that runs on main may take the WM lock (or dispatch to main only after the lock is dropped). How to provoke it: spam `komorebic retile` / workspace switches (with ghosts) while plugging or unplugging a monitor; the symptom is a daemon that answers no command (`komorebic state` hangs).
|
||||
B. **cmd.exe and explorer.exe in the macOS bar** (`komorebi-for-mac/komorebi-bar/src/os.rs`, `BarPlatform::open_system_tool`): the battery click spawns `cmd.exe` (power settings), the update click spawns `explorer.exe` with the release URL; neither exists on macOS. The same file's CPU (task manager) and network settings tools should be Activity Monitor and System Settings. The fix is one function in that file; it was preserved on purpose during the bar move.
|
||||
C. **Update widget refresh thread polls the Windows repo's GitHub API** on macOS too (update.rs has a second URL that does not go through the hook), and the macOS update link is `.../releases/v..` built for the Windows repo.
|
||||
D. **Other raw AX sites remain outside `Window`**: window.rs (38 inside `Window`/`AdhocWindow`, expected), application.rs 11 (`Application`, not a window), process_event.rs 7 (events that hand over a bare element: `window_id` of an element, the tab check `AccessibilityApi::window_id(&window.element.0)`), animation/animator.rs 6 (lane threads hold `WindowHandle` clones of the element), border_manager 7 (observers on tracked elements), window_manager.rs 4 (timeouts list holds elements, `window_id` of an element), reaper.rs 2 (`notify_if_gone` takes an element so lanes can use it), input_event_listener.rs 1, process_command.rs 1. They need either an id to AX registry (step 11(ii), not started) or a `WindowHandle` type; they were left alone because routing them changes who owns the element.
|
||||
D2. **Step 11(ii) status.** Done: the id registry (`ax_registry`, over the tested `komorebi_backend::Registry`), populated at `Window::new`, kept in step for native tabs, emptied on death, reap and application quit; `MacosBackend` resolves ids through it. NOT done, on purpose, because each needs a decision that cannot be verified without a Mac: (a) the animator lanes (`WindowHandle`) keep their own snapshot of the element: a lane must keep writing to the element of the move it was given even if a tab swap replaced the registry entry, and replacing the snapshot by a lookup per write changes what a late write hits; (b) borders keep `tracking_element` (observer sources are added and removed on that exact element, on main); (c) `reaper::notify_if_gone` and the window manager's live-resize `timeouts` list take elements, including application elements, that are not registry entries; (d) `application.rs` is the application, not a window. (e) The model (`Window`, containers, workspaces) still holds `Window` values, not bare `WindowId`s: that is step 11(iii), after steps 8-9. A stale registry id answers `Error::WindowGone` (no panic); a window that was deserialised from state (default system-wide element) is never registered.
|
||||
E. `MacosBackend` (step 7c/11(i)) needs 11(ii) before it can be used: `windows()` answers only what was `register`ed, `hide` needs the corner, `raise` also focuses, `monitors()` reads a cache nobody fills yet (seam.md section 9.2). `AdhocWindow` (bare foreground element) still has its own minimize, close, hide, restore, raise.
|
||||
F. In `window.rs` `AdhocWindow::hide` / `Window::hide` duplicate the restore-position bookkeeping (`WINDOW_RESTORE_POSITIONS`), one on a `Window` and one on a bare element; they must stay in step.
|
||||
|
||||
## E. What is not checked at all
|
||||
|
||||
Everything above. In particular: no macOS test (399+ unit tests incl. those in window.rs for drag state) has run against any of these revisions; the unified binaries do not exist yet; no real Accessibility call was made; `komorebi-recorder` captures need a Mac.
|
||||
@@ -0,0 +1,320 @@
|
||||
# Settings: replacing the process-wide statics
|
||||
|
||||
Status: design (plan step 10, phase 1). Measured on `wip-main` 633e7453 (the Windows tree
|
||||
`komorebi/src`, KDE `komorebi-for-kde/komorebi/src`, macOS `komorebi-for-mac/komorebi/src`). Nothing
|
||||
here was run: counts come from `grep` and reading, and macOS cannot run on this host. The shared type
|
||||
is landed as the crate `crates/komorebi-settings` (phase 2) and **no daemon uses it yet**.
|
||||
|
||||
Abbreviations: `W/`, `K/`, `M/` are the three `src` trees. `apply_globals` is
|
||||
`StaticConfig::apply_globals` (`W/static_config.rs:396`, `K/static_config.rs:414`,
|
||||
`M/static_config.rs:392`).
|
||||
|
||||
## 1. What the statics are
|
||||
|
||||
Declarations of `static`, `static ref` and `lazy_static` (thread locals and per-call counters left out):
|
||||
**Windows 126, KDE 53, macOS 74.** Most are not settings. Four kinds:
|
||||
|
||||
| kind | examples | goes into `Settings`? |
|
||||
|---|---|---|
|
||||
| **config**: written by `komorebi.json` load and/or a `SocketMessage`, read by other threads | `BORDER_*`, `ANIMATION_*`, paddings, rule lists, stackbar | yes |
|
||||
| **session state**: changes while running, is not configuration | `SESSION_FLOATING_APPLICATIONS`, `UNMANAGED_WINDOW_IDS`, `HIDDEN_HWNDS`, `WORKSPACE_MATCHING_RULES`, `INITIAL_CONFIGURATION_LOADED`, `CUSTOM_FFM` (command line) | no; stays where it is (core step 9) |
|
||||
| **plumbing**: channels, `OnceLock<Sender>`, caches of OS handles, per-window tables | `CHANNEL`, `BORDER_STATE`, `MONITOR_CACHE`, `HWNDS_CACHE`, `PARKED_WINDOWS`, `live_resize.rs` flags | no |
|
||||
| **environment**: computed once | `HOME_DIR`, `DATA_DIR`, `AHK_EXE`, `WINDOWS_11` | no |
|
||||
|
||||
Config-class statics by my count: **Windows 61, KDE 35, macOS 36** (these include the session-state
|
||||
rule lists that sit next to them; see 2.3). What `apply_globals` itself writes (distinct statics,
|
||||
counted on the function body): **Windows 51, KDE 29, macOS 28.** The plan's "19-27 written per
|
||||
platform" counted scalar settings only; the 11 rule lists, the 7 per-animation/global animation
|
||||
statics and the stackbar block make the totals larger.
|
||||
|
||||
## 2. The inventory (config class)
|
||||
|
||||
"Writers": `load` is `apply_globals` (runs on start-up through `preload`, and again on every
|
||||
`ReloadConfiguration` through `reload`), `cmd` is a `SocketMessage` arm of `process_command.rs`,
|
||||
`theme` is `theme_manager`, `thr` is another thread. "Readers" lists only threads that are not the
|
||||
window-manager thread; "wm" means code that runs under the window-manager lock. Match is the name
|
||||
on the other platforms (`=` same name and type, `~` same name, different default or type, `-`
|
||||
absent).
|
||||
|
||||
### 2.1 Scalars and small values
|
||||
|
||||
| static | type | writers | readers | W / K / M | shared? | note |
|
||||
|---|---|---|---|---|---|---|
|
||||
| `BORDER_ENABLED` | AtomicBool | load, cmd `Border` | border thread (all 3), wm | = = = | shared | K reads it to decide whether borders take room in the layout (`BORDER_DRAWN` is its derived twin, K only) |
|
||||
| `BORDER_WIDTH` | AtomicI32 | load, cmd | border thread, wm (offsets), stackbar (W) | ~ default 8 / 10 / 10 | shared | |
|
||||
| `BORDER_OFFSET` | AtomicI32 | load, cmd | border thread, wm | ~ default -1 / 0 / 0 | shared | |
|
||||
| `BORDER_RADIUS` | AtomicI32 | load | K effect, M `ns_window` | - K M | K+M | Windows draws square or via DWM (`STYLE`) |
|
||||
| `BORDER_OFFSET_ADJUSTMENT` | `static i32` = 7 | nobody | M border | - - M | platform constant | stays a constant |
|
||||
| `FOCUSED UNFOCUSED UNFOCUSED_LOCKED MONOCLE STACK FLOATING` | 6 x AtomicU32 | load, cmd `BorderColour`, theme | border thread | = = = | shared | `UNFOCUSED_LOCKED` is written by theme only (load never writes it); one theme change writes 6 border and (W) 3 stackbar values one by one |
|
||||
| `STYLE` | AtomicCell<BorderStyle> | load, cmd | border thread, wm | W only | W platform | load resets it to default when the file has none |
|
||||
| `IMPLEMENTATION` | AtomicCell<BorderImplementation> | load, cmd | border thread | W only | W platform | |
|
||||
| `ANIMATION_ENABLED_GLOBAL` | Arc<AtomicBool> | load, cmd, **scoped override**, shutdown | W animation engine, M animator and lane threads, wm | = = = | shared | see 4 (override) |
|
||||
| `ANIMATION_STYLE_GLOBAL` | Arc<Mutex<AnimationStyle>> | load, cmd | same | = = = | shared | |
|
||||
| `ANIMATION_DURATION_GLOBAL` | Arc<AtomicU64> | load, cmd | same | = = = | shared | |
|
||||
| `ANIMATION_{ENABLED,STYLE,DURATION}_PER_ANIMATION` | Arc<Mutex<HashMap<AnimationPrefix, _>>> x3 | load, cmd (2 sites for style), shutdown (enabled) | same | = = = | shared | `load` clears the map when a global value is given, replaces it when a prefix map is given |
|
||||
| `ANIMATION_FPS` | AtomicU64 | load, cmd | W engine, M animator (`frame_period`) | = = = | shared | load writes the default when `animation` is present but `fps` is not |
|
||||
| `GHOST_MOVEMENT_ENABLED` | AtomicBool | load | W ghost dispatcher, live resize | W only | W platform | |
|
||||
| `TRANSPARENCY_ALPHA` | AtomicU8 | load, cmd | W/K transparency manager | = = - | shared (W, K) | default 200 |
|
||||
| `TRANSPARENCY_ENABLED` | AtomicBool | load (`transparency`), cmd (set, toggle) | transparency manager, W process_event | = = - | shared (W, K) | a command toggles what the file set; a reload overwrites it only when the key is present |
|
||||
| `DEFAULT_WORKSPACE_PADDING`, `DEFAULT_CONTAINER_PADDING` | AtomicI32 | load | wm (every layout), W stackbar | ~ default 10 / 5 / 5 | shared | load keeps the old value when the key is absent |
|
||||
| `DEFAULT_RESIZE_DELTA`, `DEFAULT_MOUSE_FOLLOWS_FOCUS` | `static i32 / bool` | nobody | wm | = = = | shared constants | become part of the platform defaults |
|
||||
| `FLOATING_WINDOW_TOGGLE_ASPECT_RATIO` | Arc<Mutex<AspectRatio>> | load (2 sites) | wm | = = = | shared | load writes a default when absent |
|
||||
| `LAYOUT_DEFAULTS` | Arc<Mutex<HashMap<DefaultLayout, LayoutDefaultEntry>>> | load (replace or clear) | wm | = = = | shared | |
|
||||
| `DISPLAY_INDEX_PREFERENCES` | Arc<RwLock<HashMap<usize, String>>> | load, cmd | monitor reconciliator thread, wm | = = = | shared | |
|
||||
| `MONITOR_INDEX_PREFERENCES` | Arc<Mutex<HashMap<usize, Rect>>> | load, cmd | W windows_api, reconciliator | W only | W platform | commented out of macOS and KDE load |
|
||||
| `DUPLICATE_MONITOR_SERIAL_IDS` | Arc<RwLock<Vec<String>>> | reconciliator, windows_api | windows_api | W only | **not config** | derived from the monitor list |
|
||||
| `HIDING_BEHAVIOUR` | Arc<Mutex<HidingBehaviour>> | load, cmd, (state loader) | **reaper thread** (every 20 ms), wm | W only | W platform | reaper reads it without the wm lock |
|
||||
| `WINDOW_HANDLING_BEHAVIOUR` | AtomicCell<WindowHandlingBehaviour> | load, **scoped override** in `border.rs:831-851` | W windows_api (every position call), ghost dispatcher, scrolling | W only | W platform | see 4 |
|
||||
| `MINIMUM_WIDTH`, `MINIMUM_HEIGHT` | AtomicI32 x2 | load | wm | W only | W platform | commented out of the macOS load |
|
||||
| `SLOW_APPLICATION_COMPENSATION_TIME` | AtomicU64 | nobody after init | W window | W only | W platform | effectively constant 20 |
|
||||
| `REMOVE_TITLEBARS` | AtomicBool | cmd | wm, workspace | W only | W platform | runtime toggle, not in `apply_globals` |
|
||||
| `STACKBAR_*` (9: font size/family, focused/unfocused text, tab background, height, width, label, mode) | AtomicI32/U32/Cell, `Mutex<Option<String>>` | load, cmd, theme (3 colours) | stackbar threads, wm | W only | W platform | load sets font size and family unconditionally (0 / None) when `stackbar.tabs` is present |
|
||||
| `STACKBAR_TEMPORARILY_DISABLED` | AtomicBool | ghost dispatcher | stackbar manager | W only | session state | |
|
||||
| `CURRENT_THEME` | AtomicCell<Option<Theme>> | theme thread | theme thread only | = = = | not config | read nowhere else |
|
||||
| `TABBED_APPLICATIONS`, `TITLELESS_APPLICATIONS`, `DO_NOT_OBSERVE_APPLICATIONS` | Arc<Mutex<Vec<String>>> | load (first two) | M window, process_event | M only | M platform | |
|
||||
|
||||
### 2.2 Rule lists (the lock-ordered set)
|
||||
|
||||
| static | writers | readers | W / K / M |
|
||||
|---|---|---|---|
|
||||
| `FLOATING_APPLICATIONS`, `IGNORE_IDENTIFIERS`, `MANAGE_IDENTIFIERS` | load (all three held at once) | wm; W also `winevent` and `window_manager_event` threads through `window_is_eligible` | = = = |
|
||||
| `TRANSPARENCY_BLACKLIST` | load | transparency manager | = = - (K: pub) |
|
||||
| `LAYERED_WHITELIST`, `TRAY_AND_MULTI_WINDOW_IDENTIFIERS`, `OBJECT_NAME_CHANGE_ON_LAUNCH`, `OBJECT_NAME_CHANGE_TITLE_IGNORE_LIST`, `SLOW_APPLICATION_IDENTIFIERS`, `NO_TITLEBAR` | load | wm, event threads | W only |
|
||||
| `REGEX_IDENTIFIERS` | load (clears), every rule check (compiles on demand) | every rule check | = = = |
|
||||
| `PERMAIGNORE_CLASSES` (W also `WSL2_UI_PROCESSES`) | nobody after init | window eligibility | = = = (W: +1) |
|
||||
| `SESSION_FLOATING_APPLICATIONS` | cmd (add/remove at run time) | window eligibility | = = = |
|
||||
| `WORKSPACE_MATCHING_RULES` | cmd, **reload (clears, then refills after `apply_globals`)** | wm, reconciliator, M process_event | = = = |
|
||||
|
||||
### 2.3 Lock-order relations
|
||||
|
||||
The documented order (comment above the statics in `komorebi/src/lib.rs` on `wip-u-kfw`; it is the
|
||||
only one: KDE and macOS declare no order and take the same lists in whatever order the code does):
|
||||
|
||||
```
|
||||
FLOATING_APPLICATIONS, SESSION_FLOATING_APPLICATIONS, TRANSPARENCY_BLACKLIST, IGNORE_IDENTIFIERS,
|
||||
MANAGE_IDENTIFIERS, LAYERED_WHITELIST, TRAY_AND_MULTI_WINDOW_IDENTIFIERS, OBJECT_NAME_CHANGE_ON_LAUNCH,
|
||||
OBJECT_NAME_CHANGE_TITLE_IGNORE_LIST, SLOW_APPLICATION_IDENTIFIERS, NO_TITLEBAR,
|
||||
WORKSPACE_MATCHING_RULES, REGEX_IDENTIFIERS
|
||||
```
|
||||
|
||||
`REGEX_IDENTIFIERS` is last (every rule check holds a list and then the regexes); `PERMAIGNORE_CLASSES`
|
||||
and `WSL2_UI_PROCESSES` are leaves. The window-manager lock is above all of them: `apply_globals` runs
|
||||
with it held (the `reload` signature takes `&mut WindowManager`), but the event threads of Windows
|
||||
(`winevent_listener` to `window_manager_event`) and the transparency manager also lock single lists
|
||||
without it.
|
||||
|
||||
Two findings:
|
||||
|
||||
1. `apply_globals` on Windows takes **eleven** list locks in a fixed order and keeps them for the whole
|
||||
function (`W/static_config.rs:562-572`), so the rules change atomically with respect to each other,
|
||||
but not with respect to the scalars (written before and after).
|
||||
2. `reload` clears `WORKSPACE_MATCHING_RULES` and refills it per monitor afterwards (`M/static_config.rs`
|
||||
after `apply_globals`, same on W and K): for the duration of the loop a reader that does not hold the
|
||||
wm lock sees an **empty** list. This is a live partial-update window today.
|
||||
|
||||
With `Settings` the immutable lists are fields of one `Arc` snapshot: readers take no lock, there is no
|
||||
order to follow, and the lock order shrinks to: wm lock, then the two session mutexes
|
||||
(`SESSION_FLOATING_APPLICATIONS`, the regex cache), never nested the other way round.
|
||||
|
||||
## 3. The design
|
||||
|
||||
### 3.1 Crates
|
||||
|
||||
New crate `crates/komorebi-settings` (std plus `parking_lot`; types from `komorebi-config`,
|
||||
`komorebi-protocol` and `komorebi-layouts`; no daemon dependency, so it tests natively):
|
||||
|
||||
```rust
|
||||
pub struct Settings<P> {
|
||||
pub shared: Shared, // the same struct on all three platforms
|
||||
pub platform: P, // Windows: border style, stackbar, hiding/handling behaviour, ...
|
||||
} // KDE: nothing yet (the compositor owns look); macOS: tabbed/titleless apps
|
||||
|
||||
pub struct Shared {
|
||||
pub border: Border, // enabled, width, offset, six colours
|
||||
pub animation: Animation, // global + per-prefix enabled/style/duration, fps; motion_for(prefix)
|
||||
pub defaults: Defaults, // container/workspace padding, resize delta, mouse-follows-focus
|
||||
pub transparency: Transparency, // enabled, alpha (Windows and KDE; macOS keeps the default)
|
||||
pub floating_window_aspect_ratio: AspectRatio,
|
||||
pub layout_defaults: HashMap<DefaultLayout, LayoutDefaultEntry>,
|
||||
pub display_index_preferences: HashMap<usize, String>,
|
||||
}
|
||||
|
||||
pub struct Handle<P> { /* RwLock<Arc<Settings<P>>> + a writer mutex */ }
|
||||
impl<P: Clone> Handle<P> {
|
||||
pub fn snapshot(&self) -> Arc<Settings<P>>; // readers
|
||||
pub fn replace(&self, s: Settings<P>); // whole new value
|
||||
pub fn update<R>(&self, f: impl FnOnce(&mut Settings<P>) -> R) -> R; // copy, edit, swap; writers serialised
|
||||
pub fn scoped<T>(&self, field: fn(&mut Settings<P>) -> &mut T, value: T) -> Scoped<'_, P, T>;
|
||||
}
|
||||
```
|
||||
|
||||
The **platform part** is a plain type parameter `P` (not a trait): each daemon names its struct
|
||||
(`WindowsSettings`, `MacosSettings`, `KdeSettings`) and the handle is `static SETTINGS: LazyLock<Handle<P>>`
|
||||
behind a `settings()` function of the daemon crate. `P` needs only `Clone + Debug`. A trait would add
|
||||
nothing, because the shared code never calls into `P`: only the platform's own subsystems read it. When
|
||||
the daemons become one crate this is `#[cfg(target_os)] type Platform = ...`.
|
||||
|
||||
The lists of rules and the stackbar block move into the platform parts first (they are Windows only or
|
||||
differ); the rule lists join `Shared` in step G7 below once the lock order is retired.
|
||||
|
||||
### 3.2 How readers get a consistent snapshot
|
||||
|
||||
* A reader calls `settings().snapshot()` **once per unit of work** (one render pass of a border, one
|
||||
`motion_for` call, one layout pass, one window eligibility check) and uses that `Arc` for the whole
|
||||
unit. Cost: one uncontended `RwLock` read and an `Arc` clone; no atomics are needed on the hot
|
||||
paths I found (border thread loops once per notification, animator once per frame, rule checks once per
|
||||
event). If a measurement shows one needs it, add an `AtomicBool` *mirror* of that single field written by
|
||||
the same `update`; do not read the mirror and the snapshot for the same decision.
|
||||
* `ArcSwap` was the first idea. It is **not in any of the three lockfiles** (checked), so it would add a
|
||||
dependency to three lockfiles and the flake hashes for no gain at this read rate. `Handle` hides the
|
||||
representation: swapping `RwLock<Arc<_>>` for `ArcSwap<_>` later changes one file.
|
||||
* Writers go through `update`, which holds a mutex while it clones, edits and publishes, so two writers
|
||||
(a `SocketMessage` and a config reload, a theme change and a command) never lose each other's field. The
|
||||
statics lose such updates today only when both write the same field, but a theme change writes nine
|
||||
separate atomics and a command can interleave.
|
||||
* A config load builds the new value and publishes it **once**; a theme change is one `update`.
|
||||
|
||||
### 3.3 Semantics that must survive: reload merges, it does not replace
|
||||
|
||||
`apply_globals` is a field-by-field merge: `if let Some(x) = self.border_width { store }`. A key absent
|
||||
from a reloaded `komorebi.json` **keeps the previous value** (and a command-set value); a few fields are
|
||||
instead reset (listed in section 4, "reset on reload"). A "build a fresh Settings from the file and swap"
|
||||
would reset every absent key to its default. So the migration keeps the merge: `Settings::apply(delta)`
|
||||
is written as the same sequence of `if let Some` over a copy of the **current** snapshot, published once.
|
||||
Replacing instead of merging is a separate, optional BEHAVIOUR change, last in the list.
|
||||
|
||||
### 3.4 The scoped override
|
||||
|
||||
Two places write a setting, do work and put it back: Windows `border.rs:831-851`
|
||||
(`WINDOW_HANDLING_BEHAVIOUR`: load, store `handling`, ..., store `previous`) and KDE
|
||||
`process_command.rs:607-609` (`ANIMATION_ENABLED_GLOBAL.swap(false)`, `add_window_to_container`,
|
||||
`store(restore)`). Both clobber a concurrent change (a reload or a command in between is overwritten with the old value). macOS
|
||||
already has the right pattern: `animation::suspend()` returns a guard that counts and `motion_for` returns
|
||||
`None` while it is held (`M/animation/mod.rs:36-71`). `Handle::scoped` gives the same for any field:
|
||||
it sets the value and, on drop, puts the previous value back **only if the field still holds the
|
||||
override value**, so a change made meanwhile wins. For animations KDE and Windows should adopt
|
||||
macOS's `suspend` counter instead (a field of `Shared::animation`, not a scoped value).
|
||||
|
||||
## 4. Statics whose behaviour would change
|
||||
|
||||
Everything here is a **BEHAVIOUR** change if it is not made to keep today's semantics. Flagged items
|
||||
say what the migration does about each.
|
||||
|
||||
**Partial updates visible mid-reload (today).** `apply_globals` publishes about 28 to 51 values
|
||||
one at a time while the border, animator, reaper and transparency threads keep reading. A border
|
||||
thread can draw once with the new width and the old colours; `motion_for` (macOS) reads enabled,
|
||||
duration and style as three separate lock/atomic reads and can mix two configurations. With `Handle` all
|
||||
readers see the old or the new `Settings`, never a mix: **BEHAVIOUR (intended, can only remove
|
||||
tears)**, on every static of the table. The e2e that would show it is `config_reload`.
|
||||
|
||||
**Reset on reload (must be kept as written):** `LAYOUT_DEFAULTS` (cleared when absent),
|
||||
`FLOATING_WINDOW_TOGGLE_ASPECT_RATIO` (default when absent), `ANIMATION_FPS` (default when `animation` is present
|
||||
without `fps`), `GHOST_MOVEMENT_ENABLED` (W), `STYLE` and `IMPLEMENTATION` (W: default when absent),
|
||||
`STACKBAR_FONT_SIZE` / `STACKBAR_FONT_FAMILY` (W: 0 / None when `stackbar.tabs` is present),
|
||||
`ANIMATION_*_PER_ANIMATION` (cleared when the global form is used) and the rule lists (`apply_globals`
|
||||
clears each only when the new file gives that list; check per list in G7).
|
||||
|
||||
**Keeps the old value when absent (must be kept):** borders (width, offset, radius, enabled, colours),
|
||||
paddings, transparency alpha, hiding and handling behaviour, minimum size, stackbar scalars, display index
|
||||
preferences.
|
||||
|
||||
**Scoped override (3.4):** KDE `ANIMATION_ENABLED_GLOBAL.swap/store` pair and Windows `WINDOW_HANDLING_BEHAVIOUR`
|
||||
pair become guards. A concurrent reload no longer gets clobbered: BEHAVIOUR.
|
||||
|
||||
**Shutdown writes** (`main.rs:367-368`, `window_manager.rs:1445-1446` on W; the Stop handler on K and M): they
|
||||
disable animation permanently before restoring windows. These are plain `update`s, not scoped.
|
||||
|
||||
**`WORKSPACE_MATCHING_RULES` empty window** (2.3): stays in the core until step 9 (session state); not part
|
||||
of `Settings`, so not changed here.
|
||||
|
||||
**Defaults differ per platform** (border width 8/10/10, offset -1/0/0, padding 10/5/5, KDE border radius):
|
||||
`Shared::defaults_for(PlatformDefaults::{WINDOWS, KDE, MACOS})`. Changing any default is user visible and is
|
||||
not part of this step.
|
||||
|
||||
**Threads read the statics without the wm lock:** border thread (all three), W reaper
|
||||
(`HIDING_BEHAVIOUR`), W winevent and window_manager_event threads (rule lists), W transparency manager,
|
||||
macOS animator thread and the per-pid lane threads, macOS border thread. These are the readers whose behaviour a snapshot
|
||||
changes (from "latest value on each read" to "value of the snapshot taken at the start of the unit"); the
|
||||
gap is at most one unit of work.
|
||||
|
||||
## 5. Migration order (least to most risky)
|
||||
|
||||
Each group is one revision per platform tree (or per platform file set), moving the writers and **all**
|
||||
readers of that group together, never dual-writing a static and a field. P = pure refactor (same
|
||||
observable behaviour); B = BEHAVIOUR (marked in the revision body, not landed until its gate ran).
|
||||
|
||||
| step | group | kind | gate |
|
||||
|---|---|---|---|
|
||||
| S0 | the crate and its tests (landed, phase 2) | P | native `cargo test -p komorebi-settings` |
|
||||
| S1 | `DEFAULT_RESIZE_DELTA`, `DEFAULT_MOUSE_FOLLOWS_FOCUS`, `BORDER_OFFSET_ADJUSTMENT`: constants into `PlatformDefaults` | P | KDE `cargo test -p komorebi --lib`, Windows clippy, macOS fake-CC check |
|
||||
| S2 | install `settings()` in each daemon with the platform defaults (no reader yet) | P | same |
|
||||
| S3 | paddings, aspect ratio, layout defaults, display index preferences (wm-lock readers and the reconciliator) | P for the readers; the load writes the new place once: B (tear) | KDE lib tests; Windows `config_reload`, `layouts`, `workspaces` e2e; macOS: reload with changed padding |
|
||||
| S4 | transparency enabled and alpha (W, K) | P | Windows `config_reload` plus the transparency scenario if it exists; KDE lib tests |
|
||||
| S5 | animation (global, per-prefix, fps): `motion_for`, engine, animator; KDE/Windows adopt `suspend()` guards | **B** (tear removed, override semantics) | KDE VM suites that stack windows (`stacks`); Windows animation e2e; **macOS hand-check**: animation on, switch workspace, change `animation.duration` by `komorebic` mid-animation, stack a window |
|
||||
| S6 | border scalars and colours, theme colours as one `update` | **B** (the 6 colour atomics change together) | Windows border e2e (screenshot) and `config_reload`; KDE VM `borders`/look suites; **macOS hand-check**: `border-colour`, `border-width`, theme change, reload with changed border |
|
||||
| S7 | Windows platform part: `HIDING_BEHAVIOUR`, `WINDOW_HANDLING_BEHAVIOUR` (with `scoped`), min size, stackbar block, border style/implementation, ghost movement | **B** (reaper reads a snapshot; override guard) | Windows: `commands`, `config_reload`, `lifecycle`, `lifecycle_hidden`, stackbars, border e2e |
|
||||
| S8 | rule lists into `Shared` (immutable `Arc<RuleSet>`), session floating and regex cache stay mutexes; retire the lock-order comment | **B** (hot path of every window event; deadlock class removed) | Windows `config_reload` (lock order), `commands`, `focus`, `lifecycle`; KDE lib tests plus VM suites; macOS: manage/ignore rules by hand |
|
||||
| S9 | `apply_globals` as one `update` (single publish), and one decision on merge versus replace | **B** | Windows `config_reload`; macOS reload by hand |
|
||||
|
||||
Risk grows with the number of threads that read without the wm lock and with how hot the read is:
|
||||
S3 has none, S5 and S6 have the macOS threads the plan names, S7 has the reaper, S8 is every event.
|
||||
Do S8 only after the Windows lock-order e2e from the `wip-u-kfw` stack has run once on the current
|
||||
tree.
|
||||
|
||||
## 6. What is not in `Settings`
|
||||
|
||||
`SESSION_FLOATING_APPLICATIONS`, `UNMANAGED_WINDOW_IDS`, `HIDDEN_HWNDS`/`HIDDEN_WINDOWS`,
|
||||
`WORKSPACE_MATCHING_RULES`, `REMOVE_TITLEBARS`, `CUSTOM_FFM`,
|
||||
`INITIAL_CONFIGURATION_LOADED`, subscriptions, `*_CHANNEL`s, caches, `BORDER_STATE`: these are session or
|
||||
plumbing state and belong to the model (step 9) or the subsystem. `Settings` is only what the user
|
||||
configures.
|
||||
|
||||
## 7. What landed (phase 2) and findings from writing it
|
||||
|
||||
`crates/komorebi-settings` (native tests, 18 passed): `Settings<P>`, `Handle<P>` (`snapshot`, `replace`,
|
||||
`update`, `scoped`), `Shared` (border, animation with `motion_for`, paddings and constants, transparency,
|
||||
aspect ratio, layout defaults, display index preferences), `PlatformDefaults::{WINDOWS, KDE, MACOS}` and
|
||||
`SharedDelta::apply`, which is `apply_globals` for the shared keys written as a function of the current
|
||||
value. Not yet in the crate: rule lists, theme application as one update, anything platform specific.
|
||||
|
||||
Findings that only showed up while encoding the semantics:
|
||||
|
||||
* `FLOATING_WINDOW_TOGGLE_ASPECT_RATIO` starts at **Widescreen** on all three platforms, but a load
|
||||
whose file has no `floating_window_aspect_ratio` writes **Standard** (`unwrap_or`). So the first
|
||||
reload of a file without the key changes the ratio. `SharedDelta::apply` keeps this; fixing it is a
|
||||
separate user-visible change.
|
||||
* `TRANSPARENCY_ENABLED` is written by the load (`transparency`) and by the toggle command, so it is a
|
||||
setting, not session state (corrected from the first draft of this document's table).
|
||||
* `komorebi-config` warns about an unused import (`crate::defaults`, `static_config.rs:39`) when it is
|
||||
built with `default-features = false`; the settings crate builds it that way. Not touched.
|
||||
* Windows `reload` runs `apply_globals` twice per reload: in `preload` of the new window manager
|
||||
(while the old one is paused) and again in `reload`; both writes become visible to the threads that
|
||||
read without the wm lock. One `update` per load keeps the two visible publishes.
|
||||
|
||||
## 8. S1 and S2 as landed for KDE and macOS, and the Windows patch (not applied)
|
||||
|
||||
KDE and macOS (`wip-u-settings`): S1 (the `DEFAULT_*` statics take their values from
|
||||
`komorebi_settings::shared`, paddings from `PlatformDefaults::{KDE, MACOS}`; the statics keep their
|
||||
names and types) and S2 (`src/settings.rs` with `KdeSettings` / `MacosSettings` and `settings()`;
|
||||
a test pins that the starting settings equal the starting values of the border and default
|
||||
statics). The new crate is a path dependency of both workspaces (manifest, package manifest,
|
||||
`Cargo.lock` +1 package). S3 was **not** started: it moves the writers (`apply_globals`) and the
|
||||
readers in `monitor.rs`, `workspace.rs`, `window.rs`, `process_command.rs`, which the KDE and macOS
|
||||
stacks are editing, and the load would publish once instead of storing key by key, which is the tear
|
||||
removal marked BEHAVIOUR in section 5. It needs the rebase onto the merged stacks and its gate.
|
||||
|
||||
Windows S1/S2, to apply when told (all in the files kfw is changing, so not done):
|
||||
|
||||
1. `komorebi/Cargo.toml`: `komorebi-settings = { path = "../crates/komorebi-settings" }` (the crate is
|
||||
already a root workspace member; `Cargo.lock` gets the dependency edge, no new package).
|
||||
2. `komorebi/src/lib.rs`: `DEFAULT_WORKSPACE_PADDING` / `DEFAULT_CONTAINER_PADDING` start from
|
||||
`PlatformDefaults::WINDOWS.workspace_padding` / `.container_padding` (10, 10);
|
||||
`DEFAULT_RESIZE_DELTA` and `DEFAULT_MOUSE_FOLLOWS_FOCUS` are `komorebi_settings::shared::...`
|
||||
(50, true); add `pub mod settings;`.
|
||||
3. New `komorebi/src/settings.rs`, a copy of the KDE one with `WindowsSettings` (empty) and
|
||||
`PlatformDefaults::WINDOWS`; its pin test compares the paddings, resize delta, mouse-follows-focus,
|
||||
`BORDER_ENABLED`, `BORDER_WIDTH` (8), `BORDER_OFFSET` (-1) and the six colours, and leaves out
|
||||
`border.radius` (Windows has no `BORDER_RADIUS`).
|
||||
4. Gate: Windows clippy (`-D warnings`) and `cargo test -p komorebi --lib`; `tools/e2e-needed` will
|
||||
say YES (the crate is in the closure of `komorebi.exe`) so one e2e run is owed, but behaviour is
|
||||
unchanged.
|
||||
@@ -0,0 +1,325 @@
|
||||
# One `komorebi`, one `komorebic`, one `komorebi-bar`
|
||||
|
||||
Goal: three packages and three binaries that build on Windows, KDE (Linux) and macOS, the platform
|
||||
chosen by `cfg(target_os)` (generics, `cfg_select!`, exhaustive `match`; no macros as a design tool).
|
||||
This file records a spike (throwaway revisions on bookmark `wip-u-pkg-spike`, titled `spike:`; nothing
|
||||
landed on `wip-main`), the layout it recommends, the migration order, the risks and the gates.
|
||||
|
||||
Measured on `wip-main` 633e7453 with the light gates only (`nice -n 19`, 3 jobs, persistent target
|
||||
dirs, `COMMIT_HASH=dev`); no nix build, no e2e, no VM. macOS is type-checked with the fake CC only: it
|
||||
was never linked or run.
|
||||
|
||||
## What the spike did
|
||||
|
||||
1. `spike: one root workspace ...` (rev `yuuyzssl`): the 10 KDE and macOS member crates became members
|
||||
of the root workspace. Their two `[workspace]` manifests were deleted, their `workspace = true`
|
||||
dependencies were written out, packages renamed (`komorebi-linux`, `komorebic-linux`,
|
||||
`komorebi-client-linux`, `komorebi-hotkeys-linux`, `version-linux`, and `-macos` for the macOS
|
||||
ones including `komorebi-bar-macos`); binary and lib names stayed (`[lib] name`, `[[bin]] name`) so
|
||||
no source file changed. One `Cargo.lock`.
|
||||
2. `spike: unified komorebic package by #[path] includes`: the root `komorebic` package became the
|
||||
unified one. `src/main.rs` is a `cfg_select!` over `target_os` that includes the old Windows
|
||||
`main.rs` (moved to `windows.rs`) and, by `#[path]`, the KDE and macOS `main.rs` where they live.
|
||||
Dependencies are in `[target.'cfg(...)'.dependencies]` tables. Edits to the old files: `fn main`
|
||||
became `pub fn main`; `crate::HOME_DIR` became `super::HOME_DIR` in KDE `hotkeys.rs`.
|
||||
3. `spike: target-gate the macOS daemon crate`: objc2 and friends under
|
||||
`[target.'cfg(target_os = "macos")'.dependencies]` plus `#![cfg(target_os = "macos")]` in
|
||||
`komorebi-macos`, to test `cargo check --workspace` on a foreign target.
|
||||
|
||||
The script that did step 1 is `S/pkg-spike.py` (scratchpad; rerunnable on a fresh `wip-main`).
|
||||
|
||||
## Results
|
||||
|
||||
| question | result |
|
||||
|---|---|
|
||||
| One lock resolves? | Yes. 859 packages (root) -> 900. All 859 Windows entries unchanged. The KDE lock had 644 and the macOS lock 786 entries, so +41 only. Crates with more than one version: 81 -> 95 (the `sysinfo` 0.38/0.39/0.40, `dirs` 6/7, `parking_lot` 0.12/0.13, `shadow-rs` 1/2, `netdev` 0.40/0.46 splits coexist; nothing needs unifying). |
|
||||
| Locked versions kept? | Not exactly: crates that only KDE or macOS use were re-resolved to newest: `zbus`/`zbus_macros` 6.1 -> 6.2, `zbus_utils`, `zruntime`, `sysinfo` 0.40.0 -> 0.40.1, `libz-sys`, `unicode-width`. Pin with `cargo update zbus@6.2.0 --precise 6.1.0` (needs the `name@version` spelling) if the VM suites must see the old versions. |
|
||||
| Windows `cargo check -p komorebic --target x86_64-pc-windows-msvc` (nix develop) | passes, 14.8 s wall warm (11.2 s compile); unified `komorebic` also passes, 7 s. |
|
||||
| KDE native `cargo check -p komorebi-linux -p komorebic-linux` | passes; 1 m 38 s cold into a fresh lite target dir. Unified `komorebic` on Linux passes (1.4 s after touch) when openssl is available (see risk 2). |
|
||||
| KDE tests unchanged | `cargo test -p komorebi-linux --lib`: 294 passed. `--test schemas -- --test-threads=1`: 5 passed. All four KDE packages, `--no-fail-fast`, 1 m 26 s warm: 879 passed, 1 failed. The failure is `tests/version.rs`: `komorebi-linux 0.1.0` instead of `komorebi 0.1.0` (clap takes the command name from `CARGO_PKG_NAME`); a renamed package needs `#[command(name = "komorebi")]`. Nothing else depends on the package name. |
|
||||
| macOS fake-CC `cargo check --target aarch64-apple-darwin -p komorebi-macos -p komorebic-macos -p komorebi-bar-macos --all-targets --locked` | passes, 32 s warm (6 warnings in the bar, as before). Unified `komorebic` on macOS passes, 12 s. Type-check only. |
|
||||
| Feature unification | Resolver 2 keeps `komorebi-layouts/darwin` off Windows: `cargo tree -p komorebic --target x86_64-pc-windows-msvc -e features -i komorebi-layouts` shows only `default`, the macOS package shows `darwin`. This holds only while the package that asks for `darwin` is not in the same build; `cargo ... --workspace` on one target selects them all (see risk 3). |
|
||||
| `cargo check --workspace` for Windows (what clippy, fmt, nextest and crane do today) | FAILS in 52 s: `objc2 only works on Apple platforms`. With objc2 target-gated and `#![cfg(target_os = "macos")]`, `komorebi-macos` compiles empty on Windows (spike 3), so the fix is to gate every foreign-platform crate, not to exclude them. Done for one crate only. |
|
||||
| Same dependency key, different path per target | REJECTED by cargo: `Dependency 'komorebi-client' has different source paths depending on the build target`. Same for `version`. So the unified package must use one key per platform (`komorebi-client-linux`, `komorebi-client-macos`, ...) and the platform module must alias it (`extern crate komorebi_client_linux as komorebi_client;` at the root, or `use komorebi_linux as komorebi;` at the top of each platform module). The spike used `extern crate`. |
|
||||
| Compile time | No extra cost on a target: a build selects its own target's dependency tables, so Windows never sees zbus or objc2 and Linux never sees `windows`. The only added cost is resolution (`cargo metadata` 6.5 s with the network). |
|
||||
|
||||
## Option A or B
|
||||
|
||||
Measured size of what would have to move into `#[cfg(target_os)] mod` of one crate (Option B):
|
||||
daemon `crate::` paths: Windows 669, KDE 447, macOS 587 (35,149 / 32,932 / 34,505 lines, 3 lib+bin
|
||||
crates each with their own tests and a `komorebi-client` that re-exports them); bar 111 / 90 (7,710 /
|
||||
5,551 lines); `komorebic` 0 (1,467 / 807 / 1,537 lines).
|
||||
|
||||
Recommendation:
|
||||
|
||||
- `komorebic`: B. One package `komorebic`, `src/main.rs` = `cfg_select!` choosing `mod windows`,
|
||||
`mod linux`, `mod macos` (each the present `main.rs`, `hotkeys.rs` for Linux), one clap command name,
|
||||
target-gated dependencies. Zero `crate::` rewrites, so the files move whole. This is what the spike
|
||||
built (with `#[path]` instead of the final moves).
|
||||
- `komorebi-bar`: B, as `bar-unification.md` already plans (`src/bar/{mod,windows,macos}.rs`,
|
||||
`os/{windows,macos}.rs`); needs the bar stack integrated first.
|
||||
- `komorebi` (daemon): A. Keep three library crates, rename to `komorebi-windows`, `komorebi-linux`,
|
||||
`komorebi-macos` (distinct lib names, `komorebi_windows` etc.), each gated to its OS
|
||||
(`#![cfg(target_os = ...)]`, target-gated dependencies, so `--workspace` works everywhere), each
|
||||
keeping its own `crate::` paths and its own tests (KDE's 881 run unchanged but for the name). One
|
||||
thin `komorebi` binary package: `src/main.rs` is a `cfg_select!` over the three daemons'
|
||||
`main` bodies (each daemon's present `main.rs` becomes `pub fn run()` of its library). Option B for
|
||||
the daemon would be a rewrite of about 1,700 `crate::` paths (669 + 447 + 587) for no behavioural gain, and it would
|
||||
put KDE's tests and the VM suites on a moving target.
|
||||
- `komorebi-client`: one package with `src/{windows,linux,macos}.rs` (211 / 394 / 225 lines, almost all
|
||||
`pub use komorebi::...`), each starting with `use komorebi_windows as komorebi;` and so on.
|
||||
|
||||
## Migration order
|
||||
|
||||
Every revision keeps the three existing trees building with their present gates. "Gate" says what
|
||||
must pass before it counts as landed: `C` compile (fast-check, the three checks), `S` the CLI oracle
|
||||
(`S/step4/oracle-check.sh`, byte-identical for all three platforms; it reads `komorebic/src/main.rs`
|
||||
of each tree, so it needs its paths updated in the revision that moves a file), `N` nix evaluation
|
||||
(`nix flake show`), `NB` a nix build of the checks in an idle window, `E` Windows e2e, `V` KDE VM `fast`.
|
||||
|
||||
0. Prerequisites, no moves (any time, small): explicit `#[command(name = ...)]` on the three CLIs;
|
||||
`build.rs` of `komorebic` stops fetching `applications.json` over the network (the file is checked
|
||||
in; a build script that needs `reqwest`, and so openssl, on Linux is what stopped the unified
|
||||
package building natively); `pub fn main` and `crate::` -> `super::` in the `komorebic` files.
|
||||
Gates C, S. Not behaviour.
|
||||
1. Package renames inside the present workspaces (KDE: `komorebi-linux` and so on; macOS the same;
|
||||
Windows daemon `komorebi-windows` last), with `[lib] name` and `[[bin]] name` unchanged. Gates C,
|
||||
N; the Windows daemon rename is `E` (the executable's inputs change).
|
||||
2. Workspace merge: delete `komorebi-for-kde/Cargo.toml` and `komorebi-for-mac/Cargo.toml`, add their
|
||||
crates to the root members, write out the inherited dependencies, one lock (+41 packages), add
|
||||
`.cargo/config.toml` with `[env] COMMIT_HASH` (KDE's file moves from `komorebi-for-kde/.cargo`;
|
||||
cargo reads it from the working directory upward only). Same revision gates every foreign crate
|
||||
(`#![cfg(target_os)]`, target-gated dependencies) so `--workspace` works on all targets. Gates C on
|
||||
all three, plus KDE tests unchanged. Cargo-wise this is one revision (the spike's script); it must
|
||||
not be split without breaking `--locked`.
|
||||
3. Flakes, same integration as 2 (nix cannot be half-merged): the root flake builds all three; the two
|
||||
nested flakes already take the whole repository as their source (`lib.mkOutputs`), so they become
|
||||
thin: `workspaceArgs` change from a subdirectory workspace to `-p <package>`. The KDE source filter
|
||||
must list the new member directories. Gates N, then `NB` (deps, clippy, nextest of each system),
|
||||
then `V`.
|
||||
4. `komorebic` unified by `#[path]` (spike 2, minus the hacks): new `komorebic/src/main.rs`, target
|
||||
tables, aliases. The old `komorebic-linux`/`-macos` packages stay until step 5 so the old names
|
||||
work. Gates C, S, and `E` for `komorebic.exe` (the Windows main moves to `windows.rs`).
|
||||
5. `komorebic` real moves, one platform per revision: `komorebi-for-kde/komorebic/src/*` to
|
||||
`komorebic/src/linux/`, the macOS one to `komorebic/src/macos/`, tests with them, then delete the old
|
||||
packages. Pure moves (jj does not follow moves, so each is a delete/modify conflict if another stack
|
||||
touches those files; today none does). Gates C, S, tests.
|
||||
6. `komorebi-client` unified (modules per platform), same pattern. Gates C, E (Windows client is in the
|
||||
closure of `komorebi.exe`).
|
||||
7. `komorebi-bar` unified after the bar stack integrates: `bar-unification.md` plan; Windows bar
|
||||
screenshot gate and the Mac hand check are owed by that stack.
|
||||
8. Daemon: three libraries gated to their OS and one thin `komorebi` package with the `cfg_select!`
|
||||
`main`. KDE `main.rs` and the Windows `main.rs` become `run()` in their libraries. Gates C, `E`, `V`,
|
||||
Mac hand check.
|
||||
9. Cutover: one flake output per binary, old per-platform package names, `justfile`, CI
|
||||
(`.github/workflows`), docs paths, release version (0.1.42 / 0.1.0 / 0.1.1 become one).
|
||||
|
||||
## Risks
|
||||
|
||||
1. One lock for three platforms: a `cargo update` for one platform moves the others; crane's dummy
|
||||
source includes every member's manifest and the lock, so any dependency change rebuilds the
|
||||
dependency derivation of all three systems (today a KDE-only lock change cannot touch Windows). The
|
||||
`COMMIT_HASH`-constant fix (flow finding 1) must be in first or every commit rebuilds ~1,000 crates.
|
||||
2. `build.rs` fetching over the network is not usable in a unified package (openssl on Linux); see step 0.
|
||||
3. `--workspace` commands (clippy, fmt, nextest, crane) select every member on every target: every
|
||||
foreign crate must compile empty (spike 3 shows it works for the daemon; only one crate was
|
||||
converted). Without it, feature unification would also turn `komorebi-layouts/darwin` on for
|
||||
Windows in a whole-workspace build.
|
||||
4. The one-key-one-path rule forces distinct dependency keys and aliases per platform module.
|
||||
5. `CARGO_BUILD_TARGET` is set by the root `nix develop` shell, so native Linux checks must run outside it
|
||||
(as `fast-check` does) or pass `--target x86_64-unknown-linux-gnu`.
|
||||
6. Command names and `--version` text come from `CARGO_PKG_NAME`/the version crate: pin them or the KDE
|
||||
`version` test and the docs oracle change. `shadow-rs` major versions differ (2 on Windows, 1 on
|
||||
macOS); the unified `komorebic` build script can only use one.
|
||||
7. The KDE VM suites rebuild on any change to the KDE closure: the merge is one full `V` run.
|
||||
8. Tests that use `CARGO_BIN_EXE_*` or relative paths (`tests/schemas.rs` writes beside the manifest)
|
||||
must move with their package; not exercised beyond the spike.
|
||||
|
||||
## Gates by step, in short
|
||||
|
||||
Compile only: 0, 4 (but see `E`), 5, 6 at the Rust level; nix evaluation only: 3 until built. Needs
|
||||
e2e (Windows guest): anything that changes an input of `komorebi.exe`, `komorebic.exe` or the client
|
||||
(`tools/e2e-needed` says: 1 for the Windows daemon, 4, 6, 8). Needs the KDE VM: 2, 3, 8. Needs a Mac,
|
||||
by hand: 4, 7, 8, 9.
|
||||
|
||||
Mac hand check (type-check proves none of it): `komorebic --version` and `--help` show the macOS
|
||||
command set and the name `komorebic`; `komorebic start` finds and starts `komorebi`, `stop` stops it;
|
||||
`komorebic docgen` unchanged; `komorebi --version`; the daemon starts, tiles and `komorebic state`
|
||||
answers; `komorebi-bar` opens, `--schema` equals `komorebi-for-mac/schema.bar.json`;
|
||||
the embedded `applications.json` is the macOS one;
|
||||
`otool -L` of each binary lists no Windows or Linux-only library.
|
||||
|
||||
## Conflicts with the open stacks (sequence in a quiet period)
|
||||
|
||||
Paths touched by each bookmark relative to `wip-main`:
|
||||
|
||||
| bookmark | touches | moves in this plan that conflict |
|
||||
|---|---|---|
|
||||
| wip-u-kfw | `komorebi/src/**`, `crates/komorebi-backend/**` | daemon rename and any move of `komorebi/` (steps 1 Windows, 8) |
|
||||
| wip-u-kfm | `komorebi-for-mac/komorebi/src/**`, `crates/komorebi-backend/**` | macOS daemon rename and moves (1, 8) |
|
||||
| wip-u-kfde | `komorebi-for-kde/komorebi/{src,tests}/**` | KDE daemon rename (1) and moves (8); tests are edited |
|
||||
| wip-u-bar | `Cargo.lock`, `komorebi-for-mac/Cargo.lock`, `komorebi-bar/src/**`, `komorebi-for-mac/komorebi-bar/src/**`, `crates/komorebi-bar-core` | step 2 (locks, manifests) and step 7 |
|
||||
| wip-u-settings | `Cargo.toml`, `Cargo.lock`, `crates/komorebi-settings` | step 2 (root manifest and lock) |
|
||||
| wip-u-nix | `flake.nix`, `komorebi-for-kde/flake.nix`, `komorebi-for-kde/nix/**` | step 3 |
|
||||
|
||||
Not touched by any open stack, so safe now: `komorebic/**` (all three), the `komorebic` tests, the
|
||||
`version` crates, the `komorebi-client` crates (steps 0, 4, 5, 6 are free of conflicts except the lock
|
||||
and root manifest lines of step 2/4). Hard conflicts: every `Cargo.lock` and the root `Cargo.toml`
|
||||
`members` list (resolve by taking one side and running `cargo metadata`; never hand-merge a lock),
|
||||
`flake.nix` lines for the extracted binaries. Suggested order: integrate kfw, kfm, kfde, bar, settings,
|
||||
nix first; then steps 0 and 1; then 2 and 3 as one integration; the rest in any order, daemon (8)
|
||||
last.
|
||||
|
||||
## What landed
|
||||
|
||||
Only this file. The spike revisions are on `wip-u-pkg-spike` and can be dropped or cherry-picked.
|
||||
Step 0 and the renames were not landed because they only pay off with step 2, which edits the locks
|
||||
and manifests that three open stacks edit.
|
||||
|
||||
## State of the migration (bookmark wip-u-pkg-mig, on wip-u-pkg-base)
|
||||
|
||||
Done, in this order (each revision keeps the three trees building; gates are in the revision messages):
|
||||
|
||||
0. `applications.json` committed (build.rs fetch gone), explicit clap names, the KDE closure list fixed.
|
||||
1. KDE and macOS packages suffixed (`komorebi-linux`, `komorebic-macos`, ...); Windows daemon `komorebi-windows`.
|
||||
2. One root workspace, one lock (901 packages), `default-members` is the Windows set.
|
||||
3. `nix/workspace-src.nix`: each flake builds its platform's source plus stubs of every other member,
|
||||
`-p` per platform.
|
||||
4. `komorebic` is one package with a `cfg_select!` over three CLI modules; the help text of each platform
|
||||
is a literal (it used to come from the package description).
|
||||
5. The Linux and macOS CLI files moved into `komorebic/src/{linux,macos}` (pure moves, one per revision);
|
||||
the KDE `komorebic` tests are `komorebic/tests/linux_*.rs`. The old `komorebic-linux` and
|
||||
`komorebic-macos` packages are shims that include the moved files; they have no tests of their own.
|
||||
6. `komorebi-client`: the three socket codes made equal (Connection on all), then one package whose
|
||||
`lib.rs` is a `cfg_select!` re-exporting `windows.rs`, `linux.rs` or `macos.rs`; old
|
||||
`komorebi-client-linux`/`-macos` are shims; `komorebic` uses the one client.
|
||||
|
||||
Measured by evaluation (no build): an edit of a Windows-only crate or of `komorebic/src/windows.rs` or
|
||||
`komorebi-client/src/windows.rs` changes the Windows derivations and no kfde derivation; an edit of a Linux
|
||||
file changes kfde and no Windows derivation; an edit of a macOS file changes neither. The cache isolation of
|
||||
the three trees survived the merge and the unified packages.
|
||||
|
||||
Costs and limits found on the way:
|
||||
- The stubbed source is a derivation that crane reads at evaluation (`readDir` in `mkDummySrc`), so
|
||||
evaluating another system's attributes needs a builder for that system (decision D-pkg-1).
|
||||
`nix flake show --all-systems` and aarch64-darwin drvPaths do not evaluate on a Linux host.
|
||||
- cargo deny, cargo fmt and taplo run over the merged workspace: deny is called with
|
||||
`--workspace --exclude <the other platforms' packages>` and the tree's own deny.toml, fmt gets `-p`;
|
||||
none of them has been built.
|
||||
- cargo allows one path per dependency key: the daemon crates keep distinct keys and the modules alias them
|
||||
(`extern crate komorebi_linux as komorebi`, `use crate::komorebi_linux as komorebi`). A dependency with
|
||||
no `package =` is named by its lib name, not by its key: write `package = "<same name>"` when the key
|
||||
must be the extern name.
|
||||
- Building both `komorebic` and `komorebic-linux` in one cargo command writes the same binary name twice.
|
||||
- Comments and docs that name `komorebic/src/main.rs`, `komorebic/tests/*.rs` or the KDE client paths
|
||||
(check.rs, ARCHITECTURE.md, scripts/compare-gen.py, the VM check suite) still carry the old paths; they
|
||||
are text in files whose change would rebuild the KDE derivations.
|
||||
|
||||
## Step 7 for the bar (B0-B3 executed, B4 not)
|
||||
|
||||
State: `crates/komorebi-bar-core` holds the shared code (config, widgets, `BarPlatform`, schema views); the
|
||||
two shells are `komorebi-bar` (Windows) and `komorebi-for-mac/komorebi-bar` (package `komorebi-bar-macos`),
|
||||
see `bar-unification.md` for what stays per platform. Both use `komorebi-bar-core` (one version) and
|
||||
differ in `main.rs`, `bar.rs`, `os.rs`, `widgets/{komorebi,network,widget,mod}.rs`; Windows adds
|
||||
`widgets/{keyboard,media,systray}.rs`. `crate::` occurs 111 times (Windows) and 90 (macOS).
|
||||
|
||||
B0. Prerequisite (done, step 6): one `komorebi-client`. In `komorebi-for-mac/komorebi-bar/Cargo.toml` change
|
||||
`komorebi-client = { package = "komorebi-client-macos", path = "../komorebi-client", ... }` to
|
||||
`komorebi-client = { path = "../../komorebi-client", default-features = false }`; the feature
|
||||
`schemars` already forwards to `komorebi-client/default`. Gate: macOS fake-CC check of
|
||||
`komorebi-bar-macos`; one revision.
|
||||
|
||||
B1. Windows bar becomes a module, in place. Create `komorebi-bar/src/windows/`; `git mv`/`jj` move
|
||||
`bar.rs config.rs os.rs widgets/` into it and `main.rs` to `windows/mod.rs` (`mod bar; mod config; mod
|
||||
os; mod widgets;` stay as they are, `fn main` becomes `pub fn main`). In the moved files replace
|
||||
`crate::` by `crate::windows::` (sed, 111 sites; do not touch `komorebi_bar_core::`). New
|
||||
`komorebi-bar/src/main.rs`: `mod windows; fn main() -> color_eyre::eyre::Result<()> { windows::main() }`.
|
||||
Pure move plus one mechanical edit, two revisions (move, then the paths). Gate: Windows clippy
|
||||
`-D warnings`; the bar screenshot gate (owed since the bar stack) and `e2e-needed` says NO for the bar.
|
||||
|
||||
B2. macOS bar the same, in its own package: `komorebi-for-mac/komorebi-bar/src/macos/`,
|
||||
`crate::` -> `crate::macos::` (90 sites), `main.rs` = `mod macos; fn main() { macos::main() }`. Gate:
|
||||
macOS fake-CC check; the Mac hand check.
|
||||
|
||||
B3. Merge into one package (one revision, with its flake edit):
|
||||
- Move `komorebi-for-mac/komorebi-bar/src/macos` to `komorebi-bar/src/macos`.
|
||||
- `komorebi-bar/src/main.rs`: `cfg_select! { target_os = "windows" => { mod windows; use windows as
|
||||
platform; } target_os = "macos" => { mod macos; use macos as platform; } }` and `fn main() { platform::main() }`.
|
||||
- `komorebi-bar/Cargo.toml`: common `[dependencies]` = what both manifests share (`komorebi-bar-core`,
|
||||
`komorebi-client`, `komorebi-themes`, `chrono`, `chrono-tz`, `clap`, `color-eyre`, `crossbeam-channel`,
|
||||
`dirs`, `dunce`, `eframe`, `egui-phosphor`, `font-loader`, `hotwatch`, `image`, `lazy_static`, `num*`,
|
||||
`parking_lot`, `random_word`, `reqwest`, `schemars`, `serde`, `serde_json`, `sysinfo`, `tracing*`);
|
||||
`[target.'cfg(windows)'.dependencies]`: `egui_extras`, `netdev = "0.46"`, `regex`, `systray-util`,
|
||||
`tokio`, `which`, `windows`, `windows-core`, both `windows-icons` revisions;
|
||||
`[target.'cfg(target_os = "macos")'.dependencies]`: `netdev = "0.40"`, `icns`, `objc2`,
|
||||
`objc2-app-kit` (the feature list of the macOS manifest), `raw-window-handle`. The dependency versions
|
||||
of the two manifests differ only for `netdev` (0.46 / 0.40), which cargo accepts per target.
|
||||
- Old package `komorebi-bar-macos` stays: `komorebi-for-mac/komorebi-bar/src/main.rs` is
|
||||
`#[path = "../../../komorebi-bar/src/macos/mod.rs"] mod macos; fn main() { macos::main() }`
|
||||
(the moved code names `crate::macos::`, which this root provides).
|
||||
- Flakes: the macOS flake `-p komorebi-bar` instead of `-p komorebi-bar-macos`, its source filter takes
|
||||
`komorebi-bar/{Cargo.toml,src/main.rs,src/macos/**}` and `isReal` `komorebi-bar`; the root filter
|
||||
leaves `komorebi-bar/src/macos` out and the KDE flake needs nothing (it never had a bar; the stub
|
||||
is the member's manifest). The `fmt`/`deny` lists drop `komorebi-bar` from the macOS exclusions.
|
||||
- Schemas: `schema.bar.json` and `komorebi-for-mac/schema.bar.json` stay; the oracle test in
|
||||
`komorebi-bar-core` reads both. `cargo run -p komorebi-bar -- --schema` prints the view of the target OS.
|
||||
Gates: Windows clippy, macOS fake-CC check of `komorebi-bar` and `komorebi-bar-macos`, the schema oracle
|
||||
(`cargo test -p komorebi-bar-core`), nix evaluation, the isolation test of the evaluation (an edit of
|
||||
`komorebi-bar/src/windows/` must not change a macOS derivation and the reverse). Owed: the Windows bar
|
||||
screenshot, the Mac hand check.
|
||||
|
||||
B4. Converge the remaining differences one revision each, each BEHAVIOUR on one platform and needing its
|
||||
screenshot or Mac check: `widgets/komorebi.rs` frame margins, `network.rs`, then the platform seams in
|
||||
`bar.rs`/`main.rs` behind `BarPlatform` hooks (list in `bar-unification.md`).
|
||||
|
||||
## Owed from the coordinator (heavy gates, idle host; everything below was evaluated, none built)
|
||||
|
||||
At bookmark `wip-u-pkg-mig`:
|
||||
|
||||
```
|
||||
tools/gate-lock run --class heavy --label "pkg checks" --est 25 -- nix build -L --no-link \
|
||||
.#checks.x86_64-linux.komorebi-workspace-clippy .#checks.x86_64-linux.komorebi-workspace-deny \
|
||||
.#checks.x86_64-linux.komorebi-workspace-fmt .#checks.x86_64-linux.komorebi-workspace-toml-fmt \
|
||||
.#checks.x86_64-linux.komorebi-workspace-nextest
|
||||
tools/gate-lock run --class heavy --label "pkg kfde checks" --est 40 -- nix build -L --no-link \
|
||||
.#checks.x86_64-linux.kfde-komorebi-workspace-{clippy,doc,deny,fmt,toml-fmt,nextest} \
|
||||
.#checks.x86_64-linux.kfde-schema-fresh .#packages.x86_64-linux.kfde-komorebic .#packages.x86_64-linux.kfde-komorebi
|
||||
nix build -L .#packages.x86_64-linux.komorebic .#packages.x86_64-linux.komorebi
|
||||
```
|
||||
|
||||
then the KDE VM `fast` suites (the KDE package derivations changed), and the Windows e2e gate
|
||||
(`tools/e2e-needed` says YES: `komorebi-windows`, `komorebic` and `komorebi-client` changed); on a Mac or
|
||||
a darwin builder `nix build -L .#packages.aarch64-darwin.kfm-komorebic .#packages.aarch64-darwin.kfm-komorebi
|
||||
.#packages.aarch64-darwin.kfm-komorebi-bar` and the `kfm-` checks. By hand on a Mac: `komorebic --help`,
|
||||
`--version`, `quickstart`, `start`, `stop`, `state`, `docgen`; `komorebi-bar` still builds from the old
|
||||
package name. If deny, fmt or taplo fail in the merged workspace, the fix is in the `cargoDenyExtraArgs`,
|
||||
`cargoExtraArgs` of the three flakes, not in the code.
|
||||
|
||||
### Bar: what was done and what was left
|
||||
|
||||
B0-B3 are done as revisions of `wip-u-pkg-mig` (client edge, Windows module, macOS module, merge). Edits
|
||||
were mechanical: `crate::` to `crate::windows::` / `crate::macos::`, one more `../` in the `include_str!`
|
||||
paths, the unused root re-export of `komorebi_bar_core::platform` dropped. `komorebi-bar-macos` remains as
|
||||
a shim. The schema gate is `S/bar2/regen.sh` (now reads `src/windows` and `src/macos`): both bars' schema
|
||||
files regenerate byte-identical on Linux. B4 was not done: the remaining differences are rendering
|
||||
(frame margins in `widgets/komorebi.rs`), `network.rs` behaviour and the window seams in `bar.rs`/`main.rs`,
|
||||
none of which can be shown to be mechanical without a screen.
|
||||
|
||||
## For the Mac Mini (aarch64-darwin, native)
|
||||
|
||||
Run on the revisions of `wip-u-pkg-mig` at or after the stated one, from the repository root:
|
||||
|
||||
```
|
||||
cargo build --locked -p komorebic -p komorebi-macos -p komorebi-bar # after "one komorebi-bar package"
|
||||
cargo build --locked -p komorebic-macos -p komorebi-bar-macos -p komorebi-client-macos # the shims still build
|
||||
cargo clippy --locked -p komorebic -p komorebi-client -p komorebi-bar -p komorebi-bar-core -p komorebi-macos --all-targets -- -D warnings
|
||||
cargo test --locked -p komorebi-macos -p komorebic -p komorebi-client -p komorebi-bar-core -p komorebi-bar
|
||||
target/debug/komorebic --help; target/debug/komorebic --version; target/debug/komorebic docgen --output /tmp/docs-mac
|
||||
target/debug/komorebi-bar --schema | cmp - komorebi-for-mac/schema.bar.json
|
||||
```
|
||||
|
||||
Note: there is no package named `komorebi` yet: the daemon is `komorebi-macos` on macOS and `komorebi-windows` on Windows (binary name `komorebi` for both; the single `komorebi` package is step 8). Never write `-p komorebi`. Do not build `komorebic` and `komorebic-macos` in the same command (same binary name). The lint fix `fix(bar-core): WidgetConfig::supported as matches!` is needed for clippy to pass.
|
||||
The macOS checks that matter by revision:
|
||||
`refactor(komorebic): move the macOS CLI ...` (komorebic, quickstart, start, stop), `refactor(client): one
|
||||
komorebi-client ...` (the client tests in `komorebi-client/src/macos.rs`), and `refactor(bar): one
|
||||
komorebi-bar package ...` (the bar opens, `--schema`). Everything in `docs/dev/macos-handcheck.md` still applies.
|
||||
@@ -215,12 +215,16 @@
|
||||
|
||||
msvcEnv = mkMsvcEnv { inherit pkgs windowsSdk; };
|
||||
|
||||
src = pkgs.lib.cleanSourceWith {
|
||||
# the files of the Windows crates; the KDE and macOS crates are in the same Cargo workspace and
|
||||
# are added as stubs (nix/workspace-src.nix), so that an edit of one changes nothing here
|
||||
real = pkgs.lib.cleanSourceWith {
|
||||
src = ./.;
|
||||
filter =
|
||||
path: type:
|
||||
# the other platforms' trees have their own workspaces and are built by their own outputs
|
||||
# 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)
|
||||
&& (
|
||||
(craneLib.filterCargoSources path type)
|
||||
|| (pkgs.lib.hasInfix "/docs/" path)
|
||||
@@ -229,13 +233,25 @@
|
||||
);
|
||||
};
|
||||
|
||||
src = import ./nix/workspace-src.nix {
|
||||
inherit pkgs real;
|
||||
repoRoot = ./.;
|
||||
isReal = member: !(pkgs.lib.hasPrefix "komorebi-for-" member);
|
||||
};
|
||||
|
||||
commonArgs = {
|
||||
inherit src version;
|
||||
cargoLock = "${real}/Cargo.lock";
|
||||
cargoToml = "${real}/Cargo.toml";
|
||||
# vendored from the filtered source, not the stubbed one: no build is needed to evaluate
|
||||
cargoVendorDir = craneLib.vendorCargoDeps { src = real; };
|
||||
strictDeps = true;
|
||||
# komorebic/build.rs downloads applications.json if it is missing, which
|
||||
# is not possible in the sandbox, so provide the pinned copy instead
|
||||
# applications.json is committed now; this copies the pinned asc input over it, so that the
|
||||
# embedded file is the pinned one even when the committed copy is older
|
||||
preBuild = "mkdir -p komorebic && cp ${inputs.asc}/applications.json komorebic/applications.json";
|
||||
COMMIT_HASH = commit;
|
||||
# a constant, so that the dependencies and every check are the same
|
||||
# derivations for every commit; only fullBuild stamps the real one
|
||||
COMMIT_HASH = "nix-check";
|
||||
|
||||
# build inputs for cross-compilation
|
||||
nativeBuildInputs = [
|
||||
@@ -278,6 +294,7 @@
|
||||
individualCrateArgs
|
||||
// {
|
||||
pname = "komorebi-workspace";
|
||||
COMMIT_HASH = commit;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -296,6 +313,7 @@
|
||||
inherit
|
||||
craneLib
|
||||
src
|
||||
real
|
||||
individualCrateArgs
|
||||
fullBuild
|
||||
msvcEnv
|
||||
@@ -493,14 +511,37 @@
|
||||
|
||||
komorebi-workspace-fmt = build.craneLib.cargoFmt {
|
||||
inherit (build) src;
|
||||
pname = "komorebi-workspace";
|
||||
version = "0.1.0";
|
||||
cargoToml = "${build.real}/Cargo.toml";
|
||||
};
|
||||
|
||||
komorebi-workspace-toml-fmt = build.craneLib.taploFmt {
|
||||
src = pkgs.lib.sources.sourceFilesBySuffices build.src [ ".toml" ];
|
||||
src = pkgs.lib.sources.sourceFilesBySuffices build.real [ ".toml" ];
|
||||
};
|
||||
|
||||
# cargo deny sees every member of the workspace: leave out the KDE and macOS packages, which
|
||||
# have their own policy (komorebi-for-*/deny.toml) in their own checks
|
||||
komorebi-workspace-deny = build.craneLib.cargoDeny {
|
||||
inherit (build) src;
|
||||
pname = "komorebi-workspace";
|
||||
version = "0.1.0";
|
||||
cargoToml = "${build.real}/Cargo.toml";
|
||||
cargoLock = "${build.real}/Cargo.lock";
|
||||
cargoDenyExtraArgs =
|
||||
"--workspace "
|
||||
+ pkgs.lib.concatMapStringsSep " " (p: "--exclude ${p}") [
|
||||
"komorebi-linux"
|
||||
"komorebic-linux"
|
||||
"komorebi-client-linux"
|
||||
"komorebi-hotkeys"
|
||||
"version-linux"
|
||||
"komorebi-macos"
|
||||
"komorebic-macos"
|
||||
"komorebi-client-macos"
|
||||
"komorebi-bar-macos"
|
||||
"version-macos"
|
||||
];
|
||||
};
|
||||
|
||||
komorebi-workspace-nextest = build.craneLib.cargoNextest build.individualCrateArgs;
|
||||
|
||||
@@ -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") | .version'`
|
||||
version := `cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "komorebi-windows") | .version'`
|
||||
|
||||
schemapub:
|
||||
rm -Force komorebi-schema
|
||||
|
||||
+26
-6
@@ -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 = [
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
use crate::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::BAR_HEIGHT;
|
||||
use crate::DEFAULT_PADDING;
|
||||
use crate::KomorebiEvent;
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
use crate::MONITOR_LEFT;
|
||||
use crate::MONITOR_RIGHT;
|
||||
use crate::MONITOR_TOP;
|
||||
use crate::config::KomobarConfig;
|
||||
use crate::config::MonitorConfigOrIndex;
|
||||
use crate::config::Position;
|
||||
use crate::config::PositionConfig;
|
||||
use crate::config::get_individual_spacing;
|
||||
use crate::render::Color32Ext;
|
||||
use crate::render::Grouping;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::render::RenderExt;
|
||||
use crate::widgets::komorebi::Komorebi;
|
||||
use crate::widgets::komorebi::MonitorInfo;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::widgets::widget::WidgetConfig;
|
||||
use crate::macos::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::macos::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::macos::BAR_HEIGHT;
|
||||
use crate::macos::DEFAULT_PADDING;
|
||||
use crate::macos::KomorebiEvent;
|
||||
use crate::macos::MAX_LABEL_WIDTH;
|
||||
use crate::macos::MONITOR_LEFT;
|
||||
use crate::macos::MONITOR_RIGHT;
|
||||
use crate::macos::MONITOR_TOP;
|
||||
use crate::macos::config::KomobarConfig;
|
||||
use crate::macos::config::MonitorConfigOrIndex;
|
||||
use crate::macos::config::Position;
|
||||
use crate::macos::config::PositionConfig;
|
||||
use crate::macos::config::get_individual_spacing;
|
||||
use crate::macos::render::Color32Ext;
|
||||
use crate::macos::render::Grouping;
|
||||
use crate::macos::render::RenderConfig;
|
||||
use crate::macos::render::RenderExt;
|
||||
use crate::macos::widgets::komorebi::Komorebi;
|
||||
use crate::macos::widgets::komorebi::MonitorInfo;
|
||||
use crate::macos::widgets::widget::BarWidget;
|
||||
use crate::macos::widgets::widget::WidgetConfig;
|
||||
use crate::macos::widgets::widget::WidgetConfigExt;
|
||||
use crossbeam_channel::Receiver;
|
||||
use crossbeam_channel::TryRecvError;
|
||||
use eframe::egui::Align;
|
||||
@@ -0,0 +1 @@
|
||||
pub use komorebi_bar_core::config::*;
|
||||
@@ -0,0 +1,387 @@
|
||||
mod bar;
|
||||
mod config;
|
||||
mod os;
|
||||
pub use komorebi_bar_core::render;
|
||||
pub use komorebi_bar_core::selected_frame;
|
||||
pub use komorebi_bar_core::ui;
|
||||
mod widgets;
|
||||
|
||||
use crate::macos::bar::Komobar;
|
||||
use crate::macos::config::KomobarConfig;
|
||||
use crate::macos::config::Position;
|
||||
use crate::macos::config::PositionConfig;
|
||||
use clap::Parser;
|
||||
use color_eyre::eyre;
|
||||
use config::MonitorConfigOrIndex;
|
||||
use eframe::egui::ViewportBuilder;
|
||||
use font_loader::system_fonts;
|
||||
use hotwatch::EventKind;
|
||||
use hotwatch::Hotwatch;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_client::SubscribeOptions;
|
||||
use komorebi_client::replace_env_in_path;
|
||||
use objc2::MainThreadMarker;
|
||||
use objc2_app_kit::NSApplication;
|
||||
use objc2_app_kit::NSApplicationActivationPolicy;
|
||||
use objc2_app_kit::NSView;
|
||||
use raw_window_handle::HasWindowHandle;
|
||||
use raw_window_handle::RawWindowHandle;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
pub use komorebi_bar_core::statics::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(name = "komorebi-bar", author, about, version)]
|
||||
struct Opts {
|
||||
/// Print the JSON schema of the configuration file and exit
|
||||
#[clap(long)]
|
||||
schema: bool,
|
||||
/// Print a list of fonts available on this system and exit
|
||||
#[clap(long)]
|
||||
fonts: bool,
|
||||
/// Path to a JSON or YAML configuration file
|
||||
#[clap(short, long)]
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
config: Option<PathBuf>,
|
||||
/// Write an example komorebi.bar.json to disk
|
||||
#[clap(long)]
|
||||
quickstart: bool,
|
||||
/// Print a list of aliases that can be renamed to canonical variants
|
||||
#[clap(long)]
|
||||
#[clap(hide = true)]
|
||||
aliases: bool,
|
||||
}
|
||||
|
||||
pub enum KomorebiEvent {
|
||||
Notification(komorebi_client::Notification),
|
||||
Reconnect,
|
||||
}
|
||||
|
||||
pub fn main() -> eyre::Result<()> {
|
||||
komorebi_bar_core::platform::install(&os::MacBar);
|
||||
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
#[cfg(feature = "schemars")]
|
||||
if opts.schema {
|
||||
print!(
|
||||
"{}",
|
||||
komorebi_bar_core::schema::generated_text::<KomobarConfig>(
|
||||
komorebi_bar_core::schema::SchemaPlatform::MacOs
|
||||
)
|
||||
);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if opts.fonts {
|
||||
for font in system_fonts::query_all() {
|
||||
println!("{font}");
|
||||
}
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LIB_BACKTRACE", "1");
|
||||
}
|
||||
}
|
||||
|
||||
color_eyre::install()?;
|
||||
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LOG", "info");
|
||||
}
|
||||
}
|
||||
|
||||
tracing::subscriber::set_global_default(
|
||||
tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.finish(),
|
||||
)?;
|
||||
|
||||
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
||||
|_| {
|
||||
dirs::home_dir()
|
||||
.expect("there is no home directory")
|
||||
.join(".config")
|
||||
.join("komorebi")
|
||||
},
|
||||
|home_path| {
|
||||
let home = home_path.replace_env();
|
||||
|
||||
assert!(
|
||||
home.is_dir(),
|
||||
"$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory"
|
||||
);
|
||||
|
||||
home
|
||||
},
|
||||
);
|
||||
|
||||
if opts.quickstart {
|
||||
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 {}",
|
||||
home_dir.display()
|
||||
);
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let default_config_path = home_dir.join("komorebi.bar.json");
|
||||
|
||||
let config_path = opts.config.or_else(|| {
|
||||
default_config_path
|
||||
.is_file()
|
||||
.then_some(default_config_path.clone())
|
||||
});
|
||||
|
||||
let mut config = match config_path {
|
||||
None => {
|
||||
let komorebi_bar_json =
|
||||
include_str!("../../../komorebi-for-mac/docs/komorebi.bar.example.json").to_string();
|
||||
|
||||
std::fs::write(&default_config_path, komorebi_bar_json)?;
|
||||
tracing::info!(
|
||||
"created example configuration file: {}",
|
||||
default_config_path.display()
|
||||
);
|
||||
|
||||
KomobarConfig::read(&default_config_path)?
|
||||
}
|
||||
Some(ref config) => {
|
||||
if !opts.aliases {
|
||||
tracing::info!("found configuration file: {}", config.display());
|
||||
}
|
||||
|
||||
KomobarConfig::read(config)?
|
||||
}
|
||||
};
|
||||
|
||||
let config_path = config_path.unwrap_or(default_config_path);
|
||||
|
||||
if opts.aliases {
|
||||
KomobarConfig::aliases(&std::fs::read_to_string(&config_path)?);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let state = serde_json::from_str::<komorebi_client::State>(&komorebi_client::send_query(
|
||||
&SocketMessage::State,
|
||||
)?)?;
|
||||
|
||||
let (usr_monitor_index, work_area_offset) = match &config.monitor {
|
||||
Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => {
|
||||
(monitor_config.index, monitor_config.work_area_offset)
|
||||
}
|
||||
Some(MonitorConfigOrIndex::Index(idx)) => (*idx, None),
|
||||
None => (0, None),
|
||||
};
|
||||
let monitor_index = state
|
||||
.monitor_usr_idx_map
|
||||
.get(&usr_monitor_index)
|
||||
.map_or(usr_monitor_index, |i| *i);
|
||||
|
||||
MONITOR_RIGHT.store(
|
||||
state.monitors.elements()[monitor_index].size.right,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_TOP.store(
|
||||
state.monitors.elements()[monitor_index].size.top,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_LEFT.store(
|
||||
state.monitors.elements()[monitor_index].size.left,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_INDEX.store(monitor_index, Ordering::SeqCst);
|
||||
|
||||
// use monitor.size for the actual monitor bounds (top-left origin in global coordinates)
|
||||
// the window level kCGBackstopMenuLevel positions the bar behind the menu bar
|
||||
match config.position {
|
||||
None => {
|
||||
config.position = Some(PositionConfig {
|
||||
start: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
}),
|
||||
end: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
}),
|
||||
})
|
||||
}
|
||||
Some(ref mut position) => {
|
||||
if position.start.is_none() {
|
||||
position.start = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
});
|
||||
}
|
||||
|
||||
if position.end.is_none() {
|
||||
position.end = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let viewport_builder = ViewportBuilder::default()
|
||||
.with_decorations(false)
|
||||
.with_transparent(true)
|
||||
.with_has_shadow(false)
|
||||
.with_taskbar(false);
|
||||
|
||||
let native_options = eframe::NativeOptions {
|
||||
viewport: viewport_builder,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if let Some(rect) = &work_area_offset {
|
||||
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(monitor_index, *rect))?;
|
||||
tracing::info!("work area offset applied to monitor: {}", monitor_index);
|
||||
}
|
||||
|
||||
let (tx_gui, rx_gui) = crossbeam_channel::unbounded();
|
||||
let (tx_config, rx_config) = crossbeam_channel::unbounded();
|
||||
|
||||
let mut hotwatch = Hotwatch::new()?;
|
||||
let config_path_cl = config_path.clone();
|
||||
|
||||
hotwatch.watch(config_path, move |event| match event.kind {
|
||||
EventKind::Modify(_) | EventKind::Remove(_) => match KomobarConfig::read(&config_path_cl) {
|
||||
Ok(updated) => {
|
||||
tracing::info!("configuration file updated: {}", config_path_cl.display());
|
||||
|
||||
if let Err(error) = tx_config.send(updated) {
|
||||
tracing::error!("could not send configuration update to gui: {error}")
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
})?;
|
||||
|
||||
tracing::info!("watching configuration file for changes");
|
||||
|
||||
eframe::run_native(
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
unsafe {
|
||||
let app = NSApplication::sharedApplication(MainThreadMarker::new_unchecked());
|
||||
app.setActivationPolicy(NSApplicationActivationPolicy::Accessory);
|
||||
}
|
||||
|
||||
if let Ok(handle) = cc.window_handle()
|
||||
&& let RawWindowHandle::AppKit(appkit_handle) = handle.as_raw() {
|
||||
// kCGBackstopMenuLevel = -20 (behind menu bar, at notch level)
|
||||
const K_CG_BACKSTOP_MENU_LEVEL: isize = -20;
|
||||
|
||||
unsafe {
|
||||
let ns_view: &NSView = appkit_handle.ns_view.cast().as_ref();
|
||||
if let Some(ns_window) = ns_view.window() {
|
||||
ns_window.setLevel(K_CG_BACKSTOP_MENU_LEVEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
ctx_repainter.request_repaint();
|
||||
});
|
||||
|
||||
let ctx_komorebi = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let subscriber_name = format!("komorebi-bar-{}", random_word::get(random_word::Lang::En));
|
||||
|
||||
let listener = komorebi_client::subscribe_with_options(&subscriber_name, SubscribeOptions {
|
||||
filter_state_changes: true,
|
||||
})
|
||||
.expect("could not subscribe to komorebi notifications");
|
||||
|
||||
tracing::info!("subscribed to komorebi notifications: \"{}\"", subscriber_name);
|
||||
|
||||
for client in listener.incoming() {
|
||||
match client {
|
||||
Ok(subscription) => {
|
||||
let mut buffer = Vec::new();
|
||||
let mut reader = BufReader::new(subscription);
|
||||
|
||||
// this is when we know a shutdown has been sent
|
||||
if matches!(reader.read_to_end(&mut buffer), Ok(0)) {
|
||||
tracing::info!("disconnected from komorebi");
|
||||
|
||||
// keep trying to reconnect to komorebi
|
||||
while komorebi_client::send_message(
|
||||
&SocketMessage::AddSubscriberSocket(subscriber_name.clone()),
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
tracing::info!("reconnected to komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Reconnect) {
|
||||
tracing::error!("could not send komorebi reconnect event to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
continue;
|
||||
}
|
||||
|
||||
match String::from_utf8(buffer) {
|
||||
Ok(notification_string) => {
|
||||
match serde_json::from_str::<komorebi_client::Notification>(
|
||||
¬ification_string,
|
||||
) {
|
||||
Ok(notification) => {
|
||||
tracing::debug!("received notification from komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Notification(notification)) {
|
||||
tracing::error!("could not send komorebi notification update to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("could not deserialize komorebi notification: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
"komorebi notification string was invalid utf8: {error}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Box::new(Komobar::new(cc, rx_gui, rx_config, config)))
|
||||
}),
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::Error::msg(error.to_string()))
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::macos::widgets::ImageIcon;
|
||||
use egui_phosphor::regular::CALENDAR;
|
||||
use komorebi_bar_core::platform::BarPlatform;
|
||||
use komorebi_bar_core::platform::SystemTool;
|
||||
use komorebi_client::SocketMessage;
|
||||
use std::io;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -21,6 +23,12 @@ impl BarPlatform for MacBar {
|
||||
.spawn(),
|
||||
// explorer.exe does not exist on macOS: this is what the update widget does today
|
||||
SystemTool::Url(url) => Command::new("explorer.exe").args([url]).spawn(),
|
||||
SystemTool::StorageLocation(label) => {
|
||||
let parts: Vec<&str> = label.split(' ').collect();
|
||||
let path = parts[..parts.len() - 1].join(" ");
|
||||
|
||||
Command::new("open").args([path]).spawn()
|
||||
}
|
||||
}
|
||||
.map(|_| ())
|
||||
}
|
||||
@@ -32,4 +40,21 @@ impl BarPlatform for MacBar {
|
||||
fn calendar_icon(&self) -> &'static str {
|
||||
CALENDAR
|
||||
}
|
||||
|
||||
fn exec_shell_command(&self, _command: &str) -> color_eyre::Result<()> {
|
||||
// the macOS bar has no shell session: the mouse commands are not supported here
|
||||
Err(io::Error::new(io::ErrorKind::Unsupported, "no shell session on macOS").into())
|
||||
}
|
||||
|
||||
fn send_komorebi_message(&self, message: &SocketMessage) -> io::Result<()> {
|
||||
komorebi_client::send_message(message)
|
||||
}
|
||||
|
||||
fn send_komorebi_batch(&self, messages: Vec<SocketMessage>) -> io::Result<()> {
|
||||
komorebi_client::send_batch(messages)
|
||||
}
|
||||
|
||||
fn command_icon(&self, _command: &str) -> Option<ImageIcon> {
|
||||
None
|
||||
}
|
||||
}
|
||||
+23
-105
@@ -1,14 +1,22 @@
|
||||
use super::ImageIcon;
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
use crate::MONITOR_INDEX;
|
||||
use crate::config::DisplayFormat;
|
||||
use crate::config::DisplayFormat::*;
|
||||
use crate::config::WorkspacesDisplayFormat;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::ui::CustomUi;
|
||||
use crate::widgets::komorebi_layout::KomorebiLayout;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::macos::MAX_LABEL_WIDTH;
|
||||
use crate::macos::MONITOR_INDEX;
|
||||
use crate::macos::config::DisplayFormat;
|
||||
use crate::macos::config::DisplayFormat::*;
|
||||
use crate::macos::config::WorkspacesDisplayFormat;
|
||||
use crate::macos::render::RenderConfig;
|
||||
use crate::macos::selected_frame::SelectableFrame;
|
||||
use crate::macos::ui::CustomUi;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfigurationSwitcherConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiFocusedContainerConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayoutConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLockedContainerConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspaceLayerConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspacesConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayout;
|
||||
use crate::macos::widgets::komorebi_layout::KomorebiLayoutExt;
|
||||
use crate::macos::widgets::widget::BarWidget;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
@@ -40,10 +48,7 @@ use komorebi_client::State;
|
||||
use komorebi_client::Window;
|
||||
use komorebi_client::Workspace;
|
||||
use komorebi_client::WorkspaceLayer;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
@@ -52,95 +57,6 @@ use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget configuration
|
||||
pub struct KomorebiConfig {
|
||||
/// Configure the Workspaces widget
|
||||
pub workspaces: Option<KomorebiWorkspacesConfig>,
|
||||
/// Configure the Layout widget
|
||||
pub layout: Option<KomorebiLayoutConfig>,
|
||||
/// Configure the Workspace Layer widget
|
||||
pub workspace_layer: Option<KomorebiWorkspaceLayerConfig>,
|
||||
/// Configure the Focused Container widget
|
||||
#[serde(alias = "focused_window")]
|
||||
pub focused_container: Option<KomorebiFocusedContainerConfig>,
|
||||
/// Configure the Locked Container widget
|
||||
pub locked_container: Option<KomorebiLockedContainerConfig>,
|
||||
/// Configure the Configuration Switcher widget
|
||||
pub configuration_switcher: Option<KomorebiConfigurationSwitcherConfig>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget workspaces configuration
|
||||
pub struct KomorebiWorkspacesConfig {
|
||||
/// Enable the Komorebi Workspaces widget
|
||||
pub enable: bool,
|
||||
/// Hide workspaces without any windows
|
||||
pub hide_empty_workspaces: bool,
|
||||
/// Display format of the workspace
|
||||
pub display: Option<WorkspacesDisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget layout configuration
|
||||
pub struct KomorebiLayoutConfig {
|
||||
/// Enable the Komorebi Layout widget
|
||||
pub enable: bool,
|
||||
/// List of layout options
|
||||
pub options: Option<Vec<KomorebiLayout>>,
|
||||
/// Display format of the current layout
|
||||
pub display: Option<DisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget workspace layer configuration
|
||||
pub struct KomorebiWorkspaceLayerConfig {
|
||||
/// Enable the Komorebi Workspace Layer widget
|
||||
pub enable: bool,
|
||||
/// Display format of the current layer
|
||||
pub display: Option<DisplayFormat>,
|
||||
/// Show the widget event if the layer is Tiling
|
||||
pub show_when_tiling: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget focused container configuration
|
||||
pub struct KomorebiFocusedContainerConfig {
|
||||
/// Enable the Komorebi Focused Container widget
|
||||
pub enable: bool,
|
||||
/// DEPRECATED: use 'display' instead (Show the icon of the currently focused container)
|
||||
pub show_icon: Option<bool>,
|
||||
/// Display format of the currently focused container
|
||||
pub display: Option<DisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget locked container configuration
|
||||
pub struct KomorebiLockedContainerConfig {
|
||||
/// Enable the Komorebi Locked Container widget
|
||||
pub enable: bool,
|
||||
/// Display format of the current locked state
|
||||
pub display: Option<DisplayFormat>,
|
||||
/// Show the widget event if the layer is unlocked
|
||||
pub show_when_unlocked: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget configuration switcher configuration
|
||||
pub struct KomorebiConfigurationSwitcherConfig {
|
||||
/// Enable the Komorebi Configurations widget
|
||||
pub enable: bool,
|
||||
/// A map of display friendly name => path to configuration.json
|
||||
pub configurations: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl From<&KomorebiConfig> for Komorebi {
|
||||
fn from(cfg: &KomorebiConfig) -> Self {
|
||||
let configuration_switcher = cfg.configuration_switcher.clone().map(|mut cs| {
|
||||
@@ -474,7 +390,7 @@ impl WorkspacesBar {
|
||||
.show(ui, |ui| {
|
||||
let (response, painter) = ui.allocate_painter(self.icon_size, Sense::hover());
|
||||
let stroke: Stroke = Stroke::new(
|
||||
1.0,
|
||||
1.0_f32,
|
||||
if ws.is_selected {
|
||||
ctx.style().visuals.selection.stroke.color
|
||||
} else {
|
||||
@@ -530,7 +446,9 @@ impl FocusedContainerBar {
|
||||
if !value.enable {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Handle legacy setting - convert show_icon to display format
|
||||
#[allow(deprecated)]
|
||||
let format = value
|
||||
.display
|
||||
.unwrap_or(if value.show_icon.unwrap_or(false) {
|
||||
@@ -643,7 +561,7 @@ impl WorkspaceLayerBar {
|
||||
if matches!(layer, WorkspaceLayer::Tiling) {
|
||||
let (response, painter) = ui.allocate_painter(size, Sense::hover());
|
||||
let color = ctx.style().visuals.selection.stroke.color;
|
||||
let stroke = Stroke::new(1.0, color);
|
||||
let stroke = Stroke::new(1.0_f32, color);
|
||||
let mut rect = response.rect;
|
||||
let corner = CornerRadius::same((rect.width() * 0.1) as u8);
|
||||
rect = rect.shrink(stroke.width);
|
||||
@@ -666,7 +584,7 @@ impl WorkspaceLayerBar {
|
||||
} else {
|
||||
let (response, painter) = ui.allocate_painter(size, Sense::hover());
|
||||
let color = ctx.style().visuals.selection.stroke.color;
|
||||
let stroke = Stroke::new(1.0, color);
|
||||
let stroke = Stroke::new(1.0_f32, color);
|
||||
let mut rect = response.rect;
|
||||
let corner = CornerRadius::same((rect.width() * 0.1) as u8);
|
||||
rect = rect.shrink(stroke.width);
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
pub use komorebi_bar_core::widgets::applications;
|
||||
pub use komorebi_bar_core::widgets::battery;
|
||||
pub use komorebi_bar_core::widgets::cpu;
|
||||
pub use komorebi_bar_core::widgets::date;
|
||||
pub mod komorebi;
|
||||
pub use komorebi_bar_core::widgets::komorebi_layout;
|
||||
pub use komorebi_bar_core::widgets::memory;
|
||||
pub mod network;
|
||||
pub use komorebi_bar_core::widgets::storage;
|
||||
pub use komorebi_bar_core::widgets::time;
|
||||
pub use komorebi_bar_core::widgets::update;
|
||||
pub mod widget;
|
||||
|
||||
pub use komorebi_bar_core::widgets::icons::ImageIcon;
|
||||
+13
-47
@@ -1,8 +1,10 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::macos::bar::Alignment;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkConfig;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkSelectConfig;
|
||||
use crate::macos::config::LabelPrefix;
|
||||
use crate::macos::render::RenderConfig;
|
||||
use crate::macos::selected_frame::SelectableFrame;
|
||||
use crate::macos::widgets::widget::BarWidget;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
@@ -12,8 +14,6 @@ use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use num_derive::FromPrimitive;
|
||||
use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
@@ -24,48 +24,14 @@ use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Networks;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Network widget configuration
|
||||
pub struct NetworkConfig {
|
||||
/// Enable the Network widget
|
||||
pub enable: bool,
|
||||
/// Show total received and transmitted activity
|
||||
#[serde(alias = "show_total_data_transmitted")]
|
||||
pub show_total_activity: bool,
|
||||
/// Show received and transmitted activity
|
||||
#[serde(alias = "show_network_activity")]
|
||||
pub show_activity: bool,
|
||||
/// Show default interface
|
||||
pub show_default_interface: Option<bool>,
|
||||
/// Characters to reserve for received and transmitted activity
|
||||
#[serde(alias = "network_activity_fill_characters")]
|
||||
pub activity_left_padding: Option<usize>,
|
||||
/// Data refresh interval in seconds
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||
pub data_refresh_interval: Option<u64>,
|
||||
/// Display label prefix
|
||||
pub label_prefix: Option<LabelPrefix>,
|
||||
/// Select when the value is over a limit (1MiB is 1048576 bytes (1024*1024))
|
||||
pub auto_select: Option<NetworkSelectConfig>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Network select configuration
|
||||
pub struct NetworkSelectConfig {
|
||||
/// Select the total received data when it's over this value
|
||||
pub total_received_over: Option<u64>,
|
||||
/// Select the total transmitted data when it's over this value
|
||||
pub total_transmitted_over: Option<u64>,
|
||||
/// Select the received data when it's over this value
|
||||
pub received_over: Option<u64>,
|
||||
/// Select the transmitted data when it's over this value
|
||||
pub transmitted_over: Option<u64>,
|
||||
}
|
||||
|
||||
impl From<NetworkConfig> for Network {
|
||||
fn from(value: NetworkConfig) -> Self {
|
||||
if value.default_interface_options.is_some() {
|
||||
tracing::warn!(
|
||||
"the network widget option `default_interface_options` is not supported on macOS and is ignored"
|
||||
);
|
||||
}
|
||||
|
||||
let default_refresh_interval = 10;
|
||||
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
use crate::macos::widgets::applications::Applications;
|
||||
use crate::macos::widgets::battery::Battery;
|
||||
use crate::macos::widgets::cpu::Cpu;
|
||||
use crate::macos::widgets::date::Date;
|
||||
use crate::macos::widgets::komorebi::Komorebi;
|
||||
use crate::macos::widgets::memory::Memory;
|
||||
use crate::macos::widgets::network::Network;
|
||||
use crate::macos::widgets::storage::Storage;
|
||||
use crate::macos::widgets::time::Time;
|
||||
use crate::macos::widgets::update::Update;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::Ui;
|
||||
|
||||
pub use komorebi_bar_core::widgets::widget::BarWidget;
|
||||
pub use komorebi_bar_core::widgets::widget::WidgetConfig;
|
||||
use komorebi_bar_core::render::RenderConfig;
|
||||
|
||||
/// Stands in for a widget that macOS cannot run; `WidgetConfig::enabled` is false for those, so
|
||||
/// this is never built from a configuration that the bar loads.
|
||||
struct Unsupported;
|
||||
|
||||
impl BarWidget for Unsupported {
|
||||
fn render(&mut self, _ctx: &Context, _ui: &mut Ui, _config: &mut RenderConfig) {}
|
||||
}
|
||||
|
||||
/// Turns a widget configuration into the widget that renders it.
|
||||
pub trait WidgetConfigExt {
|
||||
fn as_boxed_bar_widget(&self) -> Box<dyn BarWidget>;
|
||||
}
|
||||
|
||||
impl WidgetConfigExt for WidgetConfig {
|
||||
fn as_boxed_bar_widget(&self) -> Box<dyn BarWidget> {
|
||||
match self {
|
||||
WidgetConfig::Applications(config) => Box::new(Applications::from(config)),
|
||||
WidgetConfig::Battery(config) => Box::new(Battery::from(*config)),
|
||||
WidgetConfig::Cpu(config) => Box::new(Cpu::from(*config)),
|
||||
WidgetConfig::Date(config) => Box::new(Date::from(config.clone())),
|
||||
WidgetConfig::Komorebi(config) => Box::new(Komorebi::from(config)),
|
||||
WidgetConfig::Memory(config) => Box::new(Memory::from(*config)),
|
||||
WidgetConfig::Network(config) => Box::new(Network::from(*config)),
|
||||
WidgetConfig::Storage(config) => Box::new(Storage::from(*config)),
|
||||
WidgetConfig::Time(config) => Box::new(Time::from(config.clone())),
|
||||
WidgetConfig::Update(config) => Box::new(Update::from(*config)),
|
||||
WidgetConfig::Keyboard(_) | WidgetConfig::Media(_) | WidgetConfig::Systray(_) => {
|
||||
Box::new(Unsupported)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-393
@@ -1,400 +1,17 @@
|
||||
mod bar;
|
||||
mod config;
|
||||
mod os;
|
||||
pub use komorebi_bar_core::platform;
|
||||
pub use komorebi_bar_core::render;
|
||||
pub use komorebi_bar_core::selected_frame;
|
||||
pub use komorebi_bar_core::ui;
|
||||
mod widgets;
|
||||
//! `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`.
|
||||
|
||||
use crate::bar::Komobar;
|
||||
use crate::config::KomobarConfig;
|
||||
use crate::config::Position;
|
||||
use crate::config::PositionConfig;
|
||||
use clap::Parser;
|
||||
use config::MonitorConfigOrIndex;
|
||||
use eframe::egui::ViewportBuilder;
|
||||
use font_loader::system_fonts;
|
||||
use hotwatch::EventKind;
|
||||
use hotwatch::Hotwatch;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_client::SubscribeOptions;
|
||||
use komorebi_client::replace_env_in_path;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Foundation::LPARAM;
|
||||
use windows::Win32::System::Threading::GetCurrentProcessId;
|
||||
use windows::Win32::System::Threading::GetCurrentThreadId;
|
||||
use windows::Win32::UI::HiDpi::DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
|
||||
use windows::Win32::UI::HiDpi::SetProcessDpiAwarenessContext;
|
||||
use windows::Win32::UI::WindowsAndMessaging::EnumThreadWindows;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
|
||||
use windows_core::BOOL;
|
||||
|
||||
pub use komorebi_bar_core::statics::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author, about, version)]
|
||||
struct Opts {
|
||||
/// Print the JSON schema of the configuration file and exit
|
||||
#[clap(long)]
|
||||
schema: bool,
|
||||
/// Print a list of fonts available on this system and exit
|
||||
#[clap(long)]
|
||||
fonts: bool,
|
||||
/// Path to a JSON or YAML configuration file
|
||||
#[clap(short, long)]
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
config: Option<PathBuf>,
|
||||
/// Write an example komorebi.bar.json to disk
|
||||
#[clap(long)]
|
||||
quickstart: bool,
|
||||
/// Print a list of aliases that can be renamed to canonical variants
|
||||
#[clap(long)]
|
||||
#[clap(hide = true)]
|
||||
aliases: bool,
|
||||
}
|
||||
|
||||
extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||
unsafe {
|
||||
let mut process_id = 0;
|
||||
GetWindowThreadProcessId(hwnd, Some(&mut process_id));
|
||||
|
||||
if process_id == GetCurrentProcessId() {
|
||||
*(lparam.0 as *mut HWND) = hwnd;
|
||||
BOOL::from(false) // Stop enumeration
|
||||
} else {
|
||||
BOOL::from(true) // Continue enumeration
|
||||
}
|
||||
cfg_select! {
|
||||
target_os = "windows" => {
|
||||
mod windows;
|
||||
use windows as platform;
|
||||
}
|
||||
}
|
||||
|
||||
fn process_hwnd() -> Option<isize> {
|
||||
unsafe {
|
||||
let mut hwnd = HWND::default();
|
||||
let _ = EnumThreadWindows(
|
||||
GetCurrentThreadId(),
|
||||
Some(enum_window),
|
||||
LPARAM(&mut hwnd as *mut HWND as isize),
|
||||
);
|
||||
|
||||
if hwnd.0 as isize == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(hwnd.0 as isize)
|
||||
}
|
||||
target_os = "macos" => {
|
||||
mod macos;
|
||||
use macos as platform;
|
||||
}
|
||||
}
|
||||
|
||||
pub enum KomorebiEvent {
|
||||
Notification(Box<komorebi_client::Notification>),
|
||||
Reconnect,
|
||||
}
|
||||
|
||||
fn main() -> color_eyre::Result<()> {
|
||||
komorebi_bar_core::platform::install(&os::WindowsBar);
|
||||
|
||||
unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) }?;
|
||||
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
#[cfg(feature = "schemars")]
|
||||
if opts.schema {
|
||||
let bar_config = schemars::schema_for!(KomobarConfig);
|
||||
let schema = serde_json::to_string_pretty(&bar_config)?;
|
||||
|
||||
println!("{schema}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if opts.fonts {
|
||||
for font in system_fonts::query_all() {
|
||||
println!("{font}");
|
||||
}
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LIB_BACKTRACE", "1");
|
||||
}
|
||||
}
|
||||
|
||||
color_eyre::install()?;
|
||||
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LOG", "info");
|
||||
}
|
||||
}
|
||||
|
||||
tracing::subscriber::set_global_default(
|
||||
tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.finish(),
|
||||
)?;
|
||||
|
||||
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
||||
|_| dirs::home_dir().expect("there is no home directory"),
|
||||
|home_path| {
|
||||
let home = home_path.replace_env();
|
||||
|
||||
assert!(
|
||||
home.is_dir(),
|
||||
"$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory"
|
||||
);
|
||||
|
||||
home
|
||||
},
|
||||
);
|
||||
|
||||
if opts.quickstart {
|
||||
let komorebi_bar_json = include_str!("../../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 {}",
|
||||
home_dir.display()
|
||||
);
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let default_config_path = home_dir.join("komorebi.bar.json");
|
||||
|
||||
let config_path = opts.config.or_else(|| {
|
||||
default_config_path
|
||||
.is_file()
|
||||
.then_some(default_config_path.clone())
|
||||
});
|
||||
|
||||
let mut config = match config_path {
|
||||
None => {
|
||||
let komorebi_bar_json =
|
||||
include_str!("../../docs/komorebi.bar.example.json").to_string();
|
||||
|
||||
std::fs::write(&default_config_path, komorebi_bar_json)?;
|
||||
tracing::info!(
|
||||
"created example configuration file: {}",
|
||||
default_config_path.display()
|
||||
);
|
||||
|
||||
KomobarConfig::read(&default_config_path)?
|
||||
}
|
||||
Some(ref config) => {
|
||||
if !opts.aliases {
|
||||
tracing::info!("found configuration file: {}", config.display());
|
||||
}
|
||||
|
||||
KomobarConfig::read(config)?
|
||||
}
|
||||
};
|
||||
|
||||
let config_path = config_path.unwrap_or(default_config_path);
|
||||
|
||||
if opts.aliases {
|
||||
KomobarConfig::aliases(&std::fs::read_to_string(&config_path)?);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let state = serde_json::from_str::<komorebi_client::State>(&komorebi_client::send_query(
|
||||
&SocketMessage::State,
|
||||
)?)?;
|
||||
|
||||
let (usr_monitor_index, work_area_offset) = match &config.monitor {
|
||||
Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => {
|
||||
(monitor_config.index, monitor_config.work_area_offset)
|
||||
}
|
||||
Some(MonitorConfigOrIndex::Index(idx)) => (*idx, None),
|
||||
None => (0, None),
|
||||
};
|
||||
|
||||
let monitor_index = state
|
||||
.monitor_usr_idx_map
|
||||
.get(&usr_monitor_index)
|
||||
.map_or(usr_monitor_index, |i| *i);
|
||||
|
||||
MONITOR_RIGHT.store(
|
||||
state.monitors.elements()[monitor_index].size.right,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_TOP.store(
|
||||
state.monitors.elements()[monitor_index].size.top,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_LEFT.store(
|
||||
state.monitors.elements()[monitor_index].size.left,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_INDEX.store(monitor_index, Ordering::SeqCst);
|
||||
|
||||
match config.position {
|
||||
None => {
|
||||
config.position = Some(PositionConfig {
|
||||
start: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
}),
|
||||
end: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
}),
|
||||
})
|
||||
}
|
||||
Some(ref mut position) => {
|
||||
if position.start.is_none() {
|
||||
position.start = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
});
|
||||
}
|
||||
|
||||
if position.end.is_none() {
|
||||
position.end = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let viewport_builder = ViewportBuilder::default()
|
||||
.with_decorations(false)
|
||||
.with_transparent(true)
|
||||
.with_taskbar(false);
|
||||
|
||||
let native_options = eframe::NativeOptions {
|
||||
viewport: viewport_builder,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if let Some(rect) = &work_area_offset {
|
||||
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(monitor_index, *rect))?;
|
||||
tracing::info!("work area offset applied to monitor: {}", monitor_index);
|
||||
}
|
||||
|
||||
let (tx_gui, rx_gui) = crossbeam_channel::unbounded();
|
||||
let (tx_config, rx_config) = crossbeam_channel::unbounded();
|
||||
|
||||
let mut hotwatch = Hotwatch::new()?;
|
||||
let config_path_cl = config_path.clone();
|
||||
|
||||
hotwatch.watch(config_path, move |event| match event.kind {
|
||||
EventKind::Modify(_) | EventKind::Remove(_) => match KomobarConfig::read(&config_path_cl) {
|
||||
Ok(updated) => {
|
||||
tracing::info!("configuration file updated: {}", config_path_cl.display());
|
||||
|
||||
if let Err(error) = tx_config.send(updated) {
|
||||
tracing::error!("could not send configuration update to gui: {error}")
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
})?;
|
||||
|
||||
tracing::info!("watching configuration file for changes");
|
||||
|
||||
eframe::run_native(
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
ctx_repainter.request_repaint();
|
||||
});
|
||||
|
||||
let ctx_komorebi = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let subscriber_name = format!("komorebi-bar-{}", random_word::get(random_word::Lang::En));
|
||||
|
||||
let listener = komorebi_client::subscribe_with_options(&subscriber_name, SubscribeOptions {
|
||||
filter_state_changes: true,
|
||||
})
|
||||
.expect("could not subscribe to komorebi notifications");
|
||||
|
||||
tracing::info!("subscribed to komorebi notifications: \"{}\"", subscriber_name);
|
||||
|
||||
for client in listener.incoming() {
|
||||
match client {
|
||||
Ok(subscription) => {
|
||||
match subscription.set_read_timeout(Some(Duration::from_secs(1))) {
|
||||
Ok(()) => {}
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
}
|
||||
let mut buffer = Vec::new();
|
||||
let mut reader = BufReader::new(subscription);
|
||||
|
||||
// this is when we know a shutdown has been sent
|
||||
if matches!(reader.read_to_end(&mut buffer), Ok(0)) {
|
||||
tracing::info!("disconnected from komorebi");
|
||||
|
||||
// keep trying to reconnect to komorebi
|
||||
while komorebi_client::send_message(
|
||||
&SocketMessage::AddSubscriberSocket(subscriber_name.clone()),
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
tracing::info!("reconnected to komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Reconnect) {
|
||||
tracing::error!("could not send komorebi reconnect event to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
continue;
|
||||
}
|
||||
|
||||
match String::from_utf8(buffer) {
|
||||
Ok(notification_string) => {
|
||||
match serde_json::from_str::<komorebi_client::Notification>(
|
||||
¬ification_string,
|
||||
) {
|
||||
Ok(notification) => {
|
||||
tracing::debug!("received notification from komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Notification(Box::new(notification))) {
|
||||
tracing::error!("could not send komorebi notification update to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("could not deserialize komorebi notification: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
"komorebi notification string was invalid utf8: {error}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Box::new(Komobar::new(cc, rx_gui, rx_config, config)))
|
||||
}),
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::Error::msg(error.to_string()))
|
||||
platform::main()
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
use egui_phosphor::regular::CALENDAR_DOTS;
|
||||
use komorebi_bar_core::platform::BarPlatform;
|
||||
use komorebi_bar_core::platform::SystemTool;
|
||||
use std::io;
|
||||
use std::process::Command;
|
||||
|
||||
pub struct WindowsBar;
|
||||
|
||||
impl BarPlatform for WindowsBar {
|
||||
fn open_system_tool(&self, tool: SystemTool) -> io::Result<()> {
|
||||
match tool {
|
||||
SystemTool::TaskManager => Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn(),
|
||||
SystemTool::PowerSettings => Command::new("cmd.exe")
|
||||
.args(["/C", "start", "ms-settings:batterysaver"])
|
||||
.spawn(),
|
||||
SystemTool::NetworkSettings => Command::new("cmd.exe").args(["/C", "ncpa"]).spawn(),
|
||||
SystemTool::Url(url) => Command::new("explorer.exe").args([url]).spawn(),
|
||||
}
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
fn latest_release_api_url(&self) -> &'static str {
|
||||
"https://api.github.com/repos/LGUG2Z/komorebi/releases/latest"
|
||||
}
|
||||
|
||||
fn calendar_icon(&self) -> &'static str {
|
||||
CALENDAR_DOTS
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
use crate::widgets::applications::Applications;
|
||||
use crate::widgets::applications::ApplicationsConfig;
|
||||
use crate::widgets::battery::Battery;
|
||||
use crate::widgets::battery::BatteryConfig;
|
||||
use crate::widgets::cpu::Cpu;
|
||||
use crate::widgets::cpu::CpuConfig;
|
||||
use crate::widgets::date::Date;
|
||||
use crate::widgets::date::DateConfig;
|
||||
use crate::widgets::keyboard::Keyboard;
|
||||
use crate::widgets::keyboard::KeyboardConfig;
|
||||
use crate::widgets::komorebi::Komorebi;
|
||||
use crate::widgets::komorebi::KomorebiConfig;
|
||||
use crate::widgets::media::Media;
|
||||
use crate::widgets::media::MediaConfig;
|
||||
use crate::widgets::memory::Memory;
|
||||
use crate::widgets::memory::MemoryConfig;
|
||||
use crate::widgets::network::Network;
|
||||
use crate::widgets::network::NetworkConfig;
|
||||
use crate::widgets::storage::Storage;
|
||||
use crate::widgets::storage::StorageConfig;
|
||||
#[cfg(target_os = "windows")]
|
||||
use crate::widgets::systray::Systray;
|
||||
#[cfg(target_os = "windows")]
|
||||
use crate::widgets::systray::SystrayConfig;
|
||||
use crate::widgets::time::Time;
|
||||
use crate::widgets::time::TimeConfig;
|
||||
use crate::widgets::update::Update;
|
||||
use crate::widgets::update::UpdateConfig;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
pub use komorebi_bar_core::widgets::widget::BarWidget;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Widget configuration
|
||||
pub enum WidgetConfig {
|
||||
/// Applications widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Applications"))]
|
||||
Applications(ApplicationsConfig),
|
||||
/// Battery widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Battery"))]
|
||||
Battery(BatteryConfig),
|
||||
/// CPU widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Cpu"))]
|
||||
Cpu(CpuConfig),
|
||||
/// Date widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Date"))]
|
||||
Date(DateConfig),
|
||||
/// Keyboard widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Keyboard"))]
|
||||
Keyboard(KeyboardConfig),
|
||||
/// Komorebi widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Komorebi"))]
|
||||
Komorebi(KomorebiConfig),
|
||||
/// Media widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Media"))]
|
||||
Media(MediaConfig),
|
||||
/// Memory widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Memory"))]
|
||||
Memory(MemoryConfig),
|
||||
/// Network widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Network"))]
|
||||
Network(NetworkConfig),
|
||||
/// Storage widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Storage"))]
|
||||
Storage(StorageConfig),
|
||||
/// System Tray widget configuration (Windows only)
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Systray"))]
|
||||
Systray(SystrayConfig),
|
||||
/// Time widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Time"))]
|
||||
Time(TimeConfig),
|
||||
/// Update widget configuration
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Update"))]
|
||||
Update(UpdateConfig),
|
||||
}
|
||||
|
||||
impl WidgetConfig {
|
||||
pub fn as_boxed_bar_widget(&self) -> Box<dyn BarWidget> {
|
||||
match self {
|
||||
WidgetConfig::Applications(config) => Box::new(Applications::from(config)),
|
||||
WidgetConfig::Battery(config) => Box::new(Battery::from(*config)),
|
||||
WidgetConfig::Cpu(config) => Box::new(Cpu::from(*config)),
|
||||
WidgetConfig::Date(config) => Box::new(Date::from(config.clone())),
|
||||
WidgetConfig::Keyboard(config) => Box::new(Keyboard::from(*config)),
|
||||
WidgetConfig::Komorebi(config) => Box::new(Komorebi::from(config)),
|
||||
WidgetConfig::Media(config) => Box::new(Media::from(*config)),
|
||||
WidgetConfig::Memory(config) => Box::new(Memory::from(*config)),
|
||||
WidgetConfig::Network(config) => Box::new(Network::from(*config)),
|
||||
WidgetConfig::Storage(config) => Box::new(Storage::from(*config)),
|
||||
#[cfg(target_os = "windows")]
|
||||
WidgetConfig::Systray(config) => Box::new(Systray::from(config)),
|
||||
WidgetConfig::Time(config) => Box::new(Time::from(config.clone())),
|
||||
WidgetConfig::Update(config) => Box::new(Update::from(*config)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enabled(&self) -> bool {
|
||||
match self {
|
||||
WidgetConfig::Applications(config) => config.enable,
|
||||
WidgetConfig::Battery(config) => config.enable,
|
||||
WidgetConfig::Cpu(config) => config.enable,
|
||||
WidgetConfig::Date(config) => config.enable,
|
||||
WidgetConfig::Keyboard(config) => config.enable,
|
||||
WidgetConfig::Komorebi(config) => {
|
||||
config.workspaces.as_ref().is_some_and(|w| w.enable)
|
||||
|| config.layout.as_ref().is_some_and(|w| w.enable)
|
||||
|| config.focused_container.as_ref().is_some_and(|w| w.enable)
|
||||
|| config
|
||||
.configuration_switcher
|
||||
.as_ref()
|
||||
.is_some_and(|w| w.enable)
|
||||
}
|
||||
WidgetConfig::Media(config) => config.enable,
|
||||
WidgetConfig::Memory(config) => config.enable,
|
||||
WidgetConfig::Network(config) => config.enable,
|
||||
WidgetConfig::Storage(config) => config.enable,
|
||||
#[cfg(target_os = "windows")]
|
||||
WidgetConfig::Systray(config) => config.enable,
|
||||
WidgetConfig::Time(config) => config.enable,
|
||||
WidgetConfig::Update(config) => config.enable,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,29 @@
|
||||
use crate::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::BAR_HEIGHT;
|
||||
use crate::DEFAULT_PADDING;
|
||||
use crate::KomorebiEvent;
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
use crate::MONITOR_LEFT;
|
||||
use crate::MONITOR_RIGHT;
|
||||
use crate::MONITOR_TOP;
|
||||
use crate::config::KomobarConfig;
|
||||
use crate::config::KomobarTheme;
|
||||
use crate::config::MonitorConfigOrIndex;
|
||||
use crate::config::Position;
|
||||
use crate::config::PositionConfig;
|
||||
use crate::config::get_individual_spacing;
|
||||
use crate::process_hwnd;
|
||||
use crate::render::Color32Ext;
|
||||
use crate::render::Grouping;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::render::RenderExt;
|
||||
use crate::take_widget_clicked;
|
||||
use crate::widgets::komorebi::Komorebi;
|
||||
use crate::widgets::komorebi::MonitorInfo;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::widgets::widget::WidgetConfig;
|
||||
use crate::windows::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::windows::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::windows::BAR_HEIGHT;
|
||||
use crate::windows::DEFAULT_PADDING;
|
||||
use crate::windows::KomorebiEvent;
|
||||
use crate::windows::MAX_LABEL_WIDTH;
|
||||
use crate::windows::MONITOR_LEFT;
|
||||
use crate::windows::MONITOR_RIGHT;
|
||||
use crate::windows::MONITOR_TOP;
|
||||
use crate::windows::config::KomobarConfig;
|
||||
use crate::windows::config::KomobarTheme;
|
||||
use crate::windows::config::MonitorConfigOrIndex;
|
||||
use crate::windows::config::Position;
|
||||
use crate::windows::config::PositionConfig;
|
||||
use crate::windows::config::get_individual_spacing;
|
||||
use crate::windows::process_hwnd;
|
||||
use crate::windows::render::Color32Ext;
|
||||
use crate::windows::render::Grouping;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::render::RenderExt;
|
||||
use crate::windows::take_widget_clicked;
|
||||
use crate::windows::widgets::komorebi::Komorebi;
|
||||
use crate::windows::widgets::komorebi::MonitorInfo;
|
||||
use crate::windows::widgets::widget::BarWidget;
|
||||
use crate::windows::widgets::widget::WidgetConfig;
|
||||
use crate::windows::widgets::widget::WidgetConfigExt;
|
||||
use color_eyre::eyre;
|
||||
use crossbeam_channel::Receiver;
|
||||
use crossbeam_channel::TryRecvError;
|
||||
@@ -1085,7 +1086,7 @@ impl eframe::App for Komobar {
|
||||
CentralPanel::default().frame(frame).show(ctx, |ui| {
|
||||
// Variable to store command to execute after widgets are rendered
|
||||
// This allows widgets to mark clicks as consumed before bar processes them
|
||||
let mut pending_command: Option<crate::config::MouseMessage> = None;
|
||||
let mut pending_command: Option<crate::windows::config::MouseMessage> = None;
|
||||
|
||||
if let Some(mouse_config) = &self.config.mouse {
|
||||
let command = if ui
|
||||
@@ -0,0 +1 @@
|
||||
pub use komorebi_bar_core::config::*;
|
||||
@@ -0,0 +1,401 @@
|
||||
mod bar;
|
||||
mod config;
|
||||
mod os;
|
||||
pub use komorebi_bar_core::render;
|
||||
pub use komorebi_bar_core::selected_frame;
|
||||
pub use komorebi_bar_core::ui;
|
||||
mod widgets;
|
||||
|
||||
use crate::windows::bar::Komobar;
|
||||
use crate::windows::config::KomobarConfig;
|
||||
use crate::windows::config::Position;
|
||||
use crate::windows::config::PositionConfig;
|
||||
use clap::Parser;
|
||||
use config::MonitorConfigOrIndex;
|
||||
use eframe::egui::ViewportBuilder;
|
||||
use font_loader::system_fonts;
|
||||
use hotwatch::EventKind;
|
||||
use hotwatch::Hotwatch;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_client::SubscribeOptions;
|
||||
use komorebi_client::replace_env_in_path;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use windows::Win32::Foundation::HWND;
|
||||
use windows::Win32::Foundation::LPARAM;
|
||||
use windows::Win32::System::Threading::GetCurrentProcessId;
|
||||
use windows::Win32::System::Threading::GetCurrentThreadId;
|
||||
use windows::Win32::UI::HiDpi::DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
|
||||
use windows::Win32::UI::HiDpi::SetProcessDpiAwarenessContext;
|
||||
use windows::Win32::UI::WindowsAndMessaging::EnumThreadWindows;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
|
||||
use windows_core::BOOL;
|
||||
|
||||
pub use komorebi_bar_core::statics::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(name = "komorebi-bar", author, about, version)]
|
||||
struct Opts {
|
||||
/// Print the JSON schema of the configuration file and exit
|
||||
#[clap(long)]
|
||||
schema: bool,
|
||||
/// Print a list of fonts available on this system and exit
|
||||
#[clap(long)]
|
||||
fonts: bool,
|
||||
/// Path to a JSON or YAML configuration file
|
||||
#[clap(short, long)]
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
config: Option<PathBuf>,
|
||||
/// Write an example komorebi.bar.json to disk
|
||||
#[clap(long)]
|
||||
quickstart: bool,
|
||||
/// Print a list of aliases that can be renamed to canonical variants
|
||||
#[clap(long)]
|
||||
#[clap(hide = true)]
|
||||
aliases: bool,
|
||||
}
|
||||
|
||||
extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
|
||||
unsafe {
|
||||
let mut process_id = 0;
|
||||
GetWindowThreadProcessId(hwnd, Some(&mut process_id));
|
||||
|
||||
if process_id == GetCurrentProcessId() {
|
||||
*(lparam.0 as *mut HWND) = hwnd;
|
||||
BOOL::from(false) // Stop enumeration
|
||||
} else {
|
||||
BOOL::from(true) // Continue enumeration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn process_hwnd() -> Option<isize> {
|
||||
unsafe {
|
||||
let mut hwnd = HWND::default();
|
||||
let _ = EnumThreadWindows(
|
||||
GetCurrentThreadId(),
|
||||
Some(enum_window),
|
||||
LPARAM(&mut hwnd as *mut HWND as isize),
|
||||
);
|
||||
|
||||
if hwnd.0 as isize == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(hwnd.0 as isize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum KomorebiEvent {
|
||||
Notification(Box<komorebi_client::Notification>),
|
||||
Reconnect,
|
||||
}
|
||||
|
||||
pub fn main() -> color_eyre::Result<()> {
|
||||
komorebi_bar_core::platform::install(&os::WindowsBar);
|
||||
|
||||
unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) }?;
|
||||
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
#[cfg(feature = "schemars")]
|
||||
if opts.schema {
|
||||
print!(
|
||||
"{}",
|
||||
komorebi_bar_core::schema::generated_text::<KomobarConfig>(
|
||||
komorebi_bar_core::schema::SchemaPlatform::Windows
|
||||
)
|
||||
);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if opts.fonts {
|
||||
for font in system_fonts::query_all() {
|
||||
println!("{font}");
|
||||
}
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LIB_BACKTRACE", "1");
|
||||
}
|
||||
}
|
||||
|
||||
color_eyre::install()?;
|
||||
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LOG", "info");
|
||||
}
|
||||
}
|
||||
|
||||
tracing::subscriber::set_global_default(
|
||||
tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.finish(),
|
||||
)?;
|
||||
|
||||
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
||||
|_| dirs::home_dir().expect("there is no home directory"),
|
||||
|home_path| {
|
||||
let home = home_path.replace_env();
|
||||
|
||||
assert!(
|
||||
home.is_dir(),
|
||||
"$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory"
|
||||
);
|
||||
|
||||
home
|
||||
},
|
||||
);
|
||||
|
||||
if opts.quickstart {
|
||||
let komorebi_bar_json = include_str!("../../../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 {}",
|
||||
home_dir.display()
|
||||
);
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let default_config_path = home_dir.join("komorebi.bar.json");
|
||||
|
||||
let config_path = opts.config.or_else(|| {
|
||||
default_config_path
|
||||
.is_file()
|
||||
.then_some(default_config_path.clone())
|
||||
});
|
||||
|
||||
let mut config = match config_path {
|
||||
None => {
|
||||
let komorebi_bar_json =
|
||||
include_str!("../../../docs/komorebi.bar.example.json").to_string();
|
||||
|
||||
std::fs::write(&default_config_path, komorebi_bar_json)?;
|
||||
tracing::info!(
|
||||
"created example configuration file: {}",
|
||||
default_config_path.display()
|
||||
);
|
||||
|
||||
KomobarConfig::read(&default_config_path)?
|
||||
}
|
||||
Some(ref config) => {
|
||||
if !opts.aliases {
|
||||
tracing::info!("found configuration file: {}", config.display());
|
||||
}
|
||||
|
||||
KomobarConfig::read(config)?
|
||||
}
|
||||
};
|
||||
|
||||
let config_path = config_path.unwrap_or(default_config_path);
|
||||
|
||||
if opts.aliases {
|
||||
KomobarConfig::aliases(&std::fs::read_to_string(&config_path)?);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let state = serde_json::from_str::<komorebi_client::State>(&komorebi_client::send_query(
|
||||
&SocketMessage::State,
|
||||
)?)?;
|
||||
|
||||
let (usr_monitor_index, work_area_offset) = match &config.monitor {
|
||||
Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => {
|
||||
(monitor_config.index, monitor_config.work_area_offset)
|
||||
}
|
||||
Some(MonitorConfigOrIndex::Index(idx)) => (*idx, None),
|
||||
None => (0, None),
|
||||
};
|
||||
|
||||
let monitor_index = state
|
||||
.monitor_usr_idx_map
|
||||
.get(&usr_monitor_index)
|
||||
.map_or(usr_monitor_index, |i| *i);
|
||||
|
||||
MONITOR_RIGHT.store(
|
||||
state.monitors.elements()[monitor_index].size.right,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_TOP.store(
|
||||
state.monitors.elements()[monitor_index].size.top,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_LEFT.store(
|
||||
state.monitors.elements()[monitor_index].size.left,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_INDEX.store(monitor_index, Ordering::SeqCst);
|
||||
|
||||
match config.position {
|
||||
None => {
|
||||
config.position = Some(PositionConfig {
|
||||
start: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
}),
|
||||
end: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
}),
|
||||
})
|
||||
}
|
||||
Some(ref mut position) => {
|
||||
if position.start.is_none() {
|
||||
position.start = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
});
|
||||
}
|
||||
|
||||
if position.end.is_none() {
|
||||
position.end = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let viewport_builder = ViewportBuilder::default()
|
||||
.with_decorations(false)
|
||||
.with_transparent(true)
|
||||
.with_taskbar(false);
|
||||
|
||||
let native_options = eframe::NativeOptions {
|
||||
viewport: viewport_builder,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if let Some(rect) = &work_area_offset {
|
||||
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(monitor_index, *rect))?;
|
||||
tracing::info!("work area offset applied to monitor: {}", monitor_index);
|
||||
}
|
||||
|
||||
let (tx_gui, rx_gui) = crossbeam_channel::unbounded();
|
||||
let (tx_config, rx_config) = crossbeam_channel::unbounded();
|
||||
|
||||
let mut hotwatch = Hotwatch::new()?;
|
||||
let config_path_cl = config_path.clone();
|
||||
|
||||
hotwatch.watch(config_path, move |event| match event.kind {
|
||||
EventKind::Modify(_) | EventKind::Remove(_) => match KomobarConfig::read(&config_path_cl) {
|
||||
Ok(updated) => {
|
||||
tracing::info!("configuration file updated: {}", config_path_cl.display());
|
||||
|
||||
if let Err(error) = tx_config.send(updated) {
|
||||
tracing::error!("could not send configuration update to gui: {error}")
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
})?;
|
||||
|
||||
tracing::info!("watching configuration file for changes");
|
||||
|
||||
eframe::run_native(
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
ctx_repainter.request_repaint();
|
||||
});
|
||||
|
||||
let ctx_komorebi = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let subscriber_name = format!("komorebi-bar-{}", random_word::get(random_word::Lang::En));
|
||||
|
||||
let listener = komorebi_client::subscribe_with_options(&subscriber_name, SubscribeOptions {
|
||||
filter_state_changes: true,
|
||||
})
|
||||
.expect("could not subscribe to komorebi notifications");
|
||||
|
||||
tracing::info!("subscribed to komorebi notifications: \"{}\"", subscriber_name);
|
||||
|
||||
for client in listener.incoming() {
|
||||
match client {
|
||||
Ok(subscription) => {
|
||||
match subscription.set_read_timeout(Some(Duration::from_secs(1))) {
|
||||
Ok(()) => {}
|
||||
Err(error) => tracing::error!("{}", error),
|
||||
}
|
||||
let mut buffer = Vec::new();
|
||||
let mut reader = BufReader::new(subscription);
|
||||
|
||||
// this is when we know a shutdown has been sent
|
||||
if matches!(reader.read_to_end(&mut buffer), Ok(0)) {
|
||||
tracing::info!("disconnected from komorebi");
|
||||
|
||||
// keep trying to reconnect to komorebi
|
||||
while komorebi_client::send_message(
|
||||
&SocketMessage::AddSubscriberSocket(subscriber_name.clone()),
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
tracing::info!("reconnected to komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Reconnect) {
|
||||
tracing::error!("could not send komorebi reconnect event to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
continue;
|
||||
}
|
||||
|
||||
match String::from_utf8(buffer) {
|
||||
Ok(notification_string) => {
|
||||
match serde_json::from_str::<komorebi_client::Notification>(
|
||||
¬ification_string,
|
||||
) {
|
||||
Ok(notification) => {
|
||||
tracing::debug!("received notification from komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Notification(Box::new(notification))) {
|
||||
tracing::error!("could not send komorebi notification update to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("could not deserialize komorebi notification: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
"komorebi notification string was invalid utf8: {error}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Box::new(Komobar::new(cc, rx_gui, rx_config, config)))
|
||||
}),
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::Error::msg(error.to_string()))
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
use crate::windows::widgets::ImageIcon;
|
||||
use egui_phosphor::regular::CALENDAR_DOTS;
|
||||
use komorebi_bar_core::platform::BarPlatform;
|
||||
use komorebi_bar_core::platform::SystemTool;
|
||||
use std::borrow::Cow;
|
||||
use komorebi_client::SocketMessage;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use which::which;
|
||||
|
||||
pub struct WindowsBar;
|
||||
|
||||
impl BarPlatform for WindowsBar {
|
||||
fn open_system_tool(&self, tool: SystemTool) -> io::Result<()> {
|
||||
match tool {
|
||||
SystemTool::TaskManager => Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn(),
|
||||
SystemTool::PowerSettings => Command::new("cmd.exe")
|
||||
.args(["/C", "start", "ms-settings:batterysaver"])
|
||||
.spawn(),
|
||||
SystemTool::NetworkSettings => Command::new("cmd.exe").args(["/C", "ncpa"]).spawn(),
|
||||
SystemTool::Url(url) => Command::new("explorer.exe").args([url]).spawn(),
|
||||
SystemTool::StorageLocation(label) => Command::new("cmd.exe")
|
||||
.args([
|
||||
"/C",
|
||||
"explorer.exe",
|
||||
label.split(' ').collect::<Vec<&str>>()[0],
|
||||
])
|
||||
.spawn(),
|
||||
}
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
fn latest_release_api_url(&self) -> &'static str {
|
||||
"https://api.github.com/repos/LGUG2Z/komorebi/releases/latest"
|
||||
}
|
||||
|
||||
fn calendar_icon(&self) -> &'static str {
|
||||
CALENDAR_DOTS
|
||||
}
|
||||
|
||||
fn exec_shell_command(&self, command: &str) -> color_eyre::Result<()> {
|
||||
crate::windows::bar::exec_powershell(command)
|
||||
}
|
||||
|
||||
fn send_komorebi_message(&self, message: &SocketMessage) -> io::Result<()> {
|
||||
komorebi_client::send_message(message)
|
||||
}
|
||||
|
||||
fn send_komorebi_batch(&self, messages: Vec<SocketMessage>) -> io::Result<()> {
|
||||
komorebi_client::send_batch(messages)
|
||||
}
|
||||
|
||||
fn command_icon(&self, command: &str) -> Option<ImageIcon> {
|
||||
let path = executable_of(command)?;
|
||||
ImageIcon::try_load(path.as_ref(), || {
|
||||
let path_str = path.to_str()?;
|
||||
windows_icons::get_icon_by_path(path_str)
|
||||
.or_else(|| windows_icons_fallback::get_icon_by_path(path_str))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to resolve the executable path from the command string.
|
||||
///
|
||||
/// Resolution logic:
|
||||
/// - Splits the command by ".exe" and checks if the first part is an existing file.
|
||||
/// - If not, attempts to locate the binary using [`which`] on this name.
|
||||
/// - If still unresolved, takes the first word (separated by whitespace) and attempts
|
||||
/// to find it in the system `PATH` using [`which`].
|
||||
///
|
||||
/// Returns `None` if no executable path can be determined.
|
||||
fn executable_of(command: &str) -> Option<Cow<'_, Path>> {
|
||||
if let Some(binary) = command.split(".exe").next().map(Path::new) {
|
||||
if binary.is_file() {
|
||||
return Some(Cow::Borrowed(binary));
|
||||
} else if let Ok(binary) = which(binary) {
|
||||
return Some(Cow::Owned(binary));
|
||||
}
|
||||
}
|
||||
|
||||
which(command.split(' ').next()?).ok().map(Cow::Owned)
|
||||
}
|
||||
+4
-18
@@ -1,6 +1,7 @@
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::windows::config::LabelPrefix;
|
||||
pub use komorebi_bar_core::widgets::platform_config::KeyboardConfig;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::widgets::widget::BarWidget;
|
||||
use color_eyre::eyre;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Context;
|
||||
@@ -9,8 +10,6 @@ use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::WidgetText;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
@@ -23,19 +22,6 @@ use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
|
||||
|
||||
const ERROR_TEXT: &str = "Error";
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Keyboard widget configuration
|
||||
pub struct KeyboardConfig {
|
||||
/// Enable the Input widget
|
||||
pub enable: bool,
|
||||
/// Data refresh interval
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||
pub data_refresh_interval: Option<u64>,
|
||||
/// Display label prefix
|
||||
pub label_prefix: Option<LabelPrefix>,
|
||||
}
|
||||
|
||||
impl From<KeyboardConfig> for Keyboard {
|
||||
fn from(value: KeyboardConfig) -> Self {
|
||||
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
|
||||
+18
-103
@@ -1,14 +1,14 @@
|
||||
use super::ImageIcon;
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
use crate::MONITOR_INDEX;
|
||||
use crate::config::DisplayFormat;
|
||||
use crate::config::DisplayFormat::*;
|
||||
use crate::config::WorkspacesDisplayFormat;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::ui::CustomUi;
|
||||
use crate::widgets::komorebi_layout::KomorebiLayout;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::windows::MAX_LABEL_WIDTH;
|
||||
use crate::windows::MONITOR_INDEX;
|
||||
use crate::windows::config::DisplayFormat;
|
||||
use crate::windows::config::DisplayFormat::*;
|
||||
use crate::windows::config::WorkspacesDisplayFormat;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::selected_frame::SelectableFrame;
|
||||
use crate::windows::ui::CustomUi;
|
||||
use crate::windows::widgets::komorebi_layout::KomorebiLayoutExt;
|
||||
use crate::windows::widgets::widget::BarWidget;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
@@ -28,6 +28,14 @@ use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::egui::vec2;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiConfigurationSwitcherConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiFocusedContainerConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayout;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLayoutConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiLockedContainerConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspaceLayerConfig;
|
||||
pub use komorebi_bar_core::widgets::komorebi_config::KomorebiWorkspacesConfig;
|
||||
use komorebi_client::Container;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::Rect;
|
||||
@@ -37,106 +45,13 @@ use komorebi_client::State;
|
||||
use komorebi_client::Window;
|
||||
use komorebi_client::Workspace;
|
||||
use komorebi_client::WorkspaceLayer;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Result as IoResult;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget configuration
|
||||
pub struct KomorebiConfig {
|
||||
/// Configure the Workspaces widget
|
||||
pub workspaces: Option<KomorebiWorkspacesConfig>,
|
||||
/// Configure the Layout widget
|
||||
pub layout: Option<KomorebiLayoutConfig>,
|
||||
/// Configure the Workspace Layer widget
|
||||
pub workspace_layer: Option<KomorebiWorkspaceLayerConfig>,
|
||||
/// Configure the Focused Container widget
|
||||
#[serde(alias = "focused_window")]
|
||||
pub focused_container: Option<KomorebiFocusedContainerConfig>,
|
||||
/// Configure the Locked Container widget
|
||||
pub locked_container: Option<KomorebiLockedContainerConfig>,
|
||||
/// Configure the Configuration Switcher widget
|
||||
pub configuration_switcher: Option<KomorebiConfigurationSwitcherConfig>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget workspaces configuration
|
||||
pub struct KomorebiWorkspacesConfig {
|
||||
/// Enable the Komorebi Workspaces widget
|
||||
pub enable: bool,
|
||||
/// Hide workspaces without any windows
|
||||
pub hide_empty_workspaces: bool,
|
||||
/// Display format of the workspace
|
||||
pub display: Option<WorkspacesDisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget layout configuration
|
||||
pub struct KomorebiLayoutConfig {
|
||||
/// Enable the Komorebi Layout widget
|
||||
pub enable: bool,
|
||||
/// List of layout options
|
||||
pub options: Option<Vec<KomorebiLayout>>,
|
||||
/// Display format of the current layout
|
||||
pub display: Option<DisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget workspace layer configuration
|
||||
pub struct KomorebiWorkspaceLayerConfig {
|
||||
/// Enable the Komorebi Workspace Layer widget
|
||||
pub enable: bool,
|
||||
/// Display format of the current layer
|
||||
pub display: Option<DisplayFormat>,
|
||||
/// Show the widget event if the layer is Tiling
|
||||
pub show_when_tiling: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget focused container configuration
|
||||
pub struct KomorebiFocusedContainerConfig {
|
||||
/// Enable the Komorebi Focused Container widget
|
||||
pub enable: bool,
|
||||
/// DEPRECATED: use `display` instead (Show the icon of the currently focused container)
|
||||
#[deprecated(note = "Use `display` instead")]
|
||||
pub show_icon: Option<bool>,
|
||||
/// Display format of the currently focused container
|
||||
pub display: Option<DisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget locked container configuration
|
||||
pub struct KomorebiLockedContainerConfig {
|
||||
/// Enable the Komorebi Locked Container widget
|
||||
pub enable: bool,
|
||||
/// Display format of the current locked state
|
||||
pub display: Option<DisplayFormat>,
|
||||
/// Show the widget event if the layer is unlocked
|
||||
pub show_when_unlocked: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi widget configuration switcher configuration
|
||||
pub struct KomorebiConfigurationSwitcherConfig {
|
||||
/// Enable the Komorebi Configurations widget
|
||||
pub enable: bool,
|
||||
/// A map of display friendly name => path to configuration.json
|
||||
pub configurations: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl From<&KomorebiConfig> for Komorebi {
|
||||
fn from(cfg: &KomorebiConfig) -> Self {
|
||||
let configuration_switcher = cfg.configuration_switcher.clone().map(|mut cs| {
|
||||
@@ -1,10 +1,11 @@
|
||||
use crate::MAX_LABEL_WIDTH;
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::MediaDisplayFormat;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::ui::CustomUi;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::windows::MAX_LABEL_WIDTH;
|
||||
use crate::windows::bar::Alignment;
|
||||
use crate::windows::config::MediaDisplayFormat;
|
||||
pub use komorebi_bar_core::widgets::platform_config::MediaConfig;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::selected_frame::SelectableFrame;
|
||||
use crate::windows::ui::CustomUi;
|
||||
use crate::windows::widgets::widget::BarWidget;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::Label;
|
||||
@@ -12,22 +13,10 @@ use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager;
|
||||
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Media widget configuration
|
||||
pub struct MediaConfig {
|
||||
/// Enable the Media widget
|
||||
pub enable: bool,
|
||||
/// Display format of the media widget (defaults to IconAndText)
|
||||
pub display: Option<MediaDisplayFormat>,
|
||||
}
|
||||
|
||||
impl From<MediaConfig> for Media {
|
||||
fn from(value: MediaConfig) -> Self {
|
||||
Self::new(
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
pub use komorebi_bar_core::widgets::applications;
|
||||
pub use komorebi_bar_core::widgets::battery;
|
||||
pub use komorebi_bar_core::widgets::cpu;
|
||||
pub use komorebi_bar_core::widgets::date;
|
||||
pub mod keyboard;
|
||||
pub mod komorebi;
|
||||
pub use komorebi_bar_core::widgets::komorebi_layout;
|
||||
pub mod media;
|
||||
pub use komorebi_bar_core::widgets::memory;
|
||||
pub mod network;
|
||||
pub use komorebi_bar_core::widgets::storage;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub mod systray;
|
||||
pub use komorebi_bar_core::widgets::time;
|
||||
pub use komorebi_bar_core::widgets::update;
|
||||
pub mod widget;
|
||||
|
||||
pub use komorebi_bar_core::widgets::icons::ICONS_CACHE;
|
||||
pub use komorebi_bar_core::widgets::icons::ImageIcon;
|
||||
pub use komorebi_bar_core::widgets::icons::ImageIconId;
|
||||
pub use komorebi_bar_core::widgets::icons::rgba_to_color_image;
|
||||
@@ -1,8 +1,12 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::windows::bar::Alignment;
|
||||
pub use komorebi_bar_core::widgets::network_config::DefaultInterfaceConfig;
|
||||
pub use komorebi_bar_core::widgets::network_config::InterfaceDisplayType;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkConfig;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkSelectConfig;
|
||||
use crate::windows::config::LabelPrefix;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::selected_frame::SelectableFrame;
|
||||
use crate::windows::widgets::widget::BarWidget;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
@@ -11,8 +15,6 @@ use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use num_derive::FromPrimitive;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
@@ -24,66 +26,6 @@ use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Networks;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Network widget configuration
|
||||
pub struct NetworkConfig {
|
||||
/// Enable the Network widget
|
||||
pub enable: bool,
|
||||
/// Show total received and transmitted activity
|
||||
#[serde(alias = "show_total_data_transmitted")]
|
||||
pub show_total_activity: bool,
|
||||
/// Show received and transmitted activity
|
||||
#[serde(alias = "show_network_activity")]
|
||||
pub show_activity: bool,
|
||||
/// Show default interface
|
||||
pub show_default_interface: Option<bool>,
|
||||
/// Default interface options: whether to show the friendly name, IPv4 or IPv6 address
|
||||
pub default_interface_options: Option<DefaultInterfaceConfig>,
|
||||
/// Characters to reserve for received and transmitted activity
|
||||
#[serde(alias = "network_activity_fill_characters")]
|
||||
pub activity_left_padding: Option<usize>,
|
||||
/// Data refresh interval in seconds
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||
pub data_refresh_interval: Option<u64>,
|
||||
/// Display label prefix
|
||||
pub label_prefix: Option<LabelPrefix>,
|
||||
/// Select when the value is over a limit (1MiB is 1048576 bytes (1024*1024))
|
||||
pub auto_select: Option<NetworkSelectConfig>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Network select configuration
|
||||
pub struct NetworkSelectConfig {
|
||||
/// Select the total received data when it's over this value
|
||||
pub total_received_over: Option<u64>,
|
||||
/// Select the total transmitted data when it's over this value
|
||||
pub total_transmitted_over: Option<u64>,
|
||||
/// Select the received data when it's over this value
|
||||
pub received_over: Option<u64>,
|
||||
/// Select the transmitted data when it's over this value
|
||||
pub transmitted_over: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Which IP address to show for the default interface
|
||||
pub enum InterfaceDisplayType {
|
||||
#[default]
|
||||
FriendlyName,
|
||||
Ipv4,
|
||||
Ipv6,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Default interface configuration
|
||||
pub struct DefaultInterfaceConfig {
|
||||
#[serde(default)]
|
||||
pub display_type: InterfaceDisplayType,
|
||||
}
|
||||
|
||||
impl From<NetworkConfig> for Network {
|
||||
fn from(value: NetworkConfig) -> Self {
|
||||
let default_refresh_interval = 10;
|
||||
+10
-106
@@ -2,11 +2,11 @@ use super::ICONS_CACHE;
|
||||
use super::ImageIcon;
|
||||
use super::ImageIconId;
|
||||
use super::rgba_to_color_image;
|
||||
use crate::bar::Alignment;
|
||||
use crate::mark_widget_clicked;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use crate::windows::bar::Alignment;
|
||||
use crate::windows::mark_widget_clicked;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::selected_frame::SelectableFrame;
|
||||
use crate::windows::widgets::widget::BarWidget;
|
||||
use crossbeam_channel::Receiver;
|
||||
use crossbeam_channel::Sender;
|
||||
use crossbeam_channel::unbounded;
|
||||
@@ -26,10 +26,13 @@ use eframe::egui::ViewportId;
|
||||
use eframe::egui::Window as EguiWindow;
|
||||
use egui_extras::Column;
|
||||
use egui_extras::TableBuilder;
|
||||
pub use komorebi_bar_core::widgets::platform_config::ButtonPosition;
|
||||
pub use komorebi_bar_core::widgets::platform_config::FieldMatch;
|
||||
pub use komorebi_bar_core::widgets::platform_config::HiddenIconRule;
|
||||
pub use komorebi_bar_core::widgets::platform_config::OverflowTogglePosition;
|
||||
pub use komorebi_bar_core::widgets::platform_config::SystrayConfig;
|
||||
use komorebi_client::MatchingStrategy;
|
||||
use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
@@ -61,105 +64,6 @@ static SHOW_HIDDEN_ICONS: AtomicBool = AtomicBool::new(false);
|
||||
/// Whether the systray info panel is currently shown
|
||||
static SHOW_SYSTRAY_INFO: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Position of the overflow toggle button
|
||||
pub enum OverflowTogglePosition {
|
||||
/// Toggle button appears on the left side (before visible icons)
|
||||
Left,
|
||||
/// Toggle button appears on the right side (after visible icons)
|
||||
#[default]
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Where to place a systray button (refresh, info, shortcuts, etc.)
|
||||
pub enum ButtonPosition {
|
||||
/// Show in the main visible area
|
||||
Visible,
|
||||
/// Show in the overflow/hidden section
|
||||
Overflow,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// A field value with an optional matching strategy.
|
||||
///
|
||||
/// A plain string uses exact (case-insensitive) matching.
|
||||
/// An object with `value` and `matching_strategy` uses the specified strategy.
|
||||
pub enum FieldMatch {
|
||||
/// Exact case-insensitive match
|
||||
Exact(String),
|
||||
/// Match using a specific strategy
|
||||
WithStrategy {
|
||||
/// The value to match against
|
||||
value: String,
|
||||
/// How to match (Equals, StartsWith, EndsWith, Contains, Regex, etc.)
|
||||
matching_strategy: MatchingStrategy,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// Rule for matching a systray icon to hide
|
||||
///
|
||||
/// A plain string matches the exe name (backward compatible).
|
||||
/// An object with optional `exe`, `tooltip`, and/or `guid` fields
|
||||
/// uses AND logic: all specified fields must match.
|
||||
/// Each field can be a plain string (exact match) or an object with
|
||||
/// `value` and `matching_strategy` for advanced matching.
|
||||
pub enum HiddenIconRule {
|
||||
/// Match by exe name (case-insensitive, exact)
|
||||
Exe(String),
|
||||
/// Match by one or more properties (all specified fields must match)
|
||||
Match {
|
||||
/// Exe name to match
|
||||
exe: Option<FieldMatch>,
|
||||
/// Tooltip text to match
|
||||
tooltip: Option<FieldMatch>,
|
||||
/// Icon GUID to match (most stable identifier across restarts)
|
||||
guid: Option<FieldMatch>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// System tray widget configuration
|
||||
pub struct SystrayConfig {
|
||||
/// Enable the System Tray widget
|
||||
pub enable: bool,
|
||||
/// A list of rules for icons to hide from the system tray
|
||||
///
|
||||
/// Each entry can be a plain string (matches exe name, case-insensitive)
|
||||
/// or an object with optional `exe`, `tooltip`, and/or `guid` fields
|
||||
/// (all specified fields must match, AND logic, case-insensitive).
|
||||
///
|
||||
/// Run komorebi-bar with RUST_LOG=info to see the properties of all
|
||||
/// systray icons in the log output.
|
||||
pub hidden_icons: Option<Vec<HiddenIconRule>>,
|
||||
/// Position of the overflow toggle button (default: Right)
|
||||
pub overflow_toggle_position: Option<OverflowTogglePosition>,
|
||||
/// Show an info button that opens a floating panel listing all systray icons
|
||||
/// with their exe, tooltip, and GUID. Set to "Visible" to show it in the main
|
||||
/// area, or "Overflow" to show it in the hidden/overflow section.
|
||||
pub info_button: Option<ButtonPosition>,
|
||||
/// Interval in seconds to automatically check for and remove stale icons
|
||||
/// whose owning process has exited. Clamped between 30 and 600 seconds.
|
||||
/// Defaults to 60. Set to 0 to disable.
|
||||
pub stale_icons_check_interval: Option<u64>,
|
||||
/// Show a refresh button that manually triggers stale icon cleanup.
|
||||
/// Set to "Visible" to show it in the main area, or "Overflow" to
|
||||
/// show it in the hidden/overflow section.
|
||||
pub refresh_button: Option<ButtonPosition>,
|
||||
/// Show a button that toggles komorebi-shortcuts (kills the process if
|
||||
/// running, starts it otherwise). Set to "Visible" to show it in the main
|
||||
/// area, or "Overflow" to show it in the hidden/overflow section.
|
||||
pub shortcuts_button: Option<ButtonPosition>,
|
||||
}
|
||||
|
||||
/// Command sent from UI to background thread
|
||||
#[derive(Debug)]
|
||||
enum SystrayCommand {
|
||||
@@ -0,0 +1,41 @@
|
||||
use crate::windows::widgets::applications::Applications;
|
||||
use crate::windows::widgets::battery::Battery;
|
||||
use crate::windows::widgets::cpu::Cpu;
|
||||
use crate::windows::widgets::date::Date;
|
||||
use crate::windows::widgets::keyboard::Keyboard;
|
||||
use crate::windows::widgets::komorebi::Komorebi;
|
||||
use crate::windows::widgets::media::Media;
|
||||
use crate::windows::widgets::memory::Memory;
|
||||
use crate::windows::widgets::network::Network;
|
||||
use crate::windows::widgets::storage::Storage;
|
||||
use crate::windows::widgets::systray::Systray;
|
||||
use crate::windows::widgets::time::Time;
|
||||
use crate::windows::widgets::update::Update;
|
||||
|
||||
pub use komorebi_bar_core::widgets::widget::BarWidget;
|
||||
pub use komorebi_bar_core::widgets::widget::WidgetConfig;
|
||||
|
||||
/// Turns a widget configuration into the widget that renders it.
|
||||
pub trait WidgetConfigExt {
|
||||
fn as_boxed_bar_widget(&self) -> Box<dyn BarWidget>;
|
||||
}
|
||||
|
||||
impl WidgetConfigExt for WidgetConfig {
|
||||
fn as_boxed_bar_widget(&self) -> Box<dyn BarWidget> {
|
||||
match self {
|
||||
WidgetConfig::Applications(config) => Box::new(Applications::from(config)),
|
||||
WidgetConfig::Battery(config) => Box::new(Battery::from(*config)),
|
||||
WidgetConfig::Cpu(config) => Box::new(Cpu::from(*config)),
|
||||
WidgetConfig::Date(config) => Box::new(Date::from(config.clone())),
|
||||
WidgetConfig::Keyboard(config) => Box::new(Keyboard::from(*config)),
|
||||
WidgetConfig::Komorebi(config) => Box::new(Komorebi::from(config)),
|
||||
WidgetConfig::Media(config) => Box::new(Media::from(*config)),
|
||||
WidgetConfig::Memory(config) => Box::new(Memory::from(*config)),
|
||||
WidgetConfig::Network(config) => Box::new(Network::from(*config)),
|
||||
WidgetConfig::Storage(config) => Box::new(Storage::from(*config)),
|
||||
WidgetConfig::Systray(config) => Box::new(Systray::from(config)),
|
||||
WidgetConfig::Time(config) => Box::new(Time::from(config.clone())),
|
||||
WidgetConfig::Update(config) => Box::new(Update::from(*config)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,27 @@ edition = "2024"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
komorebi = { path = "../komorebi", default-features = false }
|
||||
# One dependency key has one path, so the daemon of each platform has a key of its own, and the module of
|
||||
# the platform names it (`use crate::komorebi_linux as komorebi`).
|
||||
|
||||
uds_windows = { workspace = true }
|
||||
[dependencies]
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
komorebi = { package = "komorebi-windows", path = "../komorebi", default-features = false }
|
||||
uds_windows = { workspace = true }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
komorebi-linux = { package = "komorebi-linux", path = "../komorebi-for-kde/komorebi", default-features = false }
|
||||
komorebi-themes = { path = "../komorebi-themes" }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
komorebi-macos = { package = "komorebi-macos", path = "../komorebi-for-mac/komorebi", default-features = false }
|
||||
komorebi-themes = { path = "../komorebi-themes" }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dev-dependencies]
|
||||
parking_lot = "0.13"
|
||||
|
||||
[features]
|
||||
default = ["schemars"]
|
||||
schemars = ["komorebi/default"]
|
||||
schemars = ["komorebi/default", "komorebi-linux/default", "komorebi-macos/default"]
|
||||
+17
-204
@@ -1,211 +1,24 @@
|
||||
#![warn(clippy::all)]
|
||||
#![allow(clippy::missing_errors_doc)]
|
||||
|
||||
pub use komorebi::AnimationsConfig;
|
||||
pub use komorebi::AppSpecificConfigurationPath;
|
||||
pub use komorebi::AspectRatio;
|
||||
pub use komorebi::BorderColours;
|
||||
pub use komorebi::Colour;
|
||||
pub use komorebi::CrossBoundaryBehaviour;
|
||||
pub use komorebi::GridLayoutOptions;
|
||||
pub use komorebi::KomorebiTheme;
|
||||
pub use komorebi::LayoutOptions;
|
||||
pub use komorebi::MonitorConfig;
|
||||
pub use komorebi::Notification;
|
||||
pub use komorebi::NotificationEvent;
|
||||
pub use komorebi::Placement;
|
||||
pub use komorebi::PredefinedAspectRatio;
|
||||
pub use komorebi::Rgb;
|
||||
pub use komorebi::RuleDebug;
|
||||
pub use komorebi::ScrollingLayoutOptions;
|
||||
pub use komorebi::StackbarConfig;
|
||||
pub use komorebi::StaticConfig;
|
||||
pub use komorebi::SubscribeOptions;
|
||||
pub use komorebi::TabsConfig;
|
||||
pub use komorebi::ThemeOptions;
|
||||
pub use komorebi::VirtualDesktopNotification;
|
||||
pub use komorebi::Wallpaper;
|
||||
pub use komorebi::WindowContainerBehaviour;
|
||||
pub use komorebi::WindowHandlingBehaviour;
|
||||
pub use komorebi::WindowsApi;
|
||||
pub use komorebi::WorkspaceConfig;
|
||||
pub use komorebi::animation::PerAnimationPrefixConfig;
|
||||
pub use komorebi::animation::prefix::AnimationPrefix;
|
||||
pub use komorebi::asc::ApplicationSpecificConfiguration;
|
||||
pub use komorebi::border_manager::BorderInfo;
|
||||
pub use komorebi::config_generation::ApplicationConfiguration;
|
||||
pub use komorebi::config_generation::IdWithIdentifier;
|
||||
pub use komorebi::config_generation::IdWithIdentifierAndComment;
|
||||
pub use komorebi::config_generation::MatchingRule;
|
||||
pub use komorebi::config_generation::MatchingStrategy;
|
||||
pub use komorebi::container::Container;
|
||||
pub use komorebi::core::AnimationStyle;
|
||||
pub use komorebi::core::ApplicationIdentifier;
|
||||
pub use komorebi::core::Arrangement;
|
||||
pub use komorebi::core::Axis;
|
||||
pub use komorebi::core::BorderImplementation;
|
||||
pub use komorebi::core::BorderStyle;
|
||||
pub use komorebi::core::Column;
|
||||
pub use komorebi::core::ColumnSplit;
|
||||
pub use komorebi::core::ColumnSplitWithCapacity;
|
||||
pub use komorebi::core::ColumnWidth;
|
||||
pub use komorebi::core::CustomLayout;
|
||||
pub use komorebi::core::CycleDirection;
|
||||
pub use komorebi::core::DefaultLayout;
|
||||
pub use komorebi::core::Direction;
|
||||
pub use komorebi::core::FloatingLayerBehaviour;
|
||||
pub use komorebi::core::FocusFollowsMouseImplementation;
|
||||
pub use komorebi::core::HidingBehaviour;
|
||||
pub use komorebi::core::Layout;
|
||||
pub use komorebi::core::MonocleFocusBehaviour;
|
||||
pub use komorebi::core::MoveBehaviour;
|
||||
pub use komorebi::core::OperationBehaviour;
|
||||
pub use komorebi::core::OperationDirection;
|
||||
pub use komorebi::core::PanDirection;
|
||||
pub use komorebi::core::PanGesture;
|
||||
pub use komorebi::core::PathExt;
|
||||
pub use komorebi::core::Rect;
|
||||
pub use komorebi::core::Sizing;
|
||||
pub use komorebi::core::SocketMessage;
|
||||
pub use komorebi::core::StackbarLabel;
|
||||
pub use komorebi::core::StackbarMode;
|
||||
pub use komorebi::core::StateQuery;
|
||||
pub use komorebi::core::WindowKind;
|
||||
pub use komorebi::core::config_generation::ApplicationConfigurationGenerator;
|
||||
pub use komorebi::core::replace_env_in_path;
|
||||
pub use komorebi::monitor::Monitor;
|
||||
pub use komorebi::monitor_reconciliator::MonitorNotification;
|
||||
pub use komorebi::ring::Ring;
|
||||
pub use komorebi::splash;
|
||||
pub use komorebi::state::GlobalState;
|
||||
pub use komorebi::state::State;
|
||||
pub use komorebi::win32_display_data;
|
||||
pub use komorebi::window::Window;
|
||||
pub use komorebi::window_manager_event::WindowManagerEvent;
|
||||
pub use komorebi::workspace::Workspace;
|
||||
pub use komorebi::workspace::WorkspaceGlobals;
|
||||
pub use komorebi::workspace::WorkspaceLayer;
|
||||
//! The client of the komorebi daemon, for Windows, KDE Plasma and macOS: one crate, with the module
|
||||
//! of the target OS re-exported at its root. The functions that talk to the daemon's socket and the
|
||||
//! types they send are the same in the three modules; what differs is the daemon crate they
|
||||
//! re-export from and the socket type (`uds_windows` on Windows, `std::os::unix` elsewhere).
|
||||
|
||||
use komorebi::DATA_DIR;
|
||||
|
||||
use std::borrow::Borrow;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::net::Shutdown;
|
||||
use std::time::Duration;
|
||||
pub use uds_windows::UnixListener;
|
||||
use uds_windows::UnixStream;
|
||||
|
||||
const KOMOREBI: &str = "komorebi.sock";
|
||||
|
||||
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())
|
||||
}
|
||||
|
||||
/// A connection to komorebi that messages are written to one after the other, which komorebi
|
||||
/// handles in the order that they were written, as it does the lines of a batch. Messages sent
|
||||
/// with [`send_message`] are each on a connection of their own, which komorebi handles on a
|
||||
/// thread of its own, so two that are sent together can be handled in either order.
|
||||
pub struct Connection {
|
||||
stream: UnixStream,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
pub fn open() -> std::io::Result<Self> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
|
||||
Ok(Self { stream })
|
||||
cfg_select! {
|
||||
target_os = "windows" => {
|
||||
mod windows;
|
||||
pub use windows::*;
|
||||
}
|
||||
|
||||
pub fn send(&mut self, message: &SocketMessage) -> std::io::Result<()> {
|
||||
let mut line = serde_json::to_string(message)?;
|
||||
line.push('\n');
|
||||
|
||||
self.stream.write_all(line.as_bytes())
|
||||
target_os = "linux" => {
|
||||
extern crate komorebi_linux;
|
||||
mod linux;
|
||||
pub use linux::*;
|
||||
}
|
||||
target_os = "macos" => {
|
||||
extern crate komorebi_macos;
|
||||
mod macos;
|
||||
pub use macos::*;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_batch<Q>(messages: impl IntoIterator<Item = Q>) -> std::io::Result<()>
|
||||
where
|
||||
Q: Borrow<SocketMessage>,
|
||||
{
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
let msgs = messages.into_iter().fold(String::new(), |mut s, m| {
|
||||
if let Ok(m_str) = serde_json::to_string(m.borrow()) {
|
||||
s.push_str(&m_str);
|
||||
s.push('\n');
|
||||
}
|
||||
s
|
||||
});
|
||||
stream.write_all(msgs.as_bytes())
|
||||
}
|
||||
|
||||
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())?;
|
||||
stream.shutdown(Shutdown::Write)?;
|
||||
|
||||
let mut reader = BufReader::new(stream);
|
||||
let mut response = String::new();
|
||||
reader.read_to_string(&mut response)?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub fn subscribe(name: &str) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocket(name.to_string()))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
|
||||
pub fn subscribe_with_options(
|
||||
name: &str,
|
||||
options: SubscribeOptions,
|
||||
) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocketWithOptions(
|
||||
name.to_string(),
|
||||
options,
|
||||
))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
@@ -0,0 +1,435 @@
|
||||
//! A client for the komorebi daemon: it writes [`SocketMessage`]s on the daemon's socket and reads
|
||||
//! the daemon's answers.
|
||||
//!
|
||||
//! The daemon listens on `komorebi.sock` in [`struct@DATA_DIR`], which is
|
||||
//! `$XDG_RUNTIME_DIR/komorebi` in a desktop session. Every function here opens a new connection
|
||||
//! and writes each message as one line of JSON. [`send_message`] and [`send_batch`] give
|
||||
//! orders and read nothing back; [`send_query`] asks a question and returns the answer, which the
|
||||
//! daemon ends by closing the connection. A function fails with the error of the connection, so a
|
||||
//! daemon that is not running is an [`std::io::ErrorKind::NotFound`] or a
|
||||
//! [`std::io::ErrorKind::ConnectionRefused`].
|
||||
//!
|
||||
//! [`subscribe`] and [`subscribe_with_options`] make the program a subscriber: they listen on a
|
||||
//! socket of its own in [`struct@DATA_DIR`], and ask the daemon to send a [`Notification`] to it
|
||||
//! after each event and each message the window manager handles.
|
||||
//!
|
||||
//! The crate also re-exports the types the messages and the answers are made of, so that a client
|
||||
//! needs nothing else, and [`check`], the checks `komorebic check` runs.
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! The examples on this page answer for the daemon: each one listens on the socket itself, in a
|
||||
//! runtime directory made for it, before it sends anything.
|
||||
//!
|
||||
//! ```rust
|
||||
//! # use std::io::{BufRead, BufReader, Write};
|
||||
//! # let runtime = format!("/tmp/komorebi-client-doc-crate-{}", std::process::id());
|
||||
//! # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
//! # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
//! # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
//! # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
//! # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
//! # let (mut stream, _) = listener.accept()?;
|
||||
//! # let mut line = String::new();
|
||||
//! # BufReader::new(stream.try_clone()?).read_line(&mut line)?;
|
||||
//! # stream.write_all(b"2")?;
|
||||
//! # Ok(line)
|
||||
//! # });
|
||||
//! use komorebi_client::SocketMessage;
|
||||
//! use komorebi_client::StateQuery;
|
||||
//! use komorebi_client::send_query;
|
||||
//!
|
||||
//! let workspace = send_query(&SocketMessage::Query(StateQuery::FocusedWorkspaceIndex))?;
|
||||
//! assert_eq!(workspace, "2");
|
||||
//!
|
||||
//! # assert_eq!(
|
||||
//! # daemon.join().unwrap()?,
|
||||
//! # r#"{"type":"Query","content":"FocusedWorkspaceIndex"}"#
|
||||
//! # );
|
||||
//! # std::fs::remove_dir_all(&runtime)?;
|
||||
//! # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
//! ```
|
||||
//!
|
||||
//! `komorebi-client/tests/daemon.rs` sends the same messages to a window manager that listens the
|
||||
//! way the daemon does, over an in-memory desktop.
|
||||
|
||||
use crate::komorebi_linux as komorebi;
|
||||
|
||||
pub use komorebi::DATA_DIR;
|
||||
pub use komorebi::LOG_DIR;
|
||||
pub use komorebi::Notification;
|
||||
pub use komorebi::NotificationEvent;
|
||||
pub use komorebi::animation::AnimationPrefix;
|
||||
pub use komorebi::check;
|
||||
pub use komorebi::container::Container;
|
||||
pub use komorebi::core::ApplicationIdentifier;
|
||||
pub use komorebi::core::Axis;
|
||||
pub use komorebi::core::CycleDirection;
|
||||
pub use komorebi::core::DefaultLayout;
|
||||
pub use komorebi::core::FocusFollowsMouseImplementation;
|
||||
pub use komorebi::core::Layout;
|
||||
pub use komorebi::core::MonocleFocusBehaviour;
|
||||
pub use komorebi::core::MoveBehaviour;
|
||||
pub use komorebi::core::OperationBehaviour;
|
||||
pub use komorebi::core::OperationDirection;
|
||||
pub use komorebi::core::PanDirection;
|
||||
pub use komorebi::core::Rect;
|
||||
pub use komorebi::core::ScrollingCentering;
|
||||
pub use komorebi::core::Sizing;
|
||||
pub use komorebi::core::SocketMessage;
|
||||
pub use komorebi::core::StateQuery;
|
||||
pub use komorebi::core::SubscribeOptions;
|
||||
pub use komorebi::core::WindowKind;
|
||||
pub use komorebi::core::animation::AnimationStyle;
|
||||
pub use komorebi::core::asc::ApplicationSpecificConfiguration;
|
||||
pub use komorebi::core::pathext::PathExt;
|
||||
pub use komorebi::core::pathext::replace_env_in_path;
|
||||
pub use komorebi::monitor_reconciliator::MonitorNotification;
|
||||
pub use komorebi::state::State;
|
||||
pub use komorebi::static_config::StaticConfig;
|
||||
pub use komorebi::window::Window;
|
||||
pub use komorebi::workspace::Workspace;
|
||||
pub use komorebi::workspace::WorkspaceLayer;
|
||||
pub use komorebi_themes::KomorebiTheme;
|
||||
pub use komorebi_themes::colour::Colour;
|
||||
pub use komorebi_themes::colour::Rgb;
|
||||
use std::borrow::Borrow;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::net::Shutdown;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::time::Duration;
|
||||
|
||||
const KOMOREBI: &str = "komorebi.sock";
|
||||
|
||||
/// Sends one message to the daemon, and does not wait for it to be handled
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The daemon's socket cannot be connected to, for example because the daemon is not running.
|
||||
/// - The message cannot be written within a second.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-message-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # let mut line = String::new();
|
||||
/// # BufReader::new(stream).read_line(&mut line)?;
|
||||
/// # Ok(line)
|
||||
/// # });
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::send_message;
|
||||
///
|
||||
/// send_message(&SocketMessage::Retile)?;
|
||||
///
|
||||
/// # assert_eq!(daemon.join().unwrap()?, r#"{"type":"Retile"}"#);
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())
|
||||
}
|
||||
|
||||
/// A connection to komorebi that messages are written to one after the other, which komorebi
|
||||
/// handles in the order that they were written, as it does the lines of a batch. Messages sent
|
||||
/// with [`send_message`] are each on a connection of their own, which komorebi handles on a
|
||||
/// thread of its own, so two that are sent together can be handled in either order.
|
||||
pub struct Connection {
|
||||
stream: UnixStream,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
/// Opens a connection to the daemon's socket.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The daemon's socket cannot be connected to, or written to within a second.
|
||||
pub fn open() -> std::io::Result<Self> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
Self::from_stream(UnixStream::connect(socket)?)
|
||||
}
|
||||
|
||||
fn from_stream(stream: UnixStream) -> std::io::Result<Self> {
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
|
||||
Ok(Self { stream })
|
||||
}
|
||||
|
||||
/// Writes one message as a line.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The message cannot be written, for example because the daemon let go of the connection.
|
||||
pub fn send(&mut self, message: &SocketMessage) -> std::io::Result<()> {
|
||||
let mut line = serde_json::to_string(message)?;
|
||||
line.push('\n');
|
||||
|
||||
self.stream.write_all(line.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends several messages to the daemon on one connection, which handles them in order, and does
|
||||
/// not wait for them to be handled
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The same as [`send_message`].
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-batch-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<Vec<String>> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # BufReader::new(stream).lines().collect()
|
||||
/// # });
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::send_batch;
|
||||
///
|
||||
/// send_batch([SocketMessage::Retile, SocketMessage::Stop])?;
|
||||
///
|
||||
/// # assert_eq!(daemon.join().unwrap()?, [r#"{"type":"Retile"}"#, r#"{"type":"Stop"}"#]);
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn send_batch<Q>(messages: impl IntoIterator<Item = Q>) -> std::io::Result<()>
|
||||
where
|
||||
Q: Borrow<SocketMessage>,
|
||||
{
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
let msgs = messages.into_iter().fold(String::new(), |mut s, m| {
|
||||
if let Ok(m_str) = serde_json::to_string(m.borrow()) {
|
||||
s.push_str(&m_str);
|
||||
s.push('\n');
|
||||
}
|
||||
s
|
||||
});
|
||||
stream.write_all(msgs.as_bytes())
|
||||
}
|
||||
|
||||
/// Sends one message to the daemon and returns its answer: JSON for
|
||||
/// [`SocketMessage::State`] and [`SocketMessage::MonitorInformation`], one value as text for
|
||||
/// [`SocketMessage::Query`], and nothing for a message that is not a question
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The daemon's socket cannot be connected to, for example because the daemon is not running.
|
||||
/// - The message cannot be written within a second.
|
||||
/// - The daemon sends nothing for a second before its answer is complete.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// The answer to [`SocketMessage::State`] reads back as a [`State`]:
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader, Write};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-query-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<()> {
|
||||
/// # let (mut stream, _) = listener.accept()?;
|
||||
/// # BufReader::new(stream.try_clone()?).read_line(&mut String::new())?;
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # stream.write_all(state.as_bytes())
|
||||
/// # });
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::State;
|
||||
/// use komorebi_client::send_query;
|
||||
///
|
||||
/// let state: State = serde_json::from_str(&send_query(&SocketMessage::State)?)?;
|
||||
/// assert!(state.mouse_follows_focus);
|
||||
///
|
||||
/// # daemon.join().unwrap()?;
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())?;
|
||||
stream.shutdown(Shutdown::Write)?;
|
||||
|
||||
let mut reader = BufReader::new(stream);
|
||||
let mut response = String::new();
|
||||
reader.read_to_string(&mut response)?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
/// Listens on the socket `name` in [`struct@DATA_DIR`], and asks the daemon to send a
|
||||
/// [`Notification`] to it after each event and each message the window manager handles
|
||||
///
|
||||
/// A socket file that is left over at that path is removed first. Each notification comes on a
|
||||
/// new connection, as JSON, and ends when the daemon closes the connection; the first is the
|
||||
/// notification of the subscription itself. When the daemon stops, it connects and closes the
|
||||
/// connection without writing anything.
|
||||
///
|
||||
/// A subscriber that the daemon cannot connect to, because its program has exited or its socket
|
||||
/// was removed, is removed at the next notification, with its socket file. It has to subscribe
|
||||
/// again: the daemon does not try it again, and does not keep its subscribers when it restarts.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The socket file left over at that path cannot be removed.
|
||||
/// - The socket cannot be bound, for example because [`struct@DATA_DIR`] does not exist.
|
||||
/// - The subscription cannot be sent, for one of the reasons [`send_message`] gives.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader, Write};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-subscribe-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the sockets are in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # let mut message = String::new();
|
||||
/// # BufReader::new(stream).read_line(&mut message)?;
|
||||
/// # let subscriber = komorebi_client::DATA_DIR.join("bar.sock");
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # let notification = format!(r#"{{"event":{message},"state":{state}}}"#);
|
||||
/// # std::os::unix::net::UnixStream::connect(subscriber)?.write_all(notification.as_bytes())?;
|
||||
/// # Ok(message)
|
||||
/// # });
|
||||
/// use std::io::Read;
|
||||
///
|
||||
/// use komorebi_client::Notification;
|
||||
/// use komorebi_client::NotificationEvent;
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::subscribe;
|
||||
///
|
||||
/// let listener = subscribe("bar.sock")?;
|
||||
///
|
||||
/// // the first notification is the one of the subscription
|
||||
/// let (mut connection, _) = listener.accept()?;
|
||||
/// let mut json = String::new();
|
||||
/// connection.read_to_string(&mut json)?;
|
||||
/// let notification: Notification = serde_json::from_str(&json)?;
|
||||
/// assert!(matches!(
|
||||
/// notification.event,
|
||||
/// NotificationEvent::Socket(SocketMessage::AddSubscriberSocket(name)) if name == "bar.sock"
|
||||
/// ));
|
||||
///
|
||||
/// # assert_eq!(
|
||||
/// # daemon.join().unwrap()?,
|
||||
/// # r#"{"type":"AddSubscriberSocket","content":"bar.sock"}"#
|
||||
/// # );
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn subscribe(name: &str) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocket(name.to_string()))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
|
||||
/// The same as [`subscribe`], with the [`SubscribeOptions`] the daemon applies to this subscriber
|
||||
///
|
||||
/// With `filter_state_changes`, the daemon sends a notification only when the event or the message
|
||||
/// changed the [`State`], and always when a window is shown, when a subscriber is added, when a
|
||||
/// theme is set and when the configuration is reloaded.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The same as [`subscribe`].
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-options-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the sockets are in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # let mut message = String::new();
|
||||
/// # BufReader::new(stream).read_line(&mut message)?;
|
||||
/// # Ok(message)
|
||||
/// # });
|
||||
/// use komorebi_client::DATA_DIR;
|
||||
/// use komorebi_client::SubscribeOptions;
|
||||
/// use komorebi_client::subscribe_with_options;
|
||||
///
|
||||
/// let options = SubscribeOptions {
|
||||
/// filter_state_changes: true,
|
||||
/// };
|
||||
/// let listener = subscribe_with_options("bar.sock", options)?;
|
||||
///
|
||||
/// let socket = DATA_DIR.join("bar.sock");
|
||||
/// assert_eq!(listener.local_addr()?.as_pathname(), Some(socket.as_path()));
|
||||
///
|
||||
/// # assert_eq!(
|
||||
/// # daemon.join().unwrap()?,
|
||||
/// # r#"{"type":"AddSubscriberSocketWithOptions","content":["bar.sock",{"filter_state_changes":true}]}"#
|
||||
/// # );
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn subscribe_with_options(
|
||||
name: &str,
|
||||
options: SubscribeOptions,
|
||||
) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocketWithOptions(
|
||||
name.to_string(),
|
||||
options,
|
||||
))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
use crate::komorebi_macos as komorebi;
|
||||
|
||||
pub use komorebi::DATA_DIR;
|
||||
pub use komorebi::Notification;
|
||||
pub use komorebi::NotificationEvent;
|
||||
pub use komorebi::animation::AnimationPrefix;
|
||||
pub use komorebi::container::Container;
|
||||
pub use komorebi::core::ApplicationIdentifier;
|
||||
pub use komorebi::core::Axis;
|
||||
pub use komorebi::core::CycleDirection;
|
||||
pub use komorebi::core::DefaultLayout;
|
||||
pub use komorebi::core::Layout;
|
||||
pub use komorebi::core::MonocleFocusBehaviour;
|
||||
pub use komorebi::core::MoveBehaviour;
|
||||
pub use komorebi::core::OperationBehaviour;
|
||||
pub use komorebi::core::OperationDirection;
|
||||
pub use komorebi::core::PanDirection;
|
||||
pub use komorebi::core::PanGesture;
|
||||
pub use komorebi::core::Rect;
|
||||
pub use komorebi::core::Sizing;
|
||||
pub use komorebi::core::SocketMessage;
|
||||
pub use komorebi::core::StateQuery;
|
||||
pub use komorebi::core::SubscribeOptions;
|
||||
pub use komorebi::core::WindowKind;
|
||||
pub use komorebi::core::animation::AnimationStyle;
|
||||
pub use komorebi::core::asc::ApplicationSpecificConfiguration;
|
||||
pub use komorebi::core::pathext::PathExt;
|
||||
pub use komorebi::core::pathext::replace_env_in_path;
|
||||
pub use komorebi::monitor_reconciliator::MonitorNotification;
|
||||
pub use komorebi::splash;
|
||||
pub use komorebi::state::State;
|
||||
pub use komorebi::static_config::StaticConfig;
|
||||
pub use komorebi::window::Window;
|
||||
pub use komorebi::workspace::Workspace;
|
||||
pub use komorebi::workspace::WorkspaceLayer;
|
||||
pub use komorebi_themes::KomorebiTheme;
|
||||
pub use komorebi_themes::colour::Colour;
|
||||
pub use komorebi_themes::colour::Rgb;
|
||||
use std::borrow::Borrow;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::net::Shutdown;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::time::Duration;
|
||||
|
||||
const KOMOREBI: &str = "komorebi.sock";
|
||||
|
||||
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())
|
||||
}
|
||||
|
||||
/// A connection to komorebi that messages are written to one after the other, which komorebi
|
||||
/// handles in the order that they were written, as it does the lines of a batch. Messages sent
|
||||
/// with [`send_message`] are each on a connection of their own, which komorebi handles on a
|
||||
/// thread of its own, so two that are sent together can be handled in either order.
|
||||
pub struct Connection {
|
||||
stream: UnixStream,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
pub fn open() -> std::io::Result<Self> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
Self::from_stream(UnixStream::connect(socket)?)
|
||||
}
|
||||
|
||||
fn from_stream(stream: UnixStream) -> std::io::Result<Self> {
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
|
||||
Ok(Self { stream })
|
||||
}
|
||||
|
||||
pub fn send(&mut self, message: &SocketMessage) -> std::io::Result<()> {
|
||||
let mut line = serde_json::to_string(message)?;
|
||||
line.push('\n');
|
||||
|
||||
self.stream.write_all(line.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_batch<Q>(messages: impl IntoIterator<Item = Q>) -> std::io::Result<()>
|
||||
where
|
||||
Q: Borrow<SocketMessage>,
|
||||
{
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
let msgs = messages.into_iter().fold(String::new(), |mut s, m| {
|
||||
if let Ok(m_str) = serde_json::to_string(m.borrow()) {
|
||||
s.push_str(&m_str);
|
||||
s.push('\n');
|
||||
}
|
||||
s
|
||||
});
|
||||
stream.write_all(msgs.as_bytes())
|
||||
}
|
||||
|
||||
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())?;
|
||||
stream.shutdown(Shutdown::Write)?;
|
||||
|
||||
let mut reader = BufReader::new(stream);
|
||||
let mut response = String::new();
|
||||
reader.read_to_string(&mut response)?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub fn subscribe(name: &str) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocket(name.to_string()))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
|
||||
pub fn subscribe_with_options(
|
||||
name: &str,
|
||||
options: SubscribeOptions,
|
||||
) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocketWithOptions(
|
||||
name.to_string(),
|
||||
options,
|
||||
))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::io::BufRead;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn messages_are_written_to_a_connection_a_line_each_in_the_order_that_they_were_sent() {
|
||||
let (ours, theirs) = UnixStream::pair().unwrap();
|
||||
let mut connection = Connection::from_stream(ours).unwrap();
|
||||
|
||||
connection
|
||||
.send(&SocketMessage::PanGesture(PanGesture::Begin))
|
||||
.unwrap();
|
||||
connection
|
||||
.send(&SocketMessage::Pan(PanDirection::Right))
|
||||
.unwrap();
|
||||
connection
|
||||
.send(&SocketMessage::PanGesture(PanGesture::Move {
|
||||
dx: 0.5,
|
||||
dy: 0.0,
|
||||
t: 12.0,
|
||||
}))
|
||||
.unwrap();
|
||||
drop(connection);
|
||||
|
||||
let lines: Vec<String> = BufReader::new(theirs)
|
||||
.lines()
|
||||
.collect::<Result<_, _>>()
|
||||
.unwrap();
|
||||
assert_eq!(lines.len(), 3, "one line to a message: {lines:?}");
|
||||
|
||||
let messages: Vec<SocketMessage> = lines
|
||||
.iter()
|
||||
.map(|line| SocketMessage::from_str(line).unwrap())
|
||||
.collect();
|
||||
assert!(matches!(
|
||||
messages[0],
|
||||
SocketMessage::PanGesture(PanGesture::Begin)
|
||||
));
|
||||
assert!(matches!(
|
||||
messages[1],
|
||||
SocketMessage::Pan(PanDirection::Right)
|
||||
));
|
||||
assert!(matches!(
|
||||
messages[2],
|
||||
SocketMessage::PanGesture(PanGesture::Move { dx, t, .. }) if dx == 0.5 && t == 12.0
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn writing_to_a_connection_that_was_let_go_of_is_an_error() {
|
||||
let (ours, theirs) = UnixStream::pair().unwrap();
|
||||
let mut connection = Connection::from_stream(ours).unwrap();
|
||||
drop(theirs);
|
||||
|
||||
assert!(
|
||||
connection
|
||||
.send(&SocketMessage::PanGesture(PanGesture::Cancel))
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
|
||||
pub use komorebi::AnimationsConfig;
|
||||
pub use komorebi::AppSpecificConfigurationPath;
|
||||
pub use komorebi::AspectRatio;
|
||||
pub use komorebi::BorderColours;
|
||||
pub use komorebi::Colour;
|
||||
pub use komorebi::CrossBoundaryBehaviour;
|
||||
pub use komorebi::GridLayoutOptions;
|
||||
pub use komorebi::KomorebiTheme;
|
||||
pub use komorebi::LayoutOptions;
|
||||
pub use komorebi::MonitorConfig;
|
||||
pub use komorebi::Notification;
|
||||
pub use komorebi::NotificationEvent;
|
||||
pub use komorebi::Placement;
|
||||
pub use komorebi::PredefinedAspectRatio;
|
||||
pub use komorebi::Rgb;
|
||||
pub use komorebi::RuleDebug;
|
||||
pub use komorebi::ScrollingLayoutOptions;
|
||||
pub use komorebi::StackbarConfig;
|
||||
pub use komorebi::StaticConfig;
|
||||
pub use komorebi::SubscribeOptions;
|
||||
pub use komorebi::TabsConfig;
|
||||
pub use komorebi::ThemeOptions;
|
||||
pub use komorebi::VirtualDesktopNotification;
|
||||
pub use komorebi::Wallpaper;
|
||||
pub use komorebi::WindowContainerBehaviour;
|
||||
pub use komorebi::WindowHandlingBehaviour;
|
||||
pub use komorebi::WindowsApi;
|
||||
pub use komorebi::WorkspaceConfig;
|
||||
pub use komorebi::animation::PerAnimationPrefixConfig;
|
||||
pub use komorebi::animation::prefix::AnimationPrefix;
|
||||
pub use komorebi::asc::ApplicationSpecificConfiguration;
|
||||
pub use komorebi::border_manager::BorderInfo;
|
||||
pub use komorebi::config_generation::ApplicationConfiguration;
|
||||
pub use komorebi::config_generation::IdWithIdentifier;
|
||||
pub use komorebi::config_generation::IdWithIdentifierAndComment;
|
||||
pub use komorebi::config_generation::MatchingRule;
|
||||
pub use komorebi::config_generation::MatchingStrategy;
|
||||
pub use komorebi::container::Container;
|
||||
pub use komorebi::core::AnimationStyle;
|
||||
pub use komorebi::core::ApplicationIdentifier;
|
||||
pub use komorebi::core::Arrangement;
|
||||
pub use komorebi::core::Axis;
|
||||
pub use komorebi::core::BorderImplementation;
|
||||
pub use komorebi::core::BorderStyle;
|
||||
pub use komorebi::core::Column;
|
||||
pub use komorebi::core::ColumnSplit;
|
||||
pub use komorebi::core::ColumnSplitWithCapacity;
|
||||
pub use komorebi::core::ColumnWidth;
|
||||
pub use komorebi::core::CustomLayout;
|
||||
pub use komorebi::core::CycleDirection;
|
||||
pub use komorebi::core::DefaultLayout;
|
||||
pub use komorebi::core::Direction;
|
||||
pub use komorebi::core::FloatingLayerBehaviour;
|
||||
pub use komorebi::core::FocusFollowsMouseImplementation;
|
||||
pub use komorebi::core::HidingBehaviour;
|
||||
pub use komorebi::core::Layout;
|
||||
pub use komorebi::core::MonocleFocusBehaviour;
|
||||
pub use komorebi::core::MoveBehaviour;
|
||||
pub use komorebi::core::OperationBehaviour;
|
||||
pub use komorebi::core::OperationDirection;
|
||||
pub use komorebi::core::PanDirection;
|
||||
pub use komorebi::core::PanGesture;
|
||||
pub use komorebi::core::PathExt;
|
||||
pub use komorebi::core::Rect;
|
||||
pub use komorebi::core::Sizing;
|
||||
pub use komorebi::core::SocketMessage;
|
||||
pub use komorebi::core::StackbarLabel;
|
||||
pub use komorebi::core::StackbarMode;
|
||||
pub use komorebi::core::StateQuery;
|
||||
pub use komorebi::core::WindowKind;
|
||||
pub use komorebi::core::config_generation::ApplicationConfigurationGenerator;
|
||||
pub use komorebi::core::replace_env_in_path;
|
||||
pub use komorebi::monitor::Monitor;
|
||||
pub use komorebi::monitor_reconciliator::MonitorNotification;
|
||||
pub use komorebi::ring::Ring;
|
||||
pub use komorebi::splash;
|
||||
pub use komorebi::state::GlobalState;
|
||||
pub use komorebi::state::State;
|
||||
pub use komorebi::win32_display_data;
|
||||
pub use komorebi::window::Window;
|
||||
pub use komorebi::window_manager_event::WindowManagerEvent;
|
||||
pub use komorebi::workspace::Workspace;
|
||||
pub use komorebi::workspace::WorkspaceGlobals;
|
||||
pub use komorebi::workspace::WorkspaceLayer;
|
||||
|
||||
pub use komorebi::DATA_DIR;
|
||||
|
||||
use std::borrow::Borrow;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::net::Shutdown;
|
||||
use std::time::Duration;
|
||||
pub use uds_windows::UnixListener;
|
||||
use uds_windows::UnixStream;
|
||||
|
||||
const KOMOREBI: &str = "komorebi.sock";
|
||||
|
||||
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())
|
||||
}
|
||||
|
||||
/// A connection to komorebi that messages are written to one after the other, which komorebi
|
||||
/// handles in the order that they were written, as it does the lines of a batch. Messages sent
|
||||
/// with [`send_message`] are each on a connection of their own, which komorebi handles on a
|
||||
/// thread of its own, so two that are sent together can be handled in either order.
|
||||
pub struct Connection {
|
||||
stream: UnixStream,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
pub fn open() -> std::io::Result<Self> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
Self::from_stream(UnixStream::connect(socket)?)
|
||||
}
|
||||
|
||||
fn from_stream(stream: UnixStream) -> std::io::Result<Self> {
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
|
||||
Ok(Self { stream })
|
||||
}
|
||||
|
||||
pub fn send(&mut self, message: &SocketMessage) -> std::io::Result<()> {
|
||||
let mut line = serde_json::to_string(message)?;
|
||||
line.push('\n');
|
||||
|
||||
self.stream.write_all(line.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_batch<Q>(messages: impl IntoIterator<Item = Q>) -> std::io::Result<()>
|
||||
where
|
||||
Q: Borrow<SocketMessage>,
|
||||
{
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
let msgs = messages.into_iter().fold(String::new(), |mut s, m| {
|
||||
if let Ok(m_str) = serde_json::to_string(m.borrow()) {
|
||||
s.push_str(&m_str);
|
||||
s.push('\n');
|
||||
}
|
||||
s
|
||||
});
|
||||
stream.write_all(msgs.as_bytes())
|
||||
}
|
||||
|
||||
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())?;
|
||||
stream.shutdown(Shutdown::Write)?;
|
||||
|
||||
let mut reader = BufReader::new(stream);
|
||||
let mut response = String::new();
|
||||
reader.read_to_string(&mut response)?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub fn subscribe(name: &str) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocket(name.to_string()))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
|
||||
pub fn subscribe_with_options(
|
||||
name: &str,
|
||||
options: SubscribeOptions,
|
||||
) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocketWithOptions(
|
||||
name.to_string(),
|
||||
options,
|
||||
))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
+2
@@ -1,7 +1,9 @@
|
||||
#![cfg(target_os = "linux")]
|
||||
//! The client against a window manager that listens the way the daemon does, with
|
||||
//! [`listen_for_commands`], over an in-memory desktop with one monitor and two windows.
|
||||
//!
|
||||
//! The tests share the window manager, and its socket in a runtime directory of this process.
|
||||
extern crate komorebi_linux as komorebi;
|
||||
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
use komorebi::backend::set_backend;
|
||||
+2
@@ -1,3 +1,4 @@
|
||||
#![cfg(target_os = "linux")]
|
||||
//! Subscribers against a window manager that listens the way the daemon does, with
|
||||
//! [`listen_for_commands`], over an in-memory desktop with one monitor: each subscriber listens on a
|
||||
//! socket of its own in a runtime directory of this process, subscribes with `komorebi-client`, and
|
||||
@@ -6,6 +7,7 @@
|
||||
//! The tests share the window manager, and take turns: every subscriber is sent every
|
||||
//! notification, so a test that ran at the same time as another would read the other's
|
||||
//! notifications too. Window ids are 901 and up.
|
||||
extern crate komorebi_linux as komorebi;
|
||||
|
||||
use komorebi::SUBSCRIPTION_SOCKETS;
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
Generated
-6580
File diff suppressed because it is too large.
Load diff
@@ -1,56 +0,0 @@
|
||||
[workspace]
|
||||
|
||||
resolver = "2"
|
||||
members = [
|
||||
"komorebi",
|
||||
"komorebi-client",
|
||||
"komorebi-hotkeys",
|
||||
"komorebic",
|
||||
"version",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
# the Backend trait every komorebi shares, and its in-memory fake
|
||||
komorebi-backend = { path = "../crates/komorebi-backend" }
|
||||
# upstream's layouts, at a revision of its `next` branch that has the fix for resizing a tile by
|
||||
# dragging its edge (LGUG2Z/komorebi#1765), the placement helpers komorebi for KDE uses and the
|
||||
# platform-free half of the rework of the Scrolling layout
|
||||
komorebi-collections = { path = "../crates/komorebi-collections" }
|
||||
# the model shared with the other komorebi daemons
|
||||
komorebi-core = { path = "../crates/komorebi-core" }
|
||||
komorebi-layouts = { path = "../komorebi-layouts", features = [
|
||||
"schemars",
|
||||
] }
|
||||
# the model of a strip of columns that the Scrolling layout is laid out with, from the same
|
||||
# revision, whose layouts re-export it as `komorebi_layouts::scrolling::model`
|
||||
komorebi-scrolling = { path = "../komorebi-scrolling" }
|
||||
# the wire types shared with the other komorebi daemons
|
||||
komorebi-config = { path = "../crates/komorebi-config", default-features = false, features = ["schemars"] }
|
||||
komorebi-protocol = { path = "../crates/komorebi-protocol", default-features = false, features = ["schemars"] }
|
||||
komorebi-transport = { path = "../crates/komorebi-transport" }
|
||||
# the themes (and the palettes made from pictures), from the same upstream revision
|
||||
komorebi-themes = { path = "../komorebi-themes" }
|
||||
|
||||
chrono = "0.4"
|
||||
clap = { version = "4", features = ["derive", "wrap_help"] }
|
||||
color-eyre = "0.6"
|
||||
crossbeam-channel = "0.5"
|
||||
crossbeam-utils = "0.8"
|
||||
dirs = "7"
|
||||
hotwatch = "0.5"
|
||||
lazy_static = "1"
|
||||
pastey = "0.2"
|
||||
schemars = "1.1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { package = "serde_json_lenient", version = "0.2" }
|
||||
shadow-rs = "2"
|
||||
sysinfo = "0.40"
|
||||
tracing = "0.1"
|
||||
tracing-appender = "0.2"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
|
||||
[workspace.metadata.crane]
|
||||
name = "komorebi-workspace"
|
||||
@@ -39,12 +39,12 @@ allow = [
|
||||
confidence-threshold = 0.8
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebi"
|
||||
crate = "komorebi-linux"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebi-client"
|
||||
crate = "komorebi-client-linux"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
@@ -64,7 +64,7 @@ expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebic"
|
||||
crate = "komorebic-linux"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
@@ -74,7 +74,7 @@ expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "version"
|
||||
crate = "version-linux"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
|
||||
+81
-18
@@ -36,12 +36,10 @@
|
||||
crane
|
||||
rust-overlay
|
||||
;
|
||||
rootCrates = [
|
||||
"crates"
|
||||
"komorebi-layouts"
|
||||
"komorebi-scrolling"
|
||||
"komorebi-themes"
|
||||
];
|
||||
# the crates of the root workspace that this workspace depends on, by path, directly or not.
|
||||
# Only these are in the source, so that an edit of another crate (the bar's) changes nothing
|
||||
# here. `tools/kde-closure-check` fails if this list and `cargo metadata` differ.
|
||||
rootCrates = builtins.fromJSON (builtins.readFile ./nix/root-crates.json);
|
||||
mkPkgs =
|
||||
system:
|
||||
import nixpkgs {
|
||||
@@ -62,7 +60,7 @@
|
||||
# the repository, cut down to this workspace and the crates of the root workspace it depends
|
||||
# on by path (komorebi-layouts and what they depend on, komorebi-themes), with the root
|
||||
# manifest those crates inherit their dependencies from
|
||||
src = pkgs.lib.cleanSourceWith {
|
||||
real = pkgs.lib.cleanSourceWith {
|
||||
src = repoRoot;
|
||||
filter =
|
||||
path: type:
|
||||
@@ -73,8 +71,34 @@
|
||||
rootCrate = builtins.any (
|
||||
crate: relative == crate || pkgs.lib.hasPrefix "${crate}/" relative
|
||||
) rootCrates;
|
||||
# the directory that holds the crates of crates/, to reach the listed ones
|
||||
rootCrateParent = relative == "crates";
|
||||
# the unified komorebic package: its manifest, build script, main and the Linux module
|
||||
# and tests; not the Windows and macOS files
|
||||
komorebic =
|
||||
builtins.elem relative [
|
||||
"komorebic"
|
||||
"komorebic/Cargo.toml"
|
||||
"komorebic/build.rs"
|
||||
"komorebic/src"
|
||||
"komorebic/src/main.rs"
|
||||
"komorebic/tests"
|
||||
]
|
||||
|| pkgs.lib.hasPrefix "komorebic/src/linux" relative
|
||||
|| pkgs.lib.hasPrefix "komorebic/tests/linux_" relative;
|
||||
# the unified komorebi-client package: its manifest, lib.rs, the Linux module and tests
|
||||
komorebiClient =
|
||||
builtins.elem relative [
|
||||
"komorebi-client"
|
||||
"komorebi-client/Cargo.toml"
|
||||
"komorebi-client/src"
|
||||
"komorebi-client/src/lib.rs"
|
||||
"komorebi-client/src/linux.rs"
|
||||
"komorebi-client/tests"
|
||||
]
|
||||
|| pkgs.lib.hasPrefix "komorebi-client/tests/linux_" relative;
|
||||
in
|
||||
(rootCrate && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || inTree)
|
||||
((rootCrate || rootCrateParent || komorebic || komorebiClient) && !(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
|
||||
@@ -98,17 +122,32 @@
|
||||
);
|
||||
};
|
||||
|
||||
# the workspace is in a subdirectory of the source, next to the crates it depends on
|
||||
# the platform is a part of the one workspace of the repository: cargo loads every member (the
|
||||
# others are stubs, see nix/workspace-src.nix) and is told which packages are this platform's
|
||||
src = import (repoRoot + "/nix/workspace-src.nix") {
|
||||
inherit pkgs repoRoot real;
|
||||
isReal =
|
||||
member:
|
||||
pkgs.lib.hasPrefix "${platformDir}/" member
|
||||
|| member == "komorebic"
|
||||
|| member == "komorebi-client"
|
||||
|| builtins.any (crate: member == crate || pkgs.lib.hasPrefix "${crate}/" member) rootCrates;
|
||||
};
|
||||
packages = "-p komorebi-linux -p komorebic -p komorebi-client -p komorebi-hotkeys";
|
||||
workspaceArgs = {
|
||||
cargoLock = "${src}/${platformDir}/Cargo.lock";
|
||||
cargoToml = "${src}/${platformDir}/Cargo.toml";
|
||||
postUnpack = "cd $sourceRoot/${platformDir}; sourceRoot=$PWD";
|
||||
pname = "komorebi-workspace";
|
||||
version = (builtins.fromTOML (builtins.readFile ./komorebi/Cargo.toml)).package.version;
|
||||
cargoLock = "${real}/Cargo.lock";
|
||||
cargoToml = "${real}/Cargo.toml";
|
||||
# vendored from the filtered source, not the stubbed one: no build is needed to evaluate
|
||||
cargoVendorDir = craneLib.vendorCargoDeps { src = real; };
|
||||
};
|
||||
|
||||
commonArgs = workspaceArgs // {
|
||||
cargoExtraArgs = "--locked ${packages}";
|
||||
inherit src;
|
||||
pname = "komorebi-workspace";
|
||||
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
|
||||
version = (builtins.fromTOML (builtins.readFile ./komorebi/Cargo.toml)).package.version;
|
||||
strictDeps = true;
|
||||
# The version crate wants a commit at compile time. It is a constant here, so that the
|
||||
# dependencies and every check are the same derivations for every commit; only the final
|
||||
@@ -148,7 +187,9 @@
|
||||
craneLib
|
||||
craneLibFmt
|
||||
src
|
||||
real
|
||||
workspaceArgs
|
||||
packages
|
||||
commonArgs
|
||||
individualCrateArgs
|
||||
fullBuild
|
||||
@@ -277,20 +318,20 @@
|
||||
|
||||
checks = {
|
||||
komorebi-workspace-fmt = build.craneLibFmt.cargoFmt (
|
||||
build.workspaceArgs // { inherit (build) src; }
|
||||
build.workspaceArgs // { inherit (build) src; cargoExtraArgs = build.packages; }
|
||||
);
|
||||
|
||||
komorebi-workspace-clippy = build.craneLib.cargoClippy (
|
||||
build.individualCrateArgs
|
||||
// {
|
||||
cargoClippyExtraArgs = "--workspace --all-targets -- -D warnings";
|
||||
cargoClippyExtraArgs = "--all-targets -- -D warnings";
|
||||
}
|
||||
);
|
||||
|
||||
komorebi-workspace-doc = build.craneLib.cargoDoc (
|
||||
build.individualCrateArgs
|
||||
// {
|
||||
cargoDocExtraArgs = "--workspace --no-deps";
|
||||
cargoDocExtraArgs = "--no-deps";
|
||||
env.RUSTDOCFLAGS = "-D warnings";
|
||||
}
|
||||
);
|
||||
@@ -298,12 +339,34 @@
|
||||
komorebi-workspace-toml-fmt = build.craneLib.taploFmt (
|
||||
build.workspaceArgs
|
||||
// {
|
||||
src = lib.sources.sourceFilesBySuffices build.src [ ".toml" ];
|
||||
src = lib.sources.sourceFilesBySuffices build.real [ ".toml" ];
|
||||
}
|
||||
);
|
||||
|
||||
# cargo deny sees every member of the workspace: leave out the other platforms' packages
|
||||
# and use this tree's policy
|
||||
komorebi-workspace-deny = build.craneLib.cargoDeny (
|
||||
build.workspaceArgs // { inherit (build) src; }
|
||||
build.workspaceArgs
|
||||
// {
|
||||
inherit (build) src;
|
||||
cargoDenyExtraArgs =
|
||||
"--workspace "
|
||||
+ lib.concatMapStringsSep " " (p: "--exclude ${p}") [
|
||||
"komorebi-windows"
|
||||
"komorebi-gui"
|
||||
"komorebic-no-console"
|
||||
"komorebi-bar"
|
||||
"komorebi-shortcuts"
|
||||
"komorebi-e2e-agent"
|
||||
"komorebi-testwin"
|
||||
"komorebi-macos"
|
||||
"komorebic-macos"
|
||||
"komorebi-client-macos"
|
||||
"komorebi-bar-macos"
|
||||
"version-macos"
|
||||
];
|
||||
cargoDenyChecks = "--config ${platformDir}/deny.toml bans licenses sources";
|
||||
}
|
||||
);
|
||||
|
||||
komorebi-workspace-nextest = build.craneLib.cargoNextest (
|
||||
|
||||
@@ -28,8 +28,8 @@ lint:
|
||||
|
||||
# the JSON Schemas of komorebi.json and of applications.json, from the Rust types
|
||||
jsonschema:
|
||||
cargo run --package komorebic --locked -- static-config-schema > schema.json
|
||||
cargo run --package komorebic --locked -- application-specific-configuration-schema > schema.asc.json
|
||||
cargo run --package komorebic-linux --locked -- static-config-schema > schema.json
|
||||
cargo run --package komorebic-linux --locked -- application-specific-configuration-schema > schema.asc.json
|
||||
|
||||
# the options of the module's `config`, from schema.json, with the hash of the schema they were
|
||||
# made from in the first line (written by schemars-nixgen; the check `schema-fresh` compares it); needs schemars-nixgen
|
||||
@@ -66,7 +66,7 @@ vm-all:
|
||||
# write the help of every komorebic subcommand to docs/cli, one page each
|
||||
docgen:
|
||||
rm -f docs/cli/*.md
|
||||
cargo run --package komorebic --locked -- docgen --output docs/cli
|
||||
cargo run --package komorebic-linux --locked -- docgen --output docs/cli
|
||||
|
||||
# the demo guest in a virtual machine, with komorebi tiling a few windows (docs/trying-it.md);
|
||||
# `just run-kde --doctor` says what this machine is missing
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
[package]
|
||||
name = "komorebi-client"
|
||||
version.workspace = true
|
||||
name = "komorebi-client-linux"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
komorebi = { path = "../komorebi", default-features = false }
|
||||
komorebi-themes = { workspace = true }
|
||||
komorebi = { package = "komorebi-linux", path = "../komorebi", default-features = false }
|
||||
komorebi-themes = { path = "../../komorebi-themes" }
|
||||
|
||||
serde_json = { workspace = true }
|
||||
serde_json = { package = "serde_json_lenient", version = "0.2" }
|
||||
|
||||
[dev-dependencies]
|
||||
parking_lot = "0.13"
|
||||
@@ -15,3 +15,6 @@ parking_lot = "0.13"
|
||||
[features]
|
||||
default = ["schemars"]
|
||||
schemars = ["komorebi/default"]
|
||||
|
||||
[lib]
|
||||
name = "komorebi_client"
|
||||
@@ -1,394 +1,9 @@
|
||||
//! A client for the komorebi daemon: it writes [`SocketMessage`]s on the daemon's socket and reads
|
||||
//! the daemon's answers.
|
||||
//!
|
||||
//! The daemon listens on `komorebi.sock` in [`struct@DATA_DIR`], which is
|
||||
//! `$XDG_RUNTIME_DIR/komorebi` in a desktop session. Every function here opens a new connection
|
||||
//! and writes each message as one line of JSON. [`send_message`] and [`send_batch`] give
|
||||
//! orders and read nothing back; [`send_query`] asks a question and returns the answer, which the
|
||||
//! daemon ends by closing the connection. A function fails with the error of the connection, so a
|
||||
//! daemon that is not running is an [`std::io::ErrorKind::NotFound`] or a
|
||||
//! [`std::io::ErrorKind::ConnectionRefused`].
|
||||
//!
|
||||
//! [`subscribe`] and [`subscribe_with_options`] make the program a subscriber: they listen on a
|
||||
//! socket of its own in [`struct@DATA_DIR`], and ask the daemon to send a [`Notification`] to it
|
||||
//! after each event and each message the window manager handles.
|
||||
//!
|
||||
//! The crate also re-exports the types the messages and the answers are made of, so that a client
|
||||
//! needs nothing else, and [`check`], the checks `komorebic check` runs.
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! The examples on this page answer for the daemon: each one listens on the socket itself, in a
|
||||
//! runtime directory made for it, before it sends anything.
|
||||
//!
|
||||
//! ```rust
|
||||
//! # use std::io::{BufRead, BufReader, Write};
|
||||
//! # let runtime = format!("/tmp/komorebi-client-doc-crate-{}", std::process::id());
|
||||
//! # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
//! # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
//! # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
//! # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
//! # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
//! # let (mut stream, _) = listener.accept()?;
|
||||
//! # let mut line = String::new();
|
||||
//! # BufReader::new(stream.try_clone()?).read_line(&mut line)?;
|
||||
//! # stream.write_all(b"2")?;
|
||||
//! # Ok(line)
|
||||
//! # });
|
||||
//! use komorebi_client::SocketMessage;
|
||||
//! use komorebi_client::StateQuery;
|
||||
//! use komorebi_client::send_query;
|
||||
//!
|
||||
//! let workspace = send_query(&SocketMessage::Query(StateQuery::FocusedWorkspaceIndex))?;
|
||||
//! assert_eq!(workspace, "2");
|
||||
//!
|
||||
//! # assert_eq!(
|
||||
//! # daemon.join().unwrap()?,
|
||||
//! # r#"{"type":"Query","content":"FocusedWorkspaceIndex"}"#
|
||||
//! # );
|
||||
//! # std::fs::remove_dir_all(&runtime)?;
|
||||
//! # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
//! ```
|
||||
//!
|
||||
//! `komorebi-client/tests/daemon.rs` sends the same messages to a window manager that listens the
|
||||
//! way the daemon does, over an in-memory desktop.
|
||||
//! `komorebi-client-linux`: the client of the unified `komorebi-client` package, kept under its old
|
||||
//! package name until the cutover. The code is in `komorebi-client/src/linux.rs`.
|
||||
|
||||
pub use komorebi::DATA_DIR;
|
||||
pub use komorebi::LOG_DIR;
|
||||
pub use komorebi::Notification;
|
||||
pub use komorebi::NotificationEvent;
|
||||
pub use komorebi::animation::AnimationPrefix;
|
||||
pub use komorebi::check;
|
||||
pub use komorebi::container::Container;
|
||||
pub use komorebi::core::ApplicationIdentifier;
|
||||
pub use komorebi::core::Axis;
|
||||
pub use komorebi::core::CycleDirection;
|
||||
pub use komorebi::core::DefaultLayout;
|
||||
pub use komorebi::core::FocusFollowsMouseImplementation;
|
||||
pub use komorebi::core::Layout;
|
||||
pub use komorebi::core::MonocleFocusBehaviour;
|
||||
pub use komorebi::core::MoveBehaviour;
|
||||
pub use komorebi::core::OperationBehaviour;
|
||||
pub use komorebi::core::OperationDirection;
|
||||
pub use komorebi::core::PanDirection;
|
||||
pub use komorebi::core::Rect;
|
||||
pub use komorebi::core::ScrollingCentering;
|
||||
pub use komorebi::core::Sizing;
|
||||
pub use komorebi::core::SocketMessage;
|
||||
pub use komorebi::core::StateQuery;
|
||||
pub use komorebi::core::SubscribeOptions;
|
||||
pub use komorebi::core::WindowKind;
|
||||
pub use komorebi::core::animation::AnimationStyle;
|
||||
pub use komorebi::core::asc::ApplicationSpecificConfiguration;
|
||||
pub use komorebi::core::pathext::PathExt;
|
||||
pub use komorebi::core::pathext::replace_env_in_path;
|
||||
pub use komorebi::monitor_reconciliator::MonitorNotification;
|
||||
pub use komorebi::state::State;
|
||||
pub use komorebi::static_config::StaticConfig;
|
||||
pub use komorebi::window::Window;
|
||||
pub use komorebi::workspace::Workspace;
|
||||
pub use komorebi::workspace::WorkspaceLayer;
|
||||
pub use komorebi_themes::KomorebiTheme;
|
||||
pub use komorebi_themes::colour::Colour;
|
||||
pub use komorebi_themes::colour::Rgb;
|
||||
use std::borrow::Borrow;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::net::Shutdown;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::time::Duration;
|
||||
extern crate komorebi as komorebi_linux;
|
||||
|
||||
const KOMOREBI: &str = "komorebi.sock";
|
||||
#[path = "../../../komorebi-client/src/linux.rs"]
|
||||
mod platform;
|
||||
|
||||
/// Sends one message to the daemon, and does not wait for it to be handled
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The daemon's socket cannot be connected to, for example because the daemon is not running.
|
||||
/// - The message cannot be written within a second.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-message-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # let mut line = String::new();
|
||||
/// # BufReader::new(stream).read_line(&mut line)?;
|
||||
/// # Ok(line)
|
||||
/// # });
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::send_message;
|
||||
///
|
||||
/// send_message(&SocketMessage::Retile)?;
|
||||
///
|
||||
/// # assert_eq!(daemon.join().unwrap()?, r#"{"type":"Retile"}"#);
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn send_message(message: &SocketMessage) -> std::io::Result<()> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())
|
||||
}
|
||||
|
||||
/// Sends several messages to the daemon on one connection, which handles them in order, and does
|
||||
/// not wait for them to be handled
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The same as [`send_message`].
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-batch-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<Vec<String>> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # BufReader::new(stream).lines().collect()
|
||||
/// # });
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::send_batch;
|
||||
///
|
||||
/// send_batch([SocketMessage::Retile, SocketMessage::Stop])?;
|
||||
///
|
||||
/// # assert_eq!(daemon.join().unwrap()?, [r#"{"type":"Retile"}"#, r#"{"type":"Stop"}"#]);
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn send_batch<Q>(messages: impl IntoIterator<Item = Q>) -> std::io::Result<()>
|
||||
where
|
||||
Q: Borrow<SocketMessage>,
|
||||
{
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
let msgs = messages.into_iter().fold(String::new(), |mut s, m| {
|
||||
if let Ok(m_str) = serde_json::to_string(m.borrow()) {
|
||||
s.push_str(&m_str);
|
||||
s.push('\n');
|
||||
}
|
||||
s
|
||||
});
|
||||
stream.write_all(msgs.as_bytes())
|
||||
}
|
||||
|
||||
/// Sends one message to the daemon and returns its answer: JSON for
|
||||
/// [`SocketMessage::State`] and [`SocketMessage::MonitorInformation`], one value as text for
|
||||
/// [`SocketMessage::Query`], and nothing for a message that is not a question
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The daemon's socket cannot be connected to, for example because the daemon is not running.
|
||||
/// - The message cannot be written within a second.
|
||||
/// - The daemon sends nothing for a second before its answer is complete.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// The answer to [`SocketMessage::State`] reads back as a [`State`]:
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader, Write};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-query-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the socket is in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<()> {
|
||||
/// # let (mut stream, _) = listener.accept()?;
|
||||
/// # BufReader::new(stream.try_clone()?).read_line(&mut String::new())?;
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # stream.write_all(state.as_bytes())
|
||||
/// # });
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::State;
|
||||
/// use komorebi_client::send_query;
|
||||
///
|
||||
/// let state: State = serde_json::from_str(&send_query(&SocketMessage::State)?)?;
|
||||
/// assert!(state.mouse_follows_focus);
|
||||
///
|
||||
/// # daemon.join().unwrap()?;
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn send_query(message: &SocketMessage) -> std::io::Result<String> {
|
||||
let socket = DATA_DIR.join(KOMOREBI);
|
||||
|
||||
let mut stream = UnixStream::connect(socket)?;
|
||||
stream.set_read_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||
stream.write_all(serde_json::to_string(message)?.as_bytes())?;
|
||||
stream.shutdown(Shutdown::Write)?;
|
||||
|
||||
let mut reader = BufReader::new(stream);
|
||||
let mut response = String::new();
|
||||
reader.read_to_string(&mut response)?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
/// Listens on the socket `name` in [`struct@DATA_DIR`], and asks the daemon to send a
|
||||
/// [`Notification`] to it after each event and each message the window manager handles
|
||||
///
|
||||
/// A socket file that is left over at that path is removed first. Each notification comes on a
|
||||
/// new connection, as JSON, and ends when the daemon closes the connection; the first is the
|
||||
/// notification of the subscription itself. When the daemon stops, it connects and closes the
|
||||
/// connection without writing anything.
|
||||
///
|
||||
/// A subscriber that the daemon cannot connect to, because its program has exited or its socket
|
||||
/// was removed, is removed at the next notification, with its socket file. It has to subscribe
|
||||
/// again: the daemon does not try it again, and does not keep its subscribers when it restarts.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - The socket file left over at that path cannot be removed.
|
||||
/// - The socket cannot be bound, for example because [`struct@DATA_DIR`] does not exist.
|
||||
/// - The subscription cannot be sent, for one of the reasons [`send_message`] gives.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader, Write};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-subscribe-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the sockets are in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # let mut message = String::new();
|
||||
/// # BufReader::new(stream).read_line(&mut message)?;
|
||||
/// # let subscriber = komorebi_client::DATA_DIR.join("bar.sock");
|
||||
/// # let state = r#"{"monitors":{"elements":[],"focused":0},"monitor_usr_idx_map":{},"is_paused":false,"resize_delta":50,"new_window_behaviour":"Create","float_override":false,"cross_monitor_move_behaviour":"Swap","monocle_focus_behaviour":"NoOp","unmanaged_window_operation_behaviour":"Op","work_area_offset":null,"mouse_follows_focus":true}"#;
|
||||
/// # let notification = format!(r#"{{"event":{message},"state":{state}}}"#);
|
||||
/// # std::os::unix::net::UnixStream::connect(subscriber)?.write_all(notification.as_bytes())?;
|
||||
/// # Ok(message)
|
||||
/// # });
|
||||
/// use std::io::Read;
|
||||
///
|
||||
/// use komorebi_client::Notification;
|
||||
/// use komorebi_client::NotificationEvent;
|
||||
/// use komorebi_client::SocketMessage;
|
||||
/// use komorebi_client::subscribe;
|
||||
///
|
||||
/// let listener = subscribe("bar.sock")?;
|
||||
///
|
||||
/// // the first notification is the one of the subscription
|
||||
/// let (mut connection, _) = listener.accept()?;
|
||||
/// let mut json = String::new();
|
||||
/// connection.read_to_string(&mut json)?;
|
||||
/// let notification: Notification = serde_json::from_str(&json)?;
|
||||
/// assert!(matches!(
|
||||
/// notification.event,
|
||||
/// NotificationEvent::Socket(SocketMessage::AddSubscriberSocket(name)) if name == "bar.sock"
|
||||
/// ));
|
||||
///
|
||||
/// # assert_eq!(
|
||||
/// # daemon.join().unwrap()?,
|
||||
/// # r#"{"type":"AddSubscriberSocket","content":"bar.sock"}"#
|
||||
/// # );
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn subscribe(name: &str) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocket(name.to_string()))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
|
||||
/// The same as [`subscribe`], with the [`SubscribeOptions`] the daemon applies to this subscriber
|
||||
///
|
||||
/// With `filter_state_changes`, the daemon sends a notification only when the event or the message
|
||||
/// changed the [`State`], and always when a window is shown, when a subscriber is added, when a
|
||||
/// theme is set and when the configuration is reloaded.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// The same as [`subscribe`].
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::io::{BufRead, BufReader};
|
||||
/// # let runtime = format!("/tmp/komorebi-client-doc-options-{}", std::process::id());
|
||||
/// # std::fs::create_dir_all(format!("{runtime}/komorebi"))?;
|
||||
/// # unsafe { std::env::set_var("XDG_RUNTIME_DIR", &runtime) }; // the sockets are in it
|
||||
/// # let socket = komorebi_client::DATA_DIR.join("komorebi.sock");
|
||||
/// # let listener = std::os::unix::net::UnixListener::bind(&socket)?;
|
||||
/// # let daemon = std::thread::spawn(move || -> std::io::Result<String> {
|
||||
/// # let (stream, _) = listener.accept()?;
|
||||
/// # let mut message = String::new();
|
||||
/// # BufReader::new(stream).read_line(&mut message)?;
|
||||
/// # Ok(message)
|
||||
/// # });
|
||||
/// use komorebi_client::DATA_DIR;
|
||||
/// use komorebi_client::SubscribeOptions;
|
||||
/// use komorebi_client::subscribe_with_options;
|
||||
///
|
||||
/// let options = SubscribeOptions {
|
||||
/// filter_state_changes: true,
|
||||
/// };
|
||||
/// let listener = subscribe_with_options("bar.sock", options)?;
|
||||
///
|
||||
/// let socket = DATA_DIR.join("bar.sock");
|
||||
/// assert_eq!(listener.local_addr()?.as_pathname(), Some(socket.as_path()));
|
||||
///
|
||||
/// # assert_eq!(
|
||||
/// # daemon.join().unwrap()?,
|
||||
/// # r#"{"type":"AddSubscriberSocketWithOptions","content":["bar.sock",{"filter_state_changes":true}]}"#
|
||||
/// # );
|
||||
/// # std::fs::remove_dir_all(&runtime)?;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
pub fn subscribe_with_options(
|
||||
name: &str,
|
||||
options: SubscribeOptions,
|
||||
) -> std::io::Result<UnixListener> {
|
||||
let socket = DATA_DIR.join(name);
|
||||
|
||||
match std::fs::remove_file(&socket) {
|
||||
Ok(()) => {}
|
||||
Err(error) => match error.kind() {
|
||||
std::io::ErrorKind::NotFound => {}
|
||||
_ => {
|
||||
return Err(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let listener = UnixListener::bind(&socket)?;
|
||||
|
||||
send_message(&SocketMessage::AddSubscriberSocketWithOptions(
|
||||
name.to_string(),
|
||||
options,
|
||||
))?;
|
||||
|
||||
Ok(listener)
|
||||
}
|
||||
pub use platform::*;
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "komorebi-hotkeys"
|
||||
version.workspace = true
|
||||
version = "0.1.0"
|
||||
description = "Reads skhd, whkd and sxhkd key binding files and plans them as KDE global shortcuts"
|
||||
edition = "2024"
|
||||
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
[package]
|
||||
name = "komorebi"
|
||||
version.workspace = true
|
||||
name = "komorebi-linux"
|
||||
version = "0.1.0"
|
||||
description = "A tiling window manager for KDE Plasma"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
komorebi-hotkeys = { path = "../komorebi-hotkeys" }
|
||||
komorebi-themes = { workspace = true }
|
||||
komorebi-backend = { workspace = true }
|
||||
komorebi-collections = { workspace = true }
|
||||
komorebi-core = { workspace = true }
|
||||
komorebi-layouts = { workspace = true }
|
||||
komorebi-scrolling = { workspace = true }
|
||||
komorebi-config = { workspace = true }
|
||||
komorebi-protocol = { workspace = true }
|
||||
komorebi-transport = { workspace = true }
|
||||
version = { path = "../version" }
|
||||
komorebi-themes = { path = "../../komorebi-themes" }
|
||||
komorebi-backend = { path = "../../crates/komorebi-backend" }
|
||||
komorebi-collections = { path = "../../crates/komorebi-collections" }
|
||||
komorebi-core = { path = "../../crates/komorebi-core" }
|
||||
komorebi-layouts = { path = "../../komorebi-layouts", features = ["schemars"] }
|
||||
komorebi-scrolling = { path = "../../komorebi-scrolling" }
|
||||
komorebi-config = { path = "../../crates/komorebi-config", default-features = false, features = ["schemars"] }
|
||||
komorebi-settings = { path = "../../crates/komorebi-settings" }
|
||||
komorebi-protocol = { path = "../../crates/komorebi-protocol", default-features = false, features = ["schemars"] }
|
||||
komorebi-transport = { path = "../../crates/komorebi-transport" }
|
||||
version = { package = "version-linux", path = "../version" }
|
||||
|
||||
clap = { workspace = true }
|
||||
color-eyre = { workspace = true }
|
||||
crossbeam-channel = { workspace = true }
|
||||
crossbeam-utils = { workspace = true }
|
||||
clap = { version = "4", features = ["derive", "wrap_help"] }
|
||||
color-eyre = { version = "0.6" }
|
||||
crossbeam-channel = { version = "0.5" }
|
||||
crossbeam-utils = { version = "0.8" }
|
||||
ctrlc = { version = "3", features = ["termination"] }
|
||||
dirs = { workspace = true }
|
||||
hotwatch = { workspace = true }
|
||||
lazy_static = { workspace = true }
|
||||
dirs = { version = "7" }
|
||||
hotwatch = { version = "0.5" }
|
||||
lazy_static = { version = "1" }
|
||||
nanoid = "0.5"
|
||||
parking_lot = "0.13"
|
||||
pastey = { workspace = true }
|
||||
pastey = { version = "0.2" }
|
||||
regex = "1"
|
||||
schemars = { workspace = true, optional = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true, features = ["preserve_order"] }
|
||||
schemars = { version = "1.1", optional = true }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { package = "serde_json_lenient", version = "0.2", features = ["preserve_order"] }
|
||||
serde_with = { version = "3", features = ["schemars_1"] }
|
||||
strum = { version = "0.28", features = ["derive"] }
|
||||
tokio = { version = "1", features = [
|
||||
@@ -40,9 +41,9 @@ tokio = { version = "1", features = [
|
||||
"sync",
|
||||
"time",
|
||||
] }
|
||||
tracing = { workspace = true }
|
||||
tracing-appender = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
tracing = { version = "0.1" }
|
||||
tracing-appender = { version = "0.2" }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
zbus = { version = "6", default-features = false, features = [
|
||||
"tokio",
|
||||
"proxy",
|
||||
@@ -57,3 +58,10 @@ uuid = { version = "1", features = ["v4"] }
|
||||
default = ["schemars"]
|
||||
deadlock_detection = ["parking_lot/deadlock_detection"]
|
||||
schemars = ["dep:schemars", "komorebi-collections/schemars", "komorebi-core/schemars"]
|
||||
|
||||
[lib]
|
||||
name = "komorebi"
|
||||
|
||||
[[bin]]
|
||||
name = "komorebi"
|
||||
path = "src/main.rs"
|
||||
@@ -85,6 +85,7 @@ pub mod process_command;
|
||||
pub mod process_event;
|
||||
pub mod reconcile;
|
||||
pub mod scrolling;
|
||||
pub mod settings;
|
||||
pub mod state;
|
||||
pub mod static_config;
|
||||
pub mod theme_manager;
|
||||
@@ -208,16 +209,18 @@ lazy_static! {
|
||||
|
||||
/// The padding, in pixels, between the edge of a monitor's work area and the tiles of its
|
||||
/// workspaces, for a monitor that sets none of its own. The default for this is 5.
|
||||
pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = AtomicI32::new(5);
|
||||
pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 =
|
||||
AtomicI32::new(komorebi_settings::shared::PlatformDefaults::KDE.workspace_padding);
|
||||
/// The padding, in pixels, around each tile, for a monitor that sets none of its own. The default
|
||||
/// for this is 5.
|
||||
pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = AtomicI32::new(5);
|
||||
pub static DEFAULT_CONTAINER_PADDING: AtomicI32 =
|
||||
AtomicI32::new(komorebi_settings::shared::PlatformDefaults::KDE.container_padding);
|
||||
/// How many pixels `ResizeWindowEdge` and `ResizeWindowAxis` resize by, when `komorebi.json` does
|
||||
/// not say
|
||||
pub static DEFAULT_RESIZE_DELTA: i32 = 50;
|
||||
pub static DEFAULT_RESIZE_DELTA: i32 = komorebi_settings::shared::DEFAULT_RESIZE_DELTA;
|
||||
/// Whether the pointer goes to the window that is given the focus, when `komorebi.json` does not
|
||||
/// say
|
||||
pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = true;
|
||||
pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = komorebi_settings::shared::DEFAULT_MOUSE_FOLLOWS_FOCUS;
|
||||
|
||||
/// The event, the message or the change of the monitors a [`Notification`] is about
|
||||
///
|
||||
|
||||
@@ -218,7 +218,7 @@ impl From<KeyPlanMode> for PlanMode {
|
||||
|
||||
/// A tiling window manager for KDE Plasma.
|
||||
#[derive(Parser)]
|
||||
#[clap(author, about, version = version::LONG_VERSION)]
|
||||
#[clap(name = "komorebi", author, about, version = version::LONG_VERSION)]
|
||||
struct Opts {
|
||||
/// Level of log output verbosity
|
||||
#[clap(long, value_enum, default_value_t=LogLevel::Info)]
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
//! The settings of this daemon, as one snapshot (plan step 10, `docs/dev/settings.md`).
|
||||
//!
|
||||
//! Nothing reads this yet: the process-wide statics are still the source of truth, and each
|
||||
//! migration step moves one group of them (writers and readers together) into
|
||||
//! [`settings()`]. Until then the value is the starting values of those statics.
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use komorebi_settings::Handle;
|
||||
use komorebi_settings::Shared;
|
||||
use komorebi_settings::shared::PlatformDefaults;
|
||||
|
||||
/// The part of the settings that only this platform has.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct KdeSettings {}
|
||||
|
||||
pub type Settings = komorebi_settings::Settings<KdeSettings>;
|
||||
|
||||
static SETTINGS: LazyLock<Handle<KdeSettings>> = LazyLock::new(|| {
|
||||
Handle::new(Settings::new(
|
||||
Shared::defaults_for(PlatformDefaults::KDE),
|
||||
KdeSettings::default(),
|
||||
))
|
||||
});
|
||||
|
||||
/// The settings of the running daemon: take a [`Handle::snapshot`] once per unit of work.
|
||||
pub fn settings() -> &'static Handle<KdeSettings> {
|
||||
&SETTINGS
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use super::*;
|
||||
use crate::border_manager;
|
||||
|
||||
// The statics are still the source of truth. These pin that the starting values of the
|
||||
// settings are the starting values of the statics, so that moving a group over changes nothing.
|
||||
// (They read the statics without any test writing them first: no test here sets them.)
|
||||
#[test]
|
||||
fn the_starting_settings_are_the_starting_values_of_the_statics() {
|
||||
let shared = &settings().snapshot().shared;
|
||||
|
||||
assert_eq!(
|
||||
shared.defaults.container_padding,
|
||||
crate::DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(
|
||||
shared.defaults.workspace_padding,
|
||||
crate::DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(shared.defaults.resize_delta, crate::DEFAULT_RESIZE_DELTA);
|
||||
assert_eq!(
|
||||
shared.defaults.mouse_follows_focus,
|
||||
crate::DEFAULT_MOUSE_FOLLOWS_FOCUS
|
||||
);
|
||||
assert_eq!(
|
||||
shared.border.enabled,
|
||||
border_manager::BORDER_ENABLED.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(
|
||||
shared.border.width,
|
||||
border_manager::BORDER_WIDTH.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(
|
||||
shared.border.offset,
|
||||
border_manager::BORDER_OFFSET.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(
|
||||
shared.border.radius,
|
||||
border_manager::BORDER_RADIUS.load(Ordering::SeqCst)
|
||||
);
|
||||
let colours = shared.border.colours;
|
||||
assert_eq!(
|
||||
colours.single,
|
||||
border_manager::FOCUSED.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(colours.stack, border_manager::STACK.load(Ordering::SeqCst));
|
||||
assert_eq!(
|
||||
colours.monocle,
|
||||
border_manager::MONOCLE.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(
|
||||
colours.floating,
|
||||
border_manager::FLOATING.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(
|
||||
colours.unfocused,
|
||||
border_manager::UNFOCUSED.load(Ordering::SeqCst)
|
||||
);
|
||||
assert_eq!(
|
||||
colours.unfocused_locked,
|
||||
border_manager::UNFOCUSED_LOCKED.load(Ordering::SeqCst)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,7 @@ use std::io::ErrorKind;
|
||||
use std::io::Write;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -729,16 +730,16 @@ impl ApplyGlobals for StaticConfig {
|
||||
pub trait StaticConfigExt: Sized {
|
||||
/// Makes the window manager from the file at `path`, and starts watching the file
|
||||
fn preload(
|
||||
path: &PathBuf,
|
||||
path: &Path,
|
||||
incoming: Receiver<WindowManagerEvent>,
|
||||
unix_listener: Option<UnixListener>,
|
||||
) -> eyre::Result<WindowManager>;
|
||||
|
||||
/// Gives the monitors of the window manager what the file says about them
|
||||
fn postload(path: &PathBuf, wm: &Arc<Mutex<WindowManager>>) -> eyre::Result<()>;
|
||||
fn postload(path: &Path, wm: &Arc<Mutex<WindowManager>>) -> eyre::Result<()>;
|
||||
|
||||
/// Replaces the configuration of the window manager with the file at `path`
|
||||
fn reload(path: &PathBuf, wm: &mut WindowManager) -> eyre::Result<()>;
|
||||
fn reload(path: &Path, wm: &mut WindowManager) -> eyre::Result<()>;
|
||||
}
|
||||
|
||||
impl StaticConfigExt for StaticConfig {
|
||||
@@ -761,7 +762,7 @@ impl StaticConfigExt for StaticConfig {
|
||||
/// - The file cannot be watched.
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn preload(
|
||||
path: &PathBuf,
|
||||
path: &Path,
|
||||
incoming: Receiver<WindowManagerEvent>,
|
||||
unix_listener: Option<UnixListener>,
|
||||
) -> eyre::Result<WindowManager> {
|
||||
@@ -836,7 +837,7 @@ impl StaticConfigExt for StaticConfig {
|
||||
known_window_ids: HashMap::new(),
|
||||
};
|
||||
|
||||
let bytes = SocketMessage::ReloadStaticConfiguration(path.clone()).as_bytes()?;
|
||||
let bytes = SocketMessage::ReloadStaticConfiguration(path.to_path_buf()).as_bytes()?;
|
||||
|
||||
wm.hotwatch.watch(path, move |event| match event.kind {
|
||||
// an editor either writes the file in place or replaces it with a new one, which is a
|
||||
@@ -866,7 +867,7 @@ impl StaticConfigExt for StaticConfig {
|
||||
/// # Errors
|
||||
///
|
||||
/// The file cannot be read or is not a configuration ([`StaticConfig::read`]).
|
||||
fn postload(path: &PathBuf, wm: &Arc<Mutex<WindowManager>>) -> eyre::Result<()> {
|
||||
fn postload(path: &Path, wm: &Arc<Mutex<WindowManager>>) -> eyre::Result<()> {
|
||||
let mut value = Self::read(path)?;
|
||||
let mut wm = wm.lock();
|
||||
|
||||
@@ -1042,7 +1043,7 @@ impl StaticConfigExt for StaticConfig {
|
||||
/// - The file cannot be read or is not a configuration ([`StaticConfig::read`]); nothing has
|
||||
/// changed then.
|
||||
/// - A rule has a regular expression that is not valid; the settings before it have changed.
|
||||
fn reload(path: &PathBuf, wm: &mut WindowManager) -> eyre::Result<()> {
|
||||
fn reload(path: &Path, wm: &mut WindowManager) -> eyre::Result<()> {
|
||||
let mut value = Self::read(path)?;
|
||||
|
||||
value.apply_globals()?;
|
||||
|
||||
@@ -215,7 +215,7 @@ fn the_kinds_of_rule_of_other_platforms_are_read_and_do_nothing() {
|
||||
|
||||
#[test]
|
||||
fn the_applications_file_komorebic_ships_floats_the_programs_it_names() {
|
||||
let shipped = Path::new(env!("CARGO_MANIFEST_DIR")).join("../komorebic/applications.json");
|
||||
let shipped = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../komorebic/src/linux/applications.json");
|
||||
let mut desktop = Desktop::load(&applications(&shipped)).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
[package]
|
||||
name = "komorebic"
|
||||
version.workspace = true
|
||||
name = "komorebic-linux"
|
||||
version = "0.1.0"
|
||||
description = "The command-line interface for Komorebi, a tiling window manager for KDE Plasma"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
komorebi-config = { workspace = true }
|
||||
komorebi = { path = "../komorebi", default-features = false }
|
||||
komorebi-client = { path = "../komorebi-client", default-features = false }
|
||||
komorebi-config = { path = "../../crates/komorebi-config", default-features = false, features = ["schemars"] }
|
||||
komorebi = { package = "komorebi-linux", path = "../komorebi", default-features = false }
|
||||
komorebi-client = { package = "komorebi-client-linux", path = "../komorebi-client", default-features = false }
|
||||
komorebi-hotkeys = { path = "../komorebi-hotkeys" }
|
||||
komorebic-core = { path = "../../crates/komorebic-core" }
|
||||
version = { path = "../version" }
|
||||
version = { package = "version-linux", path = "../version" }
|
||||
|
||||
clap = { workspace = true }
|
||||
clap = { version = "4", features = ["derive", "wrap_help"] }
|
||||
clap_complete = "4"
|
||||
chrono = { workspace = true }
|
||||
color-eyre = { workspace = true }
|
||||
dirs = { workspace = true }
|
||||
chrono = { version = "0.4" }
|
||||
color-eyre = { version = "0.6" }
|
||||
dirs = { version = "7" }
|
||||
fs-tail = "0.1"
|
||||
lazy_static = { workspace = true }
|
||||
schemars = { workspace = true, optional = true }
|
||||
serde_json = { workspace = true }
|
||||
sysinfo = { workspace = true }
|
||||
lazy_static = { version = "1" }
|
||||
schemars = { version = "1.1", optional = true }
|
||||
serde_json = { package = "serde_json_lenient", version = "0.2" }
|
||||
sysinfo = { version = "0.40" }
|
||||
|
||||
[features]
|
||||
default = ["schemars"]
|
||||
@@ -29,3 +29,7 @@ schemars = ["dep:schemars", "komorebi-client/default"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(FALSE)'] }
|
||||
|
||||
[[bin]]
|
||||
name = "komorebic"
|
||||
path = "src/main.rs"
|
||||
@@ -1,789 +1,9 @@
|
||||
//! `komorebic`, the command line interface of komorebi for KDE Plasma.
|
||||
//!
|
||||
//! A subcommand that asks something of the daemon is one message on its socket: an order, such as
|
||||
//! `stop` or `retile`, is written and `komorebic` exits; a question, such as `state` or `query`,
|
||||
//! is written and the answer is printed. The messages are [`komorebi_client::SocketMessage`]s,
|
||||
//! sent with [`komorebi_client::send_message`] and [`komorebi_client::send_query`].
|
||||
//!
|
||||
//! The orders that change what the daemon tiles:
|
||||
//!
|
||||
//! - `focus` and `cycle-focus` give the focus to another window of the focused workspace, and
|
||||
//! `mouse-follows-focus` and `toggle-mouse-follows-focus` set whether the pointer goes with it.
|
||||
//! - `move` and `cycle-move` move the focused window to another tile.
|
||||
//! - `change-layout`, `cycle-layout` and `flip-layout` change the layout of the focused
|
||||
//! workspace, `scrolling-layout-columns` and `layout-ratios` tune it, `toggle-tiling` turns its
|
||||
//! tiling off and on, and `preselect-direction` and `cancel-preselect` reserve the place of the
|
||||
//! next window and give it up.
|
||||
//! - `consume`, `expel` and `toggle-column-stack` put windows in the same column of the Scrolling
|
||||
//! layout and take them out, `scrolling-layout-full-width`, `center-focus` and `expand` make the
|
||||
//! focused column as wide as the screen, put it in the middle and fill the room that is left,
|
||||
//! and `pan` moves the view along the strip without moving the focus.
|
||||
//! - `stack` puts the focused window in one container with the window on one side of it, so that
|
||||
//! they share a tile and only one is in sight, `unstack` takes it out again, and `stack-all` and
|
||||
//! `unstack-all` do it for the whole workspace and for the focused stack. `cycle-stack` brings
|
||||
//! the next or the previous window of the focused stack to the front, `cycle-stack-index` moves
|
||||
//! the front window along the stack, and `focus-stack-window` brings the window at an index to
|
||||
//! the front. `toggle-window-container-behaviour` and
|
||||
//! `toggle-workspace-window-container-behaviour` make a window that opens join the focused
|
||||
//! container instead of getting a tile, and `toggle-float-override` and
|
||||
//! `toggle-workspace-float-override` make it float.
|
||||
//! - `promote`, `promote-swap`, `promote-focus` and `promote-window` bring a window to the largest
|
||||
//! tile, or the focus to it.
|
||||
//! - `toggle-float` takes the focused window out of the layout, or puts it back,
|
||||
//! `toggle-workspace-layer` switches the focused workspace between its tiled windows and its
|
||||
//! floating ones, and `toggle-lock` locks the focused container at its index, or unlocks it.
|
||||
//! - `toggle-monocle` gives the focused container the whole work area, or puts it back, and
|
||||
//! `monocle-focus-behaviour` and `toggle-monocle-focus-behaviour` set what focusing in a
|
||||
//! direction does meanwhile. `toggle-maximize` has KWin maximize the focused window, which
|
||||
//! leaves the layout, and restores it.
|
||||
//! - `focused-workspace-padding`, `focused-workspace-container-padding`, `workspace-padding`,
|
||||
//! `container-padding` and the two `adjust-*-padding` set the padding around the tiles and
|
||||
//! between them, and `global-work-area-offset`, `monitor-work-area-offset`,
|
||||
//! `workspace-work-area-offset` and `toggle-window-based-work-area-offset` keep parts of the work
|
||||
//! area free of tiles.
|
||||
//! - `minimize` and `close` minimize and close the focused window, `unmanage` takes it out of
|
||||
//! the layout until `manage` takes it back, `unmanaged-window-operation-behaviour` sets whether
|
||||
//! the daemon carries out an order while the focused window is not one it tiles, and
|
||||
//! `toggle-pause` pauses the daemon and resumes it.
|
||||
//! - `resize-edge` and `resize-axis` resize the focused window by the `resize-delta`, and
|
||||
//! `quick-save-resize`, `quick-load-resize`, `save-resize` and `load-resize` save the sizes of
|
||||
//! the tiles of the focused workspace and load them back.
|
||||
//! - `focus-workspace` shows another workspace of the focused monitor, `move-to-workspace` moves
|
||||
//! the focused window to a workspace and shows it, and `send-to-workspace` moves it there and
|
||||
//! stays. A workspace is KWin's virtual desktop of the same number, counted from 0.
|
||||
//! `cycle-workspace`, `cycle-empty-workspace`, `cycle-move-to-workspace` and
|
||||
//! `cycle-send-to-workspace` go to the next or the previous workspace, `focus-last-workspace`,
|
||||
//! `move-to-last-workspace` and `send-to-last-workspace` to the one that was in front before,
|
||||
//! `focus-workspaces` shows a workspace on every monitor, and `new-workspace` and
|
||||
//! `close-workspace` add a workspace and remove an empty one.
|
||||
//! - `focus-monitor`, `cycle-monitor` and `focus-monitor-at-cursor` focus another monitor, and
|
||||
//! `focus-monitor-workspace` a workspace of another monitor; `move-to-monitor`,
|
||||
//! `send-to-monitor`, their `cycle-` forms, `move-to-monitor-workspace`,
|
||||
//! `send-to-monitor-workspace`, `move-to-named-workspace` and `send-to-named-workspace` take the
|
||||
//! focused window to another monitor; `move-workspace-to-monitor`,
|
||||
//! `cycle-move-workspace-to-monitor` and `swap-workspaces-with-monitor` take workspaces there;
|
||||
//! `cross-monitor-move-behaviour` and `toggle-cross-monitor-move-behaviour` set what `move` does
|
||||
//! at the edge of a monitor, and `display-index-preference` gives a monitor an index.
|
||||
//! `eager-focus` focuses the first window of an executable, on any workspace of any monitor.
|
||||
//! - `workspace-name` names a workspace, which `focus-named-workspace`, `named-workspace-layout`,
|
||||
//! `named-workspace-tiling`, `named-workspace-padding` and `named-workspace-container-padding`
|
||||
//! find by its name; `workspace-layout` and `workspace-tiling` set the layout and the tiling of
|
||||
//! a workspace by its index, and `ensure-workspaces` and `ensure-named-workspaces` give a
|
||||
//! monitor workspaces up to a number, or with names.
|
||||
//! - `border` sets whether the compositor draws a border around each window, `border-colour` the
|
||||
//! color of the border of a kind of window, and `border-width` and `border-offset` the room the
|
||||
//! layout leaves for it.
|
||||
//! - `focus-follows-mouse` and `toggle-focus-follows-mouse` set whether KWin gives the focus to the
|
||||
//! window under the pointer, as the pointer moves.
|
||||
//! - `transparency` and `toggle-transparency` set whether the windows that do not have the focus
|
||||
//! are see-through, and `transparency-alpha` how opaque they are.
|
||||
//! - `animation`, `animation-duration` and `animation-style` set whether windows are animated going
|
||||
//! to their places, for how long and with what easing, and `animation-fps` the frame rate that
|
||||
//! is stored and ignored.
|
||||
//!
|
||||
//! `ignore-rule` and `manage-rule` add a rule that keeps an application out of the layout or
|
||||
//! always in it, `session-float-rule` floats the focused window and every window like it until the
|
||||
//! daemon stops, `session-float-rules` shows those rules and `clear-session-float-rules` removes
|
||||
//! them, and `global-state` shows the rules the daemon has. `visible-windows` shows the windows
|
||||
//! that can be seen on the workspace each monitor shows.
|
||||
//!
|
||||
//! `initial-workspace-rule`, `initial-named-workspace-rule`, `workspace-rule` and
|
||||
//! `named-workspace-rule` send the windows of an application to a workspace, when they open or
|
||||
//! always, `clear-workspace-rules`, `clear-named-workspace-rules` and `clear-all-workspace-rules`
|
||||
//! take those rules away, and `enforce-workspace-rules` applies them to the windows that are open.
|
||||
//!
|
||||
//! `workspace-layout-rule` and `named-workspace-layout-rule` make a workspace change layout once
|
||||
//! it has so many windows, and `clear-workspace-layout-rules` and
|
||||
//! `clear-named-workspace-layout-rules` take those rules away. `generate-static-config` prints the
|
||||
//! settings of the daemon as a `komorebi.json`, and `replace-configuration` makes the daemon
|
||||
//! start over with another one.
|
||||
//!
|
||||
//! `subscribe-socket` and `unsubscribe-socket` add and remove a subscriber: a program that listens
|
||||
//! on a socket in the daemon's data directory, to which the daemon sends a notification after each
|
||||
//! event and each message it handles.
|
||||
//!
|
||||
//! The others work without the daemon: `quickstart` writes an example `komorebi.json`,
|
||||
//! `applications.json` and `skhdrc` in the config home, `enable-autostart` and `disable-autostart` write and
|
||||
//! remove the entry that has Plasma start komorebi at login, `start` runs `komorebi` in the
|
||||
//! background, with the `komorebi.json` it is given with `--config`, `check` reads the
|
||||
//! `komorebi.json` the daemon would and the key binding file, looks at the desktop, and reports
|
||||
//! what is wrong, exiting with status 1 if something is an error, `configuration` shows the path
|
||||
//! of the `komorebi.json` the daemon reads, `log` follows its log, `data-directory` shows where its
|
||||
//! socket is, `completions` prints a completion script for a shell, and `static-config-schema`,
|
||||
//! `application-specific-configuration-schema`, `notification-schema` and `socket-schema` print
|
||||
//! the JSON Schema of `komorebi.json`, of an `applications.json`, of a notification and of a
|
||||
//! message. The hidden `docgen` writes the help of every subcommand as Markdown, wrapped
|
||||
//! at 100 columns whatever the width of the terminal, which is how `docs/cli` is made.
|
||||
//!
|
||||
//! `export-kde-shortcuts` and `hotkeys compile` read a key binding file (an skhdrc, a whkdrc or an
|
||||
//! sxhkdrc) and write the bindings KDE can run by itself as shortcut files. `hotkeys state`,
|
||||
//! `hotkeys reload` and `hotkeys release` look after the keys the daemon registers with KDE; the
|
||||
//! [`hotkeys`] module has the details.
|
||||
//! `komorebic-linux`: the KDE command line of the unified `komorebic` package, kept under its old
|
||||
//! package name until the cutover. The code is in `komorebic/src/linux`.
|
||||
|
||||
use chrono::Utc;
|
||||
use clap::Parser;
|
||||
use clap::Subcommand;
|
||||
use color_eyre::eyre;
|
||||
use fs_tail::TailedFile;
|
||||
use komorebi_client::FocusFollowsMouseImplementation;
|
||||
use komorebi_client::PanDirection;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_client::WindowKind;
|
||||
use komorebi_client::replace_env_in_path;
|
||||
use komorebi_client::send_message;
|
||||
use komorebi_client::send_query;
|
||||
use komorebic_core::args::BooleanState;
|
||||
use komorebic_core::args::OneEnum;
|
||||
use komorebic_core::cli::Cmd;
|
||||
use komorebic_core::cli::Meta;
|
||||
use komorebic_core::cli::command;
|
||||
use komorebic_core::docgen::DocFormat;
|
||||
use komorebic_core::launcher;
|
||||
use komorebic_core::launcher::Launcher;
|
||||
use komorebic_core::messages::Messages;
|
||||
use lazy_static::lazy_static;
|
||||
use std::fs::File;
|
||||
use std::io::BufRead;
|
||||
use std::io::Write;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
use sysinfo::ProcessesToUpdate;
|
||||
#[path = "../../../komorebic/src/linux/mod.rs"]
|
||||
mod linux;
|
||||
|
||||
mod hotkeys;
|
||||
|
||||
lazy_static! {
|
||||
static ref HAS_CUSTOM_CONFIG_HOME: AtomicBool = AtomicBool::new(false);
|
||||
static ref HOME_DIR: PathBuf = {
|
||||
std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
||||
|_| dirs::home_dir().expect("there is no home directory").join(".config").join("komorebi"),
|
||||
|home_path| {
|
||||
let home = home_path.replace_env();
|
||||
if home.as_path().is_dir() {
|
||||
HAS_CUSTOM_CONFIG_HOME.store(true, Ordering::SeqCst);
|
||||
home
|
||||
} else {
|
||||
panic!(
|
||||
"$KOMOREBI_CONFIG_HOME is set to \"{home_path}\", which is not a valid directory",
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct MonocleFocusBehaviour {
|
||||
/// Desired monocle focus behavior
|
||||
#[clap(value_enum)]
|
||||
behaviour: komorebi_client::MonocleFocusBehaviour,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
struct Start {
|
||||
/// Path to a static configuration JSON file
|
||||
#[clap(short, long)]
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
config: Option<PathBuf>,
|
||||
/// Arguments to pass to komorebi, after a `--`: `komorebic start -- --log-level debug`
|
||||
#[clap(last = true)]
|
||||
komorebi_args: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Stop {
|
||||
/// Do not restore windows after stopping komorebi
|
||||
#[clap(long, hide = true)]
|
||||
ignore_restore: bool,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct EnableAutostart {
|
||||
/// Path to a static configuration JSON file
|
||||
#[clap(action, short, long)]
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
config: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct EagerFocus {
|
||||
/// Case-sensitive exe identifier
|
||||
exe: String,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct ScrollingLayoutColumns {
|
||||
/// Desired number of visible columns
|
||||
count: NonZeroUsize,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Pan {
|
||||
/// The way that the view goes
|
||||
#[clap(value_enum)]
|
||||
direction: PanDirection,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct LayoutRatios {
|
||||
/// Column width ratios (space-separated values between 0.1 and 0.9)
|
||||
#[clap(short, long, num_args = 1..)]
|
||||
columns: Option<Vec<f32>>,
|
||||
/// Row height ratios (space-separated values between 0.1 and 0.9)
|
||||
#[clap(short, long, num_args = 1..)]
|
||||
rows: Option<Vec<f32>>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct BorderColour {
|
||||
#[clap(value_enum, short, long, default_value = "single")]
|
||||
window_kind: WindowKind,
|
||||
/// Red
|
||||
r: u32,
|
||||
/// Green
|
||||
g: u32,
|
||||
/// Blue
|
||||
b: u32,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct TransparencyAlpha {
|
||||
/// Alpha
|
||||
alpha: u8,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct FocusFollowsMouse {
|
||||
/// On KDE both are KWin's own focus policy
|
||||
#[clap(value_enum, short, long, default_value = "windows")]
|
||||
implementation: FocusFollowsMouseImplementation,
|
||||
#[clap(value_enum)]
|
||||
boolean_state: BooleanState,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct ToggleFocusFollowsMouse {
|
||||
/// On KDE both are KWin's own focus policy
|
||||
#[clap(value_enum, short, long, default_value = "windows")]
|
||||
implementation: FocusFollowsMouseImplementation,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Animation {
|
||||
#[clap(value_enum)]
|
||||
boolean_state: BooleanState,
|
||||
/// Animation type to apply the state to. If not specified, sets global state
|
||||
#[clap(value_enum, short, long)]
|
||||
animation_type: Option<komorebi_client::AnimationPrefix>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct AnimationDuration {
|
||||
/// Desired animation durations in ms
|
||||
duration: u64,
|
||||
/// Animation type to apply the duration to. If not specified, sets global duration
|
||||
#[clap(value_enum, short, long)]
|
||||
animation_type: Option<komorebi_client::AnimationPrefix>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct AnimationStyle {
|
||||
/// Desired ease function for animation
|
||||
#[clap(value_enum, short, long, default_value = "linear")]
|
||||
style: komorebi_client::AnimationStyle,
|
||||
/// Animation type to apply the style to. If not specified, sets global style
|
||||
#[clap(value_enum, short, long)]
|
||||
animation_type: Option<komorebi_client::AnimationPrefix>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Docgen {
|
||||
/// Output directory for generated documentation files
|
||||
#[clap(short, long)]
|
||||
output: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Check {
|
||||
/// Path to a static configuration JSON file
|
||||
#[clap(action, short, long)]
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
komorebi_config: Option<PathBuf>,
|
||||
/// Look at the configuration and the key bindings only, not at the desktop
|
||||
#[clap(long)]
|
||||
configuration_only: bool,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Completions {
|
||||
#[clap(value_enum)]
|
||||
shell: clap_complete::Shell,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum KdeCommands {
|
||||
#[clap(hide = true)]
|
||||
Docgen(Docgen),
|
||||
/// Generate komorebic CLI completions for the target shell
|
||||
#[clap(arg_required_else_help = true)]
|
||||
Completions(Completions),
|
||||
/// Gather example configurations for a new-user quickstart
|
||||
Quickstart,
|
||||
/// Turn an skhdrc into KDE global shortcuts (they work over RDP, unlike evdev hotkey daemons)
|
||||
ExportKdeShortcuts(hotkeys::ExportKdeShortcuts),
|
||||
/// Key bindings: KDE global shortcuts from a key binding file, and the keys of the daemon
|
||||
#[clap(arg_required_else_help = true)]
|
||||
Hotkeys(hotkeys::Hotkeys),
|
||||
/// Start komorebi as a background process
|
||||
Start(Start),
|
||||
/// Stop the komorebi process
|
||||
Stop(Stop),
|
||||
/// Check komorebi configuration and the desktop it runs on for common errors
|
||||
Check(Check),
|
||||
/// Show the path to komorebi.json
|
||||
#[clap(alias = "config")]
|
||||
Configuration,
|
||||
/// Show the path to komorebi's data directory, which has its socket
|
||||
#[clap(alias = "datadir")]
|
||||
DataDirectory,
|
||||
// /// Subscribe to komorebi events using a Named Pipe
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// #[clap(alias = "subscribe")]
|
||||
// SubscribePipe(SubscribePipe),
|
||||
// /// Unsubscribe from komorebi events
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// #[clap(alias = "unsubscribe")]
|
||||
// UnsubscribePipe(UnsubscribePipe),
|
||||
/// Tail komorebi's process logs (cancel with Ctrl-C)
|
||||
Log,
|
||||
// /// Forcibly focus the window at the cursor with a left mouse click
|
||||
// ForceFocus,
|
||||
// /// Set the invisible border dimensions around each window
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// InvisibleBorders(InvisibleBorders),
|
||||
/// Move the view of the Scrolling layout a column to the left or the right, which does
|
||||
/// nothing in any other layout
|
||||
#[clap(arg_required_else_help = true)]
|
||||
Pan(Pan),
|
||||
/// Set the layout column and row ratios for the focused workspace
|
||||
LayoutRatios(LayoutRatios),
|
||||
// /// Load a custom layout from file for the focused workspace
|
||||
// #[clap(hide = true)]
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// LoadCustomLayout(LoadCustomLayout),
|
||||
// /// Set the monitor index preference for a monitor identified using its size
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// MonitorIndexPreference(MonitorIndexPreference),
|
||||
// /// Set a custom layout for the specified workspace
|
||||
// #[clap(hide = true)]
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// WorkspaceCustomLayout(WorkspaceCustomLayout),
|
||||
// /// Set a custom layout for the specified workspace
|
||||
// #[clap(hide = true)]
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// NamedWorkspaceCustomLayout(NamedWorkspaceCustomLayout),
|
||||
// /// Add a dynamic custom layout for the specified workspace
|
||||
// #[clap(hide = true)]
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// WorkspaceCustomLayoutRule(WorkspaceCustomLayoutRule),
|
||||
// /// Add a dynamic custom layout for the specified workspace
|
||||
// #[clap(hide = true)]
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// NamedWorkspaceCustomLayoutRule(NamedWorkspaceCustomLayoutRule),
|
||||
/// Toggle the compositor's maximization for the focused window
|
||||
ToggleMaximize,
|
||||
// /// Set the border style
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// BorderStyle(BorderStyle),
|
||||
// /// Set the border implementation
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// BorderImplementation(BorderImplementation),
|
||||
/// Enable or disable transparency for unfocused windows
|
||||
#[clap(arg_required_else_help = true)]
|
||||
Transparency(OneEnum<BooleanState>),
|
||||
/// Set the alpha value for unfocused window transparency
|
||||
#[clap(arg_required_else_help = true)]
|
||||
TransparencyAlpha(TransparencyAlpha),
|
||||
/// Toggle transparency for unfocused windows
|
||||
ToggleTransparency,
|
||||
/// Enable or disable focus follows mouse (KWin's own focus policy)
|
||||
#[clap(arg_required_else_help = true)]
|
||||
FocusFollowsMouse(FocusFollowsMouse),
|
||||
/// Toggle focus follows mouse (KWin's own focus policy)
|
||||
ToggleFocusFollowsMouse(ToggleFocusFollowsMouse),
|
||||
/// Generate a JSON Schema for applications.json
|
||||
#[clap(alias = "asc-schema")]
|
||||
ApplicationSpecificConfigurationSchema,
|
||||
/// Generate a JSON Schema of subscription notifications
|
||||
NotificationSchema,
|
||||
/// Generate a JSON Schema of socket messages
|
||||
SocketSchema,
|
||||
/// Generate a JSON Schema of the static configuration file
|
||||
StaticConfigSchema,
|
||||
/// Generates a static configuration JSON file based on the current window manager state
|
||||
GenerateStaticConfig,
|
||||
/// Writes an XDG autostart entry so komorebi starts with the Plasma session
|
||||
EnableAutostart(EnableAutostart),
|
||||
/// Removes the XDG autostart entry
|
||||
DisableAutostart,
|
||||
}
|
||||
|
||||
/// `~/.config/autostart/komorebi.desktop`, which Plasma runs at login
|
||||
fn autostart_entry() -> PathBuf {
|
||||
dirs::config_dir()
|
||||
.expect("there is no config directory")
|
||||
.join("autostart")
|
||||
.join("komorebi.desktop")
|
||||
}
|
||||
|
||||
fn print_query(message: &SocketMessage) {
|
||||
match send_query(message) {
|
||||
Ok(response) => println!("{response}"),
|
||||
Err(error) => panic!("{}", error),
|
||||
}
|
||||
}
|
||||
|
||||
/// Starting `komorebi` for `komorebic start`: a `Command` for the daemon, found among the
|
||||
/// processes by its exact name.
|
||||
struct KdeLauncher<'a> {
|
||||
args: &'a Start,
|
||||
system: sysinfo::System,
|
||||
}
|
||||
|
||||
impl Launcher for KdeLauncher<'_> {
|
||||
fn daemon_name(&self) -> &str {
|
||||
"komorebi"
|
||||
}
|
||||
|
||||
fn spawn(&mut self) -> eyre::Result<()> {
|
||||
let mut command = Command::new("komorebi");
|
||||
|
||||
if let Some(config) = &self.args.config {
|
||||
command.args(["--config", &config.display().to_string()]);
|
||||
}
|
||||
|
||||
command
|
||||
.args(&self.args.komorebi_args)
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.stdin(Stdio::null())
|
||||
.spawn()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_running(&mut self) -> eyre::Result<bool> {
|
||||
self.system.refresh_processes(ProcessesToUpdate::All, true);
|
||||
|
||||
Ok(self
|
||||
.system
|
||||
.processes_by_exact_name("komorebi".as_ref())
|
||||
.next()
|
||||
.is_some())
|
||||
}
|
||||
|
||||
fn diagnose(&mut self) -> eyre::Result<()> {
|
||||
let mut command = Command::new("komorebi");
|
||||
|
||||
if let Some(config) = &self.args.config {
|
||||
command.args(["--config", &config.display().to_string()]);
|
||||
}
|
||||
|
||||
if let Ok(output) = command.args(&self.args.komorebi_args).output() {
|
||||
println!("{}", String::from_utf8(output.stderr)?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// What the top of the help and `--version` say.
|
||||
const META: Meta = Meta {
|
||||
name: "komorebic",
|
||||
about: env!("CARGO_PKG_DESCRIPTION"),
|
||||
author: env!("CARGO_PKG_AUTHORS"),
|
||||
version: version::LONG_VERSION,
|
||||
};
|
||||
|
||||
/// Write a message to the daemon's socket, or, if the daemon answers it, print the answer.
|
||||
fn send_or_query(messages: Messages) -> eyre::Result<()> {
|
||||
let query = messages.is_query();
|
||||
let message = SocketMessage::from(messages);
|
||||
if query {
|
||||
print_query(&message);
|
||||
} else {
|
||||
send_message(&message)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
let opts = komorebic_core::cli::parse::<KdeCommands>(&META);
|
||||
|
||||
match opts.cmd {
|
||||
Cmd::Messages(messages) => send_or_query(messages)?,
|
||||
Cmd::Platform(platform) => match platform {
|
||||
KdeCommands::Docgen(args) => {
|
||||
let output_dir = args.output.unwrap_or_else(|| PathBuf::from("docs/cli"));
|
||||
let pages = komorebic_core::docgen::write(
|
||||
command::<KdeCommands>(&META),
|
||||
&DocFormat::KDE,
|
||||
&output_dir,
|
||||
)?;
|
||||
for page in pages {
|
||||
println!("{}", page.display());
|
||||
}
|
||||
}
|
||||
KdeCommands::Completions(args) => {
|
||||
let mut cli = command::<KdeCommands>(&META);
|
||||
clap_complete::generate(args.shell, &mut cli, "komorebic", &mut std::io::stdout());
|
||||
}
|
||||
KdeCommands::ExportKdeShortcuts(args) => hotkeys::export_kde_shortcuts(args)?,
|
||||
KdeCommands::Hotkeys(args) => hotkeys::hotkeys(args)?,
|
||||
KdeCommands::Quickstart => {
|
||||
fn write_file_with_prompt(
|
||||
path: &PathBuf,
|
||||
content: &str,
|
||||
created_files: &mut Vec<String>,
|
||||
) -> eyre::Result<()> {
|
||||
if path.exists() {
|
||||
print!(
|
||||
"{} will be overwritten, do you want to continue? (y/N): ",
|
||||
path.display()
|
||||
);
|
||||
std::io::stdout().flush()?;
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_line(&mut input)?;
|
||||
let trimmed = input.trim().to_lowercase();
|
||||
if trimmed == "y" || trimmed == "yes" {
|
||||
std::fs::write(path, content)?;
|
||||
created_files.push(path.display().to_string());
|
||||
} else {
|
||||
println!("Skipping {}", path.display());
|
||||
}
|
||||
} else {
|
||||
std::fs::write(path, content)?;
|
||||
created_files.push(path.display().to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
std::fs::create_dir_all(&*HOME_DIR)?;
|
||||
std::fs::create_dir_all(&*komorebi_client::DATA_DIR)?;
|
||||
|
||||
let komorebi_json = include_str!("../../docs/komorebi.example.json").to_string();
|
||||
let komorebi_path = HOME_DIR.join("komorebi.json");
|
||||
let applications_path = HOME_DIR.join("applications.json");
|
||||
let skhdrc_path = HOME_DIR.join("skhdrc");
|
||||
|
||||
let mut written_files = Vec::new();
|
||||
|
||||
write_file_with_prompt(&komorebi_path, &komorebi_json, &mut written_files)?;
|
||||
|
||||
let applications_json = include_str!("../applications.json");
|
||||
write_file_with_prompt(&applications_path, applications_json, &mut written_files)?;
|
||||
|
||||
let skhdrc = include_str!("../../docs/skhdrc.sample");
|
||||
write_file_with_prompt(&skhdrc_path, skhdrc, &mut written_files)?;
|
||||
if written_files.is_empty() {
|
||||
println!("\nNo files were written.")
|
||||
} else {
|
||||
println!(
|
||||
"\nThe following example files were written:\n{}",
|
||||
written_files.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
println!("\nYou can now run: komorebic start");
|
||||
}
|
||||
KdeCommands::EnableAutostart(args) => {
|
||||
let exec = match args.config {
|
||||
None => String::from("komorebi"),
|
||||
Some(config) => format!("komorebi --config \"{}\"", config.display()),
|
||||
};
|
||||
|
||||
let target = autostart_entry();
|
||||
if let Some(dir) = target.parent() {
|
||||
std::fs::create_dir_all(dir)?;
|
||||
}
|
||||
|
||||
std::fs::write(
|
||||
&target,
|
||||
format!(
|
||||
"[Desktop Entry]\nType=Application\nName=komorebi\nComment=A tiling window manager for KDE Plasma\nExec={exec}\nX-KDE-autostart-after=plasma-workspace\nTerminal=false\n"
|
||||
),
|
||||
)?;
|
||||
|
||||
println!("Wrote {}", target.display());
|
||||
}
|
||||
KdeCommands::DisableAutostart => {
|
||||
let target = autostart_entry();
|
||||
if target.exists() {
|
||||
std::fs::remove_file(&target)?;
|
||||
println!("Deleted {}", target.display());
|
||||
} else {
|
||||
println!("There is no autostart entry at {}", target.display());
|
||||
}
|
||||
}
|
||||
KdeCommands::Check(args) => {
|
||||
use komorebi_client::check::Finding;
|
||||
use komorebi_client::check::Report;
|
||||
|
||||
let mut report = Report::default();
|
||||
|
||||
// where komorebi looks
|
||||
let mut place = vec![];
|
||||
if std::env::var_os("KOMOREBI_CONFIG_HOME").is_some() {
|
||||
place.push(Finding::note(format!(
|
||||
"KOMOREBI_CONFIG_HOME is set: looking in {}",
|
||||
HOME_DIR.display()
|
||||
)));
|
||||
} else {
|
||||
place.push(Finding::note(format!(
|
||||
"KOMOREBI_CONFIG_HOME is not set: looking in {}",
|
||||
HOME_DIR.display()
|
||||
)));
|
||||
}
|
||||
|
||||
let static_config = match args.komorebi_config {
|
||||
Some(path) => {
|
||||
place.push(Finding::note(format!(
|
||||
"using the configuration file given with --komorebi-config: {}",
|
||||
path.display()
|
||||
)));
|
||||
path
|
||||
}
|
||||
None => HOME_DIR.join("komorebi.json"),
|
||||
};
|
||||
|
||||
let (findings, wants) = komorebi_client::check::check_configuration(&static_config);
|
||||
place.extend(findings);
|
||||
report.push("Configuration", place);
|
||||
|
||||
report.push("Key bindings", hotkeys::check(&HOME_DIR));
|
||||
|
||||
if !args.configuration_only {
|
||||
report.push(
|
||||
"The desktop",
|
||||
komorebi_client::check::check_environment(&wants),
|
||||
);
|
||||
}
|
||||
|
||||
print!("{}", report.render());
|
||||
|
||||
if report.has_errors() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
KdeCommands::Start(args) => {
|
||||
launcher::start(&mut KdeLauncher {
|
||||
args: &args,
|
||||
system: sysinfo::System::new_all()?,
|
||||
})?;
|
||||
}
|
||||
KdeCommands::Stop(args) => {
|
||||
send_message(&launcher::stop_message(args.ignore_restore))?;
|
||||
}
|
||||
KdeCommands::Configuration => {
|
||||
let static_config = HOME_DIR.join("komorebi.json");
|
||||
|
||||
if static_config.exists() {
|
||||
println!("{}", static_config.display());
|
||||
}
|
||||
}
|
||||
KdeCommands::DataDirectory => {
|
||||
let dir = &*komorebi_client::DATA_DIR;
|
||||
if dir.exists() {
|
||||
println!("{}", dir.display());
|
||||
}
|
||||
}
|
||||
KdeCommands::Log => {
|
||||
let timestamp = Utc::now().format("%Y-%m-%d").to_string();
|
||||
let color_log = komorebi_client::LOG_DIR.join(format!("komorebi.log.{timestamp}"));
|
||||
let file = TailedFile::new(File::open(color_log)?);
|
||||
let locked = file.lock();
|
||||
#[allow(clippy::significant_drop_in_scrutinee, clippy::lines_filter_map_ok)]
|
||||
for line in locked.lines().flatten() {
|
||||
println!("{line}");
|
||||
}
|
||||
}
|
||||
KdeCommands::ToggleMaximize => {
|
||||
send_message(&SocketMessage::ToggleMaximize)?;
|
||||
}
|
||||
KdeCommands::Pan(args) => {
|
||||
send_message(&SocketMessage::Pan(args.direction))?;
|
||||
}
|
||||
KdeCommands::LayoutRatios(args) => {
|
||||
if args.columns.is_none() && args.rows.is_none() {
|
||||
println!(
|
||||
"No ratios provided, nothing to change. Use --columns or --rows to specify ratios."
|
||||
);
|
||||
} else {
|
||||
send_message(&SocketMessage::LayoutRatios(args.columns, args.rows))?;
|
||||
}
|
||||
}
|
||||
KdeCommands::ApplicationSpecificConfigurationSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let schema = komorebi_config::schema::view::<
|
||||
komorebi_client::ApplicationSpecificConfiguration,
|
||||
>(komorebi_config::schema::Platform::CURRENT);
|
||||
print!("{schema}");
|
||||
}
|
||||
}
|
||||
KdeCommands::NotificationSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let notification = schemars::schema_for!(komorebi_client::Notification);
|
||||
let schema = serde_json::to_string_pretty(¬ification)?;
|
||||
println!("{schema}");
|
||||
}
|
||||
}
|
||||
KdeCommands::SocketSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let socket_message = schemars::schema_for!(SocketMessage);
|
||||
let schema = serde_json::to_string_pretty(&socket_message)?;
|
||||
println!("{schema}");
|
||||
}
|
||||
}
|
||||
KdeCommands::StaticConfigSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let schema = komorebi_config::schema::view::<
|
||||
komorebi_config::static_config::StaticConfig,
|
||||
>(komorebi_config::schema::Platform::CURRENT);
|
||||
print!("{schema}");
|
||||
}
|
||||
}
|
||||
KdeCommands::GenerateStaticConfig => {
|
||||
print_query(&SocketMessage::GenerateStaticConfig);
|
||||
}
|
||||
KdeCommands::Transparency(args) => {
|
||||
send_message(&SocketMessage::Transparency(args.value.into()))?;
|
||||
}
|
||||
KdeCommands::TransparencyAlpha(args) => {
|
||||
send_message(&SocketMessage::TransparencyAlpha(args.alpha))?;
|
||||
}
|
||||
KdeCommands::ToggleTransparency => {
|
||||
send_message(&SocketMessage::ToggleTransparency)?;
|
||||
}
|
||||
KdeCommands::FocusFollowsMouse(args) => {
|
||||
send_message(&SocketMessage::FocusFollowsMouse(
|
||||
args.implementation,
|
||||
args.boolean_state.into(),
|
||||
))?;
|
||||
}
|
||||
KdeCommands::ToggleFocusFollowsMouse(args) => {
|
||||
send_message(&SocketMessage::ToggleFocusFollowsMouse(args.implementation))?;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
fn main() -> color_eyre::eyre::Result<()> {
|
||||
linux::main()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
[
|
||||
"crates/komorebi-backend",
|
||||
"crates/komorebi-collections",
|
||||
"crates/komorebi-config",
|
||||
"crates/komorebi-core",
|
||||
"crates/komorebi-protocol",
|
||||
"crates/komorebi-settings",
|
||||
"crates/komorebi-transport",
|
||||
"crates/komorebic-core",
|
||||
"komorebi-layouts",
|
||||
"komorebi-scrolling",
|
||||
"komorebi-themes"
|
||||
]
|
||||
@@ -40,7 +40,9 @@ let
|
||||
pyproject = true;
|
||||
src = lib.fileset.toSource {
|
||||
root = ./lib;
|
||||
fileset = ./lib;
|
||||
# not the unit tests: the VM never runs them (setuptools does not package them), so
|
||||
# editing one must not rebuild every suite; `libCheck` keeps them
|
||||
fileset = lib.fileset.difference ./lib ./lib/tests;
|
||||
};
|
||||
build-system = [ ps.setuptools ];
|
||||
dependencies = [ ps.pillow ];
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
[package]
|
||||
name = "version"
|
||||
name = "version-linux"
|
||||
edition = "2024"
|
||||
version.workspace = true
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
shadow-rs = { workspace = true }
|
||||
shadow-rs = { version = "2" }
|
||||
|
||||
[build-dependencies]
|
||||
shadow-rs = { workspace = true }
|
||||
shadow-rs = { version = "2" }
|
||||
|
||||
[lib]
|
||||
name = "version"
|
||||
@@ -2,6 +2,5 @@
|
||||
/result*
|
||||
/.idea
|
||||
/.direnv
|
||||
/komorebic/applications.json
|
||||
/komorebi-schema
|
||||
/bar-schema
|
||||
Generated
-8122
File diff suppressed because it is too large.
Load diff
@@ -1,53 +0,0 @@
|
||||
[workspace]
|
||||
|
||||
resolver = "2"
|
||||
members = [
|
||||
"komorebi",
|
||||
"komorebi-bar",
|
||||
"komorebi-client",
|
||||
"komorebic",
|
||||
"version",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
komorebi-themes = { path = "../komorebi-themes" }
|
||||
komorebi-backend = { path = "../crates/komorebi-backend" }
|
||||
komorebi-collections = { path = "../crates/komorebi-collections" }
|
||||
komorebi-config = { path = "../crates/komorebi-config", default-features = false, features = ["schemars"] }
|
||||
komorebi-protocol = { path = "../crates/komorebi-protocol", default-features = false, features = ["schemars"] }
|
||||
komorebi-transport = { path = "../crates/komorebi-transport" }
|
||||
komorebi-layouts = { path = "../komorebi-layouts", features = [
|
||||
"darwin",
|
||||
"schemars",
|
||||
] }
|
||||
|
||||
chrono = "0.4"
|
||||
chrono-tz = "0.10"
|
||||
clap = { version = "4", features = ["derive", "wrap_help"] }
|
||||
color-eyre = "0.6"
|
||||
crossbeam-channel = "0.5"
|
||||
crossbeam-utils = "0.8"
|
||||
dirs = "6"
|
||||
dunce = "1"
|
||||
eframe = "0.33"
|
||||
egui_extras = "0.33"
|
||||
hotwatch = "0.5"
|
||||
lazy_static = "1"
|
||||
parking_lot = "0.12"
|
||||
pastey = "0.2"
|
||||
schemars = "1.1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { package = "serde_json_lenient", version = "0.2" }
|
||||
shadow-rs = "1"
|
||||
sysinfo = "0.38"
|
||||
thiserror = "2"
|
||||
tracing = "0.1"
|
||||
tracing-appender = "0.2"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
which = "8"
|
||||
|
||||
[workspace.metadata.crane]
|
||||
name = "komorebi-workspace"
|
||||
@@ -44,12 +44,12 @@ allow = [
|
||||
confidence-threshold = 0.8
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebi"
|
||||
crate = "komorebi-macos"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebi-client"
|
||||
crate = "komorebi-client-macos"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
@@ -64,12 +64,12 @@ expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebic"
|
||||
crate = "komorebic-macos"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "komorebi-bar"
|
||||
crate = "komorebi-bar-macos"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
@@ -79,7 +79,7 @@ expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
[[licenses.clarify]]
|
||||
crate = "version"
|
||||
crate = "version-macos"
|
||||
expression = "LicenseRef-Komorebi-2.0"
|
||||
license-files = []
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
# the repository, cut down to this workspace and the crates of the root workspace it depends
|
||||
# on by path, with the root manifest those crates inherit their dependencies from
|
||||
src = pkgs.lib.cleanSourceWith {
|
||||
real = pkgs.lib.cleanSourceWith {
|
||||
src = repoRoot;
|
||||
filter =
|
||||
path: type:
|
||||
@@ -62,23 +62,72 @@
|
||||
rootCrate = builtins.any (
|
||||
crate: relative == crate || pkgs.lib.hasPrefix "${crate}/" relative
|
||||
) rootCrates;
|
||||
# the unified komorebic package: its manifest, build script, main and the macOS module
|
||||
komorebic =
|
||||
builtins.elem relative [
|
||||
"komorebic"
|
||||
"komorebic/Cargo.toml"
|
||||
"komorebic/build.rs"
|
||||
"komorebic/src"
|
||||
"komorebic/src/main.rs"
|
||||
]
|
||||
|| pkgs.lib.hasPrefix "komorebic/src/macos" relative;
|
||||
|
||||
# the unified komorebi-client package: its manifest, lib.rs and the module of this platform
|
||||
komorebiClient =
|
||||
builtins.elem relative [
|
||||
"komorebi-client"
|
||||
"komorebi-client/Cargo.toml"
|
||||
"komorebi-client/src"
|
||||
"komorebi-client/src/lib.rs"
|
||||
"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 && !(pkgs.lib.hasSuffix "/Cargo.lock" path) || relative == "Cargo.toml" || 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)
|
||||
|| (builtins.match ".*/docs/.*" path != null)
|
||||
# embedded by include_str! in komorebic
|
||||
|| (pkgs.lib.hasSuffix "/komorebic/src/macos/applications.json" path)
|
||||
);
|
||||
};
|
||||
|
||||
# the workspace is in a subdirectory of the source, next to the crates it depends on
|
||||
# the platform is a part of the one workspace of the repository: cargo loads every member (the
|
||||
# others are stubs, see nix/workspace-src.nix) and is told which packages are this platform's
|
||||
src = import (repoRoot + "/nix/workspace-src.nix") {
|
||||
inherit pkgs repoRoot real;
|
||||
isReal =
|
||||
member:
|
||||
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";
|
||||
workspaceArgs = {
|
||||
cargoLock = "${src}/${platformDir}/Cargo.lock";
|
||||
cargoToml = "${src}/${platformDir}/Cargo.toml";
|
||||
postUnpack = "cd $sourceRoot/${platformDir}; sourceRoot=$PWD";
|
||||
pname = "komorebi-workspace";
|
||||
inherit version;
|
||||
cargoLock = "${real}/Cargo.lock";
|
||||
cargoToml = "${real}/Cargo.toml";
|
||||
# vendored from the filtered source, not the stubbed one: no build is needed to evaluate
|
||||
cargoVendorDir = craneLib.vendorCargoDeps { src = real; };
|
||||
};
|
||||
|
||||
commonArgs = workspaceArgs // {
|
||||
cargoExtraArgs = "--locked ${packages}";
|
||||
inherit src version;
|
||||
strictDeps = true;
|
||||
COMMIT_HASH = self.rev or (pkgs.lib.removeSuffix "-dirty" (self.dirtyRev or "unknown"));
|
||||
@@ -127,7 +176,9 @@
|
||||
inherit
|
||||
craneLib
|
||||
src
|
||||
real
|
||||
workspaceArgs
|
||||
packages
|
||||
individualCrateArgs
|
||||
fullBuild
|
||||
;
|
||||
@@ -192,17 +243,38 @@
|
||||
checks = {
|
||||
komorebi-workspace-clippy = build.craneLib.cargoClippy build.individualCrateArgs;
|
||||
|
||||
komorebi-workspace-fmt = build.craneLib.cargoFmt (build.workspaceArgs // { inherit (build) src; });
|
||||
komorebi-workspace-fmt = build.craneLib.cargoFmt (build.workspaceArgs // { inherit (build) src; cargoExtraArgs = build.packages; });
|
||||
|
||||
komorebi-workspace-toml-fmt = build.craneLib.taploFmt (
|
||||
build.workspaceArgs
|
||||
// {
|
||||
src = pkgs.lib.sources.sourceFilesBySuffices build.src [ ".toml" ];
|
||||
src = pkgs.lib.sources.sourceFilesBySuffices build.real [ ".toml" ];
|
||||
}
|
||||
);
|
||||
|
||||
# cargo deny sees every member of the workspace: leave out the other platforms' packages
|
||||
# and use this tree's policy
|
||||
komorebi-workspace-deny = build.craneLib.cargoDeny (
|
||||
build.workspaceArgs // { inherit (build) src; }
|
||||
build.workspaceArgs
|
||||
// {
|
||||
inherit (build) src;
|
||||
cargoDenyExtraArgs =
|
||||
"--workspace "
|
||||
+ pkgs.lib.concatMapStringsSep " " (p: "--exclude ${p}") [
|
||||
"komorebi-windows"
|
||||
"komorebi-gui"
|
||||
"komorebic-no-console"
|
||||
"komorebi-shortcuts"
|
||||
"komorebi-e2e-agent"
|
||||
"komorebi-testwin"
|
||||
"komorebi-linux"
|
||||
"komorebic-linux"
|
||||
"komorebi-client-linux"
|
||||
"komorebi-hotkeys"
|
||||
"version-linux"
|
||||
];
|
||||
cargoDenyChecks = "--config ${platformDir}/deny.toml bans licenses sources";
|
||||
}
|
||||
);
|
||||
|
||||
komorebi-workspace-nextest = build.craneLib.cargoNextest build.individualCrateArgs;
|
||||
|
||||
@@ -64,14 +64,14 @@ deadlock $RUST_LOG="trace":
|
||||
|
||||
docgen starlight:
|
||||
rm {{ starlight }}/src/data/cli/macos/*.md
|
||||
cargo run --package komorebic -- docgen --output {{ starlight }}/src/data/cli/macos
|
||||
cargo run --package komorebic-macos -- docgen --output {{ starlight }}/src/data/cli/macos
|
||||
schemars-docgen ./schema.json --output {{ starlight }}/src/content/docs/reference/komorebi-macos.mdx --title "komorebi.json (macOS)" --description "komorebi for Mac configuration schema reference"
|
||||
schemars-docgen ./schema.bar.json --output {{ starlight }}/src/content/docs/reference/bar-macos.mdx --title "komorebi.bar.json (macOS)" --description "komorebi-bar for Mac configuration schema reference"
|
||||
|
||||
jsonschema:
|
||||
cargo run --package komorebic -- static-config-schema > schema.json
|
||||
cargo run --package komorebic -- application-specific-configuration-schema > schema.asc.json
|
||||
cargo run --package komorebi-bar -- --schema > schema.bar.json
|
||||
cargo run --package komorebic-macos -- static-config-schema > schema.json
|
||||
cargo run --package komorebic-macos -- application-specific-configuration-schema > schema.asc.json
|
||||
cargo run --package komorebi-bar-macos -- --schema > schema.bar.json
|
||||
|
||||
nixgen:
|
||||
schemars-nixgen schema.json -o nix/komorebi-options.nix --name komorebi --description "komorebi for Mac configuration"
|
||||
@@ -79,7 +79,7 @@ nixgen:
|
||||
nix fmt nix/
|
||||
nix build -f nix/tests/default.nix
|
||||
|
||||
version := `cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "komorebi") | .version'`
|
||||
version := `cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "komorebi-macos") | .version'`
|
||||
|
||||
schemapub:
|
||||
rm -rf komorebi-schema
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "komorebi-bar"
|
||||
name = "komorebi-bar-macos"
|
||||
version = "0.1.1"
|
||||
edition = "2024"
|
||||
|
||||
@@ -7,23 +7,23 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
komorebi-bar-core = { path = "../../crates/komorebi-bar-core", default-features = false }
|
||||
komorebi-client = { path = "../komorebi-client", default-features = false }
|
||||
komorebi-themes = { workspace = true }
|
||||
komorebi-client = { path = "../../komorebi-client", default-features = false }
|
||||
komorebi-themes = { path = "../../komorebi-themes" }
|
||||
|
||||
chrono = { workspace = true }
|
||||
chrono-tz = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
color-eyre = { workspace = true }
|
||||
crossbeam-channel = { workspace = true }
|
||||
dirs = { workspace = true }
|
||||
dunce = { workspace = true }
|
||||
eframe = { workspace = true }
|
||||
chrono = { version = "0.4" }
|
||||
chrono-tz = { version = "0.10" }
|
||||
clap = { version = "4", features = ["derive", "wrap_help"] }
|
||||
color-eyre = { version = "0.6" }
|
||||
crossbeam-channel = { version = "0.5" }
|
||||
dirs = { version = "6" }
|
||||
dunce = { version = "1" }
|
||||
eframe = { version = "0.33" }
|
||||
egui-phosphor = { git = "https://github.com/amPerl/egui-phosphor", rev = "d13688738478ecd12b426e3e74c59d6577a85b59" }
|
||||
font-loader = "0.11"
|
||||
hotwatch = { workspace = true }
|
||||
hotwatch = { version = "0.5" }
|
||||
icns = "0.4"
|
||||
image = "0.25"
|
||||
lazy_static = { workspace = true }
|
||||
lazy_static = { version = "1" }
|
||||
netdev = "0.40"
|
||||
num = "0.4"
|
||||
num-derive = "0.4"
|
||||
@@ -37,15 +37,15 @@ objc2-app-kit = { version = "0.3", default-features = false, features = [
|
||||
"NSWindow",
|
||||
] }
|
||||
raw-window-handle = "0.6"
|
||||
parking_lot = { workspace = true }
|
||||
parking_lot = { version = "0.12" }
|
||||
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 }
|
||||
sysinfo = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
schemars = { version = "1.1", optional = true }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { package = "serde_json_lenient", version = "0.2" }
|
||||
sysinfo = { version = "0.38" }
|
||||
tracing = { version = "0.1" }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
|
||||
[features]
|
||||
default = ["schemars"]
|
||||
@@ -55,3 +55,7 @@ schemars = [
|
||||
"komorebi-client/default",
|
||||
"komorebi-themes/default",
|
||||
]
|
||||
|
||||
[[bin]]
|
||||
name = "komorebi-bar"
|
||||
path = "src/main.rs"
|
||||
@@ -1,582 +0,0 @@
|
||||
use crate::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::DEFAULT_PADDING;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::render::RenderExt;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::FontId;
|
||||
use eframe::egui::TextStyle;
|
||||
use komorebi_themes::colour::Colour;
|
||||
use komorebi_themes::colour::Rgb;
|
||||
use std::num::NonZeroU32;
|
||||
use std::sync::atomic::Ordering;
|
||||
// use crate::bar::exec_powershell;
|
||||
use crate::render::Grouping;
|
||||
use crate::widgets::widget::WidgetConfig;
|
||||
use color_eyre::eyre;
|
||||
use eframe::egui::TextBuffer;
|
||||
use komorebi_client::Rect;
|
||||
use komorebi_themes::KomobarTheme;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// The `komorebi.bar.json` static configuration file reference for komorebi for Mac `v0.1.0`
|
||||
///
|
||||
/// `"$schema": "https://komorebi-for-mac.lgug2z.com/komorebi.bar.0.1.0.schema.json"`
|
||||
pub struct KomobarConfig {
|
||||
/// Bar height
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 50.0)))]
|
||||
pub height: Option<f32>,
|
||||
/// Bar padding. Use one value for all sides or use a grouped padding for horizontal and/or
|
||||
/// vertical definition which can each take a single value for a symmetric padding or two
|
||||
/// values for each side, i.e.:
|
||||
/// ```json
|
||||
/// "padding": {
|
||||
/// "horizontal": 10.0
|
||||
/// }
|
||||
/// ```
|
||||
/// or:
|
||||
/// ```json
|
||||
/// "padding": {
|
||||
/// "horizontal": [left, right]
|
||||
/// }
|
||||
/// ```
|
||||
/// You can also set individual padding on each side like this:
|
||||
/// ```json
|
||||
/// "padding": {
|
||||
/// "top": 10.0,
|
||||
/// "bottom": 10.0,
|
||||
/// "left": 10.0,
|
||||
/// "right": 10.0
|
||||
/// }
|
||||
/// ```
|
||||
pub padding: Option<Padding>,
|
||||
/// Bar margin. Use one value for all sides or use a grouped margin for horizontal and/or
|
||||
/// vertical definition which can each take a single value for a symmetric margin or two
|
||||
/// values for each side, i.e.:
|
||||
/// ```json
|
||||
/// "margin": {
|
||||
/// "horizontal": 10.0
|
||||
/// }
|
||||
/// ```
|
||||
/// or:
|
||||
/// ```json
|
||||
/// "margin": {
|
||||
/// "vertical": [top, bottom]
|
||||
/// }
|
||||
/// ```
|
||||
/// You can also set individual margin on each side like this:
|
||||
/// ```json
|
||||
/// "margin": {
|
||||
/// "top": 10.0,
|
||||
/// "bottom": 10.0,
|
||||
/// "left": 10.0,
|
||||
/// "right": 10.0
|
||||
/// }
|
||||
/// ```
|
||||
pub margin: Option<Margin>,
|
||||
/// Bar positioning options
|
||||
#[serde(alias = "viewport")]
|
||||
pub position: Option<PositionConfig>,
|
||||
/// Frame options (see: https://docs.rs/egui/latest/egui/containers/frame/struct.Frame.html)
|
||||
pub frame: Option<FrameConfig>,
|
||||
/// The monitor index or the full monitor options
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = MonitorConfigOrIndex::Index(0))))]
|
||||
pub monitor: Option<MonitorConfigOrIndex>,
|
||||
/// Font family
|
||||
pub font_family: Option<String>,
|
||||
/// Font size
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 12.5)))]
|
||||
pub font_size: Option<f32>,
|
||||
/// Scale of the icons relative to the font_size [[1.0-2.0]]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 1.4)))]
|
||||
pub icon_scale: Option<f32>,
|
||||
/// Max label width before text truncation
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 400.0)))]
|
||||
pub max_label_width: Option<f32>,
|
||||
/// Theme
|
||||
pub theme: Option<KomobarTheme>,
|
||||
/// Alpha value for the color transparency [[0-255]]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 200)))]
|
||||
pub transparency_alpha: Option<u8>,
|
||||
/// Spacing between widgets
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10.0)))]
|
||||
pub widget_spacing: Option<f32>,
|
||||
/// Visual grouping for widgets
|
||||
pub grouping: Option<Grouping>,
|
||||
// /// Options for mouse interaction on the bar
|
||||
// pub mouse: Option<MouseConfig>,
|
||||
/// Left side widgets (ordered left-to-right)
|
||||
pub left_widgets: Vec<WidgetConfig>,
|
||||
/// Center widgets (ordered left-to-right)
|
||||
pub center_widgets: Option<Vec<WidgetConfig>>,
|
||||
/// Right side widgets (ordered left-to-right)
|
||||
pub right_widgets: Vec<WidgetConfig>,
|
||||
}
|
||||
|
||||
impl KomobarConfig {
|
||||
pub fn aliases(raw: &str) {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("position", ["viewport"]);
|
||||
map.insert("end", ["inner_frame"]);
|
||||
|
||||
let mut display = false;
|
||||
|
||||
for aliases in map.values() {
|
||||
for a in aliases {
|
||||
if raw.contains(a) {
|
||||
display = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if display {
|
||||
println!(
|
||||
"\nYour bar configuration file contains some options that have been renamed or deprecated:\n"
|
||||
);
|
||||
for (canonical, aliases) in map {
|
||||
for alias in aliases {
|
||||
if raw.contains(alias) {
|
||||
println!(r#""{alias}" is now "{canonical}""#);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_all_icons_on_komorebi_workspace(widgets: &[WidgetConfig]) -> bool {
|
||||
widgets
|
||||
.iter()
|
||||
.any(|w| matches!(w, WidgetConfig::Komorebi(config) if config.workspaces.is_some_and(|w| w.enable && w.display.is_some_and(|s| matches!(s,
|
||||
WorkspacesDisplayFormat::AllIcons
|
||||
| WorkspacesDisplayFormat::AllIconsAndText
|
||||
| WorkspacesDisplayFormat::AllIconsAndTextOnSelected)))))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Position configuration
|
||||
pub struct PositionConfig {
|
||||
/// The desired starting position of the bar (0,0 = top left of the screen)
|
||||
#[serde(alias = "position")]
|
||||
pub start: Option<Position>,
|
||||
/// The desired size of the bar from the starting position (usually monitor width x desired height)
|
||||
#[serde(alias = "inner_size")]
|
||||
pub end: Option<Position>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Frame configuration
|
||||
pub struct FrameConfig {
|
||||
/// Margin inside the painted frame
|
||||
pub inner_margin: Position,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// Monitor configuration or monitor index
|
||||
pub enum MonitorConfigOrIndex {
|
||||
/// The monitor index where you want the bar to show
|
||||
Index(usize),
|
||||
/// The full monitor options with the index and an optional work_area_offset
|
||||
MonitorConfig(MonitorConfig),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Monitor configuration
|
||||
pub struct MonitorConfig {
|
||||
/// Komorebi monitor index of the monitor on which to render the bar
|
||||
pub index: usize,
|
||||
/// Automatically apply a work area offset for this monitor to accommodate the bar
|
||||
pub work_area_offset: Option<Rect>,
|
||||
}
|
||||
|
||||
pub type Padding = SpacingKind;
|
||||
pub type Margin = SpacingKind;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
// WARNING: To any developer messing with this code in the future: The order here matters!
|
||||
// `Grouped` needs to come last, otherwise serde might mistaken an `IndividualSpacingConfig` for a
|
||||
// `GroupedSpacingConfig` with both `vertical` and `horizontal` set to `None` ignoring the
|
||||
// individual values.
|
||||
/// Spacing kind
|
||||
pub enum SpacingKind {
|
||||
/// Spacing applied to all sides
|
||||
All(f32),
|
||||
/// Individual spacing applied to each side
|
||||
Individual(IndividualSpacingConfig),
|
||||
/// Grouped vertical and horizontal spacing
|
||||
Grouped(GroupedSpacingConfig),
|
||||
}
|
||||
|
||||
impl SpacingKind {
|
||||
pub fn to_individual(&self, default: f32) -> IndividualSpacingConfig {
|
||||
match self {
|
||||
SpacingKind::All(m) => IndividualSpacingConfig::all(*m),
|
||||
SpacingKind::Grouped(grouped_spacing_config) => {
|
||||
let vm = grouped_spacing_config.vertical.as_ref().map_or(
|
||||
IndividualSpacingConfig::vertical(default),
|
||||
|vm| match vm {
|
||||
GroupedSpacingOptions::Symmetrical(m) => {
|
||||
IndividualSpacingConfig::vertical(*m)
|
||||
}
|
||||
GroupedSpacingOptions::Split(tm, bm) => {
|
||||
IndividualSpacingConfig::vertical(*tm).bottom(*bm)
|
||||
}
|
||||
},
|
||||
);
|
||||
let hm = grouped_spacing_config.horizontal.as_ref().map_or(
|
||||
IndividualSpacingConfig::horizontal(default),
|
||||
|hm| match hm {
|
||||
GroupedSpacingOptions::Symmetrical(m) => {
|
||||
IndividualSpacingConfig::horizontal(*m)
|
||||
}
|
||||
GroupedSpacingOptions::Split(lm, rm) => {
|
||||
IndividualSpacingConfig::horizontal(*lm).right(*rm)
|
||||
}
|
||||
},
|
||||
);
|
||||
IndividualSpacingConfig {
|
||||
top: vm.top,
|
||||
bottom: vm.bottom,
|
||||
left: hm.left,
|
||||
right: hm.right,
|
||||
}
|
||||
}
|
||||
SpacingKind::Individual(m) => *m,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Grouped vertical and horizontal spacing
|
||||
pub struct GroupedSpacingConfig {
|
||||
/// Vertical grouped spacing
|
||||
pub vertical: Option<GroupedSpacingOptions>,
|
||||
/// Horizontal grouped spacing
|
||||
pub horizontal: Option<GroupedSpacingOptions>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[serde(untagged)]
|
||||
/// Grouped spacing options
|
||||
pub enum GroupedSpacingOptions {
|
||||
/// Symmetrical grouped spacing
|
||||
Symmetrical(f32),
|
||||
/// Split grouped spacing
|
||||
Split(f32, f32),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Individual spacing configuration
|
||||
pub struct IndividualSpacingConfig {
|
||||
/// Spacing for the top
|
||||
pub top: f32,
|
||||
/// Spacing for the bottom
|
||||
pub bottom: f32,
|
||||
/// Spacing for the left
|
||||
pub left: f32,
|
||||
/// Spacing for the right
|
||||
pub right: f32,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl IndividualSpacingConfig {
|
||||
pub const ZERO: Self = IndividualSpacingConfig {
|
||||
top: 0.0,
|
||||
bottom: 0.0,
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
};
|
||||
|
||||
pub fn all(value: f32) -> Self {
|
||||
IndividualSpacingConfig {
|
||||
top: value,
|
||||
bottom: value,
|
||||
left: value,
|
||||
right: value,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn horizontal(value: f32) -> Self {
|
||||
IndividualSpacingConfig {
|
||||
top: 0.0,
|
||||
bottom: 0.0,
|
||||
left: value,
|
||||
right: value,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vertical(value: f32) -> Self {
|
||||
IndividualSpacingConfig {
|
||||
top: value,
|
||||
bottom: value,
|
||||
left: 0.0,
|
||||
right: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn top(self, value: f32) -> Self {
|
||||
IndividualSpacingConfig { top: value, ..self }
|
||||
}
|
||||
|
||||
pub fn bottom(self, value: f32) -> Self {
|
||||
IndividualSpacingConfig {
|
||||
bottom: value,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn left(self, value: f32) -> Self {
|
||||
IndividualSpacingConfig {
|
||||
left: value,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn right(self, value: f32) -> Self {
|
||||
IndividualSpacingConfig {
|
||||
right: value,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_individual_spacing(
|
||||
default: f32,
|
||||
spacing: &Option<SpacingKind>,
|
||||
) -> IndividualSpacingConfig {
|
||||
spacing
|
||||
.as_ref()
|
||||
.map_or(IndividualSpacingConfig::all(default), |s| {
|
||||
s.to_individual(default)
|
||||
})
|
||||
}
|
||||
|
||||
// #[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
// #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
// #[serde(untagged)]
|
||||
// pub enum MouseMessage {
|
||||
// /// Send a message to the komorebi client.
|
||||
// /// By default, a batch of messages are sent in the following order:
|
||||
// /// FocusMonitorAtCursor =>
|
||||
// /// MouseFollowsFocus(false) =>
|
||||
// /// {message} =>
|
||||
// /// MouseFollowsFocus({original.value})
|
||||
// ///
|
||||
// /// Example:
|
||||
// /// ```json
|
||||
// /// "on_extra2_click": {
|
||||
// /// "message": {
|
||||
// /// "type": "NewWorkspace"
|
||||
// /// }
|
||||
// /// },
|
||||
// /// ```
|
||||
// /// or:
|
||||
// /// ```json
|
||||
// /// "on_middle_click": {
|
||||
// /// "focus_monitor_at_cursor": false,
|
||||
// /// "ignore_mouse_follows_focus": false,
|
||||
// /// "message": {
|
||||
// /// "type": "TogglePause"
|
||||
// /// }
|
||||
// /// }
|
||||
// /// ```
|
||||
// /// or:
|
||||
// /// ```json
|
||||
// /// "on_scroll_up": {
|
||||
// /// "message": {
|
||||
// /// "type": "CycleFocusWorkspace",
|
||||
// /// "content": "Previous"
|
||||
// /// }
|
||||
// /// }
|
||||
// /// ```
|
||||
// Komorebi(KomorebiMouseMessage),
|
||||
// /// Execute a custom command.
|
||||
// /// CMD (%variable%), Bash ($variable) and PowerShell ($Env:variable) variables will be resolved.
|
||||
// /// Example: `komorebic toggle-pause`
|
||||
// Command(String),
|
||||
// }
|
||||
//
|
||||
// #[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
// #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
// pub struct KomorebiMouseMessage {
|
||||
// /// Send the FocusMonitorAtCursor message (default:true)
|
||||
// pub focus_monitor_at_cursor: Option<bool>,
|
||||
// /// Wrap the {message} with a MouseFollowsFocus(false) and MouseFollowsFocus({original.value}) message (default:true)
|
||||
// pub ignore_mouse_follows_focus: Option<bool>,
|
||||
// /// The message to send to the komorebi client
|
||||
// pub message: komorebi_client::SocketMessage,
|
||||
// }
|
||||
//
|
||||
// #[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
// #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
// pub struct MouseConfig {
|
||||
// /// Command to send on primary/left double button click
|
||||
// pub on_primary_double_click: Option<MouseMessage>,
|
||||
// /// Command to send on secondary/right button click
|
||||
// pub on_secondary_click: Option<MouseMessage>,
|
||||
// /// Command to send on middle button click
|
||||
// pub on_middle_click: Option<MouseMessage>,
|
||||
// /// Command to send on extra1/back button click
|
||||
// pub on_extra1_click: Option<MouseMessage>,
|
||||
// /// Command to send on extra2/forward button click
|
||||
// pub on_extra2_click: Option<MouseMessage>,
|
||||
//
|
||||
// /// Defines how many points a user needs to scroll vertically to make a "tick" on a mouse/touchpad/touchscreen (default: 30)
|
||||
// pub vertical_scroll_threshold: Option<f32>,
|
||||
// /// Command to send on scrolling up (every tick)
|
||||
// pub on_scroll_up: Option<MouseMessage>,
|
||||
// /// Command to send on scrolling down (every tick)
|
||||
// pub on_scroll_down: Option<MouseMessage>,
|
||||
//
|
||||
// /// Defines how many points a user needs to scroll horizontally to make a "tick" on a mouse/touchpad/touchscreen (default: 30)
|
||||
// pub horizontal_scroll_threshold: Option<f32>,
|
||||
// /// Command to send on scrolling left (every tick)
|
||||
// pub on_scroll_left: Option<MouseMessage>,
|
||||
// /// Command to send on scrolling right (every tick)
|
||||
// pub on_scroll_right: Option<MouseMessage>,
|
||||
// }
|
||||
//
|
||||
// impl MouseConfig {
|
||||
// pub fn has_command(&self) -> bool {
|
||||
// [
|
||||
// &self.on_primary_double_click,
|
||||
// &self.on_secondary_click,
|
||||
// &self.on_middle_click,
|
||||
// &self.on_extra1_click,
|
||||
// &self.on_extra2_click,
|
||||
// &self.on_scroll_up,
|
||||
// &self.on_scroll_down,
|
||||
// &self.on_scroll_left,
|
||||
// &self.on_scroll_right,
|
||||
// ]
|
||||
// .iter()
|
||||
// .any(|opt| matches!(opt, Some(MouseMessage::Command(_))))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// impl MouseMessage {
|
||||
// pub fn execute(&self, mouse_follows_focus: bool) {
|
||||
// match self {
|
||||
// MouseMessage::Komorebi(config) => {
|
||||
// let mut messages = Vec::new();
|
||||
//
|
||||
// if config.focus_monitor_at_cursor.unwrap_or(true) {
|
||||
// messages.push(SocketMessage::FocusMonitorAtCursor);
|
||||
// }
|
||||
//
|
||||
// if config.ignore_mouse_follows_focus.unwrap_or(true) {
|
||||
// messages.push(SocketMessage::MouseFollowsFocus(false));
|
||||
// messages.push(config.message.clone());
|
||||
// messages.push(SocketMessage::MouseFollowsFocus(mouse_follows_focus));
|
||||
// } else {
|
||||
// messages.push(config.message.clone());
|
||||
// }
|
||||
//
|
||||
// tracing::debug!("Sending messages: {messages:?}");
|
||||
//
|
||||
// if komorebi_client::send_batch(messages).is_err() {
|
||||
// tracing::error!("could not send commands");
|
||||
// }
|
||||
// }
|
||||
// MouseMessage::Command(cmd) => {
|
||||
// tracing::debug!("Executing command: {}", cmd);
|
||||
//
|
||||
// let cmd_no_env = cmd.replace_env();
|
||||
//
|
||||
// if exec_powershell(cmd_no_env.to_str().expect("Invalid command")).is_err() {
|
||||
// tracing::error!("Failed to execute '{}'", cmd);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
impl KomobarConfig {
|
||||
pub fn read(path: &PathBuf) -> eyre::Result<Self> {
|
||||
let content = std::fs::read_to_string(path)?;
|
||||
let mut value: Self = match path.extension().unwrap().to_string_lossy().as_str() {
|
||||
"json" => serde_json::from_str(&content)?,
|
||||
_ => panic!("unsupported format"),
|
||||
};
|
||||
|
||||
if value.frame.is_none() {
|
||||
value.frame = Some(FrameConfig {
|
||||
inner_margin: Position {
|
||||
x: DEFAULT_PADDING,
|
||||
y: DEFAULT_PADDING,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderExt for &KomobarConfig {
|
||||
fn new_renderconfig(
|
||||
&self,
|
||||
ctx: &Context,
|
||||
background_color: Color32,
|
||||
icon_scale: Option<f32>,
|
||||
) -> RenderConfig {
|
||||
let text_font_id = ctx
|
||||
.style()
|
||||
.text_styles
|
||||
.get(&TextStyle::Body)
|
||||
.cloned()
|
||||
.unwrap_or_else(FontId::default);
|
||||
|
||||
let mut icon_font_id = text_font_id.clone();
|
||||
icon_font_id.size *= icon_scale.unwrap_or(1.4).clamp(1.0, 2.0);
|
||||
|
||||
let monitor_idx = match &self.monitor {
|
||||
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
|
||||
let show_all_icons =
|
||||
KomobarConfig::show_all_icons_on_komorebi_workspace(&self.left_widgets)
|
||||
|| self
|
||||
.center_widgets
|
||||
.as_ref()
|
||||
.is_some_and(|list| KomobarConfig::show_all_icons_on_komorebi_workspace(list))
|
||||
|| KomobarConfig::show_all_icons_on_komorebi_workspace(&self.right_widgets);
|
||||
|
||||
RenderConfig {
|
||||
monitor_idx,
|
||||
spacing: self.widget_spacing.unwrap_or(10.0),
|
||||
grouping: self.grouping.unwrap_or(Grouping::None),
|
||||
background_color,
|
||||
alignment: None,
|
||||
more_inner_margin: false,
|
||||
applied_on_widget: false,
|
||||
text_font_id,
|
||||
icon_font_id,
|
||||
show_all_icons,
|
||||
auto_select_fill: NonZeroU32::new(AUTO_SELECT_FILL_COLOUR.load(Ordering::SeqCst))
|
||||
.map(|c| Colour::Rgb(Rgb::from(c.get())).into()),
|
||||
auto_select_text: NonZeroU32::new(AUTO_SELECT_TEXT_COLOUR.load(Ordering::SeqCst))
|
||||
.map(|c| Colour::Rgb(Rgb::from(c.get())).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use komorebi_bar_core::config::types::*;
|
||||
@@ -1,386 +1,9 @@
|
||||
mod bar;
|
||||
mod config;
|
||||
mod os;
|
||||
pub use komorebi_bar_core::platform;
|
||||
pub use komorebi_bar_core::render;
|
||||
pub use komorebi_bar_core::selected_frame;
|
||||
pub use komorebi_bar_core::ui;
|
||||
mod widgets;
|
||||
//! `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`.
|
||||
|
||||
use crate::bar::Komobar;
|
||||
use crate::config::KomobarConfig;
|
||||
use crate::config::Position;
|
||||
use crate::config::PositionConfig;
|
||||
use clap::Parser;
|
||||
use color_eyre::eyre;
|
||||
use config::MonitorConfigOrIndex;
|
||||
use eframe::egui::ViewportBuilder;
|
||||
use font_loader::system_fonts;
|
||||
use hotwatch::EventKind;
|
||||
use hotwatch::Hotwatch;
|
||||
use komorebi_client::PathExt;
|
||||
use komorebi_client::SocketMessage;
|
||||
use komorebi_client::SubscribeOptions;
|
||||
use komorebi_client::replace_env_in_path;
|
||||
use objc2::MainThreadMarker;
|
||||
use objc2_app_kit::NSApplication;
|
||||
use objc2_app_kit::NSApplicationActivationPolicy;
|
||||
use objc2_app_kit::NSView;
|
||||
use raw_window_handle::HasWindowHandle;
|
||||
use raw_window_handle::RawWindowHandle;
|
||||
use std::io::BufReader;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
#[path = "../../../komorebi-bar/src/macos/mod.rs"]
|
||||
mod macos;
|
||||
|
||||
pub use komorebi_bar_core::statics::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author, about, version)]
|
||||
struct Opts {
|
||||
/// Print the JSON schema of the configuration file and exit
|
||||
#[clap(long)]
|
||||
schema: bool,
|
||||
/// Print a list of fonts available on this system and exit
|
||||
#[clap(long)]
|
||||
fonts: bool,
|
||||
/// Path to a JSON or YAML configuration file
|
||||
#[clap(short, long)]
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
config: Option<PathBuf>,
|
||||
/// Write an example komorebi.bar.json to disk
|
||||
#[clap(long)]
|
||||
quickstart: bool,
|
||||
/// Print a list of aliases that can be renamed to canonical variants
|
||||
#[clap(long)]
|
||||
#[clap(hide = true)]
|
||||
aliases: bool,
|
||||
}
|
||||
|
||||
pub enum KomorebiEvent {
|
||||
Notification(komorebi_client::Notification),
|
||||
Reconnect,
|
||||
}
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
komorebi_bar_core::platform::install(&os::MacBar);
|
||||
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
#[cfg(feature = "schemars")]
|
||||
if opts.schema {
|
||||
let bar_config = schemars::schema_for!(KomobarConfig);
|
||||
let schema = serde_json::to_string_pretty(&bar_config)?;
|
||||
|
||||
println!("{schema}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if opts.fonts {
|
||||
for font in system_fonts::query_all() {
|
||||
println!("{font}");
|
||||
}
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if std::env::var("RUST_LIB_BACKTRACE").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LIB_BACKTRACE", "1");
|
||||
}
|
||||
}
|
||||
|
||||
color_eyre::install()?;
|
||||
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LOG", "info");
|
||||
}
|
||||
}
|
||||
|
||||
tracing::subscriber::set_global_default(
|
||||
tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.finish(),
|
||||
)?;
|
||||
|
||||
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
||||
|_| {
|
||||
dirs::home_dir()
|
||||
.expect("there is no home directory")
|
||||
.join(".config")
|
||||
.join("komorebi")
|
||||
},
|
||||
|home_path| {
|
||||
let home = home_path.replace_env();
|
||||
|
||||
assert!(
|
||||
home.is_dir(),
|
||||
"$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory"
|
||||
);
|
||||
|
||||
home
|
||||
},
|
||||
);
|
||||
|
||||
if opts.quickstart {
|
||||
let komorebi_bar_json = include_str!("../../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 {}",
|
||||
home_dir.display()
|
||||
);
|
||||
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let default_config_path = home_dir.join("komorebi.bar.json");
|
||||
|
||||
let config_path = opts.config.or_else(|| {
|
||||
default_config_path
|
||||
.is_file()
|
||||
.then_some(default_config_path.clone())
|
||||
});
|
||||
|
||||
let mut config = match config_path {
|
||||
None => {
|
||||
let komorebi_bar_json =
|
||||
include_str!("../../docs/komorebi.bar.example.json").to_string();
|
||||
|
||||
std::fs::write(&default_config_path, komorebi_bar_json)?;
|
||||
tracing::info!(
|
||||
"created example configuration file: {}",
|
||||
default_config_path.display()
|
||||
);
|
||||
|
||||
KomobarConfig::read(&default_config_path)?
|
||||
}
|
||||
Some(ref config) => {
|
||||
if !opts.aliases {
|
||||
tracing::info!("found configuration file: {}", config.display());
|
||||
}
|
||||
|
||||
KomobarConfig::read(config)?
|
||||
}
|
||||
};
|
||||
|
||||
let config_path = config_path.unwrap_or(default_config_path);
|
||||
|
||||
if opts.aliases {
|
||||
KomobarConfig::aliases(&std::fs::read_to_string(&config_path)?);
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let state = serde_json::from_str::<komorebi_client::State>(&komorebi_client::send_query(
|
||||
&SocketMessage::State,
|
||||
)?)?;
|
||||
|
||||
let (usr_monitor_index, work_area_offset) = match &config.monitor {
|
||||
Some(MonitorConfigOrIndex::MonitorConfig(monitor_config)) => {
|
||||
(monitor_config.index, monitor_config.work_area_offset)
|
||||
}
|
||||
Some(MonitorConfigOrIndex::Index(idx)) => (*idx, None),
|
||||
None => (0, None),
|
||||
};
|
||||
let monitor_index = state
|
||||
.monitor_usr_idx_map
|
||||
.get(&usr_monitor_index)
|
||||
.map_or(usr_monitor_index, |i| *i);
|
||||
|
||||
MONITOR_RIGHT.store(
|
||||
state.monitors.elements()[monitor_index].size.right,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_TOP.store(
|
||||
state.monitors.elements()[monitor_index].size.top,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_LEFT.store(
|
||||
state.monitors.elements()[monitor_index].size.left,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
MONITOR_INDEX.store(monitor_index, Ordering::SeqCst);
|
||||
|
||||
// use monitor.size for the actual monitor bounds (top-left origin in global coordinates)
|
||||
// the window level kCGBackstopMenuLevel positions the bar behind the menu bar
|
||||
match config.position {
|
||||
None => {
|
||||
config.position = Some(PositionConfig {
|
||||
start: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
}),
|
||||
end: Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
}),
|
||||
})
|
||||
}
|
||||
Some(ref mut position) => {
|
||||
if position.start.is_none() {
|
||||
position.start = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.left as f32,
|
||||
y: state.monitors.elements()[monitor_index].size.top as f32,
|
||||
});
|
||||
}
|
||||
|
||||
if position.end.is_none() {
|
||||
position.end = Some(Position {
|
||||
x: state.monitors.elements()[monitor_index].size.right as f32,
|
||||
y: 50.0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let viewport_builder = ViewportBuilder::default()
|
||||
.with_decorations(false)
|
||||
.with_transparent(true)
|
||||
.with_has_shadow(false)
|
||||
.with_taskbar(false);
|
||||
|
||||
let native_options = eframe::NativeOptions {
|
||||
viewport: viewport_builder,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if let Some(rect) = &work_area_offset {
|
||||
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(monitor_index, *rect))?;
|
||||
tracing::info!("work area offset applied to monitor: {}", monitor_index);
|
||||
}
|
||||
|
||||
let (tx_gui, rx_gui) = crossbeam_channel::unbounded();
|
||||
let (tx_config, rx_config) = crossbeam_channel::unbounded();
|
||||
|
||||
let mut hotwatch = Hotwatch::new()?;
|
||||
let config_path_cl = config_path.clone();
|
||||
|
||||
hotwatch.watch(config_path, move |event| match event.kind {
|
||||
EventKind::Modify(_) | EventKind::Remove(_) => match KomobarConfig::read(&config_path_cl) {
|
||||
Ok(updated) => {
|
||||
tracing::info!("configuration file updated: {}", config_path_cl.display());
|
||||
|
||||
if let Err(error) = tx_config.send(updated) {
|
||||
tracing::error!("could not send configuration update to gui: {error}")
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
})?;
|
||||
|
||||
tracing::info!("watching configuration file for changes");
|
||||
|
||||
eframe::run_native(
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
unsafe {
|
||||
let app = NSApplication::sharedApplication(MainThreadMarker::new_unchecked());
|
||||
app.setActivationPolicy(NSApplicationActivationPolicy::Accessory);
|
||||
}
|
||||
|
||||
if let Ok(handle) = cc.window_handle()
|
||||
&& let RawWindowHandle::AppKit(appkit_handle) = handle.as_raw() {
|
||||
// kCGBackstopMenuLevel = -20 (behind menu bar, at notch level)
|
||||
const K_CG_BACKSTOP_MENU_LEVEL: isize = -20;
|
||||
|
||||
unsafe {
|
||||
let ns_view: &NSView = appkit_handle.ns_view.cast().as_ref();
|
||||
if let Some(ns_window) = ns_view.window() {
|
||||
ns_window.setLevel(K_CG_BACKSTOP_MENU_LEVEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
ctx_repainter.request_repaint();
|
||||
});
|
||||
|
||||
let ctx_komorebi = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let subscriber_name = format!("komorebi-bar-{}", random_word::get(random_word::Lang::En));
|
||||
|
||||
let listener = komorebi_client::subscribe_with_options(&subscriber_name, SubscribeOptions {
|
||||
filter_state_changes: true,
|
||||
})
|
||||
.expect("could not subscribe to komorebi notifications");
|
||||
|
||||
tracing::info!("subscribed to komorebi notifications: \"{}\"", subscriber_name);
|
||||
|
||||
for client in listener.incoming() {
|
||||
match client {
|
||||
Ok(subscription) => {
|
||||
let mut buffer = Vec::new();
|
||||
let mut reader = BufReader::new(subscription);
|
||||
|
||||
// this is when we know a shutdown has been sent
|
||||
if matches!(reader.read_to_end(&mut buffer), Ok(0)) {
|
||||
tracing::info!("disconnected from komorebi");
|
||||
|
||||
// keep trying to reconnect to komorebi
|
||||
while komorebi_client::send_message(
|
||||
&SocketMessage::AddSubscriberSocket(subscriber_name.clone()),
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
tracing::info!("reconnected to komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Reconnect) {
|
||||
tracing::error!("could not send komorebi reconnect event to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
continue;
|
||||
}
|
||||
|
||||
match String::from_utf8(buffer) {
|
||||
Ok(notification_string) => {
|
||||
match serde_json::from_str::<komorebi_client::Notification>(
|
||||
¬ification_string,
|
||||
) {
|
||||
Ok(notification) => {
|
||||
tracing::debug!("received notification from komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Notification(notification)) {
|
||||
tracing::error!("could not send komorebi notification update to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("could not deserialize komorebi notification: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
"komorebi notification string was invalid utf8: {error}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("{error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Box::new(Komobar::new(cc, rx_gui, rx_config, config)))
|
||||
}),
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::Error::msg(error.to_string()))
|
||||
fn main() -> color_eyre::Result<()> {
|
||||
macos::main()
|
||||
}
|
||||
@@ -1,407 +0,0 @@
|
||||
use super::ImageIcon;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::CornerRadius;
|
||||
use eframe::egui::FontId;
|
||||
use eframe::egui::Frame;
|
||||
use eframe::egui::Image;
|
||||
use eframe::egui::Label;
|
||||
use eframe::egui::Margin;
|
||||
use eframe::egui::RichText;
|
||||
use eframe::egui::Sense;
|
||||
use eframe::egui::Stroke;
|
||||
use eframe::egui::StrokeKind;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::vec2;
|
||||
use komorebi_client::PathExt;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use tracing;
|
||||
|
||||
/// Minimum interval between consecutive application launches to prevent accidental spamming.
|
||||
const MIN_LAUNCH_INTERVAL: Duration = Duration::from_millis(800);
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Applications widget configuration
|
||||
pub struct ApplicationsConfig {
|
||||
/// Enables or disables the applications widget.
|
||||
pub enable: bool,
|
||||
/// Whether to show the launch command on hover (optional).
|
||||
/// Could be overridden per application. Defaults to `false` if not set.
|
||||
pub show_command_on_hover: Option<bool>,
|
||||
/// Horizontal spacing between application buttons.
|
||||
pub spacing: Option<f32>,
|
||||
/// Default display format for all applications (optional).
|
||||
/// Could be overridden per application. Defaults to `Icon`.
|
||||
pub display: Option<ApplicationsDisplayFormat>,
|
||||
/// List of configured applications to display.
|
||||
pub items: Vec<AppConfig>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Application button configuration
|
||||
pub struct AppConfig {
|
||||
/// Whether to enable this application button (optional).
|
||||
/// Inherits from the global `Applications` setting if omitted.
|
||||
pub enable: Option<bool>,
|
||||
/// Whether to show the launch command on hover (optional).
|
||||
/// Inherits from the global `Applications` setting if omitted.
|
||||
pub show_command_on_hover: Option<bool>,
|
||||
/// Display name of the application.
|
||||
pub name: String,
|
||||
/// Optional icon: a path to an image or a text-based glyph (e.g., from Nerd Fonts).
|
||||
/// If not set, and if the `command` is a path to an executable, an icon might be extracted from it.
|
||||
/// Note: glyphs require a compatible `font_family`.
|
||||
pub icon: Option<String>,
|
||||
/// Command to execute (e.g. path to the application or shell command).
|
||||
pub command: String,
|
||||
/// Display format for this application button (optional). Overrides global format if set.
|
||||
pub display: Option<ApplicationsDisplayFormat>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Applications widget display format
|
||||
pub enum ApplicationsDisplayFormat {
|
||||
/// Show only the application icon.
|
||||
#[default]
|
||||
Icon,
|
||||
/// Show only the application name as text.
|
||||
Text,
|
||||
/// Show both the application icon and name.
|
||||
IconAndText,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Applications {
|
||||
/// Whether the applications widget is enabled.
|
||||
pub enable: bool,
|
||||
/// Horizontal spacing between application buttons.
|
||||
pub spacing: Option<f32>,
|
||||
/// Applications to be rendered in the UI.
|
||||
pub items: Vec<App>,
|
||||
}
|
||||
|
||||
impl BarWidget for Applications {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) {
|
||||
if !self.enable {
|
||||
return;
|
||||
}
|
||||
|
||||
let icon_config = IconConfig {
|
||||
font_id: config.icon_font_id.clone(),
|
||||
size: config.icon_font_id.size,
|
||||
color: ctx.style().visuals.selection.stroke.color,
|
||||
};
|
||||
|
||||
if let Some(spacing) = self.spacing {
|
||||
ui.spacing_mut().item_spacing.x = spacing;
|
||||
}
|
||||
|
||||
config.apply_on_widget(false, ui, |ui| {
|
||||
for app in &mut self.items {
|
||||
app.render(ctx, ui, &icon_config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ApplicationsConfig> for Applications {
|
||||
fn from(applications_config: &ApplicationsConfig) -> Self {
|
||||
let items = applications_config
|
||||
.items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, config)| {
|
||||
let command = UserCommand::new(&config.command);
|
||||
|
||||
App {
|
||||
enable: config.enable.unwrap_or(applications_config.enable),
|
||||
#[allow(clippy::obfuscated_if_else)]
|
||||
name: config
|
||||
.name
|
||||
.is_empty()
|
||||
.then(|| format!("App {}", index + 1))
|
||||
.unwrap_or_else(|| config.name.clone()),
|
||||
icon: Icon::try_from_path(config.icon.as_deref())
|
||||
.or_else(|| Icon::try_from_command(&command)),
|
||||
command,
|
||||
display: config
|
||||
.display
|
||||
.or(applications_config.display)
|
||||
.unwrap_or_default(),
|
||||
show_command_on_hover: config
|
||||
.show_command_on_hover
|
||||
.or(applications_config.show_command_on_hover)
|
||||
.unwrap_or(false),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
enable: applications_config.enable,
|
||||
items,
|
||||
spacing: applications_config.spacing,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A single resolved application entry used at runtime.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct App {
|
||||
/// Whether this application is enabled.
|
||||
pub enable: bool,
|
||||
/// Display name of the application. Defaults to "App N" if not set.
|
||||
pub name: String,
|
||||
/// Icon to display for this application, if available.
|
||||
pub icon: Option<Icon>,
|
||||
/// Command to execute when the application is launched.
|
||||
pub command: UserCommand,
|
||||
/// Display format (icon, text, or both).
|
||||
pub display: ApplicationsDisplayFormat,
|
||||
/// Whether to show the launch command on hover.
|
||||
pub show_command_on_hover: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Renders the application button in the provided `Ui` context with a given icon size.
|
||||
#[inline]
|
||||
pub fn render(&mut self, ctx: &Context, ui: &mut Ui, icon_config: &IconConfig) {
|
||||
if self.enable
|
||||
&& SelectableFrame::new(false)
|
||||
.show(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing = Vec2::splat(4.0);
|
||||
|
||||
match self.display {
|
||||
ApplicationsDisplayFormat::Icon => self.draw_icon(ctx, ui, icon_config),
|
||||
ApplicationsDisplayFormat::Text => self.draw_name(ui),
|
||||
ApplicationsDisplayFormat::IconAndText => {
|
||||
self.draw_icon(ctx, ui, icon_config);
|
||||
self.draw_name(ui);
|
||||
}
|
||||
}
|
||||
|
||||
// Add hover text with command information
|
||||
let response = ui.response();
|
||||
if self.show_command_on_hover {
|
||||
response.on_hover_text(format!("Launch: {}", self.command.as_ref()));
|
||||
}
|
||||
})
|
||||
.clicked()
|
||||
{
|
||||
// Launch the application when clicked
|
||||
self.command.launch_if_ready();
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws the application's icon within the UI if available,
|
||||
/// or falls back to a default placeholder icon.
|
||||
#[inline]
|
||||
fn draw_icon(&self, ctx: &Context, ui: &mut Ui, icon_config: &IconConfig) {
|
||||
if let Some(icon) = &self.icon {
|
||||
icon.draw(ctx, ui, icon_config);
|
||||
} else {
|
||||
Icon::draw_fallback(ui, Vec2::splat(icon_config.size));
|
||||
}
|
||||
}
|
||||
|
||||
/// Displays the application's name as a non-selectable label within the UI.
|
||||
#[inline]
|
||||
fn draw_name(&self, ui: &mut Ui) {
|
||||
ui.add(Label::new(&self.name).selectable(false));
|
||||
}
|
||||
}
|
||||
|
||||
/// Holds image/text data to be used as an icon in the UI.
|
||||
/// This represents source icon data before rendering.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Icon {
|
||||
/// RGBA image used for rendering the icon.
|
||||
Image(ImageIcon),
|
||||
/// Text-based icon, e.g. from a font like Nerd Fonts.
|
||||
Text(String),
|
||||
}
|
||||
|
||||
impl Icon {
|
||||
/// Attempts to create an [`Icon`] from a string path or text glyph/glyphs.
|
||||
///
|
||||
/// - Environment variables in the path are resolved using [`PathExt::replace_env`].
|
||||
/// - Uses [`ImageIcon::try_load`] to load and cache the icon image based on the resolved path.
|
||||
/// - If the path is invalid but the string is non-empty, it is interpreted as a text-based icon and
|
||||
/// returned as [`Icon::Text`].
|
||||
/// - Returns `None` if the input is empty, `None`, or image loading fails.
|
||||
#[inline]
|
||||
pub fn try_from_path(icon: Option<&str>) -> Option<Self> {
|
||||
let icon = icon.map(str::trim)?;
|
||||
if icon.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let path = icon.replace_env();
|
||||
if !path.is_file() {
|
||||
return Some(Icon::Text(icon.to_owned()));
|
||||
}
|
||||
|
||||
let image_icon = ImageIcon::try_load(path.as_ref(), || match image::open(&path) {
|
||||
Ok(img) => Some(img),
|
||||
Err(err) => {
|
||||
tracing::error!("Failed to load icon from {:?}, error: {}", path, err);
|
||||
None
|
||||
}
|
||||
})?;
|
||||
|
||||
Some(Icon::Image(image_icon))
|
||||
}
|
||||
|
||||
/// Attempts to create an [`Icon`] by extracting an image from the executable path of a [`UserCommand`].
|
||||
///
|
||||
/// - Uses [`ImageIcon::try_load`] to load and cache the icon image based on the resolved executable path.
|
||||
/// - Returns [`Icon::Image`] if an icon is successfully extracted.
|
||||
/// - Returns `None` if the executable path is unavailable or icon extraction fails.
|
||||
#[inline]
|
||||
pub fn try_from_command(_command: &UserCommand) -> Option<Self> {
|
||||
// let path = command.get_executable()?;
|
||||
// let image_icon = ImageIcon::try_load(path.as_ref(), || {
|
||||
// let path_str = path.to_str()?;
|
||||
// windows_icons::get_icon_by_path(path_str)
|
||||
// .or_else(|| windows_icons_fallback::get_icon_by_path(path_str))
|
||||
// })?;
|
||||
// Some(Icon::Image(image_icon))
|
||||
None
|
||||
}
|
||||
|
||||
/// Renders the icon in the given [`Ui`] using the provided [`IconConfig`].
|
||||
#[inline]
|
||||
pub fn draw(&self, ctx: &Context, ui: &mut Ui, icon_config: &IconConfig) {
|
||||
match self {
|
||||
Icon::Image(image_icon) => {
|
||||
Frame::NONE
|
||||
.inner_margin(Margin::same(ui.style().spacing.button_padding.y as i8))
|
||||
.show(ui, |ui| {
|
||||
ui.add(
|
||||
Image::from_texture(&image_icon.texture(ctx))
|
||||
.maintain_aspect_ratio(true)
|
||||
.fit_to_exact_size(Vec2::splat(icon_config.size)),
|
||||
);
|
||||
});
|
||||
}
|
||||
Icon::Text(icon) => {
|
||||
let rich_text = RichText::new(icon)
|
||||
.font(icon_config.font_id.clone())
|
||||
.size(icon_config.size)
|
||||
.color(icon_config.color);
|
||||
ui.add(Label::new(rich_text).selectable(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws a fallback icon when the specified icon cannot be loaded.
|
||||
/// Displays a simple crossed-out rectangle as a placeholder.
|
||||
#[inline]
|
||||
pub fn draw_fallback(ui: &mut Ui, icon_size: Vec2) {
|
||||
let (response, painter) = ui.allocate_painter(icon_size, Sense::hover());
|
||||
let stroke = Stroke::new(1.0, ui.style().visuals.text_color());
|
||||
let mut rect = response.rect;
|
||||
let rounding = CornerRadius::same((rect.width() * 0.1) as u8);
|
||||
rect = rect.shrink(stroke.width);
|
||||
let c = rect.center();
|
||||
let r = rect.width() / 2.0;
|
||||
painter.rect_stroke(rect, rounding, stroke, StrokeKind::Outside);
|
||||
painter.line_segment([c - vec2(r, r), c + vec2(r, r)], stroke);
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration structure for icon rendering
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IconConfig {
|
||||
/// Font used for text-based icons
|
||||
pub font_id: FontId,
|
||||
/// Size of the icon
|
||||
pub size: f32,
|
||||
/// Color of the icon used for text-based icons
|
||||
pub color: Color32,
|
||||
}
|
||||
|
||||
/// A structure to manage command execution with cooldown prevention.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UserCommand {
|
||||
/// The command string to execute
|
||||
pub command: Arc<str>,
|
||||
/// Last time this command was executed (used for cooldown control)
|
||||
pub last_launch: Instant,
|
||||
}
|
||||
|
||||
impl AsRef<str> for UserCommand {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.command
|
||||
}
|
||||
}
|
||||
|
||||
impl UserCommand {
|
||||
/// Creates a new [`UserCommand`] with environment variables in the command path
|
||||
/// resolved using [`PathExt::replace_env`].
|
||||
#[inline]
|
||||
pub fn new(command: &str) -> Self {
|
||||
// Allow immediate launch by initializing last_launch in the past
|
||||
let last_launch = Instant::now() - 2 * MIN_LAUNCH_INTERVAL;
|
||||
|
||||
Self {
|
||||
command: Arc::from(command.replace_env().to_str().unwrap_or_default()),
|
||||
last_launch,
|
||||
}
|
||||
}
|
||||
|
||||
// /// Attempts to resolve the executable path from the command string.
|
||||
// ///
|
||||
// /// Resolution logic:
|
||||
// /// - Splits the command by ".exe" and checks if the first part is an existing file.
|
||||
// /// - If not, attempts to locate the binary using [`which`] on this name.
|
||||
// /// - If still unresolved, takes the first word (separated by whitespace) and attempts
|
||||
// /// to find it in the system `PATH` using [`which`].
|
||||
// ///
|
||||
// /// Returns `None` if no executable path can be determined.
|
||||
// #[inline]
|
||||
// pub fn get_executable(&self) -> Option<Cow<'_, Path>> {
|
||||
// if let Some(binary) = self.command.split(".exe").next().map(Path::new) {
|
||||
// if binary.is_file() {
|
||||
// return Some(Cow::Borrowed(binary));
|
||||
// } else if let Ok(binary) = which(binary) {
|
||||
// return Some(Cow::Owned(binary));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// which(self.command.split(' ').next()?).ok().map(Cow::Owned)
|
||||
// }
|
||||
|
||||
/// Attempts to launch the specified command in a separate thread if enough time has passed
|
||||
/// since the last launch. This prevents repeated launches from rapid consecutive clicks.
|
||||
///
|
||||
/// Errors during launch are logged using the `tracing` crate.
|
||||
pub fn launch_if_ready(&mut self) {
|
||||
let now = Instant::now();
|
||||
// Check if enough time has passed since the last launch
|
||||
if now.duration_since(self.last_launch) < MIN_LAUNCH_INTERVAL {
|
||||
return;
|
||||
}
|
||||
|
||||
self.last_launch = now;
|
||||
let command_string = self.command.clone();
|
||||
// Launch the application in a separate thread to avoid blocking the UI
|
||||
std::thread::spawn(move || {
|
||||
if let Err(e) = Command::new("cmd").args(["/C", &command_string]).spawn() {
|
||||
tracing::error!("Failed to launch command '{}': {}", command_string, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,329 +0,0 @@
|
||||
use crate::config::DisplayFormat;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::komorebi::KomorebiLayoutConfig;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::CornerRadius;
|
||||
use eframe::egui::FontId;
|
||||
use eframe::egui::Frame;
|
||||
use eframe::egui::Label;
|
||||
use eframe::egui::Sense;
|
||||
use eframe::egui::Stroke;
|
||||
use eframe::egui::StrokeKind;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::vec2;
|
||||
use komorebi_client::SocketMessage;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::de::Error;
|
||||
use serde_json::from_str;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Komorebi layout kind
|
||||
pub enum KomorebiLayout {
|
||||
/// Predefined layout
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Default"))]
|
||||
Default(komorebi_client::DefaultLayout),
|
||||
/// Monocle mode
|
||||
Monocle,
|
||||
/// Floating layer
|
||||
Floating,
|
||||
/// Paused
|
||||
Paused,
|
||||
/// Custom layout
|
||||
Custom,
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for KomorebiLayout {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s: String = String::deserialize(deserializer)?;
|
||||
|
||||
// Attempt to deserialize the string as a DefaultLayout
|
||||
if let Ok(default_layout) = from_str::<komorebi_client::DefaultLayout>(&format!("\"{s}\""))
|
||||
{
|
||||
return Ok(KomorebiLayout::Default(default_layout));
|
||||
}
|
||||
|
||||
// Handle other cases
|
||||
match s.as_str() {
|
||||
"Monocle" => Ok(KomorebiLayout::Monocle),
|
||||
"Floating" => Ok(KomorebiLayout::Floating),
|
||||
"Paused" => Ok(KomorebiLayout::Paused),
|
||||
"Custom" => Ok(KomorebiLayout::Custom),
|
||||
_ => Err(Error::custom(format!("Invalid layout: {s}"))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for KomorebiLayout {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
KomorebiLayout::Default(layout) => write!(f, "{layout}"),
|
||||
KomorebiLayout::Monocle => write!(f, "Monocle"),
|
||||
KomorebiLayout::Floating => write!(f, "Floating"),
|
||||
KomorebiLayout::Paused => write!(f, "Paused"),
|
||||
KomorebiLayout::Custom => write!(f, "Custom"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KomorebiLayout {
|
||||
fn is_default(&mut self) -> bool {
|
||||
matches!(self, KomorebiLayout::Default(_))
|
||||
}
|
||||
|
||||
fn on_click(
|
||||
&mut self,
|
||||
show_options: &bool,
|
||||
monitor_idx: usize,
|
||||
workspace_idx: Option<usize>,
|
||||
) -> bool {
|
||||
if self.is_default() {
|
||||
!show_options
|
||||
} else {
|
||||
self.on_click_option(monitor_idx, workspace_idx);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn on_click_option(&mut self, monitor_idx: usize, workspace_idx: Option<usize>) {
|
||||
match self {
|
||||
KomorebiLayout::Default(option) => {
|
||||
if let Some(ws_idx) = workspace_idx
|
||||
&& komorebi_client::send_message(&SocketMessage::WorkspaceLayout(
|
||||
monitor_idx,
|
||||
ws_idx,
|
||||
*option,
|
||||
))
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("could not send message to komorebi: WorkspaceLayout");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Monocle => {
|
||||
if komorebi_client::send_batch([
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleMonocle,
|
||||
])
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("could not send message to komorebi: ToggleMonocle");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Floating => {
|
||||
if komorebi_client::send_batch([
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleTiling,
|
||||
])
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("could not send message to komorebi: ToggleTiling");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Paused => {
|
||||
if komorebi_client::send_message(&SocketMessage::TogglePause).is_err() {
|
||||
tracing::error!("could not send message to komorebi: TogglePause");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Custom => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn show_icon(&mut self, is_selected: bool, font_id: FontId, ctx: &Context, ui: &mut Ui) {
|
||||
// paint custom icons for the layout
|
||||
let size = Vec2::splat(font_id.size);
|
||||
let (response, painter) = ui.allocate_painter(size, Sense::hover());
|
||||
let color = if is_selected {
|
||||
ctx.style().visuals.selection.stroke.color
|
||||
} else {
|
||||
ui.style().visuals.text_color()
|
||||
};
|
||||
let stroke = Stroke::new(1.0, color);
|
||||
let mut rect = response.rect;
|
||||
let rounding = CornerRadius::same((rect.width() * 0.1) as u8);
|
||||
rect = rect.shrink(stroke.width);
|
||||
let c = rect.center();
|
||||
let r = rect.width() / 2.0;
|
||||
painter.rect_stroke(rect, rounding, stroke, StrokeKind::Outside);
|
||||
|
||||
match self {
|
||||
KomorebiLayout::Default(layout) => match layout {
|
||||
komorebi_client::DefaultLayout::BSP => {
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c, c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c + vec2(r / 2.0, 0.0), c + vec2(r / 2.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::Columns => {
|
||||
painter.line_segment([c - vec2(r / 2.0, r), c + vec2(-r / 2.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(-r / 2.0, r), c + vec2(r / 2.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::Rows => {
|
||||
painter.line_segment([c - vec2(r, r / 2.0), c + vec2(r, -r / 2.0)], stroke);
|
||||
painter.line_segment([c - vec2(r, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c - vec2(r, -r / 2.0), c + vec2(r, r / 2.0)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::VerticalStack => {
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c, c + vec2(r, 0.0)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::RightMainVerticalStack => {
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(r, 0.0), c], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::HorizontalStack => {
|
||||
painter.line_segment([c - vec2(r, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c, c + vec2(0.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::UltrawideVerticalStack => {
|
||||
painter.line_segment([c - vec2(r / 2.0, r), c + vec2(-r / 2.0, r)], stroke);
|
||||
painter.line_segment([c + vec2(r / 2.0, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c - vec2(-r / 2.0, r), c + vec2(r / 2.0, r)], stroke);
|
||||
}
|
||||
komorebi_client::DefaultLayout::Grid => {
|
||||
painter.line_segment([c - vec2(r, 0.0), c + vec2(r, 0.0)], stroke);
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
}
|
||||
// TODO: @CtByte can you think of a nice icon to draw here?
|
||||
komorebi_client::DefaultLayout::Scrolling => {
|
||||
painter.line_segment([c - vec2(r / 2.0, r), c + vec2(-r / 2.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c - vec2(-r / 2.0, r), c + vec2(r / 2.0, r)], stroke);
|
||||
}
|
||||
},
|
||||
KomorebiLayout::Monocle => {}
|
||||
KomorebiLayout::Floating => {
|
||||
let mut rect_left = response.rect;
|
||||
rect_left.set_width(rect.width() * 0.5);
|
||||
rect_left.set_height(rect.height() * 0.5);
|
||||
let mut rect_right = rect_left;
|
||||
rect_left = rect_left.translate(Vec2::new(
|
||||
rect.width() * 0.1 + stroke.width,
|
||||
rect.width() * 0.1 + stroke.width,
|
||||
));
|
||||
rect_right = rect_right.translate(Vec2::new(
|
||||
rect.width() * 0.35 + stroke.width,
|
||||
rect.width() * 0.35 + stroke.width,
|
||||
));
|
||||
painter.rect_filled(rect_left, rounding, color);
|
||||
painter.rect_stroke(rect_right, rounding, stroke, StrokeKind::Outside);
|
||||
}
|
||||
KomorebiLayout::Paused => {
|
||||
let mut rect_left = response.rect;
|
||||
rect_left.set_width(rect.width() * 0.25);
|
||||
rect_left.set_height(rect.height() * 0.8);
|
||||
let mut rect_right = rect_left;
|
||||
rect_left = rect_left.translate(Vec2::new(
|
||||
rect.width() * 0.2 + stroke.width,
|
||||
rect.width() * 0.1 + stroke.width,
|
||||
));
|
||||
rect_right = rect_right.translate(Vec2::new(
|
||||
rect.width() * 0.55 + stroke.width,
|
||||
rect.width() * 0.1 + stroke.width,
|
||||
));
|
||||
painter.rect_filled(rect_left, rounding, color);
|
||||
painter.rect_filled(rect_right, rounding, color);
|
||||
}
|
||||
KomorebiLayout::Custom => {
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
painter.line_segment([c + vec2(0.0, r / 2.0), c + vec2(r, r / 2.0)], stroke);
|
||||
painter.line_segment([c - vec2(0.0, r / 3.0), c - vec2(r, r / 3.0)], stroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
render_config: &mut RenderConfig,
|
||||
layout_config: &KomorebiLayoutConfig,
|
||||
workspace_idx: Option<usize>,
|
||||
) {
|
||||
let monitor_idx = render_config.monitor_idx;
|
||||
let font_id = render_config.icon_font_id.clone();
|
||||
let mut show_options = RenderConfig::load_show_komorebi_layout_options();
|
||||
let format = layout_config.display.unwrap_or(DisplayFormat::IconAndText);
|
||||
|
||||
if !self.is_default() {
|
||||
show_options = false;
|
||||
}
|
||||
|
||||
render_config.apply_on_widget(false, ui, |ui| {
|
||||
let layout_frame = SelectableFrame::new(false)
|
||||
.show(ui, |ui| {
|
||||
if let DisplayFormat::Icon | DisplayFormat::IconAndText = format {
|
||||
self.show_icon(true, font_id.clone(), ctx, ui);
|
||||
}
|
||||
|
||||
if let DisplayFormat::Text | DisplayFormat::IconAndText = format {
|
||||
ui.add(Label::new(self.to_string()).selectable(false));
|
||||
}
|
||||
})
|
||||
.on_hover_text(self.to_string());
|
||||
|
||||
if layout_frame.clicked() {
|
||||
show_options = self.on_click(&show_options, monitor_idx, workspace_idx);
|
||||
}
|
||||
|
||||
if show_options && let Some(workspace_idx) = workspace_idx {
|
||||
Frame::NONE.show(ui, |ui| {
|
||||
ui.add(
|
||||
Label::new(egui_phosphor::regular::ARROW_FAT_LINES_RIGHT.to_string())
|
||||
.selectable(false),
|
||||
);
|
||||
|
||||
let mut layout_options = layout_config.options.clone().unwrap_or(vec![
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::BSP),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::Columns),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::Rows),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::VerticalStack),
|
||||
KomorebiLayout::Default(
|
||||
komorebi_client::DefaultLayout::RightMainVerticalStack,
|
||||
),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::HorizontalStack),
|
||||
KomorebiLayout::Default(
|
||||
komorebi_client::DefaultLayout::UltrawideVerticalStack,
|
||||
),
|
||||
KomorebiLayout::Default(komorebi_client::DefaultLayout::Grid),
|
||||
//KomorebiLayout::Custom,
|
||||
KomorebiLayout::Monocle,
|
||||
KomorebiLayout::Floating,
|
||||
KomorebiLayout::Paused,
|
||||
]);
|
||||
|
||||
for layout_option in &mut layout_options {
|
||||
let is_selected = self == layout_option;
|
||||
|
||||
if SelectableFrame::new(is_selected)
|
||||
.show(ui, |ui| {
|
||||
layout_option.show_icon(is_selected, font_id.clone(), ctx, ui)
|
||||
})
|
||||
.on_hover_text(match layout_option {
|
||||
KomorebiLayout::Default(layout) => layout.to_string(),
|
||||
KomorebiLayout::Monocle => "Toggle monocle".to_string(),
|
||||
KomorebiLayout::Floating => "Toggle tiling".to_string(),
|
||||
KomorebiLayout::Paused => "Toggle pause".to_string(),
|
||||
KomorebiLayout::Custom => "Custom".to_string(),
|
||||
})
|
||||
.clicked()
|
||||
{
|
||||
layout_option.on_click_option(monitor_idx, Some(workspace_idx));
|
||||
show_options = false;
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
RenderConfig::store_show_komorebi_layout_options(show_options);
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
use eframe::egui::ColorImage;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::TextureHandle;
|
||||
use eframe::egui::TextureOptions;
|
||||
use image::RgbaImage;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::RwLock;
|
||||
|
||||
pub mod applications;
|
||||
pub use komorebi_bar_core::widgets::battery;
|
||||
pub use komorebi_bar_core::widgets::cpu;
|
||||
pub use komorebi_bar_core::widgets::date;
|
||||
pub mod komorebi;
|
||||
mod komorebi_layout;
|
||||
pub use komorebi_bar_core::widgets::memory;
|
||||
pub mod network;
|
||||
pub mod storage;
|
||||
pub mod time;
|
||||
pub use komorebi_bar_core::widgets::update;
|
||||
pub mod widget;
|
||||
|
||||
/// Global cache for icon images and their associated GPU textures.
|
||||
pub static ICONS_CACHE: IconsCache = IconsCache::new();
|
||||
|
||||
/// In-memory cache for icon images and their associated GPU textures.
|
||||
///
|
||||
/// Stores raw [`ColorImage`]s and [`TextureHandle`]s keyed by [`ImageIconId`].
|
||||
/// Texture entries are context-dependent and automatically invalidated when the [`Context`] changes.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub struct IconsCache {
|
||||
textures: LazyLock<RwLock<(Option<Context>, HashMap<ImageIconId, TextureHandle>)>>,
|
||||
images: LazyLock<RwLock<HashMap<ImageIconId, Arc<ColorImage>>>>,
|
||||
}
|
||||
|
||||
impl IconsCache {
|
||||
/// Creates a new empty IconsCache instance.
|
||||
#[inline]
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
textures: LazyLock::new(|| RwLock::new((None, HashMap::new()))),
|
||||
images: LazyLock::new(|| RwLock::new(HashMap::new())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves or creates a texture handle for the given icon ID and image.
|
||||
///
|
||||
/// If a texture for the given ID already exists for the current [`Context`], it is reused.
|
||||
/// Otherwise, a new texture is created, inserted into the cache, and returned.
|
||||
/// The cache is reset if the [`Context`] has changed.
|
||||
#[inline]
|
||||
pub fn texture(&self, ctx: &Context, id: &ImageIconId, img: &Arc<ColorImage>) -> TextureHandle {
|
||||
if let Some(texture) = self.get_texture(ctx, id) {
|
||||
return texture;
|
||||
}
|
||||
let texture_handle = ctx.load_texture("icon", img.clone(), TextureOptions::default());
|
||||
self.insert_texture(ctx, id.clone(), texture_handle.clone());
|
||||
texture_handle
|
||||
}
|
||||
|
||||
/// Returns the cached texture for the given icon ID if it exists and matches the current [`Context`].
|
||||
pub fn get_texture(&self, ctx: &Context, id: &ImageIconId) -> Option<TextureHandle> {
|
||||
let textures_lock = self.textures.read().unwrap();
|
||||
if textures_lock.0.as_ref() == Some(ctx) {
|
||||
return textures_lock.1.get(id).cloned();
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Inserts a texture handle, resetting the cache if the [`Context`] has changed.
|
||||
pub fn insert_texture(&self, ctx: &Context, id: ImageIconId, texture: TextureHandle) {
|
||||
let mut textures_lock = self.textures.write().unwrap();
|
||||
|
||||
if textures_lock.0.as_ref() != Some(ctx) {
|
||||
textures_lock.0 = Some(ctx.clone());
|
||||
textures_lock.1.clear();
|
||||
}
|
||||
|
||||
textures_lock.1.insert(id, texture);
|
||||
}
|
||||
|
||||
/// Returns the cached image for the given icon ID, if available.
|
||||
pub fn get_image(&self, id: &ImageIconId) -> Option<Arc<ColorImage>> {
|
||||
self.images.read().unwrap().get(id).cloned()
|
||||
}
|
||||
|
||||
/// Caches a raw [`ColorImage`] associated with the given icon ID.
|
||||
pub fn insert_image(&self, id: ImageIconId, image: Arc<ColorImage>) {
|
||||
self.images.write().unwrap().insert(id, image);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn rgba_to_color_image(rgba_image: &RgbaImage) -> ColorImage {
|
||||
let size = [rgba_image.width() as usize, rgba_image.height() as usize];
|
||||
let pixels = rgba_image.as_flat_samples();
|
||||
ColorImage::from_rgba_unmultiplied(size, pixels.as_slice())
|
||||
}
|
||||
|
||||
/// Represents an image-based icon with a unique ID and pixel data.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ImageIcon {
|
||||
/// Unique identifier for the image icon, used for texture caching.
|
||||
pub id: ImageIconId,
|
||||
/// Shared pixel data of the icon in `ColorImage` format.
|
||||
pub image: Arc<ColorImage>,
|
||||
}
|
||||
|
||||
impl ImageIcon {
|
||||
/// Creates a new [`ImageIcon`] from the given ID and image data.
|
||||
#[inline]
|
||||
pub fn new(id: ImageIconId, image: Arc<ColorImage>) -> Self {
|
||||
Self { id, image }
|
||||
}
|
||||
|
||||
/// Loads an [`ImageIcon`] from [`ICONS_CACHE`] or calls `loader` if not cached.
|
||||
/// The loaded image is converted to a [`ColorImage`], cached, and returned.
|
||||
#[inline]
|
||||
pub fn try_load<F, I>(id: impl Into<ImageIconId>, loader: F) -> Option<Self>
|
||||
where
|
||||
F: FnOnce() -> Option<I>,
|
||||
I: Into<RgbaImage>,
|
||||
{
|
||||
let id = id.into();
|
||||
let image = ICONS_CACHE.get_image(&id).or_else(|| {
|
||||
let img = loader()?;
|
||||
let img = Arc::new(rgba_to_color_image(&img.into()));
|
||||
ICONS_CACHE.insert_image(id.clone(), img.clone());
|
||||
Some(img)
|
||||
})?;
|
||||
|
||||
Some(ImageIcon::new(id, image))
|
||||
}
|
||||
|
||||
/// Returns a texture handle for the icon, using the given [`Context`].
|
||||
///
|
||||
/// If the texture is already cached in [`ICONS_CACHE`], it is reused.
|
||||
/// Otherwise, a new texture is created from the [`ColorImage`] and cached.
|
||||
#[inline]
|
||||
pub fn texture(&self, ctx: &Context) -> TextureHandle {
|
||||
ICONS_CACHE.texture(ctx, &self.id, &self.image)
|
||||
}
|
||||
}
|
||||
|
||||
/// Unique identifier for an image-based icon.
|
||||
///
|
||||
/// Used to distinguish cached images and textures by either a file path
|
||||
/// or a Windows window handle.
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum ImageIconId {
|
||||
/// Identifier based on a file system path.
|
||||
Path(Arc<Path>),
|
||||
/// Window ID
|
||||
WindowId(u32),
|
||||
}
|
||||
|
||||
impl From<&Path> for ImageIconId {
|
||||
#[inline]
|
||||
fn from(value: &Path) -> Self {
|
||||
Self::Path(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for ImageIconId {
|
||||
#[inline]
|
||||
fn from(value: u32) -> Self {
|
||||
Self::WindowId(value)
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::Label;
|
||||
use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Disks;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Storage widget configuration
|
||||
pub struct StorageConfig {
|
||||
/// Enable the Storage widget
|
||||
pub enable: bool,
|
||||
/// Data refresh interval in seconds
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
|
||||
pub data_refresh_interval: Option<u64>,
|
||||
/// Display label prefix
|
||||
pub label_prefix: Option<LabelPrefix>,
|
||||
/// Show disks that are read only
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = false)))]
|
||||
pub show_read_only_disks: Option<bool>,
|
||||
/// Show removable disks
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = true)))]
|
||||
pub show_removable_disks: Option<bool>,
|
||||
/// Storage display name
|
||||
pub storage_display_name: Option<StorageDisplayName>,
|
||||
/// Select when the current percentage is over this value [[1-100]]
|
||||
pub auto_select_over: Option<u8>,
|
||||
/// Hide when the current percentage is under this value [[1-100]]
|
||||
pub auto_hide_under: Option<u8>,
|
||||
}
|
||||
|
||||
impl From<StorageConfig> for Storage {
|
||||
fn from(value: StorageConfig) -> Self {
|
||||
Self {
|
||||
enable: value.enable,
|
||||
disks: Disks::new_with_refreshed_list(),
|
||||
data_refresh_interval: value.data_refresh_interval.unwrap_or(10),
|
||||
label_prefix: value.label_prefix.unwrap_or(LabelPrefix::IconAndText),
|
||||
show_read_only_disks: value.show_read_only_disks.unwrap_or(false),
|
||||
show_removable_disks: value.show_removable_disks.unwrap_or(true),
|
||||
storage_display_name: value
|
||||
.storage_display_name
|
||||
.unwrap_or(StorageDisplayName::Mount),
|
||||
auto_select_over: value.auto_select_over.map(|o| o.clamp(1, 100)),
|
||||
auto_hide_under: value.auto_hide_under.map(|o| o.clamp(1, 100)),
|
||||
last_updated: Instant::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub enum StorageDisplayName {
|
||||
/// Display label as mount point eg. /
|
||||
Mount,
|
||||
/// Display label as name eg. Macintosh HD
|
||||
Name,
|
||||
/// Display label as mount then name eg. / Macintosh HD
|
||||
MountAndName,
|
||||
/// Display label as name then mount eg. Macintosh HD /
|
||||
NameAndMount,
|
||||
}
|
||||
|
||||
struct StorageDisk {
|
||||
label: String,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
pub struct Storage {
|
||||
pub enable: bool,
|
||||
disks: Disks,
|
||||
data_refresh_interval: u64,
|
||||
label_prefix: LabelPrefix,
|
||||
show_read_only_disks: bool,
|
||||
show_removable_disks: bool,
|
||||
storage_display_name: StorageDisplayName,
|
||||
auto_select_over: Option<u8>,
|
||||
auto_hide_under: Option<u8>,
|
||||
last_updated: Instant,
|
||||
}
|
||||
|
||||
impl Storage {
|
||||
fn output(&mut self) -> Vec<StorageDisk> {
|
||||
let now = Instant::now();
|
||||
if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) {
|
||||
self.disks.refresh(true);
|
||||
self.last_updated = now;
|
||||
}
|
||||
|
||||
let mut disks = vec![];
|
||||
|
||||
for disk in &self.disks {
|
||||
if disk.is_read_only() && !self.show_read_only_disks {
|
||||
continue;
|
||||
}
|
||||
if disk.is_removable() && !self.show_removable_disks {
|
||||
continue;
|
||||
}
|
||||
let mount = disk.mount_point();
|
||||
let name = disk.name();
|
||||
let display_name = match self.storage_display_name {
|
||||
StorageDisplayName::Mount => mount.to_string_lossy(),
|
||||
StorageDisplayName::Name => name.to_string_lossy(),
|
||||
StorageDisplayName::MountAndName => {
|
||||
mount.to_string_lossy() + name.to_string_lossy()
|
||||
}
|
||||
StorageDisplayName::NameAndMount => {
|
||||
name.to_string_lossy() + mount.to_string_lossy()
|
||||
}
|
||||
};
|
||||
let total = disk.total_space();
|
||||
let available = disk.available_space();
|
||||
let used = total - available;
|
||||
let percentage = ((used * 100) / total) as u8;
|
||||
|
||||
let hide = self.auto_hide_under.is_some_and(|u| percentage <= u);
|
||||
|
||||
if !hide {
|
||||
let selected = self.auto_select_over.is_some_and(|o| percentage >= o);
|
||||
|
||||
disks.push(StorageDisk {
|
||||
label: match self.label_prefix {
|
||||
LabelPrefix::Text | LabelPrefix::IconAndText => {
|
||||
format!("{} {}%", display_name, percentage)
|
||||
}
|
||||
LabelPrefix::None | LabelPrefix::Icon => format!("{percentage}%"),
|
||||
},
|
||||
selected,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
disks.sort_by(|a, b| a.label.cmp(&b.label));
|
||||
|
||||
disks
|
||||
}
|
||||
}
|
||||
|
||||
impl BarWidget for Storage {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) {
|
||||
if self.enable {
|
||||
let mut output = self.output();
|
||||
let is_reversed = matches!(config.alignment, Some(Alignment::Right));
|
||||
|
||||
if is_reversed {
|
||||
output.reverse();
|
||||
}
|
||||
|
||||
for output in output {
|
||||
let auto_text_color = config.auto_select_text.filter(|_| output.selected);
|
||||
|
||||
let mut layout_job = LayoutJob::simple(
|
||||
match self.label_prefix {
|
||||
LabelPrefix::Icon | LabelPrefix::IconAndText => {
|
||||
egui_phosphor::regular::HARD_DRIVES.to_string()
|
||||
}
|
||||
LabelPrefix::None | LabelPrefix::Text => String::new(),
|
||||
},
|
||||
config.icon_font_id.clone(),
|
||||
auto_text_color.unwrap_or(ctx.style().visuals.selection.stroke.color),
|
||||
100.0,
|
||||
);
|
||||
|
||||
layout_job.append(
|
||||
&output.label,
|
||||
10.0,
|
||||
TextFormat {
|
||||
font_id: config.text_font_id.clone(),
|
||||
color: auto_text_color.unwrap_or(ctx.style().visuals.text_color()),
|
||||
valign: Align::Center,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
let auto_focus_fill = config.auto_select_fill;
|
||||
|
||||
config.apply_on_widget(false, ui, |ui| {
|
||||
if SelectableFrame::new_auto(output.selected, auto_focus_fill)
|
||||
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
|
||||
.clicked()
|
||||
{
|
||||
let parts: Vec<&str> = output.label.split(' ').collect();
|
||||
let path = parts[..parts.len() - 1].join(" ");
|
||||
|
||||
if let Err(error) = Command::new("open").args([path]).spawn() {
|
||||
eprintln!("{error}")
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,542 +0,0 @@
|
||||
use crate::bar::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
use chrono::Local;
|
||||
use chrono::NaiveTime;
|
||||
use chrono_tz::Tz;
|
||||
use eframe::egui::Align;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::CornerRadius;
|
||||
use eframe::egui::Label;
|
||||
use eframe::egui::Sense;
|
||||
use eframe::egui::Stroke;
|
||||
use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use eframe::epaint::StrokeKind;
|
||||
use lazy_static::lazy_static;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
lazy_static! {
|
||||
static ref TIME_RANGES: Vec<(&'static str, NaiveTime)> = {
|
||||
vec![
|
||||
(
|
||||
egui_phosphor::regular::MOON,
|
||||
NaiveTime::from_hms_opt(0, 0, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::ALARM,
|
||||
NaiveTime::from_hms_opt(6, 0, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::BREAD,
|
||||
NaiveTime::from_hms_opt(6, 1, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::BARBELL,
|
||||
NaiveTime::from_hms_opt(6, 30, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::COFFEE,
|
||||
NaiveTime::from_hms_opt(8, 0, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::CLOCK,
|
||||
NaiveTime::from_hms_opt(8, 30, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::HAMBURGER,
|
||||
NaiveTime::from_hms_opt(12, 0, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::CLOCK_AFTERNOON,
|
||||
NaiveTime::from_hms_opt(12, 30, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::FORK_KNIFE,
|
||||
NaiveTime::from_hms_opt(18, 0, 0).expect("invalid"),
|
||||
),
|
||||
(
|
||||
egui_phosphor::regular::MOON_STARS,
|
||||
NaiveTime::from_hms_opt(18, 30, 0).expect("invalid"),
|
||||
),
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Time widget configuration
|
||||
pub struct TimeConfig {
|
||||
/// Enable the Time widget
|
||||
pub enable: bool,
|
||||
/// Set the Time format
|
||||
pub format: TimeFormat,
|
||||
/// Display label prefix
|
||||
pub label_prefix: Option<LabelPrefix>,
|
||||
/// TimeZone (https://docs.rs/chrono-tz/latest/chrono_tz/enum.Tz.html)
|
||||
///
|
||||
/// Use a custom format to display additional information, i.e.:
|
||||
/// ```json
|
||||
/// {
|
||||
/// "Time": {
|
||||
/// "enable": true,
|
||||
/// "format": { "Custom": "%T %Z (Tokyo)" },
|
||||
/// "timezone": "Asia/Tokyo"
|
||||
/// }
|
||||
///}
|
||||
/// ```
|
||||
pub timezone: Option<String>,
|
||||
/// Change the icon depending on the time. The default icon is used between 8:30 and 12:00
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = false)))]
|
||||
pub changing_icon: Option<bool>,
|
||||
}
|
||||
|
||||
impl From<TimeConfig> for Time {
|
||||
fn from(value: TimeConfig) -> Self {
|
||||
// using 1 second made the widget look "less accurate" and lagging (especially having multiple with seconds).
|
||||
// This is still better than getting an update every frame
|
||||
let data_refresh_interval = 500;
|
||||
|
||||
Self {
|
||||
enable: value.enable,
|
||||
format: value.format,
|
||||
label_prefix: value.label_prefix.unwrap_or(LabelPrefix::Icon),
|
||||
timezone: value.timezone,
|
||||
changing_icon: value.changing_icon.unwrap_or_default(),
|
||||
data_refresh_interval_millis: data_refresh_interval,
|
||||
last_state: TimeOutput::new(),
|
||||
last_updated: Instant::now()
|
||||
.checked_sub(Duration::from_millis(data_refresh_interval))
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Time format
|
||||
pub enum TimeFormat {
|
||||
/// Twelve-hour format (with seconds)
|
||||
TwelveHour,
|
||||
/// Twelve-hour format (without seconds)
|
||||
TwelveHourWithoutSeconds,
|
||||
/// Twenty-four-hour format (with seconds)
|
||||
TwentyFourHour,
|
||||
/// Twenty-four-hour format (without seconds)
|
||||
TwentyFourHourWithoutSeconds,
|
||||
/// Twenty-four-hour format displayed as a binary clock with circles (with seconds) (https://en.wikipedia.org/wiki/Binary_clock)
|
||||
BinaryCircle,
|
||||
/// Twenty-four-hour format displayed as a binary clock with rectangles (with seconds) (https://en.wikipedia.org/wiki/Binary_clock)
|
||||
BinaryRectangle,
|
||||
/// Custom format (https://docs.rs/chrono/latest/chrono/format/strftime/index.html)
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "Default"))]
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
impl TimeFormat {
|
||||
pub fn toggle(&mut self) {
|
||||
match self {
|
||||
TimeFormat::TwelveHour => *self = TimeFormat::TwelveHourWithoutSeconds,
|
||||
TimeFormat::TwelveHourWithoutSeconds => *self = TimeFormat::TwentyFourHour,
|
||||
TimeFormat::TwentyFourHour => *self = TimeFormat::TwentyFourHourWithoutSeconds,
|
||||
TimeFormat::TwentyFourHourWithoutSeconds => *self = TimeFormat::BinaryCircle,
|
||||
TimeFormat::BinaryCircle => *self = TimeFormat::BinaryRectangle,
|
||||
TimeFormat::BinaryRectangle => *self = TimeFormat::TwelveHour,
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
fn fmt_string(&self) -> String {
|
||||
match self {
|
||||
TimeFormat::TwelveHour => String::from("%l:%M:%S %p"),
|
||||
TimeFormat::TwelveHourWithoutSeconds => String::from("%l:%M %p"),
|
||||
TimeFormat::TwentyFourHour => String::from("%T"),
|
||||
TimeFormat::TwentyFourHourWithoutSeconds => String::from("%H:%M"),
|
||||
TimeFormat::BinaryCircle => String::from("c%T"),
|
||||
TimeFormat::BinaryRectangle => String::from("r%T"),
|
||||
TimeFormat::Custom(format) => format.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct TimeOutput {
|
||||
label: String,
|
||||
icon: String,
|
||||
}
|
||||
|
||||
impl TimeOutput {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
label: String::new(),
|
||||
icon: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Time {
|
||||
pub enable: bool,
|
||||
pub format: TimeFormat,
|
||||
label_prefix: LabelPrefix,
|
||||
timezone: Option<String>,
|
||||
changing_icon: bool,
|
||||
data_refresh_interval_millis: u64,
|
||||
last_state: TimeOutput,
|
||||
last_updated: Instant,
|
||||
}
|
||||
|
||||
impl Time {
|
||||
fn output(&mut self) -> TimeOutput {
|
||||
let mut output = self.last_state.clone();
|
||||
let now = Instant::now();
|
||||
|
||||
if now.duration_since(self.last_updated)
|
||||
> Duration::from_millis(self.data_refresh_interval_millis)
|
||||
{
|
||||
let (formatted, current_time) = match &self.timezone {
|
||||
Some(timezone) => match timezone.parse::<Tz>() {
|
||||
Ok(tz) => {
|
||||
let dt = Local::now().with_timezone(&tz);
|
||||
(
|
||||
dt.format(&self.format.fmt_string())
|
||||
.to_string()
|
||||
.trim()
|
||||
.to_string(),
|
||||
Some(dt.time()),
|
||||
)
|
||||
}
|
||||
Err(_) => (format!("Invalid timezone: {timezone:?}"), None),
|
||||
},
|
||||
None => {
|
||||
let dt = Local::now();
|
||||
(
|
||||
dt.format(&self.format.fmt_string())
|
||||
.to_string()
|
||||
.trim()
|
||||
.to_string(),
|
||||
Some(dt.time()),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
if current_time.is_none() {
|
||||
return TimeOutput {
|
||||
label: formatted,
|
||||
icon: egui_phosphor::regular::WARNING_CIRCLE.to_string(),
|
||||
};
|
||||
}
|
||||
|
||||
let current_range = match &self.changing_icon {
|
||||
true => TIME_RANGES
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|&(_, start)| current_time.unwrap() > *start)
|
||||
.cloned(),
|
||||
false => None,
|
||||
}
|
||||
.unwrap_or((egui_phosphor::regular::CLOCK, NaiveTime::default()));
|
||||
|
||||
output = TimeOutput {
|
||||
label: formatted,
|
||||
icon: current_range.0.to_string(),
|
||||
};
|
||||
|
||||
self.last_state.clone_from(&output);
|
||||
self.last_updated = now;
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
fn paint_binary_circle(
|
||||
&mut self,
|
||||
size: f32,
|
||||
number: u32,
|
||||
max_power: usize,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
let full_height = size;
|
||||
let height = full_height / 4.0;
|
||||
let width = height;
|
||||
let offset = height / 2.0 - height / 8.0;
|
||||
|
||||
let (response, painter) =
|
||||
ui.allocate_painter(Vec2::new(width, full_height + offset * 2.0), Sense::hover());
|
||||
let color = ctx.style().visuals.text_color();
|
||||
|
||||
let c = response.rect.center();
|
||||
let r = height / 2.0 - 0.5;
|
||||
|
||||
if number == 1 || number == 3 || number == 5 || number == 7 || number == 9 {
|
||||
painter.circle_filled(c + Vec2::new(0.0, height * 1.50 + offset), r, color);
|
||||
} else {
|
||||
painter.circle_filled(c + Vec2::new(0.0, height * 1.50 + offset), r / 2.5, color);
|
||||
}
|
||||
|
||||
if number == 2 || number == 3 || number == 6 || number == 7 {
|
||||
painter.circle_filled(c + Vec2::new(0.0, height * 0.50 + offset), r, color);
|
||||
} else {
|
||||
painter.circle_filled(c + Vec2::new(0.0, height * 0.50 + offset), r / 2.5, color);
|
||||
}
|
||||
|
||||
if number == 4 || number == 5 || number == 6 || number == 7 {
|
||||
painter.circle_filled(c + Vec2::new(0.0, -height * 0.50 + offset), r, color);
|
||||
} else if max_power > 2 {
|
||||
painter.circle_filled(c + Vec2::new(0.0, -height * 0.50 + offset), r / 2.5, color);
|
||||
}
|
||||
|
||||
if number == 8 || number == 9 {
|
||||
painter.circle_filled(c + Vec2::new(0.0, -height * 1.50 + offset), r, color);
|
||||
} else if max_power > 3 {
|
||||
painter.circle_filled(c + Vec2::new(0.0, -height * 1.50 + offset), r / 2.5, color);
|
||||
}
|
||||
}
|
||||
|
||||
fn paint_binary_rect(
|
||||
&mut self,
|
||||
size: f32,
|
||||
number: u32,
|
||||
max_power: usize,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
let full_height = size;
|
||||
let height = full_height / 4.0;
|
||||
let width = height * 1.5;
|
||||
let offset = height / 2.0 - height / 8.0;
|
||||
|
||||
let (response, painter) =
|
||||
ui.allocate_painter(Vec2::new(width, full_height + offset * 2.0), Sense::hover());
|
||||
let color = ctx.style().visuals.text_color();
|
||||
let stroke = Stroke::new(1.0, color);
|
||||
|
||||
let round_all = CornerRadius::same((response.rect.width() * 0.1) as u8);
|
||||
let round_top = CornerRadius {
|
||||
nw: round_all.nw,
|
||||
ne: round_all.ne,
|
||||
..Default::default()
|
||||
};
|
||||
let round_none = CornerRadius::ZERO;
|
||||
let round_bottom = CornerRadius {
|
||||
sw: round_all.nw,
|
||||
se: round_all.ne,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if max_power == 2 {
|
||||
let mut rect = response
|
||||
.rect
|
||||
.shrink2(Vec2::new(stroke.width, stroke.width + offset));
|
||||
rect.set_height(rect.height() - height * 2.0);
|
||||
rect = rect.translate(Vec2::new(0.0, height * 2.0 + offset));
|
||||
painter.rect_stroke(rect, round_all, stroke, StrokeKind::Outside);
|
||||
} else if max_power == 3 {
|
||||
let mut rect = response
|
||||
.rect
|
||||
.shrink2(Vec2::new(stroke.width, stroke.width + offset));
|
||||
rect.set_height(rect.height() - height);
|
||||
rect = rect.translate(Vec2::new(0.0, height + offset));
|
||||
painter.rect_stroke(rect, round_all, stroke, StrokeKind::Outside);
|
||||
} else {
|
||||
let mut rect = response
|
||||
.rect
|
||||
.shrink2(Vec2::new(stroke.width, stroke.width + offset));
|
||||
rect = rect.translate(Vec2::new(0.0, 0.0 + offset));
|
||||
painter.rect_stroke(rect, round_all, stroke, StrokeKind::Outside);
|
||||
}
|
||||
|
||||
let mut rect_bin = response.rect;
|
||||
rect_bin.set_width(width);
|
||||
|
||||
if number == 1 || number == 5 || number == 9 {
|
||||
rect_bin.set_height(height);
|
||||
painter.rect_filled(
|
||||
rect_bin.translate(Vec2::new(stroke.width, height * 3.0 + offset * 2.0)),
|
||||
round_bottom,
|
||||
color,
|
||||
);
|
||||
}
|
||||
if number == 2 {
|
||||
rect_bin.set_height(height);
|
||||
painter.rect_filled(
|
||||
rect_bin.translate(Vec2::new(stroke.width, height * 2.0 + offset * 2.0)),
|
||||
if max_power == 2 {
|
||||
round_top
|
||||
} else {
|
||||
round_none
|
||||
},
|
||||
color,
|
||||
);
|
||||
}
|
||||
if number == 3 {
|
||||
rect_bin.set_height(height * 2.0);
|
||||
painter.rect_filled(
|
||||
rect_bin.translate(Vec2::new(stroke.width, height * 2.0 + offset * 2.0)),
|
||||
round_bottom,
|
||||
color,
|
||||
);
|
||||
}
|
||||
if number == 4 || number == 5 {
|
||||
rect_bin.set_height(height);
|
||||
painter.rect_filled(
|
||||
rect_bin.translate(Vec2::new(stroke.width, height * 1.0 + offset * 2.0)),
|
||||
if max_power == 3 {
|
||||
round_top
|
||||
} else {
|
||||
round_none
|
||||
},
|
||||
color,
|
||||
);
|
||||
}
|
||||
if number == 6 {
|
||||
rect_bin.set_height(height * 2.0);
|
||||
painter.rect_filled(
|
||||
rect_bin.translate(Vec2::new(stroke.width, height * 1.0 + offset * 2.0)),
|
||||
if max_power == 3 {
|
||||
round_top
|
||||
} else {
|
||||
round_none
|
||||
},
|
||||
color,
|
||||
);
|
||||
}
|
||||
if number == 7 {
|
||||
rect_bin.set_height(height * 3.0);
|
||||
painter.rect_filled(
|
||||
rect_bin.translate(Vec2::new(stroke.width, height + offset * 2.0)),
|
||||
if max_power == 3 {
|
||||
round_all
|
||||
} else {
|
||||
round_bottom
|
||||
},
|
||||
color,
|
||||
);
|
||||
}
|
||||
if number == 8 || number == 9 {
|
||||
rect_bin.set_height(height);
|
||||
painter.rect_filled(
|
||||
rect_bin.translate(Vec2::new(stroke.width, 0.0 + offset * 2.0)),
|
||||
round_top,
|
||||
color,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BarWidget for Time {
|
||||
fn render(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) {
|
||||
if self.enable {
|
||||
let mut output = self.output();
|
||||
if !output.label.is_empty() {
|
||||
let use_binary_circle = output.label.starts_with('c');
|
||||
let use_binary_rectangle = output.label.starts_with('r');
|
||||
|
||||
let mut layout_job = LayoutJob::simple(
|
||||
match self.label_prefix {
|
||||
LabelPrefix::Icon | LabelPrefix::IconAndText => output.icon,
|
||||
LabelPrefix::None | LabelPrefix::Text => String::new(),
|
||||
},
|
||||
config.icon_font_id.clone(),
|
||||
ctx.style().visuals.selection.stroke.color,
|
||||
100.0,
|
||||
);
|
||||
|
||||
if let LabelPrefix::Text | LabelPrefix::IconAndText = self.label_prefix {
|
||||
output.label.insert_str(0, "TIME: ");
|
||||
}
|
||||
|
||||
if !use_binary_circle && !use_binary_rectangle {
|
||||
layout_job.append(
|
||||
&output.label,
|
||||
10.0,
|
||||
TextFormat {
|
||||
font_id: config.text_font_id.clone(),
|
||||
color: ctx.style().visuals.text_color(),
|
||||
valign: Align::Center,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let font_id = config.icon_font_id.clone();
|
||||
let is_reversed = matches!(config.alignment, Some(Alignment::Right));
|
||||
|
||||
config.apply_on_widget(false, ui, |ui| {
|
||||
if SelectableFrame::new(false)
|
||||
.show(ui, |ui| {
|
||||
if !is_reversed {
|
||||
ui.add(Label::new(layout_job.clone()).selectable(false));
|
||||
}
|
||||
|
||||
if use_binary_circle || use_binary_rectangle {
|
||||
let ordered_output = if is_reversed {
|
||||
output.label.chars().rev().collect()
|
||||
} else {
|
||||
output.label
|
||||
};
|
||||
|
||||
for (section_index, section) in
|
||||
ordered_output.split(':').enumerate()
|
||||
{
|
||||
ui.scope(|ui| {
|
||||
ui.spacing_mut().item_spacing = Vec2::splat(2.0);
|
||||
for (number_index, number_char) in
|
||||
section.chars().enumerate()
|
||||
{
|
||||
if let Some(number) = number_char.to_digit(10) {
|
||||
// the hour is the second char in the first section (in reverse, it's in the last section)
|
||||
let max_power = match (
|
||||
is_reversed,
|
||||
section_index,
|
||||
number_index,
|
||||
) {
|
||||
(true, 2, 1) | (false, 0, 1) => 2,
|
||||
(true, _, 1) | (false, _, 0) => 3,
|
||||
_ => 4,
|
||||
};
|
||||
|
||||
if use_binary_circle {
|
||||
self.paint_binary_circle(
|
||||
font_id.size,
|
||||
number,
|
||||
max_power,
|
||||
ctx,
|
||||
ui,
|
||||
);
|
||||
} else if use_binary_rectangle {
|
||||
self.paint_binary_rect(
|
||||
font_id.size,
|
||||
number,
|
||||
max_power,
|
||||
ctx,
|
||||
ui,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if is_reversed {
|
||||
ui.add(Label::new(layout_job.clone()).selectable(false));
|
||||
}
|
||||
})
|
||||
.clicked()
|
||||
{
|
||||
self.format.toggle()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 142 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user