xwayland: Handle _NET_ACTIVE_WINDOW client messages

Allow X11 clients to activate a window.

This shares the logic with xdg-activation. It might make sense to handle
the urgent hint on an X11 Window natively, but for now this just marks a
workspace as urgent on activation in the same way xdg-activation does.
This commit is contained in:
Ian Douglas Scott 2025-11-25 14:37:48 -08:00 • committed by Victoria Brekenfeld
parent 8fc7f0809f
commit cf55b6c899
2 changed files with 139 additions and 114 deletions

View file

@ -106,22 +106,39 @@ impl XdgActivationHandler for State {
let Some(context) = token_data.user_data.get::<ActivationContext>() else { let Some(context) = token_data.user_data.get::<ActivationContext>() else {
return; return;
}; };
let mut shell = self.common.shell.write();
match context { match context {
ActivationContext::UrgentOnly => { ActivationContext::UrgentOnly => {
let shell = self.common.shell.write();
if let Some((workspace, _output)) = shell.workspace_for_surface(&surface) { if let Some((workspace, _output)) = shell.workspace_for_surface(&surface) {
let mut workspace_guard = self.common.workspace_state.update(); let mut workspace_guard = self.common.workspace_state.update();
workspace_guard.add_workspace_state(&workspace, WState::Urgent); workspace_guard.add_workspace_state(&workspace, WState::Urgent);
} }
} }
ActivationContext::Workspace(_) => { ActivationContext::Workspace(_) => {
self.activate_surface(
&surface,
Some((ActivationKey::Wayland(surface.clone()), *context)),
);
}
}
}
}
impl State {
pub fn activate_surface(
&mut self,
surface: &WlSurface,
pending_activation: Option<(ActivationKey, ActivationContext)>,
) {
let mut shell = self.common.shell.write();
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
let current_output = seat.active_output(); let current_output = seat.active_output();
if let Some(element) = shell.element_for_surface(&surface).cloned() { if let Some(element) = shell.element_for_surface(surface).cloned() {
if element.is_minimized() { if element.is_minimized() {
shell.unminimize_request(&surface, &seat, &self.common.event_loop_handle); shell.unminimize_request(surface, &seat, &self.common.event_loop_handle);
} }
let Some((element_output, element_workspace)) = shell let Some((element_output, element_workspace)) = shell
@ -161,7 +178,7 @@ impl XdgActivationHandler for State {
if let Some((window, _)) = element.windows().find(|(window, _)| { if let Some((window, _)) = element.windows().find(|(window, _)| {
let mut found = false; let mut found = false;
window.with_surfaces(|wl_surface, _| { window.with_surfaces(|wl_surface, _| {
if wl_surface == &surface { if wl_surface == surface {
found = true; found = true;
} }
}); });
@ -175,7 +192,7 @@ impl XdgActivationHandler for State {
} }
if seat.get_keyboard().unwrap().current_focus() != Some(element.clone().into()) if seat.get_keyboard().unwrap().current_focus() != Some(element.clone().into())
&& current_workspace.is_tiled(&surface) && current_workspace.is_tiled(surface)
{ {
for mapped in current_workspace for mapped in current_workspace
.mapped() .mapped()
@ -224,14 +241,10 @@ impl XdgActivationHandler for State {
let mut workspace_guard = self.common.workspace_state.update(); let mut workspace_guard = self.common.workspace_state.update();
workspace_guard.add_workspace_state(&workspace, WState::Urgent); workspace_guard.add_workspace_state(&workspace, WState::Urgent);
} }
} else { } else if let Some((activation_key, context)) = pending_activation {
shell shell.pending_activations.insert(activation_key, context);
.pending_activations
.insert(ActivationKey::Wayland(surface), *context);
}; };
} }
}
}
} }
delegate_xdg_activation!(State); delegate_xdg_activation!(State);

View file

@ -1110,6 +1110,18 @@ impl XwmHandler for State {
} }
} }
fn active_window_request(
&mut self,
_xwm: XwmId,
window: X11Surface,
_timestamp: u32,
_currently_active_window: Option<X11Surface>,
) {
if let Some(surface) = window.wl_surface() {
self.activate_surface(&surface, None);
}
}
fn send_selection( fn send_selection(
&mut self, &mut self,
_xwm: XwmId, _xwm: XwmId,