diff options
Diffstat (limited to 'sway/xdg_activation_v1.c')
-rw-r--r-- | sway/xdg_activation_v1.c | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/sway/xdg_activation_v1.c b/sway/xdg_activation_v1.c index 6c70c785..b7c80dd4 100644 --- a/sway/xdg_activation_v1.c +++ b/sway/xdg_activation_v1.c | |||
@@ -1,20 +1,65 @@ | |||
1 | #include <wlr/types/wlr_xdg_activation_v1.h> | 1 | #include <wlr/types/wlr_xdg_activation_v1.h> |
2 | #include <wlr/types/wlr_xdg_shell.h> | ||
3 | #include "sway/desktop/launcher.h" | ||
2 | #include "sway/tree/view.h" | 4 | #include "sway/tree/view.h" |
5 | #include "sway/tree/workspace.h" | ||
3 | 6 | ||
4 | void xdg_activation_v1_handle_request_activate(struct wl_listener *listener, | 7 | void xdg_activation_v1_handle_request_activate(struct wl_listener *listener, |
5 | void *data) { | 8 | void *data) { |
6 | const struct wlr_xdg_activation_v1_request_activate_event *event = data; | 9 | const struct wlr_xdg_activation_v1_request_activate_event *event = data; |
7 | 10 | ||
8 | if (!wlr_surface_is_xdg_surface(event->surface)) { | 11 | struct wlr_xdg_surface *xdg_surface = |
12 | wlr_xdg_surface_try_from_wlr_surface(event->surface); | ||
13 | if (xdg_surface == NULL) { | ||
9 | return; | 14 | return; |
10 | } | 15 | } |
11 | |||
12 | struct wlr_xdg_surface *xdg_surface = | ||
13 | wlr_xdg_surface_from_wlr_surface(event->surface); | ||
14 | struct sway_view *view = xdg_surface->data; | 16 | struct sway_view *view = xdg_surface->data; |
15 | if (!xdg_surface->mapped || view == NULL) { | 17 | if (view == NULL) { |
18 | return; | ||
19 | } | ||
20 | |||
21 | struct launcher_ctx *ctx = event->token->data; | ||
22 | if (ctx == NULL) { | ||
23 | return; | ||
24 | } | ||
25 | |||
26 | if (!xdg_surface->surface->mapped) { | ||
27 | // This is a startup notification. If we are tracking it, the data | ||
28 | // field is a launcher_ctx. | ||
29 | if (ctx->activated) { | ||
30 | // This ctx has already been activated and cannot be used again | ||
31 | // for a startup notification. It will be destroyed | ||
32 | return; | ||
33 | } else { | ||
34 | ctx->activated = true; | ||
35 | view_assign_ctx(view, ctx); | ||
36 | } | ||
16 | return; | 37 | return; |
17 | } | 38 | } |
18 | 39 | ||
19 | view_request_activate(view); | 40 | // This is an activation request. If this context is internal we have ctx->seat. |
41 | struct sway_seat *seat = ctx->seat; | ||
42 | if (!seat) { | ||
43 | // Otherwise, use the seat indicated by the launcher client in set_serial | ||
44 | seat = ctx->token->seat ? ctx->token->seat->data : NULL; | ||
45 | } | ||
46 | |||
47 | if (seat && ctx->had_focused_surface) { | ||
48 | view_request_activate(view, seat); | ||
49 | } else { | ||
50 | // The token is valid, but cannot be used to activate a window | ||
51 | view_request_urgent(view); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void xdg_activation_v1_handle_new_token(struct wl_listener *listener, void *data) { | ||
56 | struct wlr_xdg_activation_token_v1 *token = data; | ||
57 | struct sway_seat *seat = token->seat ? token->seat->data : | ||
58 | input_manager_current_seat(); | ||
59 | |||
60 | struct sway_workspace *ws = seat_get_focused_workspace(seat); | ||
61 | if (ws) { | ||
62 | launcher_ctx_create(token, &ws->node); | ||
63 | return; | ||
64 | } | ||
20 | } | 65 | } |