Skip to main content

gpui_linux/
linux.rs

1mod dispatcher;
2mod display_connection;
3mod headless;
4mod keyboard;
5mod platform;
6#[cfg(any(feature = "wayland", feature = "x11"))]
7mod power;
8mod system_notifications;
9#[cfg(any(feature = "wayland", feature = "x11"))]
10mod text_system;
11#[cfg(feature = "wayland")]
12mod wayland;
13#[cfg(feature = "x11")]
14mod x11;
15
16#[cfg(any(feature = "wayland", feature = "x11"))]
17mod xdg_desktop_portal;
18
19pub use dispatcher::*;
20pub(crate) use display_connection::{Backend, DisplayConnection, select_backend};
21pub(crate) use headless::*;
22pub(crate) use keyboard::*;
23pub(crate) use platform::*;
24#[cfg(any(feature = "wayland", feature = "x11"))]
25pub(crate) use text_system::*;
26#[cfg(feature = "wayland")]
27pub(crate) use wayland::*;
28#[cfg(feature = "x11")]
29pub(crate) use x11::*;
30
31use std::rc::Rc;
32
33use gpui::WindowingModes;
34
35/// Returns the default platform implementation for the current OS.
36///
37/// A windowed platform connects to the display server the process environment names, or starts
38/// headless when it names none, and can switch between those modes later. A headless platform
39/// stays headless.
40pub fn current_platform(headless: bool) -> Rc<dyn gpui::Platform> {
41    if headless || std::env::var_os("ZED_HEADLESS").is_some() {
42        linux_platform(WindowingModes::HEADLESS)
43    } else {
44        linux_platform(WindowingModes::all())
45    }
46}
47
48/// Returns a platform that may switch among `allowed_modes`.
49///
50/// It starts windowed in the process's own environment, or headless if that names no allowed
51/// display server. Set another initial mode with [`gpui::Application::with_windowing`].
52pub fn linux_platform(allowed_modes: WindowingModes) -> Rc<dyn gpui::Platform> {
53    Rc::new(LinuxPlatform::new(allowed_modes))
54}