aboutsummaryrefslogtreecommitdiffstats
path: root/sway/xdg_activation_v1.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/xdg_activation_v1.c')
-rw-r--r--sway/xdg_activation_v1.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/sway/xdg_activation_v1.c b/sway/xdg_activation_v1.c
new file mode 100644
index 00000000..c26ee19a
--- /dev/null
+++ b/sway/xdg_activation_v1.c
@@ -0,0 +1,50 @@
1#include <wlr/types/wlr_xdg_activation_v1.h>
2#include "sway/desktop/launcher.h"
3#include "sway/tree/view.h"
4#include "sway/tree/workspace.h"
5
6void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
7 void *data) {
8 const struct wlr_xdg_activation_v1_request_activate_event *event = data;
9
10 struct wlr_xdg_surface *xdg_surface =
11 wlr_xdg_surface_try_from_wlr_surface(event->surface);
12 if (xdg_surface == NULL) {
13 return;
14 }
15 struct sway_view *view = xdg_surface->data;
16 if (view == NULL) {
17 return;
18 }
19
20 if (!xdg_surface->surface->mapped) {
21 // This is a startup notification. If we are tracking it, the data
22 // field is a launcher_ctx.
23 struct launcher_ctx *ctx = event->token->data;
24 if (!ctx || ctx->activated) {
25 // This ctx has already been activated and cannot be used again
26 // for a startup notification. It will be destroyed
27 return;
28 } else {
29 ctx->activated = true;
30 view_assign_ctx(view, ctx);
31 }
32 return;
33 }
34
35 struct wlr_seat *wlr_seat = event->token->seat;
36 struct sway_seat *seat = wlr_seat ? wlr_seat->data : NULL;
37 view_request_activate(view, seat);
38}
39
40void xdg_activation_v1_handle_new_token(struct wl_listener *listener, void *data) {
41 struct wlr_xdg_activation_token_v1 *token = data;
42 struct sway_seat *seat = token->seat ? token->seat->data :
43 input_manager_current_seat();
44
45 struct sway_workspace *ws = seat_get_focused_workspace(seat);
46 if (ws) {
47 launcher_ctx_create(token, &ws->node);
48 return;
49 }
50}