1mod dispatcher;
2mod headless;
3mod keyboard;
4mod platform;
5mod system_notifications;
6#[cfg(any(feature = "wayland", feature = "x11"))]
7mod text_system;
8#[cfg(feature = "wayland")]
9mod wayland;
10#[cfg(feature = "x11")]
11mod x11;
12
13#[cfg(any(feature = "wayland", feature = "x11"))]
14mod xdg_desktop_portal;
15
16pub use dispatcher::*;
17pub(crate) use headless::*;
18pub(crate) use keyboard::*;
19pub(crate) use platform::*;
20pub use platform::gpu_preference_from_env;
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
31pub fn current_platform(headless: bool) -> Rc<dyn gpui_platform::Platform> {
33 #[cfg(feature = "x11")]
34 use anyhow::Context as _;
35
36 if headless {
37 return Rc::new(LinuxPlatform {
38 inner: HeadlessClient::new(),
39 });
40 }
41
42 match gpui_platform::guess_compositor() {
43 #[cfg(feature = "wayland")]
44 "Wayland" => Rc::new(LinuxPlatform {
45 inner: WaylandClient::new(),
46 }),
47
48 #[cfg(feature = "x11")]
49 "X11" => Rc::new(LinuxPlatform {
50 inner: X11Client::new()
51 .context("Failed to initialize X11 client.")
52 .unwrap(),
53 }),
54
55 "Headless" => Rc::new(LinuxPlatform {
56 inner: HeadlessClient::new(),
57 }),
58 _ => unreachable!(
59 r#"At least one of the "wayland" or "x11" features must be enabled on gpui_linux or gpui."#
60 ),
61 }
62}