diff options
Diffstat (limited to 'tdekbdledsync/main.cpp')
-rw-r--r-- | tdekbdledsync/main.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tdekbdledsync/main.cpp b/tdekbdledsync/main.cpp index a439ebd41..1dbf7ef73 100644 --- a/tdekbdledsync/main.cpp +++ b/tdekbdledsync/main.cpp @@ -193,11 +193,16 @@ unsigned int xkb_mask_modifier(XkbDescPtr xkb, const char *name) { } for( i = 0; i < XkbNumVirtualMods; i++ ) { char* modStr = XGetAtomName( xkb->dpy, xkb->names->vmods[i] ); - if( modStr != NULL && strcmp(name, modStr) == 0 ) { + if( modStr == NULL ) { + continue; + } + if( strcmp(name, modStr) == 0 ) { unsigned int mask; XkbVirtualModsToReal( xkb, 1 << i, &mask ); + XFree(modStr); return mask; } + XFree(modStr); } return 0; } @@ -404,14 +409,12 @@ int main() { if (x11_vt_num == vtstat.v_active) { // Get Virtual Core keyboard status - if (XkbGetIndicatorState(display, XkbUseCoreKbd, &states) != Success) { + if (XkbGetState(display, XkbUseCoreKbd, &state) != Success) { fprintf(stderr, "[tdekbdledsync] Unable to query X11 Virtual Core keyboard!\n"); releaseLock(lockfd, lockFileName); return -7; } - XkbGetState(display, XkbUseCoreKbd, &state); - caps_lock_set = (state.mods & caps_lock_mask); num_lock_set = (state.mods & num_lock_mask); scroll_lock_set = (state.mods & scroll_lock_mask); @@ -440,6 +443,11 @@ int main() { } } } + else { + // Ensure the X server is still alive + // If the X server has terminated, this will fail and the program will terminate + XSync(display, False); + } // Check the hotplug monitoring process to see if any keyboards were added or removed fd_set readfds; @@ -459,11 +467,15 @@ int main() { else { dev = udev_monitor_receive_device(mon); if (dev) { + int reload_keyboards = 0; if (strcmp(udev_device_get_action(dev), "add") == 0) { - // Reload keyboards - break; + reload_keyboards = 1; } if (strcmp(udev_device_get_action(dev), "remove") == 0) { + reload_keyboards = 1; + } + udev_device_unref(dev); + if( reload_keyboards ) { // Reload keyboards break; } @@ -499,5 +511,7 @@ int main() { } releaseLock(lockfd, lockFileName); + udev_monitor_unref(mon); + udev_unref(udev); return 0; } |