1
0
Fork 0
forked from wry/wry

tree: move shared tree types into workspace crate

This commit is contained in:
kossLAN 2026-05-29 11:11:54 -04:00
parent a1e4641e82
commit 89dc6c91cf
No known key found for this signature in database
6 changed files with 303 additions and 266 deletions

11
tree-types/Cargo.toml Normal file
View file

@ -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"] }

269
tree-types/src/lib.rs Normal file
View file

@ -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<ConfigWorkspaceDisplayOrder> for WorkspaceDisplayOrder {
fn from(value: ConfigWorkspaceDisplayOrder) -> Self {
match value {
ConfigWorkspaceDisplayOrder::Manual => WorkspaceDisplayOrder::Manual,
ConfigWorkspaceDisplayOrder::Sorted => WorkspaceDisplayOrder::Sorted,
}
}
}
impl Into<ConfigWorkspaceDisplayOrder> 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<ConfigTransform> 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<ConfigTransform> 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<T>(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<Self> {
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<ConfigTileState> for TileState {
type Error = ();
fn try_from(value: ConfigTileState) -> Result<Self, Self::Error> {
let v = match value {
ConfigTileState::Tiled => TileState::Tiled,
ConfigTileState::Floating => TileState::Floating,
_ => return Err(()),
};
Ok(v)
}
}
impl Into<ConfigTileState> 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<ConfigDirection> 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)
}
}