diff options
Diffstat (limited to 'sway/workspace.c')
-rw-r--r-- | sway/workspace.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/sway/workspace.c b/sway/workspace.c index 82573d2e..5319aec4 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <wlc/wlc.h> | 5 | #include <wlc/wlc.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <strings.h> | 7 | #include <strings.h> |
8 | #include <sys/types.h> | ||
8 | #include "ipc-server.h" | 9 | #include "ipc-server.h" |
9 | #include "workspace.h" | 10 | #include "workspace.h" |
10 | #include "layout.h" | 11 | #include "layout.h" |
@@ -309,3 +310,54 @@ bool workspace_switch(swayc_t *workspace) { | |||
309 | arrange_windows(output, -1, -1); | 310 | arrange_windows(output, -1, -1); |
310 | return true; | 311 | return true; |
311 | } | 312 | } |
313 | |||
314 | swayc_t *workspace_for_pid(pid_t pid) { | ||
315 | int i; | ||
316 | swayc_t *ws = NULL; | ||
317 | struct pid_workspace *pw = NULL; | ||
318 | |||
319 | sway_log(L_DEBUG, "looking for workspace for pid %d", pid); | ||
320 | |||
321 | // leaving this here as it's useful for debugging | ||
322 | // sway_log(L_DEBUG, "all pid_workspaces"); | ||
323 | // for (int k = 0; k < config->pid_workspaces->length; k++) { | ||
324 | // pw = config->pid_workspaces->items[k]; | ||
325 | // sway_log(L_DEBUG, "pid %d workspace %s time_added %li", *pw->pid, pw->workspace, *pw->time_added); | ||
326 | // } | ||
327 | |||
328 | do { | ||
329 | for (i = 0; i < config->pid_workspaces->length; i++) { | ||
330 | pw = config->pid_workspaces->items[i]; | ||
331 | pid_t *pw_pid = pw->pid; | ||
332 | |||
333 | if (pid == *pw_pid) { | ||
334 | sway_log(L_DEBUG, "found pid_workspace for pid %d, workspace %s", pid, pw->workspace); | ||
335 | break; // out of for loop | ||
336 | } | ||
337 | |||
338 | pw = NULL; | ||
339 | } | ||
340 | |||
341 | if (pw) { | ||
342 | break; // out of do-while loop | ||
343 | } | ||
344 | |||
345 | pid = get_parent_pid(pid); | ||
346 | // no sense in looking for matches for pid 0. | ||
347 | // also, if pid == getpid(), that is the compositor's | ||
348 | // pid, which definitely isn't helpful | ||
349 | } while (pid > 0 && pid != getpid()); | ||
350 | |||
351 | if (pw) { | ||
352 | ws = workspace_by_name(pw->workspace); | ||
353 | |||
354 | if (!ws) { | ||
355 | sway_log(L_DEBUG, "Creating workspace %s for pid %d because it disappeared", pw->workspace, pid); | ||
356 | ws = workspace_create(pw->workspace); | ||
357 | } | ||
358 | |||
359 | list_del(config->pid_workspaces, i); | ||
360 | } | ||
361 | |||
362 | return ws; | ||
363 | } | ||