Skip to content

Commit a098cbe

Browse files
author
Robin Müller
committed
Added functionality to read the keys from the configuration file
1 parent b3cc78d commit a098cbe

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
bin_PROGRAMS = touch_gestures
2-
touch_gestures_SOURCES = main.c array.c gestures_device.c gesture_detection.c configuraion.c
2+
touch_gestures_SOURCES = main.c array.c gestures_device.c gesture_detection.c configuraion.c keys.c

src/configuraion.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
#include "configuraion.h"
3030
#include "common.h"
31+
#include "keys.h"
32+
33+
34+
char *directions[4] = { "up", "down", "left", "right" };
3135

3236
static void clean_config(configuration_t *config) {
3337
int32_t i, j, k;
@@ -40,6 +44,27 @@ static void clean_config(configuration_t *config) {
4044
}
4145
}
4246

47+
static void fill_keys_array(int (*keys_array)[MAX_KEYS_PER_GESTURE], char *keys) {
48+
if (keys) {
49+
char *ptr = strtok(keys, "+");
50+
uint8_t i = 0;
51+
while (ptr) {
52+
if (i >= MAX_KEYS_PER_GESTURE) {
53+
fprintf(stderr, "error: for each gesture only %d keystrokes are allowed\n", MAX_KEYS_PER_GESTURE);
54+
exit(EXIT_FAILURE);
55+
}
56+
int key_code = get_key_code(ptr);
57+
if (key_code < 0) {
58+
fprintf(stderr, "error: wrong key name '%s'\n", ptr);
59+
exit(EXIT_FAILURE);
60+
}
61+
(*keys_array)[i] = key_code;
62+
ptr = strtok(NULL, "+");
63+
i++;
64+
}
65+
}
66+
}
67+
4368
configuration_t read_config(const char *filename) {
4469
configuration_t result;
4570
clean_config(&result);
@@ -55,8 +80,18 @@ configuration_t read_config(const char *filename) {
5580
}
5681
result.vert_scroll = iniparser_getboolean(ini, "scroll:vertical", false);
5782
result.horz_scroll = iniparser_getboolean(ini, "scroll:horizontal", false);
58-
result.vert_threshold_percentage = iniparser_getint(ini, "thresholds:vertical", 15),
59-
result.horz_threshold_percentage = iniparser_getint(ini, "thresholds:horizontal", 15),
83+
result.vert_threshold_percentage = iniparser_getint(ini, "thresholds:vertical", 15);
84+
result.horz_threshold_percentage = iniparser_getint(ini, "thresholds:horizontal", 15);
85+
86+
uint8_t i, j;
87+
for (i = 0; i < MAX_FINGERS; i++) {
88+
for (j = 0; j < DIRECTIONS_COUNT; j++) {
89+
char ini_key[15];
90+
sprintf(ini_key, "%d-fingers:%s", INDEX_TO_FINGER(i), directions[j]);
91+
fill_keys_array(&result.swipe_keys[i][j].keys, iniparser_getstring(ini, ini_key, NULL));
92+
}
93+
}
94+
6095
iniparser_freedict(ini);
6196
return result;
6297
}

src/configuraion.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ typedef enum direction { UP, DOWN, LEFT, RIGHT, NONE } direction_t;
5252

5353
configuration_t read_config(const char *filename);
5454

55+
#define FINGER_TO_INDEX(finger) (finger - 1)
56+
#define INDEX_TO_FINGER(index) (index + 1)
57+
5558
#endif // CONFIGURATION_H_

src/gesture_detection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static input_event_array_t *process_syn_event(struct input_event event,
145145
if (direction != NONE) {
146146
uint8_t i;
147147
for (i = MAX_KEYS_PER_GESTURE; i > 0; i--) {
148-
int key = config.swipe_keys[*finger_count][direction].keys[i - 1];
148+
int key = config.swipe_keys[FINGER_TO_INDEX(*finger_count)][direction].keys[i - 1];
149149
if (key > 0) {
150150
if (!result) {
151151
result = new_input_event_array(i);

src/main.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ int main(int argc, char *argv[]) {
5656
if (fd < 0) {
5757
die("error: open");
5858
}
59-
config.swipe_keys[3][UP].keys[0] = KEY_LEFTCTRL;
60-
config.swipe_keys[3][UP].keys[1] = KEY_LEFTALT;
61-
config.swipe_keys[3][UP].keys[2] = KEY_DOWN;
62-
config.swipe_keys[3][DOWN].keys[0] = KEY_LEFTCTRL;
63-
config.swipe_keys[3][DOWN].keys[1] = KEY_LEFTALT;
64-
config.swipe_keys[3][DOWN].keys[2] = KEY_UP;
6559
process_events(fd, config, &execute_events);
6660
close(fd);
6761
}

0 commit comments

Comments
 (0)