refactor(config): move the behaviour enums into komorebi-config

WindowContainerBehaviour, FloatingLayerBehaviour (with should_float), Placement (with should_center and should_resize), CrossBoundaryBehaviour, WindowHidingPosition (KDE and macOS), WindowHandlingBehaviour and ZOrder (with its From<ZOrder> for isize; Windows) in behaviour.rs. The text is the KDE copy for the five that all trees share (identical to the Windows and macOS copies after the previous converge revision) and the Windows copy for the two Windows-only enums. A platform-only enum is defined here without a cfg: the daemon that does not read the key says so at load time. The trees keep their copies until the next revisions. The crate gains the clap dependency (ValueEnum) and the three Cargo.lock files the package entry.

The oracle gains a check that the generated definition of each enum equals the $defs entry of every checked-in schema.json that has it (all three trees for four of them, KDE and macOS for WindowHidingPosition, Windows for the other two).

Verified: native cargo test -p komorebi-config: 4 unit + 4 schemas passed, 0 failed (tier 1).
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent aa78347add
commit 79c9af95d1
7 files changed
+177

No files matched your search

Generated
+1
View File
@@ -3444,6 +3444,7 @@ dependencies = [
name = "komorebi-config"
version = "0.1.42"
dependencies = [
"clap",
"komorebi-layouts",
"komorebi-protocol",
"komorebi-themes",
+1
View File
@@ -9,6 +9,7 @@ komorebi-layouts = { path = "../../komorebi-layouts" }
komorebi-protocol = { path = "../komorebi-protocol", default-features = false }
komorebi-themes = { path = "../../komorebi-themes" }
clap = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, features = ["preserve_order"] }
strum = { workspace = true }
+152
View File
@@ -0,0 +1,152 @@
//! The small enums that `komorebi.json` uses to choose how a window or a container behaves.
//!
//! Some belong to one platform only (`WindowHidingPosition` to KDE and macOS,
//! `WindowHandlingBehaviour` and `ZOrder` to Windows): they are defined here all the same,
//! and a daemon that does not read the key says so when it loads the file.
use clap::ValueEnum;
use serde::Deserialize;
use serde::Serialize;
use strum::Display;
use strum::EnumString;
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Window container behaviour when a new window is opened
pub enum WindowContainerBehaviour {
/// Create a new container for each new window
#[default]
Create,
/// Append new windows to the focused window container
Append,
}
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Floating layer behaviour when a new window is opened
pub enum FloatingLayerBehaviour {
/// Tile new windows (unless they match a float rule or float override is active)
#[default]
Tile,
/// Float new windows
Float,
}
impl FloatingLayerBehaviour {
pub fn should_float(&self) -> bool {
match self {
FloatingLayerBehaviour::Tile => false,
FloatingLayerBehaviour::Float => true,
}
}
}
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Window hiding position
pub enum WindowHidingPosition {
/// Hide windows in the bottom left corner of the screen
#[default]
BottomLeft,
/// Hide windows in the bottom right corner of the screen
BottomRight,
}
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Placement behaviour for floating windows
pub enum Placement {
/// Does not change the size or position of the window
#[default]
None,
/// Center the window without changing the size
Center,
/// Center the window and resize it according to the `AspectRatio`
CenterAndResize,
}
impl Placement {
pub fn should_center(&self) -> bool {
match self {
Placement::None => false,
Placement::Center | Placement::CenterAndResize => true,
}
}
pub fn should_resize(&self) -> bool {
match self {
Placement::None | Placement::Center => false,
Placement::CenterAndResize => true,
}
}
}
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Behaviour when an action would cross a monitor boundary
pub enum CrossBoundaryBehaviour {
/// Attempt to perform actions across a workspace boundary
Workspace,
/// Attempt to perform actions across a monitor boundary
#[default]
Monitor,
}
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Window handling behaviour
pub enum WindowHandlingBehaviour {
#[default]
/// Synchronous
Sync,
/// Asynchronous
Async,
}
#[derive(Debug, Copy, Clone, Display, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Z Order (https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos)
pub enum ZOrder {
/// HWND_TOP
///
/// Places the window at the top of the Z order.
Top,
/// HWND_NOTOPMOST
///
/// Places the window above all non-topmost windows (that is, behind all topmost windows).
/// This flag has no effect if the window is already a non-topmost window.
NoTopMost,
/// HWND_BOTTOM
///
/// Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window,
/// the window loses its topmost status and is placed at the bottom of all other windows.
Bottom,
/// HWND_TOPMOST
///
/// Places the window above all non-topmost windows.
/// The window maintains its topmost position even when it is deactivated.
TopMost,
}
impl From<ZOrder> for isize {
fn from(val: ZOrder) -> Self {
match val {
ZOrder::Top => 0,
ZOrder::NoTopMost => -2,
ZOrder::Bottom => 1,
ZOrder::TopMost => -1,
}
}
}
+1
View File
@@ -10,4 +10,5 @@
#[cfg(feature = "schemars")]
pub mod schema;
pub mod behaviour;
pub mod matching;
+20
View File
@@ -168,3 +168,23 @@ fn the_matching_types_are_the_definitions_of_every_tree() {
// The workspace rules are an input of the daemons only: no schema carries them.
let _ = generated::<WorkspaceMatchingRule>();
}
#[test]
fn the_behaviour_enums_are_the_definitions_of_the_trees_that_have_them() {
use komorebi_config::behaviour::CrossBoundaryBehaviour;
use komorebi_config::behaviour::FloatingLayerBehaviour;
use komorebi_config::behaviour::Placement;
use komorebi_config::behaviour::WindowContainerBehaviour;
use komorebi_config::behaviour::WindowHandlingBehaviour;
use komorebi_config::behaviour::WindowHidingPosition;
use komorebi_config::behaviour::ZOrder;
let [windows, kde, macos] = &TREES;
assert_same_definitions::<WindowContainerBehaviour>(&all(), &["WindowContainerBehaviour"]);
assert_same_definitions::<FloatingLayerBehaviour>(&all(), &["FloatingLayerBehaviour"]);
assert_same_definitions::<Placement>(&all(), &["Placement"]);
assert_same_definitions::<CrossBoundaryBehaviour>(&all(), &["CrossBoundaryBehaviour"]);
assert_same_definitions::<WindowHidingPosition>(&[kde, macos], &["WindowHidingPosition"]);
assert_same_definitions::<WindowHandlingBehaviour>(&[windows], &["WindowHandlingBehaviour"]);
assert_same_definitions::<ZOrder>(&[windows], &["ZOrder"]);
}
+1
View File
@@ -2550,6 +2550,7 @@ dependencies = [
name = "komorebi-config"
version = "0.1.42"
dependencies = [
"clap",
"komorebi-layouts",
"komorebi-protocol",
"komorebi-themes",
+1
View File
@@ -3260,6 +3260,7 @@ dependencies = [
name = "komorebi-config"
version = "0.1.42"
dependencies = [
"clap",
"komorebi-layouts",
"komorebi-protocol",
"komorebi-themes",