Skip to main content

gpui_linux/
linux.rs

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