aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config/seat.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config/seat.c')
-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 }