aboutsummaryrefslogtreecommitdiff
path: root/sway/config
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config')
-rw-r--r--sway/config/bar.c22
-rw-r--r--sway/config/input.c2
-rw-r--r--sway/config/output.c114
-rw-r--r--sway/config/seat.c64
4 files changed, 147 insertions, 55 deletions
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 7bca5f49..701bf051 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -1,5 +1,4 @@
#define _POSIX_C_SOURCE 200809L
-#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -13,6 +12,7 @@
#include <signal.h>
#include "sway/config.h"
#include "sway/output.h"
+#include "config.h"
#include "stringop.h"
#include "list.h"
#include "log.h"
@@ -50,13 +50,10 @@ void free_bar_config(struct bar_config *bar) {
free(bar->font);
free(bar->separator_symbol);
for (int i = 0; i < bar->bindings->length; i++) {
- struct bar_binding *binding = bar->bindings->items[i];
- free_bar_binding(binding);
+ free_bar_binding(bar->bindings->items[i]);
}
list_free(bar->bindings);
- if (bar->outputs) {
- free_flat_list(bar->outputs);
- }
+ list_free_items_and_destroy(bar->outputs);
if (bar->pid != 0) {
terminate_swaybar(bar->pid);
}
@@ -81,6 +78,10 @@ void free_bar_config(struct bar_config *bar) {
free(bar->colors.binding_mode_border);
free(bar->colors.binding_mode_bg);
free(bar->colors.binding_mode_text);
+#if HAVE_TRAY
+ list_free_items_and_destroy(bar->tray_outputs);
+ free(bar->icon_theme);
+#endif
free(bar);
}
@@ -95,15 +96,18 @@ struct bar_config *default_bar_config(void) {
bar->pango_markup = false;
bar->swaybar_command = NULL;
bar->font = NULL;
- bar->height = -1;
+ bar->height = 0;
bar->workspace_buttons = true;
bar->wrap_scroll = false;
bar->separator_symbol = NULL;
bar->strip_workspace_numbers = false;
+ bar->strip_workspace_name = false;
bar->binding_mode_indicator = true;
bar->verbose = false;
bar->pid = 0;
bar->modifier = get_modifier_mask_by_name("Mod4");
+ bar->status_padding = 1;
+ bar->status_edge_padding = 3;
if (!(bar->mode = strdup("dock"))) {
goto cleanup;
}
@@ -168,6 +172,10 @@ struct bar_config *default_bar_config(void) {
bar->colors.binding_mode_bg = NULL;
bar->colors.binding_mode_text = NULL;
+#if HAVE_TRAY
+ bar->tray_padding = 2;
+#endif
+
list_add(config->bars, bar);
return bar;
cleanup:
diff --git a/sway/config/input.c b/sway/config/input.c
index d5d2d90b..d649d34d 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -1,4 +1,4 @@
-#define _XOPEN_SOURCE 700
+#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <limits.h>
#include <float.h>
diff --git a/sway/config/output.c b/sway/config/output.c
index 07543e3c..f24e7d66 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -1,4 +1,4 @@
-#define _XOPEN_SOURCE 700
+#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <stdbool.h>
#include <string.h>
@@ -179,10 +179,6 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) {
if (oc && oc->enabled == 0) {
if (output->enabled) {
- if (output->bg_pid != 0) {
- terminate_swaybg(output->bg_pid);
- output->bg_pid = 0;
- }
output_disable(output);
wlr_output_layout_remove(root->output_layout, wlr_output);
}
@@ -276,18 +272,86 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) {
}
}
-static struct output_config *get_output_config(char *name, char *identifier) {
+static void default_output_config(struct output_config *oc,
+ struct wlr_output *wlr_output) {
+ oc->enabled = 1;
+ if (!wl_list_empty(&wlr_output->modes)) {
+ struct wlr_output_mode *mode =
+ wl_container_of(wlr_output->modes.prev, mode, link);
+ oc->width = mode->width;
+ oc->height = mode->height;
+ oc->refresh_rate = mode->refresh;
+ }
+ oc->x = oc->y = -1;
+ oc->scale = 1;
+ oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
+}
+
+static struct output_config *get_output_config(char *identifier,
+ struct sway_output *sway_output) {
+ const char *name = sway_output->wlr_output->name;
+ struct output_config *oc_name = NULL;
int i = list_seq_find(config->output_configs, output_name_cmp, name);
if (i >= 0) {
- return config->output_configs->items[i];
+ oc_name = config->output_configs->items[i];
}
+ struct output_config *oc_id = NULL;
i = list_seq_find(config->output_configs, output_name_cmp, identifier);
if (i >= 0) {
- return config->output_configs->items[i];
+ oc_id = config->output_configs->items[i];
+ }
+
+ struct output_config *result = result = new_output_config("temp");
+ if (config->reloading) {
+ default_output_config(result, sway_output->wlr_output);
+ }
+ if (oc_name && oc_id) {
+ // Generate a config named `<identifier> on <name>` which contains a
+ // merged copy of the identifier on name. This will make sure that both
+ // identifier and name configs are respected, with identifier getting
+ // priority
+ size_t length = snprintf(NULL, 0, "%s on %s", identifier, name) + 1;
+ char *temp = malloc(length);
+ snprintf(temp, length, "%s on %s", identifier, name);
+
+ free(result->name);
+ result->name = temp;
+ merge_output_config(result, oc_name);
+ merge_output_config(result, oc_id);
+
+ wlr_log(WLR_DEBUG, "Generated output config \"%s\" (enabled: %d)"
+ " (%dx%d@%fHz position %d,%d scale %f transform %d) (bg %s %s)"
+ " (dpms %d)", result->name, result->enabled, result->width,
+ result->height, result->refresh_rate, result->x, result->y,
+ result->scale, result->transform, result->background,
+ result->background_option, result->dpms_state);
+ } else if (oc_name) {
+ // No identifier config, just return a copy of the name config
+ free(result->name);
+ result->name = strdup(name);
+ merge_output_config(result, oc_name);
+ } else if (oc_id) {
+ // No name config, just return a copy of the identifier config
+ free(result->name);
+ result->name = strdup(identifier);
+ merge_output_config(result, oc_id);
+ } else if (config->reloading) {
+ // Neither config exists, but we need to reset the output so create a
+ // default config for the output and if a wildcard config exists, merge
+ // that on top
+ free(result->name);
+ result->name = strdup("*");
+ i = list_seq_find(config->output_configs, output_name_cmp, "*");
+ if (i >= 0) {
+ merge_output_config(result, config->output_configs->items[i]);
+ }
+ } else {
+ free_output_config(result);
+ result = NULL;
}
- return NULL;
+ return result;
}
void apply_output_config_to_outputs(struct output_config *oc) {
@@ -301,14 +365,17 @@ void apply_output_config_to_outputs(struct output_config *oc) {
char *name = sway_output->wlr_output->name;
output_get_identifier(id, sizeof(id), sway_output);
if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) {
- struct output_config *current = oc;
+ struct output_config *current = new_output_config(oc->name);
+ merge_output_config(current, oc);
if (wildcard) {
- struct output_config *tmp = get_output_config(name, id);
+ struct output_config *tmp = get_output_config(id, sway_output);
if (tmp) {
+ free_output_config(current);
current = tmp;
}
}
apply_output_config(current, sway_output);
+ free_output_config(current);
if (!wildcard) {
// Stop looking if the output config isn't applicable to all
@@ -329,28 +396,3 @@ void free_output_config(struct output_config *oc) {
free(oc->background_fallback);
free(oc);
}
-
-static void default_output_config(struct output_config *oc,
- struct wlr_output *wlr_output) {
- oc->enabled = 1;
- if (!wl_list_empty(&wlr_output->modes)) {
- struct wlr_output_mode *mode =
- wl_container_of(wlr_output->modes.prev, mode, link);
- oc->width = mode->width;
- oc->height = mode->height;
- oc->refresh_rate = mode->refresh;
- }
- oc->x = oc->y = -1;
- oc->scale = 1;
- oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
-}
-
-void create_default_output_configs(void) {
- struct sway_output *sway_output;
- wl_list_for_each(sway_output, &root->all_outputs, link) {
- char *name = sway_output->wlr_output->name;
- struct output_config *oc = new_output_config(name);
- default_output_config(oc, sway_output->wlr_output);
- list_add(config->output_configs, oc);
- }
-}
diff --git a/sway/config/seat.c b/sway/config/seat.c
index 46456caf..d7316c68 100644
--- a/sway/config/seat.c
+++ b/sway/config/seat.c
@@ -1,4 +1,4 @@
-#define _XOPEN_SOURCE 700
+#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <string.h>
#include "sway/config.h"
@@ -11,7 +11,6 @@ struct seat_config *new_seat_config(const char* name) {
return NULL;
}
- wlr_log(WLR_DEBUG, "new_seat_config(%s)", name);
seat->name = strdup(name);
if (!sway_assert(seat->name, "could not allocate name for seat")) {
free(seat);
@@ -26,10 +25,57 @@ struct seat_config *new_seat_config(const char* name) {
free(seat);
return NULL;
}
+ seat->hide_cursor_timeout = -1;
return seat;
}
+static void merge_wildcard_on_all(struct seat_config *wildcard) {
+ for (int i = 0; i < config->seat_configs->length; i++) {
+ struct seat_config *sc = config->seat_configs->items[i];
+ if (strcmp(wildcard->name, sc->name) != 0) {
+ wlr_log(WLR_DEBUG, "Merging seat * config on %s", sc->name);
+ merge_seat_config(sc, wildcard);
+ }
+ }
+}
+
+struct seat_config *store_seat_config(struct seat_config *sc) {
+ bool wildcard = strcmp(sc->name, "*") == 0;
+ if (wildcard) {
+ merge_wildcard_on_all(sc);
+ }
+
+ int i = list_seq_find(config->seat_configs, seat_name_cmp, sc->name);
+ if (i >= 0) {
+ wlr_log(WLR_DEBUG, "Merging on top of existing seat config");
+ struct seat_config *current = config->seat_configs->items[i];
+ merge_seat_config(current, sc);
+ free_seat_config(sc);
+ sc = current;
+ } else if (!wildcard) {
+ wlr_log(WLR_DEBUG, "Adding non-wildcard seat config");
+ i = list_seq_find(config->seat_configs, seat_name_cmp, "*");
+ if (i >= 0) {
+ wlr_log(WLR_DEBUG, "Merging on top of seat * config");
+ struct seat_config *current = new_seat_config(sc->name);
+ merge_seat_config(current, config->seat_configs->items[i]);
+ merge_seat_config(current, sc);
+ free_seat_config(sc);
+ sc = current;
+ }
+ list_add(config->seat_configs, sc);
+ } else {
+ // New wildcard config. Just add it
+ wlr_log(WLR_DEBUG, "Adding seat * config");
+ list_add(config->seat_configs, sc);
+ }
+
+ wlr_log(WLR_DEBUG, "Config stored for seat %s", sc->name);
+
+ return sc;
+}
+
struct seat_attachment_config *seat_attachment_config_new(void) {
struct seat_attachment_config *attachment =
calloc(1, sizeof(struct seat_attachment_config));
@@ -65,11 +111,6 @@ static void merge_seat_attachment_config(struct seat_attachment_config *dest,
}
void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
- if (source->name) {
- free(dest->name);
- dest->name = strdup(source->name);
- }
-
if (source->fallback != -1) {
dest->fallback = source->fallback;
}
@@ -97,6 +138,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
}
}
}
+
+ if (source->hide_cursor_timeout != -1) {
+ dest->hide_cursor_timeout = source->hide_cursor_timeout;
+ }
}
struct seat_config *copy_seat_config(struct seat_config *seat) {
@@ -117,11 +162,8 @@ void free_seat_config(struct seat_config *seat) {
free(seat->name);
for (int i = 0; i < seat->attachments->length; ++i) {
- struct seat_attachment_config *attachment =
- seat->attachments->items[i];
- seat_attachment_config_free(attachment);
+ seat_attachment_config_free(seat->attachments->items[i]);
}
-
list_free(seat->attachments);
free(seat);
}