libwmctl/model/
mod.rs

1//! Models for working with X11 windows
2//!
3//! ### How to use the `model` module
4//! ```
5//! use libwmctl::prelude::*;
6//! ```
7mod gravity;
8mod info;
9mod kind;
10mod map_state;
11mod position;
12mod property;
13mod shape;
14mod state;
15
16// Export contents of modules
17pub use gravity::*;
18pub use info::*;
19pub use kind::*;
20pub use map_state::*;
21pub use position::*;
22pub use property::*;
23pub use shape::*;
24pub use state::*;
25
26// Define the second byte of the move resize flags 32bit value
27// Used to indicate that the associated value has been changed and needs to be acted upon
28pub type MoveResizeWindowFlags = u32;
29pub const MOVE_RESIZE_WINDOW_X: MoveResizeWindowFlags = 1 << 8;
30pub const MOVE_RESIZE_WINDOW_Y: MoveResizeWindowFlags = 1 << 9;
31pub const MOVE_RESIZE_WINDOW_WIDTH: MoveResizeWindowFlags = 1 << 10;
32pub const MOVE_RESIZE_WINDOW_HEIGHT: MoveResizeWindowFlags = 1 << 11;
33
34pub type WindowStateAction = u32;
35pub const WINDOW_STATE_ACTION_REMOVE: WindowStateAction = 0;
36pub const WINDOW_STATE_ACTION_ADD: WindowStateAction = 1;
37
38/// Border provides a simple way to store border values
39#[derive(Default)]
40pub struct Border {
41    pub l: u32,
42    pub r: u32,
43    pub t: u32,
44    pub b: u32,
45}
46
47impl Border {
48    pub fn new(l: u32, r: u32, t: u32, b: u32) -> Self {
49        Self { l, r, t, b }
50    }
51
52    // Check if any values are non zero
53    pub fn any(&self) -> bool {
54        self.l > 0 || self.r > 0 || self.t > 0 || self.b > 0
55    }
56
57    // Summed the left and right borders as a single value
58    pub fn w(&self) -> u32 {
59        self.l + self.r
60    }
61
62    // Summed the top and bottom borders as a single value
63    pub fn h(&self) -> u32 {
64        self.t + self.b
65    }
66}
67
68/// Rect provides a simple way to store the width and height of an area
69#[derive(Default)]
70pub struct Rect {
71    pub w: u32,
72    pub h: u32,
73}
74
75impl Rect {
76    pub fn new(w: u32, h: u32) -> Self {
77        Self { w, h }
78    }
79}