Skip to content

Commit b4800fb

Browse files
alebastremersion
authored andcommitted
xdg-activation: distinguish activation and urgency requests
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)
1 parent d91779d commit b4800fb

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

Diff for: include/sway/desktop/launcher.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct launcher_ctx {
1414
struct wl_listener seat_destroy;
1515

1616
bool activated;
17+
bool had_focused_surface;
1718

1819
struct sway_node *node;
1920
struct wl_listener node_destroy;

Diff for: include/sway/tree/view.h

+5
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ void view_set_activated(struct sway_view *view, bool activated);
277277
*/
278278
void view_request_activate(struct sway_view *view, struct sway_seat *seat);
279279

280+
/*
281+
* Called when the view requests urgent state
282+
*/
283+
void view_request_urgent(struct sway_view *view);
284+
280285
/**
281286
* If possible, instructs the client to change their decoration mode.
282287
*/

Diff for: sway/desktop/launcher.c

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ struct launcher_ctx *launcher_ctx_create(struct wlr_xdg_activation_token_v1 *tok
216216
ctx->fallback_name = strdup(fallback_name);
217217
ctx->token = token;
218218
ctx->node = node;
219+
// Having surface set means that the focus check in wlroots has passed
220+
ctx->had_focused_surface = token->surface != NULL;
219221

220222
ctx->node_destroy.notify = ctx_handle_node_destroy;
221223
wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy);

Diff for: sway/tree/view.c

+6
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ void view_request_activate(struct sway_view *view, struct sway_seat *seat) {
399399
transaction_commit_dirty();
400400
}
401401

402+
void view_request_urgent(struct sway_view *view) {
403+
if (config->focus_on_window_activation != FOWA_NONE) {
404+
view_set_urgent(view, true);
405+
}
406+
}
407+
402408
void view_set_csd_from_server(struct sway_view *view, bool enabled) {
403409
sway_log(SWAY_DEBUG, "Telling view %p to set CSD to %i", view, enabled);
404410
if (view->xdg_decoration) {

Diff for: sway/xdg_activation_v1.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
4343
seat = ctx->token->seat ? ctx->token->seat->data : NULL;
4444
}
4545

46-
if (seat) {
46+
if (seat && ctx->had_focused_surface) {
4747
view_request_activate(view, seat);
48+
} else {
49+
// The token is valid, but cannot be used to activate a window
50+
view_request_urgent(view);
4851
}
4952
}
5053

0 commit comments

Comments
 (0)