diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-06-11 15:02:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-11 15:02:26 -0400 |
commit | 6388e1e288009fc12af3fe418a6faf8cfe9926f7 (patch) | |
tree | d1b4fb33848d09c71602005c57919a903ce3d72d /sway/config.c | |
parent | cb0cc32265136522f7bfbb768f55f35718248d71 (diff) | |
parent | 2298143d09ce8810d9772f95e1cb605fb6b08536 (diff) |
Merge pull request #701 from zandrmartin/assign-command
messy start of a fix for #462
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/sway/config.c b/sway/config.c index 7530e530..819a70ce 100644 --- a/sway/config.c +++ b/sway/config.c @@ -89,6 +89,60 @@ static void free_workspace_output(struct workspace_output *wo) { free(wo); } +static void pid_workspace_cleanup() { + struct timespec ts; + struct pid_workspace *pw = NULL; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + // work backwards through list and remove any entries + // older than PID_WORKSPACE_TIMEOUT + for (int i = config->pid_workspaces->length - 1; i > -1; i--) { + pw = config->pid_workspaces->items[i]; + + if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) { + list_del(config->pid_workspaces, i); + } + } +} + +// de-dupe pid_workspaces to ensure pid uniqueness +void pid_workspace_add(struct pid_workspace *pw) { + struct pid_workspace *list_pw = NULL; + struct timespec ts; + time_t *now = malloc(sizeof(time_t)); + + pid_workspace_cleanup(); + + // add current time to pw + clock_gettime(CLOCK_MONOTONIC, &ts); + *now = ts.tv_sec; + + pw->time_added = now; + + // work backwards through list and delete any entries that + // have the same pid as that in our new pid_workspace + for (int i = config->pid_workspaces->length - 1; i > -1; i--) { + list_pw = config->pid_workspaces->items[i]; + + if (pw->pid == list_pw->pid) { + list_del(config->pid_workspaces, i); + } + } + + list_add(config->pid_workspaces, pw); +} + +void free_pid_workspace(struct pid_workspace *pw) { + if (!pw) { + return; + } + free(pw->pid); + free(pw->workspace); + free(pw->time_added); + free(pw); +} + void free_config(struct sway_config *config) { int i; for (i = 0; i < config->symbols->length; ++i) { @@ -113,6 +167,11 @@ void free_config(struct sway_config *config) { } list_free(config->workspace_outputs); + for (i = 0; i < config->pid_workspaces->length; ++i) { + free_pid_workspace(config->pid_workspaces->items[i]); + } + list_free(config->pid_workspaces); + for (i = 0; i < config->criteria->length; ++i) { free_criteria(config->criteria->items[i]); } @@ -148,6 +207,7 @@ static void config_defaults(struct sway_config *config) { config->modes = create_list(); config->bars = create_list(); config->workspace_outputs = create_list(); + config->pid_workspaces = create_list(); config->criteria = create_list(); config->input_configs = create_list(); config->output_configs = create_list(); |