feat(xwayland): xwayland feature
This commit is contained in:
11
Cargo.toml
11
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
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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::<ClientState>() {
|
||||
&client_state.compositor_state
|
||||
} else if let Some(xwayland_client_data) = client.get_data::<XWaylandClientData>() {
|
||||
&xwayland_client_data.compositor_state
|
||||
} else {
|
||||
#[cfg(feature = "xwayland")]
|
||||
if let Some(xwayland_client_data) = client.get_data::<XWaylandClientData>() {
|
||||
return &xwayland_client_data.compositor_state;
|
||||
}
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Dmabuf>,
|
||||
wayland_state: Arc<Mutex<WaylandState>>,
|
||||
pub xwayland_state: XWaylandState,
|
||||
#[cfg(feature = "xwayland")]
|
||||
pub xwayland_state: xwayland::XWaylandState,
|
||||
}
|
||||
impl Wayland {
|
||||
pub fn new() -> Result<Self> {
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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<X11Surface>,
|
||||
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<WlSurface> {
|
||||
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<WlSurface> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user