feat(backend): FakeBackend with failure injection and frame offsets

The in-memory desktop of komorebi-for-kde (backend/fake.rs) moved into the shared crate, rewritten against WindowId/MonitorId/Result and the generic Backend only (look, border colours, wallpaper and drag frames stay out: they are KDE's).

Same behaviour as the KDE fake (permissive mode, minimum sizes, user_* helpers, maximize, fullscreen, workspaces, the ordered Command log with 15 of KDE's 18 variants; close() leaves the foreground window alone, as KDE's did), plus:
- failure injection: fail_next(Op, Error) and fail_next_for(Op, WindowId, Error), oldest first, one per call; the failed call is still logged as a command and changes nothing else (none existed on KDE);
- frame offsets: set_frame_offset / set_window_frame_offset make window_rect differ from the request by a constant, as the Windows shadow border does;
- capabilities: all four on by default, set_supported switches one off and its operations return Unsupported without being logged;
- batches: begin/end are counted (open_batches) and logged as BatchBegin/BatchEnd;
- FakeBackend<X>: a platform extension logs its own commands in order with record_ext (Command::Ext(X)); the shared fake is FakeBackend<NoExt> (new/permissive/with_one_monitor), an extension uses empty/permissive_ext/one_monitor because default type parameters are not inferred.

Verified: native cargo test -p komorebi-backend: 24 unit tests and 6 doctests passed, 0 failed (the KDE fake tests were ported and 6 failure/offset/capability/batch/extension tests added); clippy --all-targets -D warnings clean; cargo fmt applied.
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent f08237d402
commit 6874a51769
3 files changed
+1451 -3

No files matched your search

+19 -2
View File
@@ -55,7 +55,7 @@ impl Capability {
/// # Who implements it
///
/// KDE (over the compositor), Windows (over `WindowsApi`), macOS (over `MacosApi` and the
/// Accessibility API) and the in-memory fake. Each method's documentation says which of
/// Accessibility API) and [`crate::fake::FakeBackend`]. Each method's documentation says which of
/// the three real platforms implement it; an operation that is optional says so and is listed in
/// [`Capability`].
///
@@ -92,7 +92,7 @@ impl Capability {
/// - to learn the achieved frame, wait for the event, or call `window_rect` where the layout
/// needs the truth (a refused width, the end of a drag).
///
/// the in-memory fake answers a read after a write at once with the request, clamped to
/// [`crate::fake::FakeBackend`] answers a read after a write at once with the request, clamped to
/// the window's minimum size and moved by its frame offset.
///
/// # Errors
@@ -342,6 +342,23 @@ pub trait Backend: Send + Sync + 'static {
///
/// A backend that cannot batch ignores it ([`Backend::begin_batch`] does nothing by default), so
/// shared code may bracket every layout with it.
///
/// # Example
///
/// ```rust
/// use komorebi_backend::{Backend, Batch, Rect, WindowId};
/// use komorebi_backend::fake::FakeBackend;
///
/// let fake = FakeBackend::with_one_monitor();
/// fake.open_window(WindowId(1));
/// {
/// let _batch = Batch::begin(&fake);
/// fake.set_rect(WindowId(1), &Rect { left: 0, top: 0, right: 100, bottom: 100 })?;
/// assert_eq!(fake.open_batches(), 1);
/// }
/// assert_eq!(fake.open_batches(), 0);
/// # Ok::<(), komorebi_backend::Error>(())
/// ```
#[must_use = "the batch ends when this is dropped"]
pub struct Batch<'a, B: Backend + ?Sized>(&'a B);
File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -10,7 +10,8 @@
//! - [`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.
//! have, and a [`Batch`] scope for writes that should appear together;
//! - [`fake::FakeBackend`], an in-memory desktop with failure injection and frame offsets.
//!
//! 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.
@@ -25,6 +26,7 @@
mod backend;
mod error;
pub mod fake;
mod id;
mod info;