Skip to content

Commit 700c1b0

Browse files
author
Robin Müller
committed
Added functionality to read configuration from an INI file
- use libiniparser from http://ndevilla.free.fr/iniparser/ to parse the config - read values for touch input device, thresholds and whether vert and horz scroll should be enabled from the config file
1 parent fe67fef commit 700c1b0

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AC_CONFIG_SRCDIR([src/main.c])
1010
AC_PROG_CC
1111

1212
# Checks for libraries.
13-
AC_CHECK_LIB([m], [sqrt])
13+
AC_CHECK_LIB([m], [sqrt], [], [AC_MSG_ERROR([libm is required])])
14+
AC_CHECK_LIB([iniparser], [iniparser_load], [], [AC_MSG_ERROR([libiniparser from http://ndevilla.free.fr/iniparser/ is required])])
1415

1516
# Checks for header files.
1617
AC_CHECK_HEADERS([fcntl.h stddef.h stdint.h stdlib.h string.h unistd.h])

src/configuraion.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
*/
2424

2525
#include <stdint.h>
26+
#include <stdbool.h>
27+
#include <iniparser.h>
2628

2729
#include "configuraion.h"
2830

29-
void clean_config(configuration_t *config) {
31+
static void clean_config(configuration_t *config) {
3032
int32_t i, j, k;
3133
for (i = 0; i < MAX_FINGERS; i++) {
3234
for (j = 0; j < DIRECTIONS_COUNT; j++) {
@@ -36,3 +38,24 @@ void clean_config(configuration_t *config) {
3638
}
3739
}
3840
}
41+
42+
configuration_t read_config(const char *filename) {
43+
configuration_t result;
44+
clean_config(&result);
45+
dictionary *ini = iniparser_load(filename);
46+
char *touch_device_path = iniparser_getstring(ini, "general:touchdevice", NULL);
47+
if (touch_device_path) {
48+
result.touch_device_path = malloc(strlen(touch_device_path) + 1);
49+
if (result.touch_device_path) {
50+
strcpy(result.touch_device_path, touch_device_path);
51+
}
52+
} else {
53+
result.touch_device_path = NULL;
54+
}
55+
result.vert_scroll = iniparser_getboolean(ini, "scroll:vertical", false);
56+
result.horz_scroll = iniparser_getboolean(ini, "scroll:horizontal", false);
57+
result.vert_threshold_percentage = iniparser_getint(ini, "thresholds:vertical", 15),
58+
result.horz_threshold_percentage = iniparser_getint(ini, "thresholds:horizontal", 15),
59+
iniparser_freedict(ini);
60+
return result;
61+
}

src/configuraion.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct keys_array {
4040
} keys_array_t;
4141

4242
typedef struct configuration {
43+
char *touch_device_path;
4344
bool vert_scroll;
4445
bool horz_scroll;
4546
uint8_t vert_threshold_percentage;
@@ -49,6 +50,6 @@ typedef struct configuration {
4950

5051
typedef enum direction { UP, DOWN, LEFT, RIGHT, NONE } direction_t;
5152

52-
void clean_config(configuration_t *config);
53+
configuration_t read_config(const char *filename);
5354

5455
#endif // CONFIGURATION_H_

src/main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ int main(int argc, char *argv[]) {
5151
free(keys);
5252

5353
if (argc > 1) {
54-
int fd = open(argv[1], O_RDONLY);
54+
configuration_t config = read_config(argv[1]);
55+
int fd = open(config.touch_device_path, O_RDONLY);
5556
if (fd < 0) {
5657
die("error: open");
5758
}
58-
configuration_t config;
59-
clean_config(&config);
60-
config.horz_threshold_percentage = 15;
61-
config.vert_threshold_percentage = 15;
6259
config.swipe_keys[3][UP].keys[0] = KEY_LEFTCTRL;
6360
config.swipe_keys[3][UP].keys[1] = KEY_LEFTALT;
6461
config.swipe_keys[3][UP].keys[2] = KEY_DOWN;

0 commit comments

Comments
 (0)