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

View file

@ -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;

View file

@ -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<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,
}
}
}
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<JayDirection> 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<u32>,
}
@ -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<Rc<ZwlrLayerSurfaceV1>>),
@ -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;