Skip to main content

gdk/
display.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::Display;
4use glib::object::IsA;
5use glib::prelude::*;
6
7#[derive(Debug, PartialEq, Eq, Ord, PartialOrd)]
8pub enum Backend {
9    Wayland,
10    X11,
11    Win32,
12    MacOS,
13    Broadway,
14}
15
16impl Backend {
17    // rustdoc-stripper-ignore-next
18    /// Equivalent to the C macro `GDK_IS_WAYLAND_DISPLAY`
19    #[doc(alias = "GDK_IS_WAYLAND_DISPLAY")]
20    pub fn is_wayland(&self) -> bool {
21        matches!(self, Self::Wayland)
22    }
23
24    // rustdoc-stripper-ignore-next
25    /// Equivalent to the C macro `GDK_IS_X11_DISPLAY`
26    #[doc(alias = "GDK_IS_X11_DISPLAY")]
27    pub fn is_x11(&self) -> bool {
28        matches!(self, Self::X11)
29    }
30
31    // rustdoc-stripper-ignore-next
32    /// Equivalent to the C macro `GDK_IS_WIN32_DISPLAY`
33    #[doc(alias = "GDK_IS_WIN32_DISPLAY")]
34    pub fn is_win32(&self) -> bool {
35        matches!(self, Self::Win32)
36    }
37
38    // rustdoc-stripper-ignore-next
39    /// Equivalent to the C macro `GDK_IS_QUARTZ_DISPLAY`
40    #[doc(alias = "GDK_IS_QUARTZ_DISPLAY")]
41    pub fn is_macos(&self) -> bool {
42        matches!(self, Self::MacOS)
43    }
44
45    // rustdoc-stripper-ignore-next
46    /// Equivalent to the C macro `GDK_IS_BROADWAY_DISPLAY`
47    #[doc(alias = "GDK_IS_BROADWAY_DISPLAY")]
48    pub fn is_broadway(&self) -> bool {
49        matches!(self, Self::Broadway)
50    }
51}
52
53pub trait DisplayExtManual: IsA<Display> + 'static {
54    // rustdoc-stripper-ignore-next
55    /// Get the currently used display backend
56    fn backend(&self) -> Backend {
57        match self.as_ref().type_().name() {
58            "GdkWaylandDisplay" => Backend::Wayland,
59            "GdkX11Display" => Backend::X11,
60            "GdkQuartzDisplay" => Backend::MacOS,
61            "GdkWin32Display" => Backend::Win32,
62            "GdkBroadwayDisplay" => Backend::Broadway,
63            e => panic!("Unsupported display backend {e}"),
64        }
65    }
66}
67
68impl<O: IsA<Display>> DisplayExtManual for O {}