From 89dc6c91cf25b49d2f7cf9d23893d9b6076ba239 Mon Sep 17 00:00:00 2001 From: kossLAN Date: Fri, 29 May 2026 11:11:54 -0400 Subject: [PATCH] tree: move shared tree types into workspace crate --- Cargo.lock | 10 ++ Cargo.toml | 2 + src/ifs/wl_output.rs | 8 ++ src/tree.rs | 269 +----------------------------------------- tree-types/Cargo.toml | 11 ++ tree-types/src/lib.rs | 269 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 303 insertions(+), 266 deletions(-) create mode 100644 tree-types/Cargo.toml create mode 100644 tree-types/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 91fc6921..cdbdf9ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -705,6 +705,7 @@ dependencies = [ "jay-time", "jay-toml-config", "jay-tracy", + "jay-tree-types", "jay-units", "jay-utils", "jay-wire-buf", @@ -862,6 +863,15 @@ dependencies = [ "tracy-client-sys", ] +[[package]] +name = "jay-tree-types" +version = "0.1.0" +dependencies = [ + "jay-config", + "jay-utils", + "linearize", +] + [[package]] name = "jay-units" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index de33725f..e36312cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ members = [ "xcon", "wire-types", "wire-buf", + "tree-types", "toml-config", "algorithms", "toml-spec", @@ -69,6 +70,7 @@ jay-dbus-core = { version = "0.1.0", path = "dbus-core" } jay-xcon = { version = "0.1.0", path = "xcon" } jay-wire-types = { version = "0.1.0", path = "wire-types" } jay-wire-buf = { version = "0.1.0", path = "wire-buf" } +jay-tree-types = { version = "0.1.0", path = "tree-types" } uapi = "0.2.13" thiserror = "2.0.11" diff --git a/src/ifs/wl_output.rs b/src/ifs/wl_output.rs index 1687824d..851fdf79 100644 --- a/src/ifs/wl_output.rs +++ b/src/ifs/wl_output.rs @@ -51,13 +51,21 @@ const SP_VERTICAL_RGB: i32 = 4; #[expect(dead_code)] const SP_VERTICAL_BGR: i32 = 5; +#[allow(dead_code)] pub const TF_NORMAL: i32 = 0; +#[allow(dead_code)] pub const TF_90: i32 = 1; +#[allow(dead_code)] pub const TF_180: i32 = 2; +#[allow(dead_code)] pub const TF_270: i32 = 3; +#[allow(dead_code)] pub const TF_FLIPPED: i32 = 4; +#[allow(dead_code)] pub const TF_FLIPPED_90: i32 = 5; +#[allow(dead_code)] pub const TF_FLIPPED_180: i32 = 6; +#[allow(dead_code)] pub const TF_FLIPPED_270: i32 = 7; const MODE_CURRENT: u32 = 1; diff --git a/src/tree.rs b/src/tree.rs index 5aa601c5..0c93db69 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -4,10 +4,6 @@ use { client::{Client, ClientId}, fixed::Fixed, ifs::{ - wl_output::{ - TF_90, TF_180, TF_270, TF_FLIPPED, TF_FLIPPED_90, TF_FLIPPED_180, TF_FLIPPED_270, - TF_NORMAL, - }, wl_seat::{ Dnd, NodeSeatState, WlSeatGlobal, tablet::{ @@ -25,19 +21,11 @@ use { keyboard::KeyboardState, rect::Rect, renderer::Renderer, - utils::{linkedlist::NodeRef, numcell::NumCell, static_text::StaticText}, - }, - jay_config::{ - Direction as JayDirection, video::Transform as ConfigTransform, - window::TileState as ConfigTileState, - workspace::WorkspaceDisplayOrder as ConfigWorkspaceDisplayOrder, - }, - linearize::{Linearize, LinearizeExt}, - std::{ - fmt::{Debug, Display}, - rc::Rc, + utils::{linkedlist::NodeRef, numcell::NumCell}, }, + std::{fmt::Display, rc::Rc}, }; +pub use jay_tree_types::*; pub use { container::*, containing::*, display::*, float::*, output::*, placeholder::*, stacked::*, toplevel::*, walker::*, workspace::*, @@ -55,206 +43,6 @@ mod toplevel; mod walker; mod workspace; -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)] -pub enum WorkspaceDisplayOrder { - #[default] - Manual, - Sorted, -} - -impl From for WorkspaceDisplayOrder { - fn from(value: ConfigWorkspaceDisplayOrder) -> Self { - match value { - ConfigWorkspaceDisplayOrder::Manual => WorkspaceDisplayOrder::Manual, - ConfigWorkspaceDisplayOrder::Sorted => WorkspaceDisplayOrder::Sorted, - } - } -} - -impl Into for WorkspaceDisplayOrder { - fn into(self) -> ConfigWorkspaceDisplayOrder { - match self { - WorkspaceDisplayOrder::Manual => ConfigWorkspaceDisplayOrder::Manual, - WorkspaceDisplayOrder::Sorted => ConfigWorkspaceDisplayOrder::Sorted, - } - } -} - -impl StaticText for WorkspaceDisplayOrder { - fn text(&self) -> &'static str { - match self { - WorkspaceDisplayOrder::Manual => "Manual", - WorkspaceDisplayOrder::Sorted => "Sorted", - } - } -} - -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)] -pub enum Transform { - #[default] - None, - Rotate90, - Rotate180, - Rotate270, - Flip, - FlipRotate90, - FlipRotate180, - FlipRotate270, -} - -impl StaticText for Transform { - fn text(&self) -> &'static str { - match self { - Transform::None => "none", - Transform::Rotate90 => "rotate-90", - Transform::Rotate180 => "rotate-180", - Transform::Rotate270 => "rotate-270", - Transform::Flip => "flip", - Transform::FlipRotate90 => "flip-rotate-90", - Transform::FlipRotate180 => "flip-rotate-180", - Transform::FlipRotate270 => "flip-rotate-270", - } - } -} - -impl From for Transform { - fn from(value: ConfigTransform) -> Self { - match value { - ConfigTransform::None => Transform::None, - ConfigTransform::Rotate90 => Transform::Rotate90, - ConfigTransform::Rotate180 => Transform::Rotate180, - ConfigTransform::Rotate270 => Transform::Rotate270, - ConfigTransform::Flip => Transform::Flip, - ConfigTransform::FlipRotate90 => Transform::FlipRotate90, - ConfigTransform::FlipRotate180 => Transform::FlipRotate180, - ConfigTransform::FlipRotate270 => Transform::FlipRotate270, - } - } -} - -impl Into for Transform { - fn into(self) -> ConfigTransform { - match self { - Transform::None => ConfigTransform::None, - Transform::Rotate90 => ConfigTransform::Rotate90, - Transform::Rotate180 => ConfigTransform::Rotate180, - Transform::Rotate270 => ConfigTransform::Rotate270, - Transform::Flip => ConfigTransform::Flip, - Transform::FlipRotate90 => ConfigTransform::FlipRotate90, - Transform::FlipRotate180 => ConfigTransform::FlipRotate180, - Transform::FlipRotate270 => ConfigTransform::FlipRotate270, - } - } -} - -impl Transform { - pub fn maybe_swap(self, (left, right): (T, T)) -> (T, T) { - match self { - Self::None | Self::Rotate180 | Self::Flip | Self::FlipRotate180 => (left, right), - Self::Rotate90 | Self::Rotate270 | Self::FlipRotate90 | Self::FlipRotate270 => { - (right, left) - } - } - } - - pub fn to_wl(self) -> i32 { - match self { - Self::None => TF_NORMAL, - Self::Rotate90 => TF_90, - Self::Rotate180 => TF_180, - Self::Rotate270 => TF_270, - Self::Flip => TF_FLIPPED, - Self::FlipRotate90 => TF_FLIPPED_90, - Self::FlipRotate180 => TF_FLIPPED_180, - Self::FlipRotate270 => TF_FLIPPED_270, - } - } - - pub fn from_wl(wl: i32) -> Option { - let tf = match wl { - TF_NORMAL => Self::None, - TF_90 => Self::Rotate90, - TF_180 => Self::Rotate180, - TF_270 => Self::Rotate270, - TF_FLIPPED => Self::Flip, - TF_FLIPPED_90 => Self::FlipRotate90, - TF_FLIPPED_180 => Self::FlipRotate180, - TF_FLIPPED_270 => Self::FlipRotate270, - _ => return None, - }; - Some(tf) - } - - pub fn apply_point(self, width: i32, height: i32, (x, y): (i32, i32)) -> (i32, i32) { - match self { - Self::None => (x, y), - Self::Rotate90 => (y, height - x), - Self::Rotate180 => (width - x, height - y), - Self::Rotate270 => (width - y, x), - Self::Flip => (width - x, y), - Self::FlipRotate90 => (y, x), - Self::FlipRotate180 => (x, height - y), - Self::FlipRotate270 => (width - y, height - x), - } - } - - pub fn inverse(self) -> Self { - match self { - Self::Rotate90 => Self::Rotate270, - Self::Rotate270 => Self::Rotate90, - _ => self, - } - } -} - -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Linearize)] -pub enum TileState { - Tiled, - Floating, -} - -impl TryFrom for TileState { - type Error = (); - - fn try_from(value: ConfigTileState) -> Result { - let v = match value { - ConfigTileState::Tiled => TileState::Tiled, - ConfigTileState::Floating => TileState::Floating, - _ => return Err(()), - }; - Ok(v) - } -} - -impl Into for TileState { - fn into(self) -> ConfigTileState { - match self { - TileState::Tiled => ConfigTileState::Tiled, - TileState::Floating => ConfigTileState::Floating, - } - } -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum Direction { - Unspecified, - Left, - Down, - Up, - Right, -} - -impl From for Direction { - fn from(d: JayDirection) -> Self { - match d { - JayDirection::Left => Self::Left, - JayDirection::Down => Self::Down, - JayDirection::Up => Self::Up, - JayDirection::Right => Self::Right, - } - } -} - pub struct NodeIds { next: NumCell, } @@ -277,7 +65,6 @@ impl NodeIds { pub struct NodeId(pub u32); impl NodeId { - #[expect(dead_code)] pub fn raw(&self) -> u32 { self.0 } @@ -289,49 +76,12 @@ impl Display for NodeId { } } -#[derive(Copy, Clone, Eq, PartialEq)] -pub enum FindTreeResult { - AcceptsInput, - Other, -} - -impl FindTreeResult { - pub fn accepts_input(self) -> bool { - self == Self::AcceptsInput - } -} - -#[derive(Copy, Clone)] -pub enum FindTreeUsecase { - None, - SelectToplevel, - SelectToplevelOrPopup, - SelectWorkspace, -} - #[derive(Copy, Clone)] pub enum NodeLocation { Workspace(OutputNodeId, WorkspaceNodeId), Output(OutputNodeId), } -#[derive(Copy, Clone, Linearize, Eq, PartialEq, Debug)] -pub enum NodeLayer { - Display, - Layer0, - Layer1, - Output, - Workspace, - Tiled, - Fullscreen, - Stacked, - Layer2, - Layer3, - StackedAboveLayers, - Lock, - InputMethod, -} - pub enum NodeLayerLink { Display, Layer0(NodeRef>), @@ -377,19 +127,6 @@ impl NodeLayerLink { } } -impl NodeLayer { - pub fn prev(self) -> Self { - if self == NodeLayer::Display { - return NodeLayer::InputMethod; - } - Self::from_linear(self.linearize() - 1).unwrap_or(NodeLayer::InputMethod) - } - - pub fn next(self) -> Self { - Self::from_linear(self.linearize() + 1).unwrap_or(NodeLayer::Display) - } -} - pub trait Node: 'static { fn node_id(&self) -> NodeId; fn node_seat_state(&self) -> &NodeSeatState; diff --git a/tree-types/Cargo.toml b/tree-types/Cargo.toml new file mode 100644 index 00000000..59506b88 --- /dev/null +++ b/tree-types/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "jay-tree-types" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-only" + +[dependencies] +jay-config = { version = "1.10.0", path = "../jay-config" } +jay-utils = { version = "0.1.0", path = "../utils" } + +linearize = { version = "0.1.3", features = ["derive"] } diff --git a/tree-types/src/lib.rs b/tree-types/src/lib.rs new file mode 100644 index 00000000..67fab81d --- /dev/null +++ b/tree-types/src/lib.rs @@ -0,0 +1,269 @@ +use { + jay_config::{ + Direction as ConfigDirection, + video::Transform as ConfigTransform, + window::TileState as ConfigTileState, + workspace::WorkspaceDisplayOrder as ConfigWorkspaceDisplayOrder, + }, + jay_utils::static_text::StaticText, + linearize::{Linearize, LinearizeExt}, +}; + +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)] +pub enum WorkspaceDisplayOrder { + #[default] + Manual, + Sorted, +} + +impl From for WorkspaceDisplayOrder { + fn from(value: ConfigWorkspaceDisplayOrder) -> Self { + match value { + ConfigWorkspaceDisplayOrder::Manual => WorkspaceDisplayOrder::Manual, + ConfigWorkspaceDisplayOrder::Sorted => WorkspaceDisplayOrder::Sorted, + } + } +} + +impl Into for WorkspaceDisplayOrder { + fn into(self) -> ConfigWorkspaceDisplayOrder { + match self { + WorkspaceDisplayOrder::Manual => ConfigWorkspaceDisplayOrder::Manual, + WorkspaceDisplayOrder::Sorted => ConfigWorkspaceDisplayOrder::Sorted, + } + } +} + +impl StaticText for WorkspaceDisplayOrder { + fn text(&self) -> &'static str { + match self { + WorkspaceDisplayOrder::Manual => "Manual", + WorkspaceDisplayOrder::Sorted => "Sorted", + } + } +} + +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)] +pub enum Transform { + #[default] + None, + Rotate90, + Rotate180, + Rotate270, + Flip, + FlipRotate90, + FlipRotate180, + FlipRotate270, +} + +impl StaticText for Transform { + fn text(&self) -> &'static str { + match self { + Transform::None => "none", + Transform::Rotate90 => "rotate-90", + Transform::Rotate180 => "rotate-180", + Transform::Rotate270 => "rotate-270", + Transform::Flip => "flip", + Transform::FlipRotate90 => "flip-rotate-90", + Transform::FlipRotate180 => "flip-rotate-180", + Transform::FlipRotate270 => "flip-rotate-270", + } + } +} + +impl From for Transform { + fn from(value: ConfigTransform) -> Self { + match value { + ConfigTransform::None => Transform::None, + ConfigTransform::Rotate90 => Transform::Rotate90, + ConfigTransform::Rotate180 => Transform::Rotate180, + ConfigTransform::Rotate270 => Transform::Rotate270, + ConfigTransform::Flip => Transform::Flip, + ConfigTransform::FlipRotate90 => Transform::FlipRotate90, + ConfigTransform::FlipRotate180 => Transform::FlipRotate180, + ConfigTransform::FlipRotate270 => Transform::FlipRotate270, + } + } +} + +impl Into for Transform { + fn into(self) -> ConfigTransform { + match self { + Transform::None => ConfigTransform::None, + Transform::Rotate90 => ConfigTransform::Rotate90, + Transform::Rotate180 => ConfigTransform::Rotate180, + Transform::Rotate270 => ConfigTransform::Rotate270, + Transform::Flip => ConfigTransform::Flip, + Transform::FlipRotate90 => ConfigTransform::FlipRotate90, + Transform::FlipRotate180 => ConfigTransform::FlipRotate180, + Transform::FlipRotate270 => ConfigTransform::FlipRotate270, + } + } +} + +const TF_NORMAL: i32 = 0; +const TF_90: i32 = 1; +const TF_180: i32 = 2; +const TF_270: i32 = 3; +const TF_FLIPPED: i32 = 4; +const TF_FLIPPED_90: i32 = 5; +const TF_FLIPPED_180: i32 = 6; +const TF_FLIPPED_270: i32 = 7; + +impl Transform { + pub fn maybe_swap(self, (left, right): (T, T)) -> (T, T) { + match self { + Self::None | Self::Rotate180 | Self::Flip | Self::FlipRotate180 => (left, right), + Self::Rotate90 | Self::Rotate270 | Self::FlipRotate90 | Self::FlipRotate270 => { + (right, left) + } + } + } + + pub fn to_wl(self) -> i32 { + match self { + Self::None => TF_NORMAL, + Self::Rotate90 => TF_90, + Self::Rotate180 => TF_180, + Self::Rotate270 => TF_270, + Self::Flip => TF_FLIPPED, + Self::FlipRotate90 => TF_FLIPPED_90, + Self::FlipRotate180 => TF_FLIPPED_180, + Self::FlipRotate270 => TF_FLIPPED_270, + } + } + + pub fn from_wl(wl: i32) -> Option { + let tf = match wl { + TF_NORMAL => Self::None, + TF_90 => Self::Rotate90, + TF_180 => Self::Rotate180, + TF_270 => Self::Rotate270, + TF_FLIPPED => Self::Flip, + TF_FLIPPED_90 => Self::FlipRotate90, + TF_FLIPPED_180 => Self::FlipRotate180, + TF_FLIPPED_270 => Self::FlipRotate270, + _ => return None, + }; + Some(tf) + } + + pub fn apply_point(self, width: i32, height: i32, (x, y): (i32, i32)) -> (i32, i32) { + match self { + Self::None => (x, y), + Self::Rotate90 => (y, height - x), + Self::Rotate180 => (width - x, height - y), + Self::Rotate270 => (width - y, x), + Self::Flip => (width - x, y), + Self::FlipRotate90 => (y, x), + Self::FlipRotate180 => (x, height - y), + Self::FlipRotate270 => (width - y, height - x), + } + } + + pub fn inverse(self) -> Self { + match self { + Self::Rotate90 => Self::Rotate270, + Self::Rotate270 => Self::Rotate90, + _ => self, + } + } +} + +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Linearize)] +pub enum TileState { + Tiled, + Floating, +} + +impl TryFrom for TileState { + type Error = (); + + fn try_from(value: ConfigTileState) -> Result { + let v = match value { + ConfigTileState::Tiled => TileState::Tiled, + ConfigTileState::Floating => TileState::Floating, + _ => return Err(()), + }; + Ok(v) + } +} + +impl Into for TileState { + fn into(self) -> ConfigTileState { + match self { + TileState::Tiled => ConfigTileState::Tiled, + TileState::Floating => ConfigTileState::Floating, + } + } +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum Direction { + Unspecified, + Left, + Down, + Up, + Right, +} + +impl From for Direction { + fn from(d: ConfigDirection) -> Self { + match d { + ConfigDirection::Left => Self::Left, + ConfigDirection::Down => Self::Down, + ConfigDirection::Up => Self::Up, + ConfigDirection::Right => Self::Right, + } + } +} + +#[derive(Copy, Clone, Eq, PartialEq)] +pub enum FindTreeResult { + AcceptsInput, + Other, +} + +impl FindTreeResult { + pub fn accepts_input(self) -> bool { + self == Self::AcceptsInput + } +} + +#[derive(Copy, Clone)] +pub enum FindTreeUsecase { + None, + SelectToplevel, + SelectToplevelOrPopup, + SelectWorkspace, +} + +#[derive(Copy, Clone, Linearize, Eq, PartialEq, Debug)] +pub enum NodeLayer { + Display, + Layer0, + Layer1, + Output, + Workspace, + Tiled, + Fullscreen, + Stacked, + Layer2, + Layer3, + StackedAboveLayers, + Lock, + InputMethod, +} + +impl NodeLayer { + pub fn prev(self) -> Self { + if self == NodeLayer::Display { + return NodeLayer::InputMethod; + } + Self::from_linear(self.linearize() - 1).unwrap_or(NodeLayer::InputMethod) + } + + pub fn next(self) -> Self { + Self::from_linear(self.linearize() + 1).unwrap_or(NodeLayer::Display) + } +}