summaryrefslogtreecommitdiffstats
path: root/sway/config
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-12-27 00:46:55 -0500
committerLibravatar emersion <contact@emersion.fr>2018-12-29 19:40:40 +0100
commit3e8f548d1d0acb3aba384842615e6528b3027283 (patch)
tree8c0bd5fbcc42d9ad08a4630940598719f3d6a54e /sway/config
parentsway-output(5): doc scaling consideration for pos (diff)
downloadsway-3e8f548d1d0acb3aba384842615e6528b3027283.tar.gz
sway-3e8f548d1d0acb3aba384842615e6528b3027283.tar.zst
sway-3e8f548d1d0acb3aba384842615e6528b3027283.zip
Revamp seat configs
This makes seat configs work like output and input configs do. This also adds support for wildcard seat configs. A seat config is still created in the main seat command handler, but instead of creating a new one in the subcommands and destroying the main seat command's instance, the seat subcommands modify the main one. The seat config is then stored, where it is merged appropriately. The seat config returned from `store_seat_config` is then applied. When attempting to apply a wildcard seat config, a seat specific config is queried for and if found, that is used. Otherwise, the wildcard config is applied directly. Additionally, instead of adding input devices to the default seat directly when there is no seat configs, a seat config for the default seat is created with only fallback set to true, which is more explicit. It also fixes an issue where running a seat command at runtime (with no seat config in the sway config), would result in all input devices being removed from the default seat and leaving sway in an unusable state. Also, instead of checking for any seat config, the search is for a seat config with a fallback option seat. This makes it so if there are only seat configs with fallback set to -1, the default seat is still created since there is no explicit notion on what to do regarding fallbacks. However, if there is even a single fallback 0, then the default seat is not used as a fallback. This will be needed for seat subcommands like hide_cursor where the user may only want to set that property without effecting anything else.
Diffstat (limited to 'sway/config')
-rw-r--r--sway/config/seat.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/sway/config/seat.c b/sway/config/seat.c
index 1cb4c363..c248990a 100644
--- a/sway/config/seat.c
+++ b/sway/config/seat.c
@@ -11,7 +11,6 @@ struct seat_config *new_seat_config(const char* name) {
11 return NULL; 11 return NULL;
12 } 12 }
13 13
14 wlr_log(WLR_DEBUG, "new_seat_config(%s)", name);
15 seat->name = strdup(name); 14 seat->name = strdup(name);
16 if (!sway_assert(seat->name, "could not allocate name for seat")) { 15 if (!sway_assert(seat->name, "could not allocate name for seat")) {
17 free(seat); 16 free(seat);
@@ -30,6 +29,52 @@ struct seat_config *new_seat_config(const char* name) {
30 return seat; 29 return seat;
31} 30}
32 31
32static void merge_wildcard_on_all(struct seat_config *wildcard) {
33 for (int i = 0; i < config->seat_configs->length; i++) {
34 struct seat_config *sc = config->seat_configs->items[i];
35 if (strcmp(wildcard->name, sc->name) != 0) {
36 wlr_log(WLR_DEBUG, "Merging seat * config on %s", sc->name);
37 merge_seat_config(sc, wildcard);
38 }
39 }
40}
41
42struct seat_config *store_seat_config(struct seat_config *sc) {
43 bool wildcard = strcmp(sc->name, "*") == 0;
44 if (wildcard) {
45 merge_wildcard_on_all(sc);
46 }
47
48 int i = list_seq_find(config->seat_configs, seat_name_cmp, sc->name);
49 if (i >= 0) {
50 wlr_log(WLR_DEBUG, "Merging on top of existing seat config");
51 struct seat_config *current = config->seat_configs->items[i];
52 merge_seat_config(current, sc);
53 free_seat_config(sc);
54 sc = current;
55 } else if (!wildcard) {
56 wlr_log(WLR_DEBUG, "Adding non-wildcard seat config");
57 i = list_seq_find(config->seat_configs, seat_name_cmp, "*");
58 if (i >= 0) {
59 wlr_log(WLR_DEBUG, "Merging on top of seat * config");
60 struct seat_config *current = new_seat_config(sc->name);
61 merge_seat_config(current, config->seat_configs->items[i]);
62 merge_seat_config(current, sc);
63 free_seat_config(sc);
64 sc = current;
65 }
66 list_add(config->seat_configs, sc);
67 } else {
68 // New wildcard config. Just add it
69 wlr_log(WLR_DEBUG, "Adding seat * config");
70 list_add(config->seat_configs, sc);
71 }
72
73 wlr_log(WLR_DEBUG, "Config stored for seat %s", sc->name);
74
75 return sc;
76}
77
33struct seat_attachment_config *seat_attachment_config_new(void) { 78struct seat_attachment_config *seat_attachment_config_new(void) {
34 struct seat_attachment_config *attachment = 79 struct seat_attachment_config *attachment =
35 calloc(1, sizeof(struct seat_attachment_config)); 80 calloc(1, sizeof(struct seat_attachment_config));
@@ -65,11 +110,6 @@ static void merge_seat_attachment_config(struct seat_attachment_config *dest,
65} 110}
66 111
67void merge_seat_config(struct seat_config *dest, struct seat_config *source) { 112void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
68 if (source->name) {
69 free(dest->name);
70 dest->name = strdup(source->name);
71 }
72
73 if (source->fallback != -1) { 113 if (source->fallback != -1) {
74 dest->fallback = source->fallback; 114 dest->fallback = source->fallback;
75 } 115 }