Unverified Commit b1d3f2ca authored by Mihai Moldovan's avatar Mihai Moldovan

Merge branch 'uli42-pr/keyboard_fixes' into arctica-3.6.x

parents 7b79e8d8 2f2ade61
...@@ -173,8 +173,6 @@ extern Status XkbGetControls( ...@@ -173,8 +173,6 @@ extern Status XkbGetControls(
#define XKB_DFLT_KB_OPTIONS NULL #define XKB_DFLT_KB_OPTIONS NULL
#endif #endif
#define NXAGENT_KEYMAP_DIR_FILE "keymap.dir"
extern int XkbDfltRepeatDelay; extern int XkbDfltRepeatDelay;
extern int XkbDfltRepeatInterval; extern int XkbDfltRepeatInterval;
...@@ -479,6 +477,11 @@ CARD8 nxagentConvertKeycode(CARD8 k) ...@@ -479,6 +477,11 @@ CARD8 nxagentConvertKeycode(CARD8 k)
{ {
if (nxagentKeycodeConversion != 0) if (nxagentKeycodeConversion != 0)
{ {
#ifdef DEBUG
if (k != nxagentConvertedKeycodes[k])
fprintf(stderr, "nxagentConvertKeycode: converting keycode [%d] to [%d]\n", k, nxagentConvertedKeycodes[k]);
#endif
return nxagentConvertedKeycodes[k]; return nxagentConvertedKeycodes[k];
} }
else else
...@@ -503,10 +506,10 @@ static void nxagentCheckXkbBaseDirectory(void) ...@@ -503,10 +506,10 @@ static void nxagentCheckXkbBaseDirectory(void)
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentCheckXkbBaseDirectory: " fprintf(stderr, "nxagentCheckXkbBaseDirectory: "
"Before calling _NXGetXkbBasePath.\n"); "Before calling _NXGetXkbBasePath:\n");
fprintf(stderr, "nxagentCheckXkbBaseDirectory: " fprintf(stderr, "nxagentCheckXkbBaseDirectory: "
"XkbBaseDirectory varible [%s].\n", "XkbBaseDirectory variable [%s].\n",
XkbBaseDirectory); XkbBaseDirectory);
#endif #endif
...@@ -514,10 +517,10 @@ static void nxagentCheckXkbBaseDirectory(void) ...@@ -514,10 +517,10 @@ static void nxagentCheckXkbBaseDirectory(void)
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentCheckXkbBaseDirectory: " fprintf(stderr, "nxagentCheckXkbBaseDirectory: "
"After calling _NXGetXkbBasePath.\n"); "After calling _NXGetXkbBasePath:\n");
fprintf(stderr, "nxagentCheckXkbBaseDirectory: " fprintf(stderr, "nxagentCheckXkbBaseDirectory: "
"XkbBaseDirectory varible [%s].\n", "XkbBaseDirectory variable [%s].\n",
XkbBaseDirectory); XkbBaseDirectory);
#endif #endif
...@@ -539,7 +542,7 @@ static char *nxagentXkbGetRules() ...@@ -539,7 +542,7 @@ static char *nxagentXkbGetRules()
sizeDflt = strlen(XKB_DFLT_RULES_FILE); sizeDflt = strlen(XKB_DFLT_RULES_FILE);
sizeAlt = strlen(XKB_ALTS_RULES_FILE); sizeAlt = strlen(XKB_ALTS_RULES_FILE);
size = strlen(XkbBaseDirectory) + strlen("/rules/"); size = strlen(XkbBaseDirectory) + strlen("/rules/");
size += (sizeDflt > sizeAlt) ? sizeDflt: sizeAlt; size += (sizeDflt > sizeAlt) ? sizeDflt : sizeAlt;
if ((path = malloc((size + 1) * sizeof(char))) == NULL) if ((path = malloc((size + 1) * sizeof(char))) == NULL)
{ {
...@@ -694,10 +697,6 @@ int nxagentKeyboardProc(DeviceIntPtr pDev, int onoff) ...@@ -694,10 +697,6 @@ int nxagentKeyboardProc(DeviceIntPtr pDev, int onoff)
int free_model = 0, free_layout = 0; int free_model = 0, free_layout = 0;
XkbDescPtr xkb = NULL; XkbDescPtr xkb = NULL;
#ifdef TEST
int ret;
#endif
switch (onoff) switch (onoff)
{ {
case DEVICE_INIT: case DEVICE_INIT:
...@@ -854,13 +853,15 @@ XkbError: ...@@ -854,13 +853,15 @@ XkbError:
(char *) values.auto_repeats, sizeof(values.auto_repeats)); (char *) values.auto_repeats, sizeof(values.auto_repeats));
#ifdef TEST #ifdef TEST
ret = {
int ret =
#endif #endif
InitKeyboardDeviceStruct((DevicePtr) pDev, &keySyms, modmap, InitKeyboardDeviceStruct((DevicePtr) pDev, &keySyms, modmap,
nxagentBell, nxagentChangeKeyboardControl); nxagentBell, nxagentChangeKeyboardControl);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: InitKeyboardDeviceStruct returns [%d].\n", ret); fprintf(stderr, "nxagentKeyboardProc: InitKeyboardDeviceStruct returns [%d].\n", ret);
}
#endif #endif
#ifdef XKB #ifdef XKB
...@@ -868,8 +869,6 @@ XkbError: ...@@ -868,8 +869,6 @@ XkbError:
FILE *file; FILE *file;
XkbConfigRtrnRec config; XkbConfigRtrnRec config;
int nxagentXkbConfigFilePathSize;
char *nxagentXkbConfigFilePath; char *nxagentXkbConfigFilePath;
XkbComponentNamesRec names; XkbComponentNamesRec names;
...@@ -879,32 +878,30 @@ XkbError: ...@@ -879,32 +878,30 @@ XkbError:
fprintf(stderr, "nxagentKeyboardProc: Using XKB extension.\n"); fprintf(stderr, "nxagentKeyboardProc: Using XKB extension.\n");
#endif #endif
#ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: nxagentKeyboard is [%s].\n", nxagentKeyboard ? nxagentKeyboard : "NULL");
#endif
memset(&names, 0, sizeof(XkbComponentNamesRec)); memset(&names, 0, sizeof(XkbComponentNamesRec));
rules = nxagentXkbGetRules(); rules = nxagentXkbGetRules();
if ((nxagentKeyboard != NULL) && (strcmp(nxagentKeyboard, "query") !=0)) if ((nxagentKeyboard != NULL) && (strcmp(nxagentKeyboard, "query") != 0))
{ {
for (i = 0; nxagentKeyboard[i] != '/' && nxagentKeyboard[i] != 0; i++); for (i = 0; nxagentKeyboard[i] != '/' && nxagentKeyboard[i] != 0; i++);
if(nxagentKeyboard[i] == 0 || nxagentKeyboard[i + 1] == 0 || i == 0) if(nxagentKeyboard[i] == 0 || nxagentKeyboard[i + 1] == 0 || i == 0)
{ {
ErrorF("Warning: Wrong keyboard type: %s.\n",nxagentKeyboard); ErrorF("Warning: Wrong keyboard type: %s.\n", nxagentKeyboard);
goto XkbError; goto XkbError;
} }
free_model = 1; free_model = 1;
model = malloc(i + 1); model = strndup(nxagentKeyboard, i);
strncpy(model, nxagentKeyboard, i);
model[i] = '\0';
free_layout = 1; free_layout = 1;
layout = malloc(strlen(&nxagentKeyboard[i + 1]) + 1); layout = strdup(&nxagentKeyboard[i + 1]);
strcpy(layout, &nxagentKeyboard[i + 1]);
/* /*
* There is no description for pc105 on Solaris. * There is no description for pc105 on Solaris.
...@@ -946,7 +943,7 @@ XkbError: ...@@ -946,7 +943,7 @@ XkbError:
options = XKB_DFLT_KB_OPTIONS; options = XKB_DFLT_KB_OPTIONS;
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: XkbInitialMap [%s]\n", XkbInitialMap ? XkbInitialMap: "NULL"); fprintf(stderr, "nxagentKeyboardProc: XkbInitialMap [%s]\n", XkbInitialMap ? XkbInitialMap : "NULL");
#endif #endif
if (XkbInitialMap) { if (XkbInitialMap) {
...@@ -990,6 +987,11 @@ XkbError: ...@@ -990,6 +987,11 @@ XkbError:
} }
fprintf(stderr, "nxagentKeyboardProc: Going to set rules and init device.\n"); fprintf(stderr, "nxagentKeyboardProc: Going to set rules and init device.\n");
#endif #endif
#ifdef DEBUG
fprintf(stderr, "nxagentKeyboardProc: Going to set rules and init device: "
"[rules='%s',model='%s',layout='%s',variants='%s',options='%s'].\n",
rules, model, layout, variants, options);
#endif
XkbSetRulesDflts(rules, model, layout, variants, options); XkbSetRulesDflts(rules, model, layout, variants, options);
XkbInitKeyboardDeviceStruct((void *)pDev, &names, &keySyms, modmap, XkbInitKeyboardDeviceStruct((void *)pDev, &names, &keySyms, modmap,
...@@ -1007,22 +1009,15 @@ XkbError: ...@@ -1007,22 +1009,15 @@ XkbError:
XkbGetControls(nxagentDisplay, XkbAllControlsMask, xkb); XkbGetControls(nxagentDisplay, XkbAllControlsMask, xkb);
if (nxagentX2go) if (nxagentX2go)
nxagentXkbConfigFilePathSize = strlen(XKB_CONFIG_FILE_X2GO); nxagentXkbConfigFilePath = strdup(XKB_CONFIG_FILE_X2GO);
else else
nxagentXkbConfigFilePathSize = strlen(XKB_CONFIG_FILE_NX); nxagentXkbConfigFilePath = strdup(XKB_CONFIG_FILE_NX);
nxagentXkbConfigFilePath = malloc((nxagentXkbConfigFilePathSize + 1) * sizeof(char)); if (nxagentXkbConfigFilePath == NULL)
if ( nxagentXkbConfigFilePath == NULL)
{ {
FatalError("nxagentKeyboardProc: malloc failed."); FatalError("nxagentKeyboardProc: malloc failed.");
} }
if (nxagentX2go)
nxagentXkbConfigFilePathSize = strlen(XKB_CONFIG_FILE_X2GO);
else
nxagentXkbConfigFilePathSize = strlen(XKB_CONFIG_FILE_NX);
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: nxagentXkbConfigFilePath [%s].\n", fprintf(stderr, "nxagentKeyboardProc: nxagentXkbConfigFilePath [%s].\n",
nxagentXkbConfigFilePath); nxagentXkbConfigFilePath);
...@@ -1074,12 +1069,13 @@ XkbError: ...@@ -1074,12 +1069,13 @@ XkbError:
else else
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: No config file.\n");
#endif
#ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: No config file, going to set rules and init device.\n"); fprintf(stderr, "nxagentKeyboardProc: No config file, going to set rules and init device.\n");
#endif #endif
#ifdef DEBUG
fprintf(stderr, "nxagentKeyboardProc: Going to set rules and init device: "
"[rules='%s',model='%s',layout='%s',variants='%s',options='%s'].\n",
rules, model, layout, variants, options);
#endif
XkbSetRulesDflts(rules, model, layout, variants, options); XkbSetRulesDflts(rules, model, layout, variants, options);
XkbInitKeyboardDeviceStruct((void *)pDev, &names, &keySyms, modmap, XkbInitKeyboardDeviceStruct((void *)pDev, &names, &keySyms, modmap,
...@@ -1099,6 +1095,11 @@ XkbError: ...@@ -1099,6 +1095,11 @@ XkbError:
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: Going to set rules and init device.\n"); fprintf(stderr, "nxagentKeyboardProc: Going to set rules and init device.\n");
#endif #endif
#ifdef DEBUG
fprintf(stderr, "nxagentKeyboardProc: Going to set rules and init device: "
"[rules='%s',model='%s',layout='%s',variants='%s',options='%s'].\n",
rules, model, layout, variants, options);
#endif
XkbSetRulesDflts(rules, model, layout, variants, options); XkbSetRulesDflts(rules, model, layout, variants, options);
XkbInitKeyboardDeviceStruct((void *)pDev, &names, &keySyms, modmap, XkbInitKeyboardDeviceStruct((void *)pDev, &names, &keySyms, modmap,
...@@ -1404,8 +1405,8 @@ void nxagentCheckRemoteKeycodes() ...@@ -1404,8 +1405,8 @@ void nxagentCheckRemoteKeycodes()
nxagentNumLockKeycode = XKeysymToKeycode(nxagentDisplay, XK_Num_Lock); nxagentNumLockKeycode = XKeysymToKeycode(nxagentDisplay, XK_Num_Lock);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentCheckRemoteKeycodes: Remote CapsLock keycode " fprintf(stderr, "nxagentCheckRemoteKeycodes: Remote keycodes: CapsLock "
"is [%d] NumLock [%d].\n", nxagentCapsLockKeycode, "[%d] NumLock [%d].\n", nxagentCapsLockKeycode,
nxagentNumLockKeycode); nxagentNumLockKeycode);
#endif #endif
} }
...@@ -1791,11 +1792,11 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout, ...@@ -1791,11 +1792,11 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
void nxagentKeycodeConversionSetup(void) void nxagentKeycodeConversionSetup(void)
{ {
char *drules = 0; char *drules = NULL;
char *dmodel = 0; char *dmodel = NULL;
char *dlayout = 0; char *dlayout = NULL;
char *dvariant = 0; char *dvariant = NULL;
char *doptions = 0; char *doptions = NULL;
unsigned int drulesLen; unsigned int drulesLen;
nxagentKeycodeConversion = 0; nxagentKeycodeConversion = 0;
...@@ -1807,8 +1808,8 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1807,8 +1808,8 @@ void nxagentKeycodeConversionSetup(void)
if (drulesLen != 0 && drules != NULL && dmodel != NULL) if (drulesLen != 0 && drules != NULL && dmodel != NULL)
{ {
fprintf(stderr, "nxagentKeycodeConversionSetup: " fprintf(stderr, "nxagentKeycodeConversionSetup: "
"Remote: [%s,%s,%s,%s,%s].\n", drules, dmodel, dlayout, "Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
dvariant, doptions); drules, dmodel, dlayout, dvariant, doptions);
} }
else else
{ {
...@@ -1820,37 +1821,40 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1820,37 +1821,40 @@ void nxagentKeycodeConversionSetup(void)
if (drulesLen != 0) if (drulesLen != 0)
{ {
char *sessionpath = nxagentGetSessionPath(); char *sessionpath = nxagentGetSessionPath();
if (sessionpath != NULL){ if (sessionpath != NULL)
{
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 == NULL)
{ {
FatalError("nxagentKeyboardProc: 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")) != NULL) {
if ( drules != NULL ) if (drules != NULL)
fprintf(keyboard_file, "rules=%s\n", drules); fprintf(keyboard_file, "rules=\"%s\"\n", drules[0] == '\0' ? "," : drules);
if ( dmodel != NULL ) if (dmodel != NULL)
fprintf(keyboard_file, "model=%s\n", dmodel); fprintf(keyboard_file, "model=\"%s\"\n", dmodel[0] == '\0' ? "," : dmodel);
if ( dlayout != NULL ) if (dlayout != NULL)
fprintf(keyboard_file, "layout=%s\n", dlayout); fprintf(keyboard_file, "layout=\"%s\"\n", dlayout[0] == '\0' ? "," : dlayout);
if ( dvariant != NULL ) if (dvariant != NULL)
fprintf(keyboard_file, "variant=%s\n", dvariant); fprintf(keyboard_file, "variant=\"%s\"\n", dvariant[0] == '\0' ? "," : dvariant);
if ( doptions != NULL ) if (doptions != NULL)
fprintf(keyboard_file, "options=%s\n", doptions); fprintf(keyboard_file, "options=\"%s\"\n", doptions[0] == '\0' ? "," : doptions);
fclose(keyboard_file); fclose(keyboard_file);
fprintf(stderr, "keyboard file created\n"); fprintf(stderr, "keyboard file created\n");
} }
else { else
{
int save_err = errno; int save_err = errno;
fprintf(stderr, "keyboard file not created: %s\n", strerror(save_err)); fprintf(stderr, "keyboard file not created: %s\n", strerror(save_err));
} }
free(keyboard_file_path); free(keyboard_file_path);
} }
else { else
{
fprintf(stderr, "SessionPath not defined\n"); fprintf(stderr, "SessionPath not defined\n");
} }
} }
...@@ -1859,11 +1863,15 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1859,11 +1863,15 @@ void nxagentKeycodeConversionSetup(void)
fprintf(stderr, "Failed to create the keyboard file\n"); fprintf(stderr, "Failed to create the keyboard file\n");
} }
if (nxagentOption(ClientOs) == ClientOsLinux && if (drules != NULL && dmodel != NULL &&
drules != NULL && dmodel != NULL && (strcmp(drules, "evdev") == 0 ||
(strcmp(drules, "evdev") == 0 || strcmp(dmodel, "evdev") == 0))
strcmp(dmodel, "evdev") == 0))
{ {
#ifdef DEBUG
fprintf(stderr, "nxagentKeycodeConversionSetup: "
"Activating KeyCode conversion.\n");
#endif
nxagentKeycodeConversion = 1; nxagentKeycodeConversion = 1;
} }
......
...@@ -438,22 +438,14 @@ Bool nxagentReconnectSession(void) ...@@ -438,22 +438,14 @@ Bool nxagentReconnectSession(void)
if (nxagentKeyboard != NULL) if (nxagentKeyboard != NULL)
{ {
int size; nxagentOldKeyboard = strndup(nxagentKeyboard, strlen(nxagentKeyboard));
if (nxagentOldKeyboard == NULL)
size = strlen(nxagentKeyboard);
if ((nxagentOldKeyboard = malloc(size + 1)) != NULL)
{ {
strncpy(nxagentOldKeyboard, nxagentKeyboard, size); /* 0 means reconnection failed */
return 0;
nxagentOldKeyboard[size] = '\0';
} }
}
if (nxagentKeyboard)
{
free(nxagentKeyboard); free(nxagentKeyboard);
nxagentKeyboard = NULL; nxagentKeyboard = NULL;
} }
......
...@@ -223,8 +223,8 @@ static int NXVerifyXkbBaseDirectory(const char *dirPath) ...@@ -223,8 +223,8 @@ static int NXVerifyXkbBaseDirectory(const char *dirPath)
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "NXVerifyXkbBaseDirectory: Can't find the keymap.dir file [%s].\n", fprintf(stderr, "NXVerifyXkbBaseDirectory: Xkb Base Directory [%s] is not valid (can't find file [%s]).\n",
rulesBaseFilePath); dirPath, rulesBaseFilePath);
#endif #endif
free(rulesBaseFilePath); free(rulesBaseFilePath);
...@@ -767,36 +767,6 @@ char tmpname[PATH_MAX]; ...@@ -767,36 +767,6 @@ char tmpname[PATH_MAX];
strncpy(nameRtrn,keymap,nameRtrnLen); strncpy(nameRtrn,keymap,nameRtrnLen);
nameRtrn[nameRtrnLen-1]= '\0'; nameRtrn[nameRtrnLen-1]= '\0';
} }
#if defined(Lynx) && defined(__i386__) && defined(NEED_POPEN_WORKAROUND)
/* somehow popen/pclose is broken on LynxOS AT 2.3.0/2.4.0!
* the problem usually shows up with XF86Setup
* this hack waits at max 5 seconds after pclose() returns
* for the output of the xkbcomp output file.
* I didn't manage to get a patch in time for the 3.2 release
*/
{
int i;
char name[PATH_MAX];
#ifdef NXAGENT_SERVER
if (_NXGetXkbCompPath(XkbBaseDirectory)!=NULL)
sprintf(name,"%s/%s%s.xkm", _NXGetXkbCompPath(XkbBaseDirectory)
,xkm_output_dir, keymap);
#else
if (XkbBaseDirectory!=NULL)
sprintf(name,"%s/%s%s.xkm", XkbBaseDirectory
,xkm_output_dir, keymap);
#endif
else
sprintf(name,"%s%s.xkm", xkm_output_dir, keymap);
for (i = 0; i < 10; i++) {
if (access(name, 0) == 0) break;
usleep(500000);
}
#ifdef DEBUG
if (i) ErrorF(">>>> Waited %d times for %s\n", i, name);
#endif
}
#endif
if (buf != NULL) if (buf != NULL)
free (buf); free (buf);
return True; return True;
......
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