Commit 1e1ea1ce authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Keyboard.c: Some code cleanups

parent a4473785
...@@ -647,11 +647,10 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) ...@@ -647,11 +647,10 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
* devices attached to the real X server. * devices attached to the real X server.
*/ */
if (nxagentOption(DeviceControl) == True) if (nxagentOption(DeviceControl))
{ {
unsigned long value_mask; unsigned long value_mask;
XKeyboardControl values; XKeyboardControl values;
int i;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentChangeKeyboardControl: WARNING! Propagating changes to keyboard settings.\n"); fprintf(stderr, "nxagentChangeKeyboardControl: WARNING! Propagating changes to keyboard settings.\n");
...@@ -686,7 +685,7 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) ...@@ -686,7 +685,7 @@ void nxagentChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
value_mask = KBLed | KBLedMode; value_mask = KBLed | KBLedMode;
for (i = 1; i <= 32; i++) for (int i = 1; i <= 32; i++)
{ {
values.led = i; values.led = i;
values.led_mode = (ctrl->leds & (1 << (i - 1))) ? LedModeOn : LedModeOff; values.led_mode = (ctrl->leds & (1 << (i - 1))) ? LedModeOn : LedModeOff;
...@@ -888,7 +887,7 @@ XkbError: ...@@ -888,7 +887,7 @@ XkbError:
#endif #endif
#ifdef XKB #ifdef XKB
} else { } else { /* if (noXkbExtension) */
FILE *file; FILE *file;
XkbConfigRtrnRec config; XkbConfigRtrnRec config;
...@@ -920,7 +919,7 @@ XkbError: ...@@ -920,7 +919,7 @@ XkbError:
layout. layout.
*/ */
if ((nxagentKeyboard != NULL) && (strcmp(nxagentKeyboard, "query") != 0)) if (nxagentKeyboard && (strcmp(nxagentKeyboard, "query") != 0))
{ {
for (i = 0; nxagentKeyboard[i] != '/' && nxagentKeyboard[i] != 0; i++); for (i = 0; nxagentKeyboard[i] != '/' && nxagentKeyboard[i] != 0; i++);
...@@ -1046,7 +1045,7 @@ XkbError: ...@@ -1046,7 +1045,7 @@ XkbError:
else else
nxagentXkbConfigFilePath = strdup(XKB_CONFIG_FILE_NX); nxagentXkbConfigFilePath = strdup(XKB_CONFIG_FILE_NX);
if (nxagentXkbConfigFilePath == NULL) if (!nxagentXkbConfigFilePath)
{ {
FatalError("nxagentKeyboardProc: malloc failed."); FatalError("nxagentKeyboardProc: malloc failed.");
} }
...@@ -1056,7 +1055,7 @@ XkbError: ...@@ -1056,7 +1055,7 @@ XkbError:
nxagentXkbConfigFilePath); nxagentXkbConfigFilePath);
#endif #endif
if ((file = fopen(nxagentXkbConfigFilePath, "r")) != NULL) { if ((file = fopen(nxagentXkbConfigFilePath, "r"))) {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: Going to parse config file.\n"); fprintf(stderr, "nxagentKeyboardProc: Going to parse config file.\n");
...@@ -1338,17 +1337,15 @@ int nxagentResetKeyboard(void) ...@@ -1338,17 +1337,15 @@ int nxagentResetKeyboard(void)
savedBellPercent, savedBellPitch, savedBellDuration); savedBellPercent, savedBellPitch, savedBellDuration);
#endif #endif
devBackup = malloc(sizeof(DeviceIntRec)); if (devBackup = malloc(sizeof(DeviceIntRec)))
if (devBackup == NULL)
{ {
#ifdef PANIC memset(devBackup, 0, sizeof(DeviceIntRec));
fprintf(stderr, "nxagentSaveKeyboardDeviceData: PANIC! Can't allocate backup structure.\n");
#endif
} }
else else
{ {
memset(devBackup, 0, sizeof(DeviceIntRec)); #ifdef PANIC
fprintf(stderr, "nxagentResetKeyboard: PANIC! Can't allocate backup structure.\n");
#endif
} }
nxagentSaveKeyboardDeviceData(dev, devBackup); nxagentSaveKeyboardDeviceData(dev, devBackup);
...@@ -1449,7 +1446,6 @@ void nxagentCheckModifierMasks(CARD8 keycode, int j) ...@@ -1449,7 +1446,6 @@ void nxagentCheckModifierMasks(CARD8 keycode, int j)
void nxagentCheckRemoteKeycodes() void nxagentCheckRemoteKeycodes()
{ {
nxagentCapsLockKeycode = XKeysymToKeycode(nxagentDisplay, XK_Caps_Lock); nxagentCapsLockKeycode = XKeysymToKeycode(nxagentDisplay, XK_Caps_Lock);
nxagentNumLockKeycode = XKeysymToKeycode(nxagentDisplay, XK_Num_Lock); nxagentNumLockKeycode = XKeysymToKeycode(nxagentDisplay, XK_Num_Lock);
#ifdef DEBUG #ifdef DEBUG
...@@ -1461,7 +1457,7 @@ void nxagentCheckRemoteKeycodes() ...@@ -1461,7 +1457,7 @@ void nxagentCheckRemoteKeycodes()
static int nxagentSaveKeyboardDeviceData(DeviceIntPtr dev, DeviceIntPtr devBackup) static int nxagentSaveKeyboardDeviceData(DeviceIntPtr dev, DeviceIntPtr devBackup)
{ {
if (devBackup == NULL) if (!devBackup)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentSaveKeyboardDeviceData: PANIC! Pointer to backup structure is null.\n"); fprintf(stderr, "nxagentSaveKeyboardDeviceData: PANIC! Pointer to backup structure is null.\n");
...@@ -1471,9 +1467,7 @@ static int nxagentSaveKeyboardDeviceData(DeviceIntPtr dev, DeviceIntPtr devBacku ...@@ -1471,9 +1467,7 @@ static int nxagentSaveKeyboardDeviceData(DeviceIntPtr dev, DeviceIntPtr devBacku
} }
devBackup -> key = dev -> key; devBackup -> key = dev -> key;
devBackup -> focus = dev -> focus; devBackup -> focus = dev -> focus;
devBackup -> kbdfeed = dev -> kbdfeed; devBackup -> kbdfeed = dev -> kbdfeed;
#ifdef DEBUG #ifdef DEBUG
...@@ -1485,7 +1479,7 @@ static int nxagentSaveKeyboardDeviceData(DeviceIntPtr dev, DeviceIntPtr devBacku ...@@ -1485,7 +1479,7 @@ static int nxagentSaveKeyboardDeviceData(DeviceIntPtr dev, DeviceIntPtr devBacku
static int nxagentRestoreKeyboardDeviceData(DeviceIntPtr devBackup, DeviceIntPtr dev) static int nxagentRestoreKeyboardDeviceData(DeviceIntPtr devBackup, DeviceIntPtr dev)
{ {
if (devBackup == NULL) if (!devBackup)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentRestoreKeyboardDeviceData: PANIC! Pointer to backup structure is null.\n"); fprintf(stderr, "nxagentRestoreKeyboardDeviceData: PANIC! Pointer to backup structure is null.\n");
...@@ -1495,9 +1489,7 @@ static int nxagentRestoreKeyboardDeviceData(DeviceIntPtr devBackup, DeviceIntPtr ...@@ -1495,9 +1489,7 @@ static int nxagentRestoreKeyboardDeviceData(DeviceIntPtr devBackup, DeviceIntPtr
} }
dev -> key = devBackup -> key; dev -> key = devBackup -> key;
dev -> focus = devBackup -> focus; dev -> focus = devBackup -> focus;
dev -> kbdfeed = devBackup -> kbdfeed; dev -> kbdfeed = devBackup -> kbdfeed;
#ifdef DEBUG #ifdef DEBUG
...@@ -1512,7 +1504,7 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev) ...@@ -1512,7 +1504,7 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev)
{ {
KbdFeedbackPtr k, knext; KbdFeedbackPtr k, knext;
if (dev == NULL) if (!dev)
{ {
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentFreeKeyboardDeviceData: PANIC! Pointer to device structure is null.\n"); fprintf(stderr, "nxagentFreeKeyboardDeviceData: PANIC! Pointer to device structure is null.\n");
...@@ -1535,14 +1527,14 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev) ...@@ -1535,14 +1527,14 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev)
free(dev->key->modifierKeyMap); free(dev->key->modifierKeyMap);
free(dev->key); free(dev->key);
dev->key=NULL; dev->key = NULL;
} }
if (dev->focus) if (dev->focus)
{ {
free(dev->focus->trace); free(dev->focus->trace);
free(dev->focus); free(dev->focus);
dev->focus=NULL; dev->focus = NULL;
} }
for (k = dev->kbdfeed; k; k = knext) for (k = dev->kbdfeed; k; k = knext)
...@@ -1624,7 +1616,7 @@ void nxagentInitXkbWrapper(void) ...@@ -1624,7 +1616,7 @@ void nxagentInitXkbWrapper(void)
fprintf(stderr, "nxagentInitXkbWrapper: Called.\n"); fprintf(stderr, "nxagentInitXkbWrapper: Called.\n");
#endif #endif
if (nxagentOption(InhibitXkb) == 0) if (!nxagentOption(InhibitXkb))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentInitXkbWrapper: Nothing to do.\n"); fprintf(stderr, "nxagentInitXkbWrapper: Nothing to do.\n");
...@@ -1635,9 +1627,7 @@ void nxagentInitXkbWrapper(void) ...@@ -1635,9 +1627,7 @@ void nxagentInitXkbWrapper(void)
memset(&nxagentXkbWrapper, 0, sizeof(XkbWrapperRec)); memset(&nxagentXkbWrapper, 0, sizeof(XkbWrapperRec));
extension = CheckExtension("XKEYBOARD"); if ((extension = CheckExtension("XKEYBOARD")))
if (extension != NULL)
{ {
nxagentXkbWrapper.base = extension -> base; nxagentXkbWrapper.base = extension -> base;
nxagentXkbWrapper.eventBase = extension -> eventBase; nxagentXkbWrapper.eventBase = extension -> eventBase;
...@@ -1668,7 +1658,7 @@ void nxagentDisableXkbExtension(void) ...@@ -1668,7 +1658,7 @@ void nxagentDisableXkbExtension(void)
if (nxagentXkbWrapper.base > 0) if (nxagentXkbWrapper.base > 0)
{ {
if (nxagentXkbWrapper.ProcXkbDispatchBackup == NULL) if (!nxagentXkbWrapper.ProcXkbDispatchBackup)
{ {
nxagentXkbWrapper.ProcXkbDispatchBackup = ProcVector[nxagentXkbWrapper.base]; nxagentXkbWrapper.ProcXkbDispatchBackup = ProcVector[nxagentXkbWrapper.base];
...@@ -1681,7 +1671,7 @@ void nxagentDisableXkbExtension(void) ...@@ -1681,7 +1671,7 @@ void nxagentDisableXkbExtension(void)
} }
#endif #endif
if (nxagentXkbWrapper.SProcXkbDispatchBackup == NULL) if (!nxagentXkbWrapper.SProcXkbDispatchBackup)
{ {
nxagentXkbWrapper.SProcXkbDispatchBackup = SwappedProcVector[nxagentXkbWrapper.base]; nxagentXkbWrapper.SProcXkbDispatchBackup = SwappedProcVector[nxagentXkbWrapper.base];
...@@ -1704,7 +1694,7 @@ void nxagentEnableXkbExtension(void) ...@@ -1704,7 +1694,7 @@ void nxagentEnableXkbExtension(void)
if (nxagentXkbWrapper.base > 0) if (nxagentXkbWrapper.base > 0)
{ {
if (nxagentXkbWrapper.ProcXkbDispatchBackup != NULL) if (nxagentXkbWrapper.ProcXkbDispatchBackup)
{ {
ProcVector[nxagentXkbWrapper.base] = nxagentXkbWrapper.ProcXkbDispatchBackup; ProcVector[nxagentXkbWrapper.base] = nxagentXkbWrapper.ProcXkbDispatchBackup;
...@@ -1717,7 +1707,7 @@ void nxagentEnableXkbExtension(void) ...@@ -1717,7 +1707,7 @@ void nxagentEnableXkbExtension(void)
} }
#endif #endif
if (nxagentXkbWrapper.SProcXkbDispatchBackup != NULL) if (nxagentXkbWrapper.SProcXkbDispatchBackup)
{ {
SwappedProcVector[nxagentXkbWrapper.base] = nxagentXkbWrapper.SProcXkbDispatchBackup; SwappedProcVector[nxagentXkbWrapper.base] = nxagentXkbWrapper.SProcXkbDispatchBackup;
...@@ -1744,7 +1734,7 @@ void nxagentEnableXkbExtension(void) ...@@ -1744,7 +1734,7 @@ void nxagentEnableXkbExtension(void)
*/ */
void nxagentTuneXkbWrapper(void) void nxagentTuneXkbWrapper(void)
{ {
if (nxagentOption(InhibitXkb) == 0) if (!nxagentOption(InhibitXkb))
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentTuneXkbWrapper: Nothing to do.\n"); fprintf(stderr, "nxagentTuneXkbWrapper: Nothing to do.\n");
...@@ -1753,8 +1743,7 @@ void nxagentTuneXkbWrapper(void) ...@@ -1753,8 +1743,7 @@ void nxagentTuneXkbWrapper(void)
return; return;
} }
if (nxagentKeyboard != NULL && if (nxagentKeyboard && strcmp(nxagentKeyboard, "query") == 0)
strcmp(nxagentKeyboard, "query") == 0)
{ {
nxagentDisableXkbExtension(); nxagentDisableXkbExtension();
} }
...@@ -1799,14 +1788,14 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout, ...@@ -1799,14 +1788,14 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
atom, 0, 256, 0, XA_STRING, &type, &format, atom, 0, 256, 0, XA_STRING, &type, &format,
&n, &after, (unsigned char **)&data); &n, &after, (unsigned char **)&data);
if (result !=Success || data == NULL) if (result != Success || !data)
{ {
return 0; return 0;
} }
if ((after > 0) || (type != XA_STRING) || (format != 8)) if ((after > 0) || (type != XA_STRING) || (format != 8))
{ {
if (data != NULL) if (data)
{ {
XFree(data); XFree(data);
return 0; return 0;
...@@ -1876,7 +1865,7 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1876,7 +1865,7 @@ void nxagentKeycodeConversionSetup(void)
&dvariant, &doptions); &dvariant, &doptions);
#ifdef DEBUG #ifdef DEBUG
if (drulesLen != 0 && drules != NULL && dmodel != NULL) if (drulesLen != 0 && drules && dmodel)
{ {
fprintf(stderr, "nxagentKeycodeConversionSetup: " fprintf(stderr, "nxagentKeycodeConversionSetup: "
"Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n", "Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
...@@ -1892,27 +1881,27 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1892,27 +1881,27 @@ void nxagentKeycodeConversionSetup(void)
if (drulesLen != 0) if (drulesLen != 0)
{ {
char *sessionpath = nxagentGetSessionPath(); char *sessionpath = nxagentGetSessionPath();
if (sessionpath != NULL) if (sessionpath)
{ {
int keyboard_file_path_size = strlen(sessionpath) + strlen("/keyboard"); int keyboard_file_path_size = strlen(sessionpath) + strlen("/keyboard");
char *keyboard_file_path = malloc((keyboard_file_path_size + 1) * sizeof(char)); char *keyboard_file_path = malloc((keyboard_file_path_size + 1) * sizeof(char));
FILE *keyboard_file; FILE *keyboard_file;
if (keyboard_file_path == NULL) if (!keyboard_file_path)
{ {
FatalError("nxagentKeycodeConversionSetup: malloc failed."); FatalError("nxagentKeycodeConversionSetup: malloc failed.");
} }
strcpy(keyboard_file_path, sessionpath); strcpy(keyboard_file_path, sessionpath);
strcat(keyboard_file_path, "/keyboard"); strcat(keyboard_file_path, "/keyboard");
if ((keyboard_file = fopen(keyboard_file_path, "w")) != NULL) { if ((keyboard_file = fopen(keyboard_file_path, "w"))) {
if (drules != NULL) if (drules)
fprintf(keyboard_file, "rules=\"%s\"\n", drules[0] == '\0' ? "," : drules); fprintf(keyboard_file, "rules=\"%s\"\n", drules[0] == '\0' ? "," : drules);
if (dmodel != NULL) if (dmodel)
fprintf(keyboard_file, "model=\"%s\"\n", dmodel[0] == '\0' ? "," : dmodel); fprintf(keyboard_file, "model=\"%s\"\n", dmodel[0] == '\0' ? "," : dmodel);
if (dlayout != NULL) if (dlayout)
fprintf(keyboard_file, "layout=\"%s\"\n", dlayout[0] == '\0' ? "," : dlayout); fprintf(keyboard_file, "layout=\"%s\"\n", dlayout[0] == '\0' ? "," : dlayout);
if (dvariant != NULL) if (dvariant)
fprintf(keyboard_file, "variant=\"%s\"\n", dvariant[0] == '\0' ? "," : dvariant); fprintf(keyboard_file, "variant=\"%s\"\n", dvariant[0] == '\0' ? "," : dvariant);
if (doptions != NULL) if (doptions)
fprintf(keyboard_file, "options=\"%s\"\n", doptions[0] == '\0' ? "," : doptions); fprintf(keyboard_file, "options=\"%s\"\n", doptions[0] == '\0' ? "," : doptions);
fclose(keyboard_file); fclose(keyboard_file);
fprintf(stderr, "Info: keyboard file created\n"); fprintf(stderr, "Info: keyboard file created\n");
...@@ -1934,7 +1923,7 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1934,7 +1923,7 @@ void nxagentKeycodeConversionSetup(void)
fprintf(stderr, "Warning: Failed to create the keyboard file\n"); fprintf(stderr, "Warning: Failed to create the keyboard file\n");
} }
if (drules != NULL && dmodel != NULL && if (drules && dmodel &&
(strcmp(drules, "evdev") == 0 || (strcmp(drules, "evdev") == 0 ||
strcmp(dmodel, "evdev") == 0)) strcmp(dmodel, "evdev") == 0))
{ {
...@@ -1951,7 +1940,7 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1951,7 +1940,7 @@ void nxagentKeycodeConversionSetup(void)
fprintf(stderr, "Info: Keycode conversion auto-determined as off\n"); fprintf(stderr, "Info: Keycode conversion auto-determined as off\n");
} }
if (drules != NULL) if (drules)
{ {
XFree(drules); XFree(drules);
} }
...@@ -1981,4 +1970,4 @@ void nxagentResetKeycodeConversion(void) ...@@ -1981,4 +1970,4 @@ void nxagentResetKeycodeConversion(void)
} }
} }
#endif #endif /* XKB */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment