diff options
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) { | |||
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 | |||
136 | void free_pid_workspace(struct pid_workspace *pw) { | ||
137 | if (!pw) { | ||
138 | return; | ||
139 | } | ||
140 | free(pw->pid); | ||
141 | free(pw->workspace); | ||
142 | free(pw->time_added); | ||
143 | free(pw); | ||
144 | } | ||
145 | |||
92 | void free_config(struct sway_config *config) { | 146 | void free_config(struct sway_config *config) { |
93 | int i; | 147 | int i; |
94 | for (i = 0; i < config->symbols->length; ++i) { | 148 | for (i = 0; i < config->symbols->length; ++i) { |
@@ -113,6 +167,11 @@ void free_config(struct sway_config *config) { | |||
113 | } | 167 | } |
114 | list_free(config->workspace_outputs); | 168 | list_free(config->workspace_outputs); |
115 | 169 | ||
170 | for (i = 0; i < config->pid_workspaces->length; ++i) { | ||
171 | free_pid_workspace(config->pid_workspaces->items[i]); | ||
172 | } | ||
173 | list_free(config->pid_workspaces); | ||
174 | |||
116 | for (i = 0; i < config->criteria->length; ++i) { | 175 | for (i = 0; i < config->criteria->length; ++i) { |
117 | free_criteria(config->criteria->items[i]); | 176 | free_criteria(config->criteria->items[i]); |
118 | } | 177 | } |
@@ -148,6 +207,7 @@ static void config_defaults(struct sway_config *config) { | |||
148 | config->modes = create_list(); | 207 | config->modes = create_list(); |
149 | config->bars = create_list(); | 208 | config->bars = create_list(); |
150 | config->workspace_outputs = create_list(); | 209 | config->workspace_outputs = create_list(); |
210 | config->pid_workspaces = create_list(); | ||
151 | config->criteria = create_list(); | 211 | config->criteria = create_list(); |
152 | config->input_configs = create_list(); | 212 | config->input_configs = create_list(); |
153 | config->output_configs = create_list(); | 213 | config->output_configs = create_list(); |