1
0
Fork 0
forked from wry/wry

config: add XWayland enabled option

This commit is contained in:
khyperia 2026-02-17 10:18:20 +01:00 committed by Julian Orth
parent 4ca67772b3
commit 49274fb1c6
13 changed files with 85 additions and 10 deletions

View file

@ -269,6 +269,7 @@ fn start_compositor2(
run_args,
xwayland: XWaylandState {
enabled: Cell::new(true),
running: Cell::new(false),
pidfd: Default::default(),
handler: Default::default(),
queue: Default::default(),

View file

@ -979,6 +979,11 @@ impl ConfigProxyHandler {
Ok(())
}
fn handle_set_x_wayland_enabled(&self, enabled: bool) -> Result<(), CphError> {
self.state.set_xwayland_enabled(enabled);
Ok(())
}
fn handle_set_ui_drag_enabled(&self, enabled: bool) {
self.state.ui_drag_enabled.set(enabled);
}
@ -3369,6 +3374,9 @@ impl ConfigProxyHandler {
ClientMessage::SetFallbackOutputMode { seat, mode } => self
.handle_set_fallback_output_mode(seat, mode)
.wrn("set_fallback_output_mode")?,
ClientMessage::SetXWaylandEnabled { enabled } => self
.handle_set_x_wayland_enabled(enabled)
.wrn("set_x_wayland_enabled")?,
}
Ok(())
}

View file

@ -313,6 +313,7 @@ pub struct ScreenlockState {
pub struct XWaylandState {
pub enabled: Cell<bool>,
pub running: Cell<bool>,
pub pidfd: CloneCell<Option<Rc<OwnedFd>>>,
pub handler: RefCell<Option<SpawnedFuture<()>>>,
pub queue: Rc<AsyncQueue<XWaylandEvent>>,
@ -968,6 +969,24 @@ impl State {
}
}
pub fn stop_xwayland(&self) {
if self.xwayland.running.get() {
return;
}
self.xwayland.handler.take();
}
pub fn set_xwayland_enabled(self: &Rc<Self>, enabled: bool) {
if self.xwayland.enabled.replace(enabled) == enabled {
return;
}
if enabled {
self.start_xwayland();
} else {
self.stop_xwayland();
}
}
pub fn next_serial(&self, client: Option<&Client>) -> u64 {
let serial = self.serial.fetch_add(1);
if let Some(client) = client {

View file

@ -110,6 +110,7 @@ pub async fn manage(state: Rc<State>) {
}
let display = format!(":{}", xsocket.id);
forker.setenv(DISPLAY.as_bytes(), display.as_bytes());
let _unsetenv = on_drop(|| forker.unsetenv(DISPLAY.as_bytes()));
log::info!("Allocated display :{} for Xwayland", xsocket.id);
log::info!("Waiting for connection attempt");
if state.backend.get().import_environment() {
@ -120,12 +121,17 @@ pub async fn manage(state: Rc<State>) {
return;
}
log::info!("Starting Xwayland");
state.xwayland.running.set(true);
if let Err(e) = run(&state, &forker, socket).await {
log::error!("Xwayland failed: {}", ErrorFmt(e));
} else {
log::warn!("Xwayland exited unexpectedly");
}
forker.unsetenv(DISPLAY.as_bytes());
state.xwayland.running.set(false);
if !state.xwayland.enabled.get() {
state.stop_xwayland();
return;
}
}
}