summaryrefslogtreecommitdiff
path: root/src/clients/monitors.rs
blob: 6ca6fdf3e3705de146e19b8a5b30d445e2a78e5f (plain)
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
use xcb::xinerama::ScreenInfo;

use super::Client;

/// Info stored for each monitor
#[derive(Debug)]
pub struct MonitorInfo {
    /// Clients attached to that monitor
    pub clients: Vec<Client>,

    /// The monitor's geometry
    pub screen_info: MonitorGeometry,
}

impl MonitorInfo {
    /// Iterate over all tiled clients, returning a mutable reference to each.
    pub fn clients_tiled_mut(&mut self) -> impl Iterator<Item = &mut Client> {
        // TODO: tag filtering
        self.clients.iter_mut().filter(|c| !c.floating())
    }
}

impl Default for MonitorInfo {
    fn default() -> Self {
        Self {
            clients: vec![],
            screen_info: MonitorGeometry {
                x_org: 0,
                y_org: 0,
                width: 0,
                height: 0,
            },
        }
    }
}

/// Info on the monitor's geometry.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MonitorGeometry {
    pub x_org: i16,
    pub y_org: i16,
    pub width: u16,
    pub height: u16,
}

impl From<ScreenInfo> for MonitorGeometry {
    fn from(value: ScreenInfo) -> Self {
        Self {
            x_org: value.x_org,
            y_org: value.y_org,
            width: value.width,
            height: value.height,
        }
    }
}