Unverified Commit ab3e1485 authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/keyboard_cleanup' into 3.6.x

parents 70cb1926 26b033b8
......@@ -81,7 +81,9 @@ is" without express or implied warranty.
static int nxagentXkbGetNames(char **rules, char **model, char **layout,
char **variant, char **options);
static void nxagentKeycodeConversionSetup(void);
static void nxagentKeycodeConversionSetup(char *rules, char *model);
void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, char *variant, char *options);
#endif /* XKB */
......@@ -706,12 +708,6 @@ N/A
#ifdef XKB
/*
* First of all the validity
* of XkbBaseDirectory global
* variable is checked.
*/
if (noXkbExtension) {
#ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: No XKB extension.\n");
......@@ -744,7 +740,7 @@ XkbError:
#ifdef XKB
} else { /* if (noXkbExtension) */
XkbComponentNamesRec names = {0};
char *rules = NULL, *variants = NULL, *options = NULL; /* use xkb default */
char *rules = NULL, *variant = NULL, *options = NULL; /* use xkb default */
#ifdef TEST
fprintf(stderr, "nxagentKeyboardProc: Using XKB extension.\n");
......@@ -816,9 +812,38 @@ XkbError:
fprintf(stderr, "nxagentKeyboardProc: Init XKB extension.\n");
#endif
xkb = XkbGetKeyboard(nxagentDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd);
{
char *remoterules = NULL;
char *remotemodel = NULL;
char *remotelayout = NULL;
char *remotevariant = NULL;
char *remoteoptions = NULL;
unsigned int remoteruleslen = nxagentXkbGetNames(&remoterules, &remotemodel, &remotelayout,
&remotevariant, &remoteoptions);
#ifdef DEBUG
if (remoteruleslen && remoterules && remotemodel)
{
fprintf(stderr, "%s: Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
__func__, remoterules, remotemodel, remotelayout, remotevariant, remoteoptions);
}
else
{
fprintf(stderr, "%s: Failed to retrieve remote rules.\n", __func__);
}
#endif
nxagentKeycodeConversionSetup();
nxagentWriteKeyboardFile(remoterules, remotemodel, remotelayout, remotevariant, remoteoptions);
nxagentKeycodeConversionSetup(remoterules, remotemodel);
if (remoterules)
{
XFree(remoterules);
}
}
xkb = XkbGetKeyboard(nxagentDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd);
if (xkb && xkb->geom)
{
......@@ -833,11 +858,11 @@ XkbError:
#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);
"[rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
rules, model, layout, variant, options);
#endif
XkbSetRulesDflts(rules, model, layout, variants, options);
XkbSetRulesDflts(rules, model, layout, variant, options);
XkbInitKeyboardDeviceStruct((void *)pDev, &names, &keySyms, modmap,
nxagentBell, nxagentChangeKeyboardControl);
......@@ -1557,49 +1582,32 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
return n;
}
void nxagentKeycodeConversionSetup(void)
void writeKeyboardfileData(FILE *out, char *rules, char *model, char *layout, char *variant, char *options)
{
char *drules = NULL;
char *dmodel = NULL;
char *dlayout = NULL;
char *dvariant = NULL;
char *doptions = NULL;
unsigned int drulesLen;
/*
How to set "empty" values with setxkbmap, result of trial and error:
- model and layout: empty strings are accepted by setxkbmap.
- rules: setxkbmap will fail if rules is an empty string
(code will intercept in an earlier stage in that case)
- variant: the variant line must be omitted completely.
- options: prepend value with "," to override, otherwise options will be added.
*/
fprintf(out, "rules=\"%s\"\n", rules);
fprintf(out, "model=\"%s\"\n", model ? model : "");
fprintf(out, "layout=\"%s\"\n", layout ? layout : "");
if (variant && variant[0] != '\0')
fprintf(out, "variant=\"%s\"\n", variant);
fprintf(out, "options=\",%s\"\n", options ? options : "");
}
if (nxagentOption(KeycodeConversion) == KeycodeConversionOff)
{
fprintf(stderr, "Info: Keycode conversion is off\n");
nxagentKeycodeConversion = False;
return;
}
else if (nxagentOption(KeycodeConversion) == KeycodeConversionOn)
void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, char *variant, char *options)
{
if (rules && rules[0] != '\0')
{
fprintf(stderr, "Info: Keycode conversion is on\n");
nxagentKeycodeConversion = True;
return;
}
nxagentKeycodeConversion = False;
drulesLen = nxagentXkbGetNames(&drules, &dmodel, &dlayout,
&dvariant, &doptions);
#ifdef DEBUG
if (drulesLen != 0 && drules && dmodel)
{
fprintf(stderr, "nxagentKeycodeConversionSetup: "
"Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
drules, dmodel, dlayout, dvariant, doptions);
}
else
{
fprintf(stderr, "nxagentKeycodeConversionSetup: "
"Failed to retrieve remote rules.\n");
}
writeKeyboardfileData(stderr, rules, model, layout, variant, options);
#endif
if (drulesLen != 0)
{
char *sessionpath = nxagentGetSessionPath();
if (sessionpath)
{
......@@ -1613,16 +1621,8 @@ void nxagentKeycodeConversionSetup(void)
free(sessionpath);
if ((keyboard_file = fopen(keyboard_file_path, "w")))
{
if (drules)
fprintf(keyboard_file, "rules=\"%s\"\n", drules[0] == '\0' ? "," : drules);
if (dmodel)
fprintf(keyboard_file, "model=\"%s\"\n", dmodel[0] == '\0' ? "," : dmodel);
if (dlayout)
fprintf(keyboard_file, "layout=\"%s\"\n", dlayout[0] == '\0' ? "," : dlayout);
if (dvariant)
fprintf(keyboard_file, "variant=\"%s\"\n", dvariant[0] == '\0' ? "," : dvariant);
if (doptions)
fprintf(keyboard_file, "options=\"%s\"\n", doptions[0] == '\0' ? "," : doptions);
writeKeyboardfileData(keyboard_file, rules, model, layout, variant, options);
fclose(keyboard_file);
fprintf(stderr, "Info: keyboard file created: '%s'\n", keyboard_file_path);
}
......@@ -1635,21 +1635,35 @@ void nxagentKeycodeConversionSetup(void)
}
else
{
fprintf(stderr, "Warning: SessionPath not defined\n");
fprintf(stderr, "Warning: Failed to create keyboard file: SessionPath not defined\n");
}
}
else
{
fprintf(stderr, "Warning: Failed to create the keyboard file\n");
}
}
if (drules && dmodel &&
(strcmp(drules, "evdev") == 0 ||
strcmp(dmodel, "evdev") == 0))
void nxagentKeycodeConversionSetup(char * rules, char * model)
{
if (nxagentOption(KeycodeConversion) == KeycodeConversionOff)
{
fprintf(stderr, "Info: Keycode conversion is off\n");
nxagentKeycodeConversion = False;
}
else if (nxagentOption(KeycodeConversion) == KeycodeConversionOn)
{
fprintf(stderr, "Info: Keycode conversion is on\n");
nxagentKeycodeConversion = True;
}
else
{
if (rules && model &&
(strcmp(rules, "evdev") == 0 ||
strcmp(model, "evdev") == 0))
{
#ifdef DEBUG
fprintf(stderr, "nxagentKeycodeConversionSetup: "
"Activating KeyCode conversion.\n");
fprintf(stderr, "%s: Activating KeyCode conversion.\n", __func__);
#endif
fprintf(stderr, "Info: Keycode conversion auto-determined as on\n");
......@@ -1657,12 +1671,13 @@ void nxagentKeycodeConversionSetup(void)
}
else
{
#ifdef DEBUG
fprintf(stderr, "%s: Deactivating KeyCode conversion.\n", __func__);
#endif
fprintf(stderr, "Info: Keycode conversion auto-determined as off\n");
nxagentKeycodeConversion = False;
}
if (drules)
{
XFree(drules);
}
}
......@@ -1677,7 +1692,21 @@ void nxagentResetKeycodeConversion(void)
if (result != 0)
{
nxagentKeycodeConversionSetup();
char *remoterules = NULL;
char *remotemodel = NULL;
char *remotelayout = NULL;
char *remotevariant = NULL;
char *remoteoptions = NULL;
unsigned int remoteruleslen;
remoteruleslen = nxagentXkbGetNames(&remoterules, &remotemodel, &remotelayout,
&remotevariant, &remoteoptions);
if (remoteruleslen && remoterules && remotemodel)
nxagentKeycodeConversionSetup(remoterules, remotemodel);
if (remoterules)
XFree(remoterules);
}
else
{
......
......@@ -584,6 +584,17 @@ Bool nxagentReconnectSession(void)
goto nxagentReconnectError;
}
/* if there's no keyboard definition in the options file
restore the previous value. */
#ifdef DEBUG
fprintf(stderr, "%s: nxagentKeyboard [%s] nxagentOldKeyboard [%s]\n", __func__, nxagentKeyboard, nxagentOldKeyboard);
#endif
if (nxagentKeyboard == NULL)
{
nxagentKeyboard = nxagentOldKeyboard;
nxagentOldKeyboard = NULL;
}
if (nxagentOption(ResetKeyboardAtResume) == 1 &&
(nxagentKeyboard == NULL || nxagentOldKeyboard == NULL ||
strcmp(nxagentKeyboard, nxagentOldKeyboard) != 0 ||
......
......@@ -620,12 +620,12 @@ settings.
.I <model>/<layout>
use the given model and layout. You can not modify keyboard rules,
variant or options. Instead preset values are used. These are
\fIxfree86\fR for rules and empty strings for variant and options.
\fIbase\fR for rules and empty strings for variant and options.
.RE
.TP 8
.PP
If \fIkeyboard\fR is omitted the internal defaults of \fBnxagent\fR will be used (rules: \fIxfree86\fR, layout: \fIus\fR, model: \fIpc102\fR, empty variant and options).
If \fIkeyboard\fR is omitted the internal defaults of \fBnxagent\fR will be used (rules: \fIbase\fR, layout: \fIus\fR, model: \fIpc102\fR, empty variant and options).
.TP 8
.B keyconv=<string>
......
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