summaryrefslogtreecommitdiff
path: root/src/wm_info_provider.rs
blob: 4e2731204c9de2c967301b505f562030852c9986 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use std::any::Any;

use wayrs_client::Connection;

use crate::config::WmConfig;
use crate::event_loop::EventLoop;
use crate::output::Output;
use crate::pointer_btn::PointerBtn;
use crate::protocol::*;
use crate::state::State;

mod dummy;
pub use dummy::*;

#[cfg(feature = "river")]
mod river;
#[cfg(feature = "river")]
pub use river::*;

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

#[cfg(feature = "niri")]
mod niri;
#[cfg(feature = "niri")]
pub use niri::*;

#[cfg(feature = "mango")]
mod mango;
#[cfg(feature = "mango")]
pub use mango::*;

pub trait WmInfoProvider: Any {
    fn register(&self, _: &mut EventLoop) {}

    fn new_ouput(&mut self, _: &mut Connection<State>, _: &Output) {}
    fn output_removed(&mut self, _: &mut Connection<State>, _: &Output) {}

    fn get_tags(&self, _: &Output) -> Vec<Tag> {
        Vec::new()
    }
    fn get_layout_name(&self, _: &Output) -> Option<String> {
        None
    }
    fn get_mode_name(&self, _: &Output) -> Option<String> {
        None
    }
    fn get_focused_window(&self, _: &Output) -> Option<FocusedWindow> {
        None
    }
    fn get_output_position(&self, _: &Output) -> Option<(i32, i32)> {
        None
    }

    fn click_on_tag(
        &mut self,
        _conn: &mut Connection<State>,
        _output: &Output,
        _seat: WlSeat,
        _tag_id: Option<u32>,
        _btn: PointerBtn,
    ) {
    }
}

#[cfg_attr(not(feature = "river"), allow(unused_variables))]
pub fn bind(conn: &mut Connection<State>, config: &WmConfig) -> Box<dyn WmInfoProvider> {
    #[cfg(feature = "mango")]
    if let Some(mango) = MangoInfoProvider::new() {
        return Box::new(mango);
    }

    #[cfg(feature = "river")]
    if let Some(river) = RiverInfoProvider::bind(conn, config) {
        return Box::new(river);
    }

    #[cfg(feature = "hyprland")]
    if let Some(hyprland) = HyprlandInfoProvider::new() {
        return Box::new(hyprland);
    }

    #[cfg(feature = "niri")]
    if let Some(niri) = NiriInfoProvider::new() {
        return Box::new(niri);
    }

    Box::new(DummyInfoProvider)
}

#[derive(Debug, Clone, PartialEq)]
pub struct FocusedWindow {
    pub app_id: String,
    pub title: String,
}

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