clean up pid/workspace stuff

This commit is contained in:
Zandr Martin 2016-06-11 09:20:09 -05:00
parent 03d79b41c7
commit beaa03344e
No known key found for this signature in database
GPG key ID: AA2BB8EF77F7BBDC
3 changed files with 68 additions and 65 deletions

View file

@ -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;
}