diff --git a/wayvr/src/backend/wayvr/client.rs b/wayvr/src/backend/wayvr/client.rs index 788ddf0d..94f58660 100644 --- a/wayvr/src/backend/wayvr/client.rs +++ b/wayvr/src/backend/wayvr/client.rs @@ -1,4 +1,10 @@ -use std::{io::Read, os::unix::net::UnixStream, path::PathBuf, sync::Arc}; +use std::{ + io::Read, + os::unix::net::UnixStream, + path::PathBuf, + process::{Child, Command}, + sync::Arc, +}; use anyhow::Context; use glam::Vec2; @@ -11,6 +17,7 @@ use smithay::{ reexports::wayland_server::{self, Resource, protocol::wl_surface::WlSurface}, utils::{Logical, Point, SerialCounter}, }; +use wgui::log::LogErr; use xkbcommon::xkb; use crate::backend::wayvr::{ExternalProcessRequest, WayVRTask}; @@ -33,6 +40,8 @@ pub struct WayVRCompositor { pub serial_counter: SerialCounter, pub wayland_env: super::WaylandEnv, + xwayland_satellite: Option, + display: wayland_server::Display, listener: wayland_server::ListeningSocket, @@ -41,6 +50,18 @@ pub struct WayVRCompositor { pub clients: Vec, } +impl Drop for WayVRCompositor { + fn drop(&mut self) { + if let Some(mut child) = self.xwayland_satellite.take() { + unsafe { + libc::kill(child.id() as i32, libc::SIGKILL); + } + // reap the pid + let _ = child.wait(); + } + } +} + fn get_wayvr_env_from_pid(pid: i32) -> anyhow::Result { let path = format!("/proc/{pid}/environ"); let mut env_data = String::new(); @@ -75,12 +96,22 @@ impl WayVRCompositor { ) -> anyhow::Result { let (wayland_env, listener) = create_wayland_listener()?; + let xwayland_satellite = Command::new("xwayland-satellite") + .arg(":20") + .env("WAYLAND_DISPLAY", wayland_env.display_num_string()) + .spawn() + .log_warn( + "Could not start xwayland-satellite. Xwayland apps will not work in native mode", + ) + .ok(); + Ok(Self { state, display, seat_keyboard, seat_pointer, listener, + xwayland_satellite, wayland_env, serial_counter: SerialCounter::new(), clients: Vec::new(),