diff options
Diffstat (limited to 'src/device.c')
-rw-r--r-- | src/device.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/device.c b/src/device.c index 9aa5485..a7735ef 100644 --- a/src/device.c +++ b/src/device.c @@ -452,7 +452,7 @@ get_keyboard_keycodes() { int keycode; gchar **lines; gchar *line; - int i; + int i, status; int index = 0; struct NonPrint_Key_Synth old_NonPrint_Key_Synth_Vals[] = {{"escape", 9}, {"esc", 9}, {"backspace", 22}, @@ -476,35 +476,40 @@ get_keyboard_keycodes() { src = (char *) malloc(sizeof(char) * 100); readed = 0; - fd = popen("xmodmap -pke", "r"); + fd = popen("xmodmap -pke 2>/dev/null", "r"); while ( ! feof(fd)) { readed += fread(src + readed, 1, 100, fd); src = (char *) realloc(src, sizeof(char)*(readed+100)); } - pclose(fd); + status = pclose(fd); - lines = g_strsplit(src, "\n", 0); + if (status != -1) { + lines = g_strsplit(src, "\n", 0); - for (index=0; lines != NULL && strcmp(*lines, ""); lines++) { - gchar **split; - line = *lines; + for (index=0; lines != NULL && strcmp(*lines, ""); lines++) { + gchar **split; + line = *lines; - split = g_strsplit(line, "=", 2); - keycode = atoi(split[0] + 7); + split = g_strsplit(line, "=", 2); + keycode = atoi(split[0] + 7); - if (strlen(split[1]) > 0) { - gchar **space_split = g_strsplit(split[1], " ", 3); - NonPrint_Key_Synth_Vals[index].sym = space_split[1]; - NonPrint_Key_Synth_Vals[index].KeyVal = keycode; - index++; + if (strlen(split[1]) > 0) { + gchar **space_split = g_strsplit(split[1], " ", 3); + NonPrint_Key_Synth_Vals[index].sym = space_split[1]; + NonPrint_Key_Synth_Vals[index].KeyVal = keycode; + index++; + } } + } else if (src) { + g_free (src); + src = NULL; } int old_len = sizeof(old_NonPrint_Key_Synth_Vals) / sizeof(struct NonPrint_Key_Synth); - for(i=0 ; index < 300 && i < old_len; index++, i++) + for(i = 0 ; index < 300 && i < old_len; index++, i++) NonPrint_Key_Synth_Vals[index] = old_NonPrint_Key_Synth_Vals[i]; NonPrint_Key_Synth_Vals[index].sym = NULL; |