Skip to content

Commit

Permalink
xdg-activation: distinguish activation and urgency requests
Browse files Browse the repository at this point in the history
Check if the app that requested a token has provided a valid input
serial and a focused surface. Downgrade activation request to urgency
otherwise.

This is mostly in line with what other Wayland compositors decided to
do, and offers a better security than the original logic.

(cherry picked from commit d19810e)
  • Loading branch information
alebastr authored and emersion committed Feb 17, 2024
1 parent d91779d commit b4800fb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/sway/desktop/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct launcher_ctx {
struct wl_listener seat_destroy;

bool activated;
bool had_focused_surface;

struct sway_node *node;
struct wl_listener node_destroy;
Expand Down
5 changes: 5 additions & 0 deletions include/sway/tree/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ void view_set_activated(struct sway_view *view, bool activated);
*/
void view_request_activate(struct sway_view *view, struct sway_seat *seat);

/*
* Called when the view requests urgent state
*/
void view_request_urgent(struct sway_view *view);

/**
* If possible, instructs the client to change their decoration mode.
*/
Expand Down
2 changes: 2 additions & 0 deletions sway/desktop/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ struct launcher_ctx *launcher_ctx_create(struct wlr_xdg_activation_token_v1 *tok
ctx->fallback_name = strdup(fallback_name);
ctx->token = token;
ctx->node = node;
// Having surface set means that the focus check in wlroots has passed
ctx->had_focused_surface = token->surface != NULL;

ctx->node_destroy.notify = ctx_handle_node_destroy;
wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy);
Expand Down
6 changes: 6 additions & 0 deletions sway/tree/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ void view_request_activate(struct sway_view *view, struct sway_seat *seat) {
transaction_commit_dirty();
}

void view_request_urgent(struct sway_view *view) {
if (config->focus_on_window_activation != FOWA_NONE) {
view_set_urgent(view, true);
}
}

void view_set_csd_from_server(struct sway_view *view, bool enabled) {
sway_log(SWAY_DEBUG, "Telling view %p to set CSD to %i", view, enabled);
if (view->xdg_decoration) {
Expand Down
5 changes: 4 additions & 1 deletion sway/xdg_activation_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
seat = ctx->token->seat ? ctx->token->seat->data : NULL;
}

if (seat) {
if (seat && ctx->had_focused_surface) {
view_request_activate(view, seat);
} else {
// The token is valid, but cannot be used to activate a window
view_request_urgent(view);
}
}

Expand Down

0 comments on commit b4800fb

Please sign in to comment.