StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | // Re-export a couple winit types and modules as the concrete implementations |
| 2 | // for the linux platform. |
| 3 | pub use crate::windowing::winit::app::App; |
| 4 | |
| 5 | use crate::{ |
| 6 | windowing::{self, WindowingSystem}, |
| 7 | AppContext, |
| 8 | }; |
| 9 | |
| 10 | use super::{app::AppBackend, AsInnerMut}; |
| 11 | |
| 12 | /// An extension trait defining additional configurability for |
| 13 | /// applications when running on Linux. |
| 14 | pub trait AppBuilderExt { |
| 15 | /// Sets the value to use for WM_CLASS (when running under X11) or app_id |
| 16 | /// (when running under Wayland). |
| 17 | /// |
| 18 | /// This is used to identify the application and link it properly to its |
| 19 | /// .desktop file and associated resources (like app icons). |
| 20 | fn set_window_class(&mut self, window_class: String); |
| 21 | |
| 22 | /// Whether or not to force the use of XWayland for users running Wayland. |
| 23 | fn force_x11(&mut self, force_x11: bool); |
| 24 | } |
| 25 | |
| 26 | impl AppBuilderExt for super::AppBuilder { |
| 27 | fn set_window_class(&mut self, window_class: String) { |
| 28 | match self.as_inner_mut() { |
| 29 | AppBackend::CurrentPlatform(app) => app.set_window_class(window_class), |
| 30 | AppBackend::Headless(_) => (), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | fn force_x11(&mut self, force_x11: bool) { |
| 35 | match self.as_inner_mut() { |
| 36 | AppBackend::CurrentPlatform(app) => app.force_x11(force_x11), |
| 37 | AppBackend::Headless(_) => (), |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /// Retrieves the windowing system that the user is running before the event loop is created. |
| 43 | pub fn user_windowing_system() -> WindowingSystem { |
| 44 | // This mirrors winit's logic [here](https://github.com/rust-windowing/winit/blob/4cd6877e8e19e7e1ba957a409394dca1af4afcdd/src/platform_impl/linux/mod.rs#L735-L745). |
| 45 | if std::env::var("WAYLAND_DISPLAY") |
| 46 | .ok() |
| 47 | .filter(|var| !var.is_empty()) |
| 48 | .or_else(|| std::env::var("WAYLAND_SOCKET").ok()) |
| 49 | .filter(|var| !var.is_empty()) |
| 50 | .is_some() |
| 51 | { |
| 52 | WindowingSystem::Wayland |
| 53 | } else { |
| 54 | WindowingSystem::X11 |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | pub fn is_wsl() -> bool { |
| 59 | use std::sync::OnceLock; |
| 60 | static IS_WSL: OnceLock<bool> = OnceLock::new(); |
| 61 | IS_WSL |
| 62 | .get_or_init(|| std::path::Path::new("/proc/sys/fs/binfmt_misc/WSLInterop").exists()) |
| 63 | .to_owned() |
| 64 | } |
| 65 | |
| 66 | pub fn is_wayland_env_var_set() -> bool { |
| 67 | std::env::var_os("WARP_ENABLE_WAYLAND") |
| 68 | .is_some_and(|warp_enable_wayland| warp_enable_wayland.eq_ignore_ascii_case("1")) |
| 69 | } |
| 70 | |
| 71 | pub fn windowing_system_is_customizable(app: &AppContext) -> bool { |
| 72 | !is_wayland_env_var_set() |
| 73 | && app |
| 74 | .windows() |
| 75 | .windowing_system() |
| 76 | .is_some_and(|windowing_system| { |
| 77 | matches!( |
| 78 | windowing_system, |
| 79 | windowing::System::X11 { is_x_wayland: true } | windowing::System::Wayland |
| 80 | ) |
| 81 | }) |
| 82 | } |
| 83 |