Skip to main content

gpui_linux/
linux.rs

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