From 062c63af2b4b32befc9a3001571d46c255acad51 Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 23 Jul 2023 09:04:22 -0400 Subject: [PATCH] feat(xwayland): xwayland feature --- Cargo.toml | 11 +++-------- src/main.rs | 1 + src/nodes/startup.rs | 9 ++++----- src/wayland/compositor.rs | 9 ++++++--- src/wayland/mod.rs | 9 ++++++--- src/wayland/panel_item.rs | 15 ++++++++++++++- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2b590be..980bba0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,9 @@ name = "stardust-xr-server" path = "src/main.rs" [features] -default = ["wayland"] +default = ["wayland", "xwayland"] wayland = ["dep:smithay", "dep:xkbcommon"] +xwayland = ["smithay/xwayland"] profile_tokio = ["dep:console-subscriber", "tokio/tracing"] profile_app = ["dep:tracing-chrome"] @@ -70,13 +71,7 @@ version = "0.16.7" git = "https://github.com/smithay/smithay.git" # Until we get stereokit to understand OES samplers and external textures # path = "../smithay" default-features = false -features = [ - "desktop", - "backend_drm", - "renderer_gl", - "wayland_frontend", - "xwayland", -] +features = ["desktop", "backend_drm", "renderer_gl", "wayland_frontend"] version = "*" optional = true diff --git a/src/main.rs b/src/main.rs index 18a37d6..20b8838 100644 --- a/src/main.rs +++ b/src/main.rs @@ -214,6 +214,7 @@ fn main() { #[cfg(feature = "wayland")] { startup_command.env("WAYLAND_DISPLAY", &wayland.as_ref().unwrap().socket_name); + #[cfg(feature = "xwayland")] startup_command.env( "DISPLAY", format!(":{}", wayland.as_ref().unwrap().xwayland_state.display), diff --git a/src/nodes/startup.rs b/src/nodes/startup.rs index 111b756..9f99f32 100644 --- a/src/nodes/startup.rs +++ b/src/nodes/startup.rs @@ -1,8 +1,6 @@ -use crate::{ - core::client::Client, - wayland::{xwayland::DISPLAY, WAYLAND_DISPLAY}, - STARDUST_INSTANCE, -}; +#[cfg(feature = "xwayland")] +use crate::wayland::xwayland::DISPLAY; +use crate::{core::client::Client, wayland::WAYLAND_DISPLAY, STARDUST_INSTANCE}; use super::{ items::{ItemAcceptor, TypeInfo}, @@ -139,6 +137,7 @@ pub fn get_connection_environment_flex( #[cfg(feature = "wayland")] { var_env_insert!(env, WAYLAND_DISPLAY); + #[cfg(feature = "xwayland")] var_env_insert!(env, DISPLAY); env.insert("GDK_BACKEND".to_string(), "wayland".to_string()); env.insert("QT_QPA_PLATFORM".to_string(), "wayland".to_string()); diff --git a/src/wayland/compositor.rs b/src/wayland/compositor.rs index 232d617..dece87d 100644 --- a/src/wayland/compositor.rs +++ b/src/wayland/compositor.rs @@ -2,11 +2,12 @@ use crate::wayland::surface::CoreSurface; use super::state::{ClientState, WaylandState}; use portable_atomic::{AtomicU32, Ordering}; +#[cfg(feature = "xwayland")] +use smithay::xwayland::XWaylandClientData; use smithay::{ delegate_compositor, reexports::wayland_server::{protocol::wl_surface::WlSurface, Client}, wayland::compositor::{self, CompositorClientState, CompositorHandler, CompositorState}, - xwayland::XWaylandClientData, }; use std::sync::Arc; use tracing::debug; @@ -41,9 +42,11 @@ impl CompositorHandler for WaylandState { fn client_compositor_state<'a>(&self, client: &'a Client) -> &'a CompositorClientState { if let Some(client_state) = client.get_data::() { &client_state.compositor_state - } else if let Some(xwayland_client_data) = client.get_data::() { - &xwayland_client_data.compositor_state } else { + #[cfg(feature = "xwayland")] + if let Some(xwayland_client_data) = client.get_data::() { + return &xwayland_client_data.compositor_state; + } unimplemented!() } } diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 9b5de21..17c91b2 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -8,9 +8,9 @@ mod state; mod surface; // mod xdg_activation; mod xdg_shell; +#[cfg(feature = "xwayland")] pub mod xwayland; -use self::xwayland::XWaylandState; use self::{state::WaylandState, surface::CORE_SURFACES}; use crate::{core::task, wayland::state::ClientState}; use color_eyre::eyre::{ensure, Result}; @@ -70,7 +70,8 @@ pub struct Wayland { renderer: GlesRenderer, dmabuf_rx: UnboundedReceiver, wayland_state: Arc>, - pub xwayland_state: XWaylandState, + #[cfg(feature = "xwayland")] + pub xwayland_state: xwayland::XWaylandState, } impl Wayland { pub fn new() -> Result { @@ -88,7 +89,8 @@ impl Wayland { let (dmabuf_tx, dmabuf_rx) = mpsc::unbounded_channel(); let display = Arc::new(Mutex::new(display)); - let xwayland_state = XWaylandState::create(display.clone(), &display_handle).unwrap(); + #[cfg(feature = "xwayland")] + let xwayland_state = xwayland::XWaylandState::create(display.clone(), &display_handle).unwrap(); let wayland_state = WaylandState::new(display.clone(), display_handle, &renderer, dmabuf_tx); @@ -116,6 +118,7 @@ impl Wayland { renderer, dmabuf_rx, wayland_state, + #[cfg(feature = "xwayland")] xwayland_state, }) } diff --git a/src/wayland/panel_item.rs b/src/wayland/panel_item.rs index ada61f0..b9fb4c2 100644 --- a/src/wayland/panel_item.rs +++ b/src/wayland/panel_item.rs @@ -40,8 +40,11 @@ use smithay::{ backend::Credentials, protocol::wl_surface::WlSurface, Resource, Weak as WlWeak, }, }, - utils::Rectangle, wayland::compositor, +}; +#[cfg(feature = "xwayland")] +use smithay::{ + utils::Rectangle, xwayland::{xwm::X11SurfaceError, X11Surface}, }; use stardust_xr::schemas::flex::{deserialize, serialize}; @@ -331,11 +334,14 @@ impl WaylandBackend { *self.cursor.lock() = surface.map(|surf| surf.downgrade()); } } + +#[cfg(feature = "xwayland")] #[derive(Debug)] pub struct X11Backend { pub toplevel_parent: Option, pub toplevel: X11Surface, } +#[cfg(feature = "xwayland")] impl X11Backend { fn configure_toplevel( &self, @@ -377,6 +383,7 @@ impl X11Backend { #[derive(Debug)] pub enum Backend { Wayland(WaylandBackend), + #[cfg(feature = "xwayland")] X11(X11Backend), } @@ -475,6 +482,7 @@ impl PanelItem { fn toplevel_wl_surface(&self) -> Option { match &self.backend { Backend::Wayland(w) => w.toplevel_wl_surface(), + #[cfg(feature = "xwayland")] Backend::X11(x) => x.toplevel.wl_surface(), } } @@ -491,6 +499,7 @@ impl PanelItem { fn wl_surface_from_id(&self, id: &SurfaceID) -> Option { match &self.backend { Backend::Wayland(w) => w.wl_surface_from_id(id), + #[cfg(feature = "xwayland")] Backend::X11(x) => x.wl_surface_from_id(id), } } @@ -631,6 +640,7 @@ impl PanelItem { keymap, match &panel_item.backend { Backend::Wayland(w) => w.input_surfaces(), + #[cfg(feature = "xwayland")] Backend::X11(_) => panel_item .toplevel_wl_surface() .map(|s| vec![s]) @@ -671,6 +681,7 @@ impl PanelItem { match &panel_item.backend { Backend::Wayland(w) => w.configure_toplevel(info.size, info.states, info.bounds), + #[cfg(feature = "xwayland")] Backend::X11(x) => x.configure_toplevel(info.size, info.states)?, } Ok(()) @@ -706,6 +717,7 @@ impl PanelItem { let Some(node) = self.node.upgrade() else { return }; let Ok(data) = (match &self.backend { Backend::Wayland(w) => w.serialize_toplevel(), + #[cfg(feature = "xwayland")] Backend::X11(x) => x.serialize_toplevel(), }) else {return}; let _ = node.send_remote_signal("commit_toplevel", &data); @@ -755,6 +767,7 @@ impl ItemSpecialization for PanelItem { )) .ok() } + #[cfg(feature = "xwayland")] Backend::X11(x) => { let size = ( x.toplevel.geometry().size.w as u32,