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/config.c | |
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/config.c')
-rw-r--r-- | sway/config.c | 45 |
1 files changed, 45 insertions, 0 deletions
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 | ||