libwmctl/model/
gravity.rs

1use std::fmt;
2
3/// Gravity
4/// When windows are resized, subwindows may be repositioned automatically relative to some position
5/// in the window. This attraction of a subwindow to some part of its parent is known as window
6/// gravity.
7///
8/// Gravity is defined as the lower byte of the move resize flags 32bit value
9/// <https://tronche.com/gui/x/xlib/window/attributes/gravity.html>
10#[derive(Debug, Clone, PartialEq)]
11pub enum Gravity {
12    Unmap,
13    Center,
14}
15
16// Implement format! support
17impl fmt::Display for Gravity {
18    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19        match self {
20            _ => write!(f, "{}", format!("{:?}", self).to_lowercase()),
21        }
22    }
23}
24
25impl From<u32> for Gravity {
26    fn from(val: u32) -> Self {
27        match val {
28            5 => Gravity::Center,
29            _ => Gravity::Unmap,
30        }
31    }
32}
33
34impl From<Gravity> for u32 {
35    fn from(val: Gravity) -> Self {
36        match val {
37            Gravity::Center => 5,
38            Gravity::Unmap => 0,
39        }
40    }
41}