diff options
Diffstat (limited to 'sway/config/input.c')
-rw-r--r-- | sway/config/input.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/sway/config/input.c b/sway/config/input.c new file mode 100644 index 00000000..5e657c43 --- /dev/null +++ b/sway/config/input.c | |||
@@ -0,0 +1,119 @@ | |||
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 | wlr_log(L_DEBUG, "Unable to allocate input config"); | ||
12 | return NULL; | ||
13 | } | ||
14 | wlr_log(L_DEBUG, "new_input_config(%s)", identifier); | ||
15 | if (!(input->identifier = strdup(identifier))) { | ||
16 | free(input); | ||
17 | wlr_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 | if (src->mapped_output) { | ||
92 | free(dst->mapped_output); | ||
93 | dst->mapped_output = strdup(src->mapped_output); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | struct input_config *copy_input_config(struct input_config *ic) { | ||
98 | struct input_config *copy = calloc(1, sizeof(struct input_config)); | ||
99 | if (copy == NULL) { | ||
100 | wlr_log(L_ERROR, "could not allocate input config"); | ||
101 | return NULL; | ||
102 | } | ||
103 | merge_input_config(copy, ic); | ||
104 | return copy; | ||
105 | } | ||
106 | |||
107 | void free_input_config(struct input_config *ic) { | ||
108 | if (!ic) { | ||
109 | return; | ||
110 | } | ||
111 | free(ic->identifier); | ||
112 | free(ic); | ||
113 | } | ||
114 | |||
115 | int input_identifier_cmp(const void *item, const void *data) { | ||
116 | const struct input_config *ic = item; | ||
117 | const char *identifier = data; | ||
118 | return strcmp(ic->identifier, identifier); | ||
119 | } | ||