Skip to main content

gpui_linux/
linux.rs

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