diff options
Diffstat (limited to 'sway/input/input.c')
-rw-r--r-- | sway/input/input.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/sway/input/input.c b/sway/input/input.c new file mode 100644 index 00000000..02b4995e --- /dev/null +++ b/sway/input/input.c | |||
@@ -0,0 +1,77 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include <ctype.h> | ||
3 | #include <float.h> | ||
4 | #include <limits.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <libinput.h> | ||
8 | #include "sway/config.h" | ||
9 | #include "sway/input.h" | ||
10 | #include "sway/server.h" | ||
11 | #include "list.h" | ||
12 | #include "log.h" | ||
13 | |||
14 | struct input_config *current_input_config = NULL; | ||
15 | |||
16 | struct sway_input *sway_input_create(struct sway_server *server) { | ||
17 | struct sway_input *input = calloc(1, sizeof(struct sway_input)); | ||
18 | if (!input) { | ||
19 | return NULL; | ||
20 | } | ||
21 | return input; | ||
22 | } | ||
23 | |||
24 | struct input_config *new_input_config(const char* identifier) { | ||
25 | struct input_config *input = calloc(1, sizeof(struct input_config)); | ||
26 | if (!input) { | ||
27 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
28 | return NULL; | ||
29 | } | ||
30 | sway_log(L_DEBUG, "new_input_config(%s)", identifier); | ||
31 | if (!(input->identifier = strdup(identifier))) { | ||
32 | free(input); | ||
33 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
34 | return NULL; | ||
35 | } | ||
36 | |||
37 | input->tap = INT_MIN; | ||
38 | input->drag_lock = INT_MIN; | ||
39 | input->dwt = INT_MIN; | ||
40 | input->send_events = INT_MIN; | ||
41 | input->click_method = INT_MIN; | ||
42 | input->middle_emulation = INT_MIN; | ||
43 | input->natural_scroll = INT_MIN; | ||
44 | input->accel_profile = INT_MIN; | ||
45 | input->pointer_accel = FLT_MIN; | ||
46 | input->scroll_method = INT_MIN; | ||
47 | input->left_handed = INT_MIN; | ||
48 | |||
49 | return input; | ||
50 | } | ||
51 | |||
52 | char *libinput_dev_unique_id(struct libinput_device *device) { | ||
53 | int vendor = libinput_device_get_id_vendor(device); | ||
54 | int product = libinput_device_get_id_product(device); | ||
55 | char *name = strdup(libinput_device_get_name(device)); | ||
56 | |||
57 | char *p = name; | ||
58 | for (; *p; ++p) { | ||
59 | if (*p == ' ') { | ||
60 | *p = '_'; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | sway_log(L_DEBUG, "rewritten name %s", name); | ||
65 | |||
66 | int len = strlen(name) + sizeof(char) * 6; | ||
67 | char *identifier = malloc(len); | ||
68 | if (!identifier) { | ||
69 | sway_log(L_ERROR, "Unable to allocate unique input device name"); | ||
70 | return NULL; | ||
71 | } | ||
72 | |||
73 | const char *fmt = "%d:%d:%s"; | ||
74 | snprintf(identifier, len, fmt, vendor, product, name); | ||
75 | free(name); | ||
76 | return identifier; | ||
77 | } | ||