diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-16 11:25:59 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-16 11:25:59 -0500 |
commit | f4a5a0ead4c8b155985c242db1fa5de5fa4807a0 (patch) | |
tree | a5f7f787aa04d68f800de9bb91b0813fb57fbc25 | |
parent | fix header includes (diff) | |
download | sway-f4a5a0ead4c8b155985c242db1fa5de5fa4807a0.tar.gz sway-f4a5a0ead4c8b155985c242db1fa5de5fa4807a0.tar.zst sway-f4a5a0ead4c8b155985c242db1fa5de5fa4807a0.zip |
put seat and input config in their own files
-rw-r--r-- | sway/config.c | 222 | ||||
-rw-r--r-- | sway/config/input.c | 105 | ||||
-rw-r--r-- | sway/config/seat.c | 127 | ||||
-rw-r--r-- | sway/meson.build | 2 |
4 files changed, 234 insertions, 222 deletions
diff --git a/sway/config.c b/sway/config.c index 4e34aa8c..b591ae9e 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <signal.h> | 12 | #include <signal.h> |
13 | #include <libinput.h> | 13 | #include <libinput.h> |
14 | #include <limits.h> | 14 | #include <limits.h> |
15 | #include <float.h> | ||
16 | #include <dirent.h> | 15 | #include <dirent.h> |
17 | #include <strings.h> | 16 | #include <strings.h> |
18 | #ifdef __linux__ | 17 | #ifdef __linux__ |
@@ -229,227 +228,6 @@ static int qstrcmp(const void* a, const void* b) { | |||
229 | return strcmp(*((char**) a), *((char**) b)); | 228 | return strcmp(*((char**) a), *((char**) b)); |
230 | } | 229 | } |
231 | 230 | ||
232 | struct input_config *new_input_config(const char* identifier) { | ||
233 | struct input_config *input = calloc(1, sizeof(struct input_config)); | ||
234 | if (!input) { | ||
235 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
236 | return NULL; | ||
237 | } | ||
238 | sway_log(L_DEBUG, "new_input_config(%s)", identifier); | ||
239 | if (!(input->identifier = strdup(identifier))) { | ||
240 | free(input); | ||
241 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
242 | return NULL; | ||
243 | } | ||
244 | |||
245 | input->tap = INT_MIN; | ||
246 | input->drag_lock = INT_MIN; | ||
247 | input->dwt = INT_MIN; | ||
248 | input->send_events = INT_MIN; | ||
249 | input->click_method = INT_MIN; | ||
250 | input->middle_emulation = INT_MIN; | ||
251 | input->natural_scroll = INT_MIN; | ||
252 | input->accel_profile = INT_MIN; | ||
253 | input->pointer_accel = FLT_MIN; | ||
254 | input->scroll_method = INT_MIN; | ||
255 | input->left_handed = INT_MIN; | ||
256 | |||
257 | return input; | ||
258 | } | ||
259 | |||
260 | void merge_input_config(struct input_config *dst, struct input_config *src) { | ||
261 | if (src->identifier) { | ||
262 | free(dst->identifier); | ||
263 | dst->identifier = strdup(src->identifier); | ||
264 | } | ||
265 | if (src->accel_profile != INT_MIN) { | ||
266 | dst->accel_profile = src->accel_profile; | ||
267 | } | ||
268 | if (src->click_method != INT_MIN) { | ||
269 | dst->click_method = src->click_method; | ||
270 | } | ||
271 | if (src->drag_lock != INT_MIN) { | ||
272 | dst->drag_lock = src->drag_lock; | ||
273 | } | ||
274 | if (src->dwt != INT_MIN) { | ||
275 | dst->dwt = src->dwt; | ||
276 | } | ||
277 | if (src->middle_emulation != INT_MIN) { | ||
278 | dst->middle_emulation = src->middle_emulation; | ||
279 | } | ||
280 | if (src->natural_scroll != INT_MIN) { | ||
281 | dst->natural_scroll = src->natural_scroll; | ||
282 | } | ||
283 | if (src->pointer_accel != FLT_MIN) { | ||
284 | dst->pointer_accel = src->pointer_accel; | ||
285 | } | ||
286 | if (src->scroll_method != INT_MIN) { | ||
287 | dst->scroll_method = src->scroll_method; | ||
288 | } | ||
289 | if (src->send_events != INT_MIN) { | ||
290 | dst->send_events = src->send_events; | ||
291 | } | ||
292 | if (src->tap != INT_MIN) { | ||
293 | dst->tap = src->tap; | ||
294 | } | ||
295 | if (src->xkb_layout) { | ||
296 | free(dst->xkb_layout); | ||
297 | dst->xkb_layout = strdup(src->xkb_layout); | ||
298 | } | ||
299 | if (src->xkb_model) { | ||
300 | free(dst->xkb_model); | ||
301 | dst->xkb_model = strdup(src->xkb_model); | ||
302 | } | ||
303 | if (src->xkb_options) { | ||
304 | free(dst->xkb_options); | ||
305 | dst->xkb_options = strdup(src->xkb_options); | ||
306 | } | ||
307 | if (src->xkb_rules) { | ||
308 | free(dst->xkb_rules); | ||
309 | dst->xkb_rules = strdup(src->xkb_rules); | ||
310 | } | ||
311 | if (src->xkb_variant) { | ||
312 | free(dst->xkb_variant); | ||
313 | dst->xkb_variant = strdup(src->xkb_variant); | ||
314 | } | ||
315 | } | ||
316 | |||
317 | void free_input_config(struct input_config *ic) { | ||
318 | if (!ic) { | ||
319 | return; | ||
320 | } | ||
321 | free(ic->identifier); | ||
322 | free(ic); | ||
323 | } | ||
324 | |||
325 | int input_identifier_cmp(const void *item, const void *data) { | ||
326 | const struct input_config *ic = item; | ||
327 | const char *identifier = data; | ||
328 | return strcmp(ic->identifier, identifier); | ||
329 | } | ||
330 | |||
331 | struct seat_config *new_seat_config(const char* name) { | ||
332 | struct seat_config *seat = calloc(1, sizeof(struct seat_config)); | ||
333 | if (!seat) { | ||
334 | sway_log(L_DEBUG, "Unable to allocate seat config"); | ||
335 | return NULL; | ||
336 | } | ||
337 | |||
338 | sway_log(L_DEBUG, "new_seat_config(%s)", name); | ||
339 | seat->name = strdup(name); | ||
340 | if (!sway_assert(seat->name, "could not allocate name for seat")) { | ||
341 | return NULL; | ||
342 | } | ||
343 | |||
344 | seat->attachments = create_list(); | ||
345 | if (!sway_assert(seat->attachments, | ||
346 | "could not allocate seat attachments list")) { | ||
347 | return NULL; | ||
348 | } | ||
349 | |||
350 | return seat; | ||
351 | } | ||
352 | |||
353 | struct seat_attachment_config *seat_attachment_config_new() { | ||
354 | struct seat_attachment_config *attachment = | ||
355 | calloc(1, sizeof(struct seat_attachment_config)); | ||
356 | if (!attachment) { | ||
357 | sway_log(L_DEBUG, "cannot allocate attachment config"); | ||
358 | return NULL; | ||
359 | } | ||
360 | return attachment; | ||
361 | } | ||
362 | |||
363 | static void seat_attachment_config_free( | ||
364 | struct seat_attachment_config *attachment) { | ||
365 | free(attachment->identifier); | ||
366 | free(attachment); | ||
367 | return; | ||
368 | } | ||
369 | |||
370 | static struct seat_attachment_config *seat_attachment_config_copy( | ||
371 | struct seat_attachment_config *attachment) { | ||
372 | struct seat_attachment_config *copy = seat_attachment_config_new(); | ||
373 | if (!copy) { | ||
374 | return NULL; | ||
375 | } | ||
376 | |||
377 | copy->identifier = strdup(attachment->identifier); | ||
378 | |||
379 | return copy; | ||
380 | } | ||
381 | |||
382 | static void merge_seat_attachment_config(struct seat_attachment_config *dest, | ||
383 | struct seat_attachment_config *source) { | ||
384 | // nothing to merge yet, but there will be some day | ||
385 | } | ||
386 | |||
387 | void merge_seat_config(struct seat_config *dest, struct seat_config *source) { | ||
388 | if (source->name) { | ||
389 | free(dest->name); | ||
390 | dest->name = strdup(source->name); | ||
391 | } | ||
392 | |||
393 | for (int i = 0; i < source->attachments->length; ++i) { | ||
394 | struct seat_attachment_config *source_attachment = | ||
395 | source->attachments->items[i]; | ||
396 | bool found = false; | ||
397 | for (int j = 0; j < dest->attachments->length; ++j) { | ||
398 | struct seat_attachment_config *dest_attachment = | ||
399 | dest->attachments->items[j]; | ||
400 | if (strcmp(source_attachment->identifier, | ||
401 | dest_attachment->identifier) == 0) { | ||
402 | merge_seat_attachment_config(dest_attachment, | ||
403 | source_attachment); | ||
404 | found = true; | ||
405 | } | ||
406 | } | ||
407 | |||
408 | if (!found) { | ||
409 | struct seat_attachment_config *copy = | ||
410 | seat_attachment_config_copy(source_attachment); | ||
411 | if (copy) { | ||
412 | list_add(dest->attachments, copy); | ||
413 | } | ||
414 | } | ||
415 | } | ||
416 | } | ||
417 | |||
418 | void free_seat_config(struct seat_config *seat) { | ||
419 | if (!seat) { | ||
420 | return; | ||
421 | } | ||
422 | |||
423 | free(seat->name); | ||
424 | for (int i = 0; i < seat->attachments->length; ++i) { | ||
425 | struct seat_attachment_config *attachment = | ||
426 | seat->attachments->items[i]; | ||
427 | seat_attachment_config_free(attachment); | ||
428 | } | ||
429 | |||
430 | list_free(seat->attachments); | ||
431 | free(seat); | ||
432 | } | ||
433 | |||
434 | int seat_name_cmp(const void *item, const void *data) { | ||
435 | const struct seat_config *sc = item; | ||
436 | const char *name = data; | ||
437 | return strcmp(sc->name, name); | ||
438 | } | ||
439 | |||
440 | struct seat_attachment_config *seat_config_get_attachment( | ||
441 | struct seat_config *seat_config, char *identifier) { | ||
442 | for (int i = 0; i < seat_config->attachments->length; ++i) { | ||
443 | struct seat_attachment_config *attachment = | ||
444 | seat_config->attachments->items[i]; | ||
445 | if (strcmp(attachment->identifier, identifier) == 0) { | ||
446 | return attachment; | ||
447 | } | ||
448 | } | ||
449 | |||
450 | return NULL; | ||
451 | } | ||
452 | |||
453 | bool load_main_config(const char *file, bool is_active) { | 231 | bool load_main_config(const char *file, bool is_active) { |
454 | char *path; | 232 | char *path; |
455 | if (file != NULL) { | 233 | if (file != NULL) { |
diff --git a/sway/config/input.c b/sway/config/input.c new file mode 100644 index 00000000..6f8d31f7 --- /dev/null +++ b/sway/config/input.c | |||
@@ -0,0 +1,105 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include <stdlib.h> | ||
3 | #include <limits.h> | ||
4 | #include <float.h> | ||
5 | #include "sway/config.h" | ||
6 | #include "log.h" | ||
7 | |||
8 | struct input_config *new_input_config(const char* identifier) { | ||
9 | struct input_config *input = calloc(1, sizeof(struct input_config)); | ||
10 | if (!input) { | ||
11 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
12 | return NULL; | ||
13 | } | ||
14 | sway_log(L_DEBUG, "new_input_config(%s)", identifier); | ||
15 | if (!(input->identifier = strdup(identifier))) { | ||
16 | free(input); | ||
17 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
18 | return NULL; | ||
19 | } | ||
20 | |||
21 | input->tap = INT_MIN; | ||
22 | input->drag_lock = INT_MIN; | ||
23 | input->dwt = INT_MIN; | ||
24 | input->send_events = INT_MIN; | ||
25 | input->click_method = INT_MIN; | ||
26 | input->middle_emulation = INT_MIN; | ||
27 | input->natural_scroll = INT_MIN; | ||
28 | input->accel_profile = INT_MIN; | ||
29 | input->pointer_accel = FLT_MIN; | ||
30 | input->scroll_method = INT_MIN; | ||
31 | input->left_handed = INT_MIN; | ||
32 | |||
33 | return input; | ||
34 | } | ||
35 | |||
36 | void merge_input_config(struct input_config *dst, struct input_config *src) { | ||
37 | if (src->identifier) { | ||
38 | free(dst->identifier); | ||
39 | dst->identifier = strdup(src->identifier); | ||
40 | } | ||
41 | if (src->accel_profile != INT_MIN) { | ||
42 | dst->accel_profile = src->accel_profile; | ||
43 | } | ||
44 | if (src->click_method != INT_MIN) { | ||
45 | dst->click_method = src->click_method; | ||
46 | } | ||
47 | if (src->drag_lock != INT_MIN) { | ||
48 | dst->drag_lock = src->drag_lock; | ||
49 | } | ||
50 | if (src->dwt != INT_MIN) { | ||
51 | dst->dwt = src->dwt; | ||
52 | } | ||
53 | if (src->middle_emulation != INT_MIN) { | ||
54 | dst->middle_emulation = src->middle_emulation; | ||
55 | } | ||
56 | if (src->natural_scroll != INT_MIN) { | ||
57 | dst->natural_scroll = src->natural_scroll; | ||
58 | } | ||
59 | if (src->pointer_accel != FLT_MIN) { | ||
60 | dst->pointer_accel = src->pointer_accel; | ||
61 | } | ||
62 | if (src->scroll_method != INT_MIN) { | ||
63 | dst->scroll_method = src->scroll_method; | ||
64 | } | ||
65 | if (src->send_events != INT_MIN) { | ||
66 | dst->send_events = src->send_events; | ||
67 | } | ||
68 | if (src->tap != INT_MIN) { | ||
69 | dst->tap = src->tap; | ||
70 | } | ||
71 | if (src->xkb_layout) { | ||
72 | free(dst->xkb_layout); | ||
73 | dst->xkb_layout = strdup(src->xkb_layout); | ||
74 | } | ||
75 | if (src->xkb_model) { | ||
76 | free(dst->xkb_model); | ||
77 | dst->xkb_model = strdup(src->xkb_model); | ||
78 | } | ||
79 | if (src->xkb_options) { | ||
80 | free(dst->xkb_options); | ||
81 | dst->xkb_options = strdup(src->xkb_options); | ||
82 | } | ||
83 | if (src->xkb_rules) { | ||
84 | free(dst->xkb_rules); | ||
85 | dst->xkb_rules = strdup(src->xkb_rules); | ||
86 | } | ||
87 | if (src->xkb_variant) { | ||
88 | free(dst->xkb_variant); | ||
89 | dst->xkb_variant = strdup(src->xkb_variant); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | void free_input_config(struct input_config *ic) { | ||
94 | if (!ic) { | ||
95 | return; | ||
96 | } | ||
97 | free(ic->identifier); | ||
98 | free(ic); | ||
99 | } | ||
100 | |||
101 | int input_identifier_cmp(const void *item, const void *data) { | ||
102 | const struct input_config *ic = item; | ||
103 | const char *identifier = data; | ||
104 | return strcmp(ic->identifier, identifier); | ||
105 | } | ||
diff --git a/sway/config/seat.c b/sway/config/seat.c new file mode 100644 index 00000000..3a2fdaa6 --- /dev/null +++ b/sway/config/seat.c | |||
@@ -0,0 +1,127 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include "sway/config.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct seat_config *new_seat_config(const char* name) { | ||
8 | struct seat_config *seat = calloc(1, sizeof(struct seat_config)); | ||
9 | if (!seat) { | ||
10 | sway_log(L_DEBUG, "Unable to allocate seat config"); | ||
11 | return NULL; | ||
12 | } | ||
13 | |||
14 | sway_log(L_DEBUG, "new_seat_config(%s)", name); | ||
15 | seat->name = strdup(name); | ||
16 | if (!sway_assert(seat->name, "could not allocate name for seat")) { | ||
17 | return NULL; | ||
18 | } | ||
19 | |||
20 | seat->attachments = create_list(); | ||
21 | if (!sway_assert(seat->attachments, | ||
22 | "could not allocate seat attachments list")) { | ||
23 | return NULL; | ||
24 | } | ||
25 | |||
26 | return seat; | ||
27 | } | ||
28 | |||
29 | struct seat_attachment_config *seat_attachment_config_new() { | ||
30 | struct seat_attachment_config *attachment = | ||
31 | calloc(1, sizeof(struct seat_attachment_config)); | ||
32 | if (!attachment) { | ||
33 | sway_log(L_DEBUG, "cannot allocate attachment config"); | ||
34 | return NULL; | ||
35 | } | ||
36 | return attachment; | ||
37 | } | ||
38 | |||
39 | static void seat_attachment_config_free( | ||
40 | struct seat_attachment_config *attachment) { | ||
41 | free(attachment->identifier); | ||
42 | free(attachment); | ||
43 | return; | ||
44 | } | ||
45 | |||
46 | static struct seat_attachment_config *seat_attachment_config_copy( | ||
47 | struct seat_attachment_config *attachment) { | ||
48 | struct seat_attachment_config *copy = seat_attachment_config_new(); | ||
49 | if (!copy) { | ||
50 | return NULL; | ||
51 | } | ||
52 | |||
53 | copy->identifier = strdup(attachment->identifier); | ||
54 | |||
55 | return copy; | ||
56 | } | ||
57 | |||
58 | static void merge_seat_attachment_config(struct seat_attachment_config *dest, | ||
59 | struct seat_attachment_config *source) { | ||
60 | // nothing to merge yet, but there will be some day | ||
61 | } | ||
62 | |||
63 | void merge_seat_config(struct seat_config *dest, struct seat_config *source) { | ||
64 | if (source->name) { | ||
65 | free(dest->name); | ||
66 | dest->name = strdup(source->name); | ||
67 | } | ||
68 | |||
69 | for (int i = 0; i < source->attachments->length; ++i) { | ||
70 | struct seat_attachment_config *source_attachment = | ||
71 | source->attachments->items[i]; | ||
72 | bool found = false; | ||
73 | for (int j = 0; j < dest->attachments->length; ++j) { | ||
74 | struct seat_attachment_config *dest_attachment = | ||
75 | dest->attachments->items[j]; | ||
76 | if (strcmp(source_attachment->identifier, | ||
77 | dest_attachment->identifier) == 0) { | ||
78 | merge_seat_attachment_config(dest_attachment, | ||
79 | source_attachment); | ||
80 | found = true; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | if (!found) { | ||
85 | struct seat_attachment_config *copy = | ||
86 | seat_attachment_config_copy(source_attachment); | ||
87 | if (copy) { | ||
88 | list_add(dest->attachments, copy); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | |||
94 | void free_seat_config(struct seat_config *seat) { | ||
95 | if (!seat) { | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | free(seat->name); | ||
100 | for (int i = 0; i < seat->attachments->length; ++i) { | ||
101 | struct seat_attachment_config *attachment = | ||
102 | seat->attachments->items[i]; | ||
103 | seat_attachment_config_free(attachment); | ||
104 | } | ||
105 | |||
106 | list_free(seat->attachments); | ||
107 | free(seat); | ||
108 | } | ||
109 | |||
110 | int seat_name_cmp(const void *item, const void *data) { | ||
111 | const struct seat_config *sc = item; | ||
112 | const char *name = data; | ||
113 | return strcmp(sc->name, name); | ||
114 | } | ||
115 | |||
116 | struct seat_attachment_config *seat_config_get_attachment( | ||
117 | struct seat_config *seat_config, char *identifier) { | ||
118 | for (int i = 0; i < seat_config->attachments->length; ++i) { | ||
119 | struct seat_attachment_config *attachment = | ||
120 | seat_config->attachments->items[i]; | ||
121 | if (strcmp(attachment->identifier, identifier) == 0) { | ||
122 | return attachment; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | return NULL; | ||
127 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index c1f75b13..3d38c7c9 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -32,6 +32,8 @@ sway_sources = files( | |||
32 | 'commands/output.c', | 32 | 'commands/output.c', |
33 | 'config.c', | 33 | 'config.c', |
34 | 'config/output.c', | 34 | 'config/output.c', |
35 | 'config/seat.c', | ||
36 | 'config/input.c', | ||
35 | 'ipc-json.c', | 37 | 'ipc-json.c', |
36 | 'ipc-server.c', | 38 | 'ipc-server.c', |
37 | 'desktop/output.c', | 39 | 'desktop/output.c', |