linux.rs

 1mod dispatcher;
 2mod headless;
 3mod keyboard;
 4mod platform;
 5#[cfg(any(feature = "wayland", feature = "x11"))]
 6mod text_system;
 7#[cfg(feature = "wayland")]
 8mod wayland;
 9#[cfg(feature = "x11")]
10mod x11;
11
12#[cfg(any(feature = "wayland", feature = "x11"))]
13mod xdg_desktop_portal;
14
15pub use dispatcher::*;
16pub(crate) use headless::*;
17pub(crate) use keyboard::*;
18pub(crate) use platform::*;
19#[cfg(any(feature = "wayland", feature = "x11"))]
20pub(crate) use text_system::*;
21#[cfg(feature = "wayland")]
22pub(crate) use wayland::*;
23#[cfg(feature = "x11")]
24pub(crate) use x11::*;
25
26use std::rc::Rc;
27
28/// Returns the default platform implementation for the current OS.
29pub fn current_platform(headless: bool) -> Rc<dyn gpui::Platform> {
30    #[cfg(feature = "x11")]
31    use anyhow::Context as _;
32
33    if headless {
34        return Rc::new(LinuxPlatform {
35            inner: HeadlessClient::new(),
36        });
37    }
38
39    match gpui::guess_compositor() {
40        #[cfg(feature = "wayland")]
41        "Wayland" => Rc::new(LinuxPlatform {
42            inner: WaylandClient::new(),
43        }),
44
45        #[cfg(feature = "x11")]
46        "X11" => Rc::new(LinuxPlatform {
47            inner: X11Client::new()
48                .context("Failed to initialize X11 client.")
49                .unwrap(),
50        }),
51
52        "Headless" => Rc::new(LinuxPlatform {
53            inner: HeadlessClient::new(),
54        }),
55        _ => unreachable!(),
56    }
57}