Skip to content

ui: Use the caller's activation token when showing the dialog - #262

Merged
iinuwa merged 1 commit into
linux-credentials:mainfrom
kpanuragh:activation-token
Nov 13, 2026
Merged

iinuwa merged 1 commit into
linux-credentials:mainfrom
kpanuragh:activation-token

Conversation

@kpanuragh

Copy link
Copy Markdown
Contributor

Closes #152.

The daemon already forwards the activation token from the portal request in PortalBackendOptions.activation_token, but the UI never used it. This PR:

  • adds activation_token to ViewRequest. An empty string counts as no token.
  • passes it through run_gui and start_gtk_app to CredentialsUi, next to parent_window.
  • calls window.set_startup_id(&token) before the window is presented. On map, GTK passes the token to gdk_toplevel_set_startup_id, which becomes xdg_activation_v1.activate(token, surface) on Wayland. The token is taken once, because activation tokens are single-use and each request creates a new CredentialsUi anyway.

Testing

I ran the dev credentialsd-ui with WAYLAND_DEBUG=1 on Hyprland and sent CreateSession from a small client:

  • Token credsd-test-token-1, no parent: the log shows xdg_activation_v1.activate("credsd-test-token-1", wl_surface#44).
  • Token plus a wayland: parent handle: import_toplevel(...), then activate("credsd-test-token-2", ...). This is the path where the window is already realized before set_startup_id.
  • Empty token: only GTK's own self-requested token is activated, as before this change.
  • cargo test -p credentialsd-ui (adds tests for passing the token through and for missing or empty tokens), cargo clippy, cargo fmt --check: clean.

I didn't use a real token from a background caller window, so I haven't seen the compositor grant focus because of it.

On X11, set_startup_id sets _NET_STARTUP_ID. That's harmless, but an xdg-activation token there won't help focus.

Unrelated: a panic I hit while testing

If the caller disconnects right after CreateSession (a one-shot busctl call, for example), the request is cancelled before the window exists. credentialsd-ui then aborts at credentialsd-ui/src/gui/view_model/gtk/mod.rs:121 with called Result::unwrap() on an Err value: SendError(..), raised inside a function that cannot unwind. The bug is already on main, so I left it out of this PR. I can open an issue or a fix if you want.

The daemon already forwards the activation token from the portal
request to the UI, but the UI dropped it. Pass it through to the GTK
window with set_startup_id() before presenting it, so GTK hands it to
the compositor (xdg_activation_v1.activate on Wayland). This lets the
dialog take focus when the requesting window is in the background and
the compositor would otherwise refuse it.

Empty tokens are treated as no token.

Closes linux-credentials#152.
@iinuwa

iinuwa commented Nov 13, 2026

Copy link
Copy Markdown
Member

Thanks!

credentialsd-ui then aborts at credentialsd-ui/src/gui/view_model/gtk/mod.rs:121 with called Result::unwrap() on an Err value: SendError(..)

Yeah, we've got to go through and remove unwraps. We can probably just log and ignore, as the event loop on the receiver would just end and stop the program anyway. an issue or PR for this one is welcome!

1 similar comment
@iinuwa

iinuwa commented Nov 13, 2026

Copy link
Copy Markdown
Member

Thanks!

credentialsd-ui then aborts at credentialsd-ui/src/gui/view_model/gtk/mod.rs:121 with called Result::unwrap() on an Err value: SendError(..)

Yeah, we've got to go through and remove unwraps. We can probably just log and ignore, as the event loop on the receiver would just end and stop the program anyway. an issue or PR for this one is welcome!

@iinuwa
iinuwa merged commit 2ab8954 into linux-credentials:main Nov 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use activation token in backend

2 participants