Skip to content

Commit 021cd14

Browse files
author
Robin Müller
committed
Init uinput with the keys from the config file
1 parent a098cbe commit 021cd14

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/main.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,45 @@
3535
#include "gestures_device.h"
3636
#include "gesture_detection.h"
3737

38-
int uinput_fd;
38+
int uinput_fd, touch_device_fd;
3939

4040
static void execute_events(input_event_array_t *input_events) {
4141
send_events(uinput_fd, input_events);
4242
}
4343

44-
int main(int argc, char *argv[]) {
45-
int_array_t *keys = new_int_array(4);
46-
keys->data[0] = KEY_LEFTCTRL;
47-
keys->data[1] = KEY_LEFTALT;
48-
keys->data[2] = KEY_UP;
49-
keys->data[3] = KEY_DOWN;
50-
uinput_fd = init_uinput(keys);
51-
free(keys);
44+
static int_array_t *get_keys_array(configuration_t config) {
45+
uint8_t i, j, k;
46+
uint8_t keys_count = 0;
47+
int_array_t *keys = new_int_array(MAX_FINGERS * DIRECTIONS_COUNT * MAX_KEYS_PER_GESTURE);
48+
for (i = 0; i < MAX_FINGERS; i++) {
49+
for (j = 0; j < DIRECTIONS_COUNT; j++) {
50+
for (k = 0; k < MAX_KEYS_PER_GESTURE; k++) {
51+
if (config.swipe_keys[i][j].keys[k] != -1) {
52+
keys->data[keys_count] = config.swipe_keys[i][j].keys[k];
53+
keys_count++;
54+
}
55+
}
56+
}
57+
}
58+
keys->length = keys_count;
59+
return keys;
60+
}
5261

62+
int main(int argc, char *argv[]) {
5363
if (argc > 1) {
5464
configuration_t config = read_config(argv[1]);
55-
int fd = open(config.touch_device_path, O_RDONLY);
56-
if (fd < 0) {
65+
int_array_t *keys = get_keys_array(config);
66+
uinput_fd = init_uinput(keys);
67+
free(keys);
68+
69+
touch_device_fd = open(config.touch_device_path, O_RDONLY);
70+
if (touch_device_fd < 0) {
5771
die("error: open");
5872
}
59-
process_events(fd, config, &execute_events);
60-
close(fd);
73+
process_events(touch_device_fd, config, &execute_events);
74+
75+
close(touch_device_fd);
76+
destroy_uinput(uinput_fd);
6177
}
62-
destroy_uinput(uinput_fd);
6378
return 0;
6479
}

0 commit comments

Comments
 (0)