lib_bpswm/
lib.rs

1use serde::{Deserialize, Serialize};
2use std::fmt::Display;
3
4#[derive(Debug, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub enum Layout {
7    Tiled,
8    PsuedoTiled,
9    Floating,
10    Monocle,
11}
12
13impl Default for Layout {
14    fn default() -> Self {
15        Self::Tiled
16    }
17}
18
19impl Display for Layout {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            Self::Tiled => write!(f, "tiled"),
23            Self::PsuedoTiled => write!(f, "pseudo-tiled"),
24            Self::Floating => write!(f, "floating"),
25            Self::Monocle => write!(f, "monocle"),
26        }
27    }
28}
29
30#[derive(Debug, Serialize, Deserialize)]
31#[serde(rename_all = "camelCase")]
32pub enum SplitType {
33    Vertical,
34    Horizontal,
35}
36
37impl Default for SplitType {
38    fn default() -> Self {
39        Self::Vertical
40    }
41}
42
43impl Display for SplitType {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        match self {
46            SplitType::Vertical => write!(f, "vertical"),
47            SplitType::Horizontal => write!(f, "horizontal"),
48        }
49    }
50}
51
52#[derive(Debug, Serialize, Deserialize)]
53#[serde(rename_all = "camelCase")]
54pub enum Layer {
55    Normal,
56}
57
58impl Default for Layer {
59    fn default() -> Self {
60        Self::Normal
61    }
62}
63
64impl Display for Layer {
65    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66        match self {
67            Layer::Normal => write!(f, "normal"),
68        }
69    }
70}
71
72#[derive(Debug, Default, Serialize, Deserialize)]
73#[serde(rename_all = "camelCase")]
74pub struct Constraints {
75    pub min_width: usize,
76    pub min_height: usize,
77}
78
79#[derive(Debug, Default, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct Padding {
82    pub top: usize,
83    pub right: usize,
84    pub bottom: usize,
85    pub left: usize,
86}
87
88#[derive(Debug, Default, Serialize, Deserialize)]
89#[serde(rename_all = "camelCase")]
90pub struct Rectangle {
91    pub x: usize,
92    pub y: usize,
93    pub width: usize,
94    pub height: usize,
95}
96
97#[derive(Debug, Default, Serialize, Deserialize)]
98#[serde(rename_all = "camelCase")]
99pub struct Focus {
100    monitor_id: usize,
101    desktop_id: usize,
102    node_id: usize,
103}
104
105#[derive(Debug, Default, Serialize, Deserialize)]
106#[serde(rename_all = "camelCase")]
107pub struct State {
108    pub focused_monitor_id: usize,
109    pub primary_monitor_id: usize,
110    pub clients_count: usize,
111    pub monitors: Vec<Monitor>,
112    pub focus_history: Vec<Focus>,
113    pub stacking_list: Vec<usize>,
114}
115
116#[derive(Debug, Default, Serialize, Deserialize)]
117#[serde(rename_all = "camelCase")]
118pub struct Monitor {
119    pub name: String,
120    pub id: usize,
121    pub randr_id: usize,
122    pub wired: bool,
123    pub sticky_count: usize,
124    pub window_gap: usize,
125    pub border_width: usize,
126    pub focused_desktop_id: usize,
127    pub desktops: Vec<Desktop>,
128}
129
130#[derive(Debug, Default, Serialize, Deserialize)]
131#[serde(rename_all = "camelCase")]
132pub struct Desktop {
133    pub name: String,
134    pub id: usize,
135    pub layout: Layout,
136    pub user_layout: Layout,
137    pub window_gap: usize,
138    pub border_width: usize,
139    pub focused_node_id: usize,
140    pub padding: Padding,
141    pub root: Option<Tree>,
142}
143
144#[derive(Debug, Default, Serialize, Deserialize)]
145#[serde(rename_all = "camelCase")]
146pub struct Tree {
147    pub id: usize,
148    pub split_type: SplitType,
149    pub vacant: bool,
150    pub hidden: bool,
151    pub sticky: bool,
152    pub private: bool,
153    pub locked: bool,
154    pub marked: bool,
155    pub presel: Option<String>,
156    pub rectangle: Rectangle,
157}
158
159#[derive(Debug, Default, Serialize, Deserialize)]
160#[serde(rename_all = "camelCase")]
161pub struct Node {
162    pub id: usize,
163    pub split_type: SplitType,
164    pub split_ratio: f32,
165    pub vacant: bool,
166    pub hidden: bool,
167    pub sticky: bool,
168    pub private: bool,
169    pub locked: bool,
170    pub marked: bool,
171    pub presel: Option<String>,
172    pub rectangle: Rectangle,
173    pub constrainnts: Option<Constraints>,
174    pub first_child: Option<Box<Node>>,
175    pub second_child: Option<Box<Node>>,
176    pub client: Client,
177}
178
179#[derive(Debug, Default, Serialize, Deserialize)]
180#[serde(rename_all = "camelCase")]
181pub struct Client {
182    pub class_name: String,
183    pub instance_name: String,
184    pub border_width: usize,
185    pub state: Layout,
186    pub last_state: Layout,
187    pub layer: Layer,
188    pub last_layer: Layer,
189    pub urgent: bool,
190    pub shown: bool,
191    pub tiled_rectangle: Rectangle,
192    pub floating_rectangle: Rectangle,
193}