gpui_linux: Fix Wayland activation requests (#64058)

Closes #59397

Wayland activation requests previously shared a single pending-action
slot. Concurrent requests could overwrite that slot, leaving an issued
token unused and Mutter's global launch indicator active until its
timeout.

Each activation token now carries its own pending window, URI, or path
action. This prevents requests from overwriting one another and removes
the resulting unpaired-token error.

Track the latest eligible keyboard or pointer press together with the
surface that received it. Window activation uses that context when
available; without it, it still requests a token for the target surface
so the compositor can indicate that the window wants attention. URI/path
opens use the input context when available and otherwise retain the
tokenless fallback. Launcher-provided startup token handling remains
unchanged.

The approach builds on the investigation and prototype attached to
#59397, but does not combine serials from unrelated Wayland protocols.

Test results:

- `cargo fmt --all -- --check`: passed after formatting the follow-up
changes.
- `cargo test -p gpui_linux --lib`: 50 passed.
- `cargo build -p zed`: passed.
- `./script/clippy -p gpui_linux`: passed (release, all
targets/features, warnings denied). The wrapper skipped its later
optional checks because `cargo-shear` is not installed.
- Current-head (`412dc7f6f6`) cold-start smoke test under isolated
headless Mutter 51.0 with `WAYLAND_DEBUG=client`: two startup activation
requests, two returned tokens, both tokens passed to `activate`, and 37
surface buffer attachments. No unpaired-token error appeared. Startup
intentionally issues activation requests now.
- Earlier manual GNOME testing covered the original implementation,
before the attention-preserving follow-up. A visual GNOME busy-cursor
check, launcher-provided-token launch, new-window shortcut, and
URL-opening retest of the current head remain outstanding; the headless
startup trace does not cover those interactions.

Release Notes:

- Fixed the global busy cursor lingering after Zed opens on GNOME
Wayland.
- [GPUI] Fixed concurrent Wayland activation requests losing their
pending actions and improved keyboard-triggered activation context
tracking.

---------

Co-authored-by: Anthony <hello@anthonyeid.me>
This commit is contained in:
Lex Berezhny
2026-10-28 16:14:18 +00:00
committed by GitHub
parent 2e794a1ea7
commit 4d847859f5
3 changed files with 118 additions and 53 deletions
+57 -40
View File
@@ -92,7 +92,7 @@ use crate::linux::{
wayland::{
clipboard::{Clipboard, DataOffer, FILE_LIST_MIME_TYPE, TEXT_MIME_TYPES},
cursor::Cursor,
serial::{Serial, SerialKind, SerialTracker},
serial::{ActivationContext, Serial, SerialKind, SerialTracker},
to_shape,
window::WaylandWindow,
},
@@ -406,7 +406,6 @@ pub(crate) struct WaylandClientState {
data_offers: Vec<DataOffer<WlDataOffer>>,
primary_data_offer: Option<DataOffer<ZwpPrimarySelectionOfferV1>>,
cursor: Cursor,
pending_activation: Option<PendingActivation>,
startup_activation_token: Option<String>,
/// The environment this connection was made in, without its activation token.
graphical_environment: GraphicalEnvironment,
@@ -657,6 +656,14 @@ impl WaylandClientStatePtr {
self.0.upgrade().unwrap().borrow().serial_tracker.get(kind)
}
pub fn activation_context(&self) -> Option<ActivationContext> {
self.0
.upgrade()?
.borrow()
.serial_tracker
.activation_context()
}
pub fn start_external_drag(
&self,
surface: &wl_surface::WlSurface,
@@ -697,11 +704,6 @@ impl WaylandClientStatePtr {
true
}
pub fn set_pending_activation(&self, window: ObjectId) {
self.0.upgrade().unwrap().borrow_mut().pending_activation =
Some(PendingActivation::Window(window));
}
pub fn enable_ime(&self) {
let client = self.get_client();
let mut state = client.borrow_mut();
@@ -1127,7 +1129,6 @@ impl WaylandConnection {
data_offers: Vec::new(),
primary_data_offer: None,
cursor,
pending_activation: None,
startup_activation_token: activation_token,
graphical_environment: GraphicalEnvironment {
activation_token: None,
@@ -1394,16 +1395,15 @@ impl WaylandConnection {
}
pub(crate) fn open_uri(&self, uri: &str) {
let mut state = self.0.borrow_mut();
if let (Some(activation), Some(window)) = (
let state = self.0.borrow();
if let (Some(activation), Some(context)) = (
state.globals.activation.clone(),
state.mouse_focused_window.clone(),
state.serial_tracker.activation_context(),
) {
state.pending_activation = Some(PendingActivation::Uri(uri.to_string()));
let token = activation.get_activation_token(&state.globals.qh, ());
let serial = state.serial_tracker.get(SerialKind::MousePress);
token.set_serial(serial.as_raw(), &state.wl_seat);
token.set_surface(&window.surface());
let token = activation
.get_activation_token(&state.globals.qh, PendingActivation::Uri(uri.to_string()));
token.set_serial(context.serial.as_raw(), &state.wl_seat);
token.set_surface(&context.requesting_surface);
token.commit();
} else {
let executor = state.common.borrow().background_executor.clone();
@@ -1412,16 +1412,15 @@ impl WaylandConnection {
}
pub(crate) fn reveal_path(&self, path: PathBuf) {
let mut state = self.0.borrow_mut();
if let (Some(activation), Some(window)) = (
let state = self.0.borrow();
if let (Some(activation), Some(context)) = (
state.globals.activation.clone(),
state.mouse_focused_window.clone(),
state.serial_tracker.activation_context(),
) {
state.pending_activation = Some(PendingActivation::Path(path));
let token = activation.get_activation_token(&state.globals.qh, ());
let serial = state.serial_tracker.get(SerialKind::MousePress);
token.set_serial(serial.as_raw(), &state.wl_seat);
token.set_surface(&window.surface());
let token =
activation.get_activation_token(&state.globals.qh, PendingActivation::Path(path));
token.set_serial(context.serial.as_raw(), &state.wl_seat);
token.set_surface(&context.requesting_surface);
token.commit();
} else {
let executor = state.common.borrow().background_executor.clone();
@@ -1932,12 +1931,14 @@ impl Dispatch<xdg_wm_base::XdgWmBase, ()> for WaylandClientStatePtr {
}
}
impl Dispatch<xdg_activation_token_v1::XdgActivationTokenV1, ()> for WaylandClientStatePtr {
impl Dispatch<xdg_activation_token_v1::XdgActivationTokenV1, PendingActivation>
for WaylandClientStatePtr
{
fn event(
this: &mut Self,
token: &xdg_activation_token_v1::XdgActivationTokenV1,
event: <xdg_activation_token_v1::XdgActivationTokenV1 as Proxy>::Event,
_: &(),
pending_activation: &PendingActivation,
_: &Connection,
_: &QueueHandle<Self>,
) {
@@ -1947,21 +1948,21 @@ impl Dispatch<xdg_activation_token_v1::XdgActivationTokenV1, ()> for WaylandClie
if let xdg_activation_token_v1::Event::Done { token } = event {
let executor = state.common.borrow().background_executor.clone();
let environment = state.graphical_environment.clone();
match state.pending_activation.take() {
Some(PendingActivation::Uri(uri)) => {
open_uri_internal(executor, &uri, Some(token), environment)
match pending_activation {
PendingActivation::Uri(uri) => {
open_uri_internal(executor, uri, Some(token), environment)
}
Some(PendingActivation::Path(path)) => {
reveal_path_internal(executor, path, Some(token), environment)
PendingActivation::Path(path) => {
reveal_path_internal(executor, path.clone(), Some(token), environment)
}
Some(PendingActivation::Window(window)) => {
let Some(window) = get_window(&mut state, &window) else {
return;
};
let activation = state.globals.activation.as_ref().unwrap();
activation.activate(token, &window.surface());
PendingActivation::Window(window) => {
let activation = state.globals.activation.clone();
if let (Some(window), Some(activation)) =
(get_window(&mut state, window), activation)
{
activation.activate(token, &window.surface());
}
}
None => log::error!("activation token received with no pending activation"),
}
}
@@ -2150,7 +2151,15 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
..
} => {
if key_state == wl_keyboard::KeyState::Pressed {
state.serial_tracker.update(SerialKind::KeyPress, serial);
let focused_surface = state
.keyboard_focused_window
.as_ref()
.map(|window| window.surface());
state.serial_tracker.update_with_focused_surface(
SerialKind::KeyPress,
serial,
focused_surface,
);
}
let focused_window = state.keyboard_focused_window.clone();
@@ -2510,7 +2519,15 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClientStatePtr {
// Record presses only. Requests referencing this serial (popup grabs,
// interactive moves) are declined when given a release serial.
if button_state == wl_pointer::ButtonState::Pressed {
state.serial_tracker.update(SerialKind::MousePress, serial);
let focused_surface = state
.mouse_focused_window
.as_ref()
.map(|window| window.surface());
state.serial_tracker.update_with_focused_surface(
SerialKind::MousePress,
serial,
focused_surface,
);
}
let button = linux_button_to_gpui(button);
let Some(button) = button else { return };
+47 -4
View File
@@ -1,4 +1,5 @@
use collections::HashMap;
use wayland_client::{Proxy, protocol::wl_surface};
#[derive(Debug, Hash, PartialEq, Eq)]
pub(crate) enum SerialKind {
@@ -27,26 +28,53 @@ impl SelectionSerial {
}
}
/// The user interaction an `xdg_activation_v1` token request must reference.
#[derive(Clone, Debug)]
pub(crate) struct ActivationContext {
pub(crate) serial: Serial,
pub(crate) requesting_surface: wl_surface::WlSurface,
}
#[derive(Debug)]
struct Press {
serial: Serial,
focused_surface: Option<wl_surface::WlSurface>,
}
#[derive(Debug)]
/// Helper for tracking of different serial kinds.
pub(crate) struct SerialTracker {
serials: HashMap<SerialKind, Serial>,
selection_serial: Option<SelectionSerial>,
latest_press: Option<Press>,
}
impl SerialTracker {
pub fn new() -> Self {
Self {
serials: HashMap::default(),
selection_serial: None,
latest_press: None,
}
}
pub fn update(&mut self, kind: SerialKind, value: u32) {
self.update_with_focused_surface(kind, value, None);
}
/// Like [`Self::update`], but for key and pointer presses also records the surface
/// that had focus, which activation token requests must name alongside the serial.
pub fn update_with_focused_surface(
&mut self,
kind: SerialKind,
value: u32,
focused_surface: Option<wl_surface::WlSurface>,
) {
let serial = Serial(value);
if matches!(&kind, SerialKind::KeyPress | SerialKind::MousePress) {
self.selection_serial = Some(SelectionSerial(serial));
self.latest_press = Some(Press {
serial,
focused_surface,
});
}
self.serials.insert(kind, serial);
@@ -60,7 +88,22 @@ impl SerialTracker {
}
pub fn selection_serial(&self) -> Option<SelectionSerial> {
self.selection_serial
self.latest_press
.as_ref()
.map(|press| SelectionSerial(press.serial))
}
/// Returns the latest press if a still-alive surface had focus when it arrived.
pub fn activation_context(&self) -> Option<ActivationContext> {
let press = self.latest_press.as_ref()?;
let surface = press
.focused_surface
.as_ref()
.filter(|surface| surface.is_alive())?;
Some(ActivationContext {
serial: press.serial,
requesting_surface: surface.clone(),
})
}
}
+14 -9
View File
@@ -32,7 +32,7 @@ use wayland_protocols_plasma::blur::client::org_kde_kwin_blur;
use wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1;
use crate::linux::wayland::{display::WaylandDisplay, serial::SerialKind};
use crate::linux::{Globals, Output, WaylandClientStatePtr, get_window};
use crate::linux::{Globals, Output, PendingActivation, WaylandClientStatePtr, get_window};
use gpui::{
AnyWindowHandle, Bounds, Capslock, Decorations, DevicePixels, ExternalDragPayload,
FrameRequestSource, GpuSpecs, Modifiers, Pixels, PlatformAtlas, PlatformDisplay,
@@ -1857,18 +1857,23 @@ impl PlatformWindow for WaylandWindow {
}
fn activate(&self) {
// Try to request an activation token. Even though the activation is likely going to be rejected,
// KWin and Mutter can use the app_id to visually indicate we're requesting attention.
let state = self.borrow();
if let (Some(activation), Some(app_id)) = (&state.globals.activation, state.app_id.clone())
{
state.client.set_pending_activation(state.surface.id());
let token = activation.get_activation_token(&state.globals.qh, ());
// The serial isn't exactly important here, since the activation is probably going to be rejected anyway.
let serial = state.client.get_serial(SerialKind::MousePress);
let token = activation.get_activation_token(
&state.globals.qh,
PendingActivation::Window(state.surface.id()),
);
token.set_app_id(app_id);
token.set_serial(serial.as_raw(), &state.globals.seat);
token.set_surface(&state.surface);
// Without a recent press the compositor won't grant focus, but still request a
// token: KWin and Mutter mark the window as demanding attention and end their
// launch feedback once the token is passed to `activate`.
if let Some(context) = state.client.activation_context() {
token.set_serial(context.serial.as_raw(), &state.globals.seat);
token.set_surface(&context.requesting_surface);
} else {
token.set_surface(&state.surface);
}
token.commit();
}
}