diff options
Diffstat (limited to 'sway/xdg_activation_v1.c')
-rw-r--r-- | sway/xdg_activation_v1.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/sway/xdg_activation_v1.c b/sway/xdg_activation_v1.c new file mode 100644 index 00000000..b7c80dd4 --- /dev/null +++ b/sway/xdg_activation_v1.c | |||
@@ -0,0 +1,65 @@ | |||
1 | #include <wlr/types/wlr_xdg_activation_v1.h> | ||
2 | #include <wlr/types/wlr_xdg_shell.h> | ||
3 | #include "sway/desktop/launcher.h" | ||
4 | #include "sway/tree/view.h" | ||
5 | #include "sway/tree/workspace.h" | ||
6 | |||
7 | void xdg_activation_v1_handle_request_activate(struct wl_listener *listener, | ||
8 | void *data) { | ||
9 | const struct wlr_xdg_activation_v1_request_activate_event *event = data; | ||
10 | |||
11 | struct wlr_xdg_surface *xdg_surface = | ||
12 | wlr_xdg_surface_try_from_wlr_surface(event->surface); | ||
13 | if (xdg_surface == NULL) { | ||
14 | return; | ||
15 | } | ||
16 | struct sway_view *view = xdg_surface->data; | ||
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 | } | ||
37 | return; | ||
38 | } | ||
39 | |||
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 | } | ||
65 | } | ||