diff options
author | Ronan Pigott <ronan@rjp.ie> | 2022-11-16 15:50:34 -0700 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-11-26 10:29:59 +0100 |
commit | cb13b9d62843169cdf07c63489ae9e2f055f338f (patch) | |
tree | 5178b3621536a58c63fcf52a7dda0949dda1dd50 | |
parent | launcher: track workspaces by node (diff) | |
download | sway-cb13b9d62843169cdf07c63489ae9e2f055f338f.tar.gz sway-cb13b9d62843169cdf07c63489ae9e2f055f338f.tar.zst sway-cb13b9d62843169cdf07c63489ae9e2f055f338f.zip |
launcher: use xdga tokens
This reuses wlroots token tracking for workspace matching. It doesn't
export any xdga tokens for clients yet.
(cherry picked from commit bd66f4943da1c96edc3ba49573e27b42b688c543)
-rw-r--r-- | sway/desktop/launcher.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/sway/desktop/launcher.c b/sway/desktop/launcher.c index dd81e23d..532d22ac 100644 --- a/sway/desktop/launcher.c +++ b/sway/desktop/launcher.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <wlr/types/wlr_xdg_activation_v1.h> | ||
4 | #include "sway/input/seat.h" | 5 | #include "sway/input/seat.h" |
5 | #include "sway/output.h" | 6 | #include "sway/output.h" |
6 | #include "sway/desktop/launcher.h" | 7 | #include "sway/desktop/launcher.h" |
@@ -15,7 +16,8 @@ static struct wl_list pid_workspaces; | |||
15 | struct pid_workspace { | 16 | struct pid_workspace { |
16 | pid_t pid; | 17 | pid_t pid; |
17 | char *name; | 18 | char *name; |
18 | struct timespec time_added; | 19 | struct wlr_xdg_activation_token_v1 *token; |
20 | struct wl_listener token_destroy; | ||
19 | 21 | ||
20 | struct sway_node *node; | 22 | struct sway_node *node; |
21 | struct wl_listener node_destroy; | 23 | struct wl_listener node_destroy; |
@@ -59,7 +61,9 @@ static pid_t get_parent_pid(pid_t child) { | |||
59 | 61 | ||
60 | static void pid_workspace_destroy(struct pid_workspace *pw) { | 62 | static void pid_workspace_destroy(struct pid_workspace *pw) { |
61 | wl_list_remove(&pw->node_destroy.link); | 63 | wl_list_remove(&pw->node_destroy.link); |
64 | wl_list_remove(&pw->token_destroy.link); | ||
62 | wl_list_remove(&pw->link); | 65 | wl_list_remove(&pw->link); |
66 | wlr_xdg_activation_token_v1_destroy(pw->token); | ||
63 | free(pw->name); | 67 | free(pw->name); |
64 | free(pw); | 68 | free(pw); |
65 | } | 69 | } |
@@ -162,6 +166,12 @@ static void pw_handle_node_destroy(struct wl_listener *listener, void *data) { | |||
162 | } | 166 | } |
163 | } | 167 | } |
164 | 168 | ||
169 | static void token_handle_destroy(struct wl_listener *listener, void *data) { | ||
170 | struct pid_workspace *pw = wl_container_of(listener, pw, token_destroy); | ||
171 | pw->token = NULL; | ||
172 | pid_workspace_destroy(pw); | ||
173 | } | ||
174 | |||
165 | void root_record_workspace_pid(pid_t pid) { | 175 | void root_record_workspace_pid(pid_t pid) { |
166 | sway_log(SWAY_DEBUG, "Recording workspace for process %d", pid); | 176 | sway_log(SWAY_DEBUG, "Recording workspace for process %d", pid); |
167 | if (!pid_workspaces.prev && !pid_workspaces.next) { | 177 | if (!pid_workspaces.prev && !pid_workspaces.next) { |
@@ -175,26 +185,21 @@ void root_record_workspace_pid(pid_t pid) { | |||
175 | return; | 185 | return; |
176 | } | 186 | } |
177 | 187 | ||
178 | struct timespec now; | ||
179 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
180 | |||
181 | // Remove expired entries | ||
182 | static const int timeout = 60; | ||
183 | struct pid_workspace *old, *_old; | ||
184 | wl_list_for_each_safe(old, _old, &pid_workspaces, link) { | ||
185 | if (now.tv_sec - old->time_added.tv_sec >= timeout) { | ||
186 | pid_workspace_destroy(old); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | struct pid_workspace *pw = calloc(1, sizeof(struct pid_workspace)); | 188 | struct pid_workspace *pw = calloc(1, sizeof(struct pid_workspace)); |
189 | struct wlr_xdg_activation_token_v1 *token = | ||
190 | wlr_xdg_activation_token_v1_create(server.xdg_activation_v1); | ||
191 | token->data = pw; | ||
191 | pw->name = strdup(ws->name); | 192 | pw->name = strdup(ws->name); |
193 | pw->token = token; | ||
192 | pw->node = &ws->node; | 194 | pw->node = &ws->node; |
193 | pw->pid = pid; | 195 | pw->pid = pid; |
194 | 196 | ||
195 | memcpy(&pw->time_added, &now, sizeof(struct timespec)); | ||
196 | pw->node_destroy.notify = pw_handle_node_destroy; | 197 | pw->node_destroy.notify = pw_handle_node_destroy; |
197 | wl_signal_add(&pw->node->events.destroy, &pw->node_destroy); | 198 | wl_signal_add(&pw->node->events.destroy, &pw->node_destroy); |
199 | |||
200 | pw->token_destroy.notify = token_handle_destroy; | ||
201 | wl_signal_add(&token->events.destroy, &pw->token_destroy); | ||
202 | |||
198 | wl_list_insert(&pid_workspaces, &pw->link); | 203 | wl_list_insert(&pid_workspaces, &pw->link); |
199 | } | 204 | } |
200 | 205 | ||