Files
komorebi/crates/komorebi-backend/src/lib.rs
T
LGUG2Z f08237d402 feat(backend): the shared Backend trait, WindowId, plain-data infos and the error type
New crate crates/komorebi-backend (edition 2024, root workspace member, depends only on komorebi-layouts for Rect).

- WindowId and MonitorId: opaque u64 newtypes. KDE and macOS ids convert with from_u32/to_u32; a Windows HWND/HMONITOR goes through from_hwnd/to_hwnd, which keep the bits of the isize unchanged (isize as usize as u64), so no handle is lost whether or not it fits in 32 bits (the e2e samples stay below 2^32, which is an observation, not a guarantee).
- WindowInfo and MonitorInfo: plain data; only id, pid, rect, minimized and alive are required, the rest (title, class, exe, path, fullscreen, maximized, normal; name and serial id of a monitor) are Option (seam.md consequence 6).
- Error: WindowGone(id) (finding 9: macOS uses a failed write as its signal that a window died), Unsupported(Capability) and Platform(cause).
- Backend: only the operations of seam.md section 2.1 that at least two platforms have (5 queries, 9 commands), a Capability query for workspaces, maximize, opacity and focus-follows-mouse (their methods default to Unsupported), begin_batch/end_batch with a no-op default plus the Batch guard (finding 8), the documented set_rect contract (a request; reads after a write return what the platform defines, consequence 2 as corrected) and the thread contract (any non-main thread, no waiting for the platform's main thread: consequences 3 and 4, written as TARGET rules). Every doc comment says which platforms implement the method.

Verified: native cargo test -p komorebi-backend (2 unit tests, 3 doctests, 0 failed) and cargo clippy -p komorebi-backend --all-targets -- -D warnings clean. The Windows/KDE/macOS gates are not affected yet (new crate, nothing depends on it).
2026-10-31 01:37:54 -07:00

41 lines
1.7 KiB
Rust

//! What every komorebi daemon asks of its platform.
//!
//! The window manager logic should talk to a [`Backend`], never to KWin, Win32 or the macOS
//! Accessibility API. This crate holds the vocabulary of that conversation and nothing that
//! belongs to one platform:
//!
//! - [`WindowId`] and [`MonitorId`], the names a backend gives windows and monitors;
//! - [`WindowInfo`] and [`MonitorInfo`], plain data, with an [`Option`] for everything that is
//! not available on every platform;
//! - [`Error`], which can say that "the window is gone" and that "this platform cannot do that";
//! - the [`Backend`] trait, with only the operations that at least two platforms have
//! (`docs/dev/seam.md`, section 2.1), a [`Capability`] query for the ones only some platforms
//! have, and a [`Batch`] scope for writes that should appear together.
//!
//! The evidence for each choice, and the status of every claim (confirmed, corrected or target),
//! is in `docs/dev/seam.md`. The doc comment of each item says which platforms implement it.
//!
//! # Platform-specific operations
//!
//! Borders and their colours, the look, the wallpaper, drag origin and end frames, stackbars,
//! observers and event taps are not here: they are one platform's business and live in that
//! platform's own trait or crate (for KDE, `komorebi::backend::Backend` still has them).
#![deny(missing_docs)]
mod backend;
mod error;
mod id;
mod info;
pub use backend::Backend;
pub use backend::Batch;
pub use backend::Capability;
pub use error::Error;
pub use error::Result;
pub use id::MonitorId;
pub use id::WindowId;
pub use info::MonitorInfo;
pub use info::WindowInfo;
pub use komorebi_layouts::Rect;