aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Aleksei Bavshin <alebastr89@gmail.com>2023-12-26 22:26:02 -0800
committerLibravatar Simon Ser <contact@emersion.fr>2024-02-17 14:27:05 +0100
commitb4800fbc90f17ed6924ce59b7d84cad38748c511 (patch)
tree444def96b49e543cde88272456b108aed3df2847
parentlauncher: track the seat in the launcher ctx (diff)
downloadsway-b4800fbc90f17ed6924ce59b7d84cad38748c511.tar.gz
sway-b4800fbc90f17ed6924ce59b7d84cad38748c511.tar.zst
sway-b4800fbc90f17ed6924ce59b7d84cad38748c511.zip
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 d19810eba8959f052d91fd6609cef6adf36b3951)
-rw-r--r--include/sway/desktop/launcher.h1
-rw-r--r--include/sway/tree/view.h5
-rw-r--r--sway/desktop/launcher.c2
-rw-r--r--sway/tree/view.c6
-rw-r--r--sway/xdg_activation_v1.c5
5 files changed, 18 insertions, 1 deletions
diff --git a/include/sway/desktop/launcher.h b/include/sway/desktop/launcher.h
index ad465a9e..412068a9 100644
--- a/include/sway/desktop/launcher.h
+++ b/include/sway/desktop/launcher.h
@@ -14,6 +14,7 @@ struct launcher_ctx {
14 struct wl_listener seat_destroy; 14 struct wl_listener seat_destroy;
15 15
16 bool activated; 16 bool activated;
17 bool had_focused_surface;
17 18
18 struct sway_node *node; 19 struct sway_node *node;
19 struct wl_listener node_destroy; 20 struct wl_listener node_destroy;
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 960f9d71..c0e5ad9b 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -277,6 +277,11 @@ void view_set_activated(struct sway_view *view, bool activated);
277 */ 277 */
278void view_request_activate(struct sway_view *view, struct sway_seat *seat); 278void view_request_activate(struct sway_view *view, struct sway_seat *seat);
279 279
280/*
281 * Called when the view requests urgent state
282 */
283void view_request_urgent(struct sway_view *view);
284
280/** 285/**
281 * If possible, instructs the client to change their decoration mode. 286 * If possible, instructs the client to change their decoration mode.
282 */ 287 */
diff --git a/sway/desktop/launcher.c b/sway/desktop/launcher.c
index 4a4255d7..0c02b997 100644
--- a/sway/desktop/launcher.c
+++ b/sway/desktop/launcher.c
@@ -216,6 +216,8 @@ struct launcher_ctx *launcher_ctx_create(struct wlr_xdg_activation_token_v1 *tok
216 ctx->fallback_name = strdup(fallback_name); 216 ctx->fallback_name = strdup(fallback_name);
217 ctx->token = token; 217 ctx->token = token;
218 ctx->node = node; 218 ctx->node = node;
219 // Having surface set means that the focus check in wlroots has passed
220 ctx->had_focused_surface = token->surface != NULL;
219 221
220 ctx->node_destroy.notify = ctx_handle_node_destroy; 222 ctx->node_destroy.notify = ctx_handle_node_destroy;
221 wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy); 223 wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy);
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 00dc4721..65ca0c9c 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -399,6 +399,12 @@ void view_request_activate(struct sway_view *view, struct sway_seat *seat) {
399 transaction_commit_dirty(); 399 transaction_commit_dirty();
400} 400}
401 401
402void 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
402void view_set_csd_from_server(struct sway_view *view, bool enabled) { 408void view_set_csd_from_server(struct sway_view *view, bool enabled) {
403 sway_log(SWAY_DEBUG, "Telling view %p to set CSD to %i", view, enabled); 409 sway_log(SWAY_DEBUG, "Telling view %p to set CSD to %i", view, enabled);
404 if (view->xdg_decoration) { 410 if (view->xdg_decoration) {
diff --git a/sway/xdg_activation_v1.c b/sway/xdg_activation_v1.c
index 399d81cd..3a035972 100644
--- a/sway/xdg_activation_v1.c
+++ b/sway/xdg_activation_v1.c
@@ -43,8 +43,11 @@ void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
43 seat = ctx->token->seat ? ctx->token->seat->data : NULL; 43 seat = ctx->token->seat ? ctx->token->seat->data : NULL;
44 } 44 }
45 45
46 if (seat) { 46 if (seat && ctx->had_focused_surface) {
47 view_request_activate(view, seat); 47 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);
48 } 51 }
49} 52}
50 53