aboutsummaryrefslogtreecommitdiff
path: root/src/backend/mod.rs
blob: 8a59e6f3e6e7a9186fab76fa7da5448423ebd226 (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
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
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::output::Output;
use smithay::wayland::dmabuf::DmabufFeedback;

use crate::input::CompositorMod;
use crate::niri::OutputRenderElements;
use crate::Niri;

pub mod tty;
pub use tty::Tty;

pub mod winit;
pub use winit::Winit;

pub enum Backend {
    Tty(Tty),
    Winit(Winit),
}

impl Backend {
    pub fn init(&mut self, niri: &mut Niri) {
        match self {
            Backend::Tty(tty) => tty.init(niri),
            Backend::Winit(winit) => winit.init(niri),
        }
    }

    pub fn seat_name(&self) -> String {
        match self {
            Backend::Tty(tty) => tty.seat_name(),
            Backend::Winit(winit) => winit.seat_name(),
        }
    }

    pub fn renderer(&mut self) -> &mut GlesRenderer {
        match self {
            Backend::Tty(tty) => tty.renderer(),
            Backend::Winit(winit) => winit.renderer(),
        }
    }

    pub fn render(
        &mut self,
        niri: &mut Niri,
        output: &Output,
        elements: &[OutputRenderElements<GlesRenderer>],
    ) -> Option<&DmabufFeedback> {
        match self {
            Backend::Tty(tty) => tty.render(niri, output, elements),
            Backend::Winit(winit) => winit.render(niri, output, elements),
        }
    }

    pub fn mod_key(&self) -> CompositorMod {
        match self {
            Backend::Tty(_) => CompositorMod::Super,
            Backend::Winit(_) => CompositorMod::Alt,
        }
    }

    pub fn change_vt(&mut self, vt: i32) {
        match self {
            Backend::Tty(tty) => tty.change_vt(vt),
            Backend::Winit(_) => (),
        }
    }

    pub fn suspend(&mut self) {
        match self {
            Backend::Tty(tty) => tty.suspend(),
            Backend::Winit(_) => (),
        }
    }

    pub fn toggle_debug_tint(&mut self) {
        match self {
            Backend::Tty(tty) => tty.toggle_debug_tint(),
            Backend::Winit(winit) => winit.toggle_debug_tint(),
        }
    }

    pub fn tty(&mut self) -> &mut Tty {
        if let Self::Tty(v) = self {
            v
        } else {
            panic!("backend is not Tty");
        }
    }

    pub fn winit(&mut self) -> &mut Winit {
        if let Self::Winit(v) = self {
            v
        } else {
            panic!("backend is not Winit")
        }
    }
}