diff options
author | Zandr Martin <zandrmartin+git@gmail.com> | 2016-06-11 12:43:34 -0500 |
---|---|---|
committer | Zandr Martin <zandrmartin+git@gmail.com> | 2016-06-11 12:43:34 -0500 |
commit | 2298143d09ce8810d9772f95e1cb605fb6b08536 (patch) | |
tree | d1b4fb33848d09c71602005c57919a903ce3d72d /sway | |
parent | Merge branch 'master' into assign-command (diff) | |
download | sway-2298143d09ce8810d9772f95e1cb605fb6b08536.tar.gz sway-2298143d09ce8810d9772f95e1cb605fb6b08536.tar.zst sway-2298143d09ce8810d9772f95e1cb605fb6b08536.zip |
cleanup + add timeouts for pid_workspace list
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/config.c | 45 | ||||
-rw-r--r-- | sway/workspace.c | 5 |
3 files changed, 48 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c index 3a6b2af5..5e84ea9a 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -555,7 +555,7 @@ static struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
555 | struct pid_workspace *pw = malloc(sizeof(struct pid_workspace)); | 555 | struct pid_workspace *pw = malloc(sizeof(struct pid_workspace)); |
556 | pw->pid = child; | 556 | pw->pid = child; |
557 | pw->workspace = strdup(ws->name); | 557 | pw->workspace = strdup(ws->name); |
558 | list_add(config->pid_workspaces, pw); | 558 | pid_workspace_add(pw); |
559 | // TODO: keep track of this pid and open the corresponding view on the current workspace | 559 | // TODO: keep track of this pid and open the corresponding view on the current workspace |
560 | // blocked pending feature in wlc | 560 | // blocked pending feature in wlc |
561 | } else { | 561 | } else { |
diff --git a/sway/config.c b/sway/config.c index 07b1f2f7..819a70ce 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -89,12 +89,57 @@ static void free_workspace_output(struct workspace_output *wo) { | |||
89 | free(wo); | 89 | free(wo); |
90 | } | 90 | } |
91 | 91 | ||
92 | static void pid_workspace_cleanup() { | ||
93 | struct timespec ts; | ||
94 | struct pid_workspace *pw = NULL; | ||
95 | |||
96 | clock_gettime(CLOCK_MONOTONIC, &ts); | ||
97 | |||
98 | // work backwards through list and remove any entries | ||
99 | // older than PID_WORKSPACE_TIMEOUT | ||
100 | for (int i = config->pid_workspaces->length - 1; i > -1; i--) { | ||
101 | pw = config->pid_workspaces->items[i]; | ||
102 | |||
103 | if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) { | ||
104 | list_del(config->pid_workspaces, i); | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | |||
109 | // de-dupe pid_workspaces to ensure pid uniqueness | ||
110 | void pid_workspace_add(struct pid_workspace *pw) { | ||
111 | struct pid_workspace *list_pw = NULL; | ||
112 | struct timespec ts; | ||
113 | time_t *now = malloc(sizeof(time_t)); | ||
114 | |||
115 | pid_workspace_cleanup(); | ||
116 | |||
117 | // add current time to pw | ||
118 | clock_gettime(CLOCK_MONOTONIC, &ts); | ||
119 | *now = ts.tv_sec; | ||
120 | |||
121 | pw->time_added = now; | ||
122 | |||
123 | // work backwards through list and delete any entries that | ||
124 | // have the same pid as that in our new pid_workspace | ||
125 | for (int i = config->pid_workspaces->length - 1; i > -1; i--) { | ||
126 | list_pw = config->pid_workspaces->items[i]; | ||
127 | |||
128 | if (pw->pid == list_pw->pid) { | ||
129 | list_del(config->pid_workspaces, i); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | list_add(config->pid_workspaces, pw); | ||
134 | } | ||
135 | |||
92 | void free_pid_workspace(struct pid_workspace *pw) { | 136 | void free_pid_workspace(struct pid_workspace *pw) { |
93 | if (!pw) { | 137 | if (!pw) { |
94 | return; | 138 | return; |
95 | } | 139 | } |
96 | free(pw->pid); | 140 | free(pw->pid); |
97 | free(pw->workspace); | 141 | free(pw->workspace); |
142 | free(pw->time_added); | ||
98 | free(pw); | 143 | free(pw); |
99 | } | 144 | } |
100 | 145 | ||
diff --git a/sway/workspace.c b/sway/workspace.c index 0c5c70a3..5319aec4 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -322,7 +322,7 @@ swayc_t *workspace_for_pid(pid_t pid) { | |||
322 | // sway_log(L_DEBUG, "all pid_workspaces"); | 322 | // sway_log(L_DEBUG, "all pid_workspaces"); |
323 | // for (int k = 0; k < config->pid_workspaces->length; k++) { | 323 | // for (int k = 0; k < config->pid_workspaces->length; k++) { |
324 | // pw = config->pid_workspaces->items[k]; | 324 | // pw = config->pid_workspaces->items[k]; |
325 | // sway_log(L_DEBUG, "pid %d workspace %s", *pw->pid, pw->workspace); | 325 | // sway_log(L_DEBUG, "pid %d workspace %s time_added %li", *pw->pid, pw->workspace, *pw->time_added); |
326 | // } | 326 | // } |
327 | 327 | ||
328 | do { | 328 | do { |
@@ -352,13 +352,12 @@ swayc_t *workspace_for_pid(pid_t pid) { | |||
352 | ws = workspace_by_name(pw->workspace); | 352 | ws = workspace_by_name(pw->workspace); |
353 | 353 | ||
354 | if (!ws) { | 354 | if (!ws) { |
355 | sway_log(L_DEBUG, "creating workspace %s because it disappeared", pw->workspace); | 355 | sway_log(L_DEBUG, "Creating workspace %s for pid %d because it disappeared", pw->workspace, pid); |
356 | ws = workspace_create(pw->workspace); | 356 | ws = workspace_create(pw->workspace); |
357 | } | 357 | } |
358 | 358 | ||
359 | list_del(config->pid_workspaces, i); | 359 | list_del(config->pid_workspaces, i); |
360 | } | 360 | } |
361 | 361 | ||
362 | free_pid_workspace(pw); | ||
363 | return ws; | 362 | return ws; |
364 | } | 363 | } |