aboutsummaryrefslogtreecommitdiff
path: root/sway/workspace.c
diff options
context:
space:
mode:
authorZandr Martin <zandrmartin+git@gmail.com>2016-06-11 09:20:09 -0500
committerZandr Martin <zandrmartin+git@gmail.com>2016-06-11 09:20:09 -0500
commitbeaa03344eda931274b75275bfc2d622e6875956 (patch)
tree166d43eb515eeb16e6fe369e7193ba268fa94406 /sway/workspace.c
parent03d79b41c71f091f61f4712963a3760fd24fdb62 (diff)
clean up pid/workspace stuff
Diffstat (limited to 'sway/workspace.c')
-rw-r--r--sway/workspace.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/sway/workspace.c b/sway/workspace.c
index 82573d2e..0c5c70a3 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -5,6 +5,7 @@
#include <wlc/wlc.h>
#include <string.h>
#include <strings.h>
+#include <sys/types.h>
#include "ipc-server.h"
#include "workspace.h"
#include "layout.h"
@@ -309,3 +310,55 @@ bool workspace_switch(swayc_t *workspace) {
arrange_windows(output, -1, -1);
return true;
}
+
+swayc_t *workspace_for_pid(pid_t pid) {
+ int i;
+ swayc_t *ws = NULL;
+ struct pid_workspace *pw = NULL;
+
+ sway_log(L_DEBUG, "looking for workspace for pid %d", pid);
+
+ // leaving this here as it's useful for debugging
+ // sway_log(L_DEBUG, "all pid_workspaces");
+ // for (int k = 0; k < config->pid_workspaces->length; k++) {
+ // pw = config->pid_workspaces->items[k];
+ // sway_log(L_DEBUG, "pid %d workspace %s", *pw->pid, pw->workspace);
+ // }
+
+ do {
+ for (i = 0; i < config->pid_workspaces->length; i++) {
+ pw = config->pid_workspaces->items[i];
+ pid_t *pw_pid = pw->pid;
+
+ if (pid == *pw_pid) {
+ sway_log(L_DEBUG, "found pid_workspace for pid %d, workspace %s", pid, pw->workspace);
+ break; // out of for loop
+ }
+
+ pw = NULL;
+ }
+
+ if (pw) {
+ break; // out of do-while loop
+ }
+
+ pid = get_parent_pid(pid);
+ // no sense in looking for matches for pid 0.
+ // also, if pid == getpid(), that is the compositor's
+ // pid, which definitely isn't helpful
+ } while (pid > 0 && pid != getpid());
+
+ if (pw) {
+ ws = workspace_by_name(pw->workspace);
+
+ if (!ws) {
+ sway_log(L_DEBUG, "creating workspace %s because it disappeared", pw->workspace);
+ ws = workspace_create(pw->workspace);
+ }
+
+ list_del(config->pid_workspaces, i);
+ }
+
+ free_pid_workspace(pw);
+ return ws;
+}