|
35 | 35 | #include "gestures_device.h"
|
36 | 36 | #include "gesture_detection.h"
|
37 | 37 |
|
38 |
| -int uinput_fd; |
| 38 | +int uinput_fd, touch_device_fd; |
39 | 39 |
|
40 | 40 | static void execute_events(input_event_array_t *input_events) {
|
41 | 41 | send_events(uinput_fd, input_events);
|
42 | 42 | }
|
43 | 43 |
|
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 | +} |
52 | 61 |
|
| 62 | +int main(int argc, char *argv[]) { |
53 | 63 | if (argc > 1) {
|
54 | 64 | 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) { |
57 | 71 | die("error: open");
|
58 | 72 | }
|
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); |
61 | 77 | }
|
62 |
| - destroy_uinput(uinput_fd); |
63 | 78 | return 0;
|
64 | 79 | }
|
0 commit comments