aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-29 22:51:48 +0200
committerLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-29 23:17:56 +0200
commitb1bd3ae6f3210e6b3ecda2d253518da18420e6cd (patch)
tree358cdee3a8c412eb22ee52c2437d8f151ef2627b /sway
parentconfig: Store 'enabled' as int (diff)
downloadsway-b1bd3ae6f3210e6b3ecda2d253518da18420e6cd.tar.gz
sway-b1bd3ae6f3210e6b3ecda2d253518da18420e6cd.tar.zst
sway-b1bd3ae6f3210e6b3ecda2d253518da18420e6cd.zip
cmd_output: Merge instead of replace output config
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c10
-rw-r--r--sway/config.c36
2 files changed, 42 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c
index f891792f..452f3c34 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -804,12 +804,14 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
804 804
805 i = list_seq_find(config->output_configs, output_name_cmp, name); 805 i = list_seq_find(config->output_configs, output_name_cmp, name);
806 if (i >= 0) { 806 if (i >= 0) {
807 // replace existing config 807 // merge existing config
808 struct output_config *oc = config->output_configs->items[i]; 808 struct output_config *oc = config->output_configs->items[i];
809 list_del(config->output_configs, i); 809 merge_output_config(oc, output);
810 free_output_config(oc); 810 free_output_config(output);
811 output = oc;
812 } else {
813 list_add(config->output_configs, output);
811 } 814 }
812 list_add(config->output_configs, output);
813 815
814 sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d) (bg %s %s)", 816 sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d) (bg %s %s)",
815 output->name, output->enabled, output->width, 817 output->name, output->enabled, output->width,
diff --git a/sway/config.c b/sway/config.c
index 67b442ad..aa4675ce 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -271,6 +271,42 @@ int output_name_cmp(const void *item, const void *data) {
271 return strcmp(output->name, name); 271 return strcmp(output->name, name);
272} 272}
273 273
274void merge_output_config(struct output_config *dst, struct output_config *src) {
275 if (src->name) {
276 if (dst->name) {
277 free(dst->name);
278 }
279 dst->name = strdup(src->name);
280 }
281 if (src->enabled != -1) {
282 dst->enabled = src->enabled;
283 }
284 if (src->width != -1) {
285 dst->width = src->width;
286 }
287 if (src->height != -1) {
288 dst->height = src->height;
289 }
290 if (src->x != -1) {
291 dst->x = src->x;
292 }
293 if (src->y != -1) {
294 dst->y = src->y;
295 }
296 if (src->background) {
297 if (dst->background) {
298 free(dst->background);
299 }
300 dst->background = strdup(src->background);
301 }
302 if (src->background_option) {
303 if (dst->background_option) {
304 free(dst->background_option);
305 }
306 dst->background_option = strdup(src->background_option);
307 }
308}
309
274void apply_output_config(struct output_config *oc, swayc_t *output) { 310void apply_output_config(struct output_config *oc, swayc_t *output) {
275 if (oc && oc->width > 0 && oc->height > 0) { 311 if (oc && oc->width > 0 && oc->height > 0) {
276 output->width = oc->width; 312 output->width = oc->width;