diff options
Diffstat (limited to 'sway/tree/root.c')
-rw-r--r-- | sway/tree/root.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/sway/tree/root.c b/sway/tree/root.c index a3830976..46a140ef 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -225,6 +225,13 @@ static pid_t get_parent_pid(pid_t child) { | |||
225 | return -1; | 225 | return -1; |
226 | } | 226 | } |
227 | 227 | ||
228 | static void pid_workspace_destroy(struct pid_workspace *pw) { | ||
229 | wl_list_remove(&pw->output_destroy.link); | ||
230 | wl_list_remove(&pw->link); | ||
231 | free(pw->workspace); | ||
232 | free(pw); | ||
233 | } | ||
234 | |||
228 | struct sway_workspace *root_workspace_for_pid(pid_t pid) { | 235 | struct sway_workspace *root_workspace_for_pid(pid_t pid) { |
229 | if (!pid_workspaces.prev && !pid_workspaces.next) { | 236 | if (!pid_workspaces.prev && !pid_workspaces.next) { |
230 | wl_list_init(&pid_workspaces); | 237 | wl_list_init(&pid_workspaces); |
@@ -261,10 +268,7 @@ found: | |||
261 | ws = workspace_create(pw->output, pw->workspace); | 268 | ws = workspace_create(pw->output, pw->workspace); |
262 | } | 269 | } |
263 | 270 | ||
264 | wl_list_remove(&pw->output_destroy.link); | 271 | pid_workspace_destroy(pw); |
265 | wl_list_remove(&pw->link); | ||
266 | free(pw->workspace); | ||
267 | free(pw); | ||
268 | } | 272 | } |
269 | 273 | ||
270 | return ws; | 274 | return ws; |
@@ -303,10 +307,7 @@ void root_record_workspace_pid(pid_t pid) { | |||
303 | struct pid_workspace *old, *_old; | 307 | struct pid_workspace *old, *_old; |
304 | wl_list_for_each_safe(old, _old, &pid_workspaces, link) { | 308 | wl_list_for_each_safe(old, _old, &pid_workspaces, link) { |
305 | if (now.tv_sec - old->time_added.tv_sec >= timeout) { | 309 | if (now.tv_sec - old->time_added.tv_sec >= timeout) { |
306 | wl_list_remove(&old->output_destroy.link); | 310 | pid_workspace_destroy(old); |
307 | wl_list_remove(&old->link); | ||
308 | free(old->workspace); | ||
309 | free(old); | ||
310 | } | 311 | } |
311 | } | 312 | } |
312 | 313 | ||
@@ -320,6 +321,20 @@ void root_record_workspace_pid(pid_t pid) { | |||
320 | wl_list_insert(&pid_workspaces, &pw->link); | 321 | wl_list_insert(&pid_workspaces, &pw->link); |
321 | } | 322 | } |
322 | 323 | ||
324 | void root_remove_workspace_pid(pid_t pid) { | ||
325 | if (!pid_workspaces.prev || !pid_workspaces.next) { | ||
326 | return; | ||
327 | } | ||
328 | |||
329 | struct pid_workspace *pw, *tmp; | ||
330 | wl_list_for_each_safe(pw, tmp, &pid_workspaces, link) { | ||
331 | if (pid == pw->pid) { | ||
332 | pid_workspace_destroy(pw); | ||
333 | return; | ||
334 | } | ||
335 | } | ||
336 | } | ||
337 | |||
323 | void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data), | 338 | void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data), |
324 | void *data) { | 339 | void *data) { |
325 | for (int i = 0; i < root->outputs->length; ++i) { | 340 | for (int i = 0; i < root->outputs->length; ++i) { |