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