summaryrefslogtreecommitdiff
path: root/src/wm_info_provider.rs
blob: e11e48e96e719ec76e33b4d450e746bf128094ce (plain) (blame)
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
use wayrs_client::connection::Connection;
use wayrs_client::global::*;

use crate::pointer_btn::PointerBtn;
use crate::protocol::*;
use crate::state::State;

#[cfg(feature = "hyprland")]
mod ext_workspace_unstable;
#[cfg(feature = "hyprland")]
use ext_workspace_unstable::*;

mod river;
use river::*;

pub enum WmInfoProvider {
    None,
    River(RiverInfoProvider),
    #[cfg(feature = "hyprland")]
    Ewu(ExtWorkspaceUnstable),
}

pub type WmInfoCallback = fn(&mut Connection<State>, &mut State, WlOutput, WmInfo);

impl WmInfoProvider {
    pub fn bind(
        conn: &mut Connection<State>,
        globals: &Globals,
        callback: WmInfoCallback,
    ) -> WmInfoProvider {
        if let Some(river) = RiverInfoProvider::bind(conn, globals, callback) {
            return Self::River(river);
        }

        #[cfg(feature = "hyprland")]
        if let Some(ext_wp_u) = ExtWorkspaceUnstable::bind(conn, globals, callback) {
            return Self::Ewu(ext_wp_u);
        }

        Self::None
    }

    pub fn new_ouput(&mut self, conn: &mut Connection<State>, output: WlOutput) {
        match self {
            Self::None => (),
            Self::River(x) => x.new_output(conn, output),
            #[cfg(feature = "hyprland")]
            Self::Ewu(x) => x.new_ouput(conn, output),
        }
    }

    pub fn output_removed(&mut self, conn: &mut Connection<State>, output: WlOutput) {
        match self {
            Self::None => (),
            Self::River(x) => x.output_removed(conn, output),
            #[cfg(feature = "hyprland")]
            Self::Ewu(x) => x.output_removed(conn, output),
        }
    }

    pub fn click_on_tag(
        &mut self,
        conn: &mut Connection<State>,
        output: WlOutput,
        seat: WlSeat,
        tag: &str,
        btn: PointerBtn,
    ) {
        match self {
            Self::None => (),
            Self::River(x) => x.click_on_tag(conn, output, seat, tag, btn),
            #[cfg(feature = "hyprland")]
            Self::Ewu(x) => x.click_on_tag(conn, output, seat, tag, btn),
        }
    }
}

#[derive(Default, Debug)]
pub struct WmInfo {
    pub layout_name: Option<String>,
    pub tags: Vec<Tag>,
}

#[derive(Debug)]
pub struct Tag {
    pub name: String,
    pub is_focused: bool,
    pub is_active: bool,
    pub is_urgent: bool,
}