1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use crate::models::Window;
use crate::models::XYHWBuilder;
use crate::models::XYHW;

#[derive(Clone, Debug, PartialEq, Copy)]
pub struct XYHWChange {
    pub x: Option<i32>,
    pub y: Option<i32>,
    pub h: Option<i32>,
    pub w: Option<i32>,
    pub minw: Option<i32>,
    pub maxw: Option<i32>,
    pub minh: Option<i32>,
    pub maxh: Option<i32>,
}

impl Default for XYHWChange {
    fn default() -> Self {
        XYHWChange {
            x: None,
            y: None,
            w: None,
            h: None,
            minw: None,
            maxw: None,
            minh: None,
            maxh: None,
        }
    }
}

impl From<XYHW> for XYHWChange {
    fn from(xywh: XYHW) -> Self {
        XYHWChange {
            x: Some(xywh.x()),
            y: Some(xywh.y()),
            w: Some(xywh.w()),
            h: Some(xywh.h()),
            minw: Some(xywh.minw()),
            maxw: Some(xywh.maxw()),
            minh: Some(xywh.minh()),
            maxh: Some(xywh.maxh()),
        }
    }
}

impl XYHWChange {
    pub fn update(&self, xyhw: &mut XYHW) -> bool {
        let mut changed = false;
        if let Some(x) = self.x {
            xyhw.set_x(x);
            changed = true;
        }
        if let Some(y) = self.y {
            xyhw.set_y(y);
            changed = true;
        }
        if let Some(w) = self.w {
            xyhw.set_w(w);
            changed = true;
        }
        if let Some(h) = self.h {
            xyhw.set_h(h);
            changed = true;
        }
        if let Some(minw) = self.minw {
            xyhw.set_minw(minw);
            changed = true;
        }
        if let Some(maxw) = self.maxw {
            xyhw.set_maxw(maxw);
            changed = true;
        }
        if let Some(minh) = self.minh {
            xyhw.set_minh(minh);
            changed = true;
        }
        if let Some(maxh) = self.maxh {
            xyhw.set_maxh(maxh);
            changed = true;
        }
        changed
    }

    pub fn update_window(&self, window: &mut Window) -> bool {
        if window.floating.is_none() {
            window.floating = Some(XYHWBuilder::default().into());
        }
        let mut xyhw = window.floating.unwrap();
        let changed = self.update(&mut xyhw);
        window.floating = Some(xyhw);
        changed
    }
}