Commit 269a352f authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Keyboard.c: refactor keycode conversion

we'll need the remote xkb in KeyboardProc in future so let's move it up.
parent d610e9c3
...@@ -81,7 +81,7 @@ is" without express or implied warranty. ...@@ -81,7 +81,7 @@ is" without express or implied warranty.
static int nxagentXkbGetNames(char **rules, char **model, char **layout, static int nxagentXkbGetNames(char **rules, char **model, char **layout,
char **variant, char **options); char **variant, char **options);
static void nxagentKeycodeConversionSetup(void); static void nxagentKeycodeConversionSetup(char *rules, char *model);
void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, char *layout, char *variant, char *options); void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, char *layout, char *variant, char *options);
...@@ -818,9 +818,38 @@ XkbError: ...@@ -818,9 +818,38 @@ XkbError:
fprintf(stderr, "nxagentKeyboardProc: Init XKB extension.\n"); fprintf(stderr, "nxagentKeyboardProc: Init XKB extension.\n");
#endif #endif
xkb = XkbGetKeyboard(nxagentDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd); {
char *drules = NULL;
char *dmodel = NULL;
char *dlayout = NULL;
char *dvariant = NULL;
char *doptions = NULL;
unsigned int drulesLen = nxagentXkbGetNames(&drules, &dmodel, &dlayout,
&dvariant, &doptions);
#ifdef DEBUG
if (drulesLen && drules && dmodel)
{
fprintf(stderr, "%s: Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
__func__, drules, dmodel, dlayout, dvariant, doptions);
}
else
{
fprintf(stderr, "%s: Failed to retrieve remote rules.\n", __func__);
}
#endif
nxagentWriteKeyboardFile(drulesLen, drules, dmodel, dlayout, dvariant, doptions);
nxagentKeycodeConversionSetup(drules, dmodel);
if (drules)
{
XFree(drules);
}
}
nxagentKeycodeConversionSetup(); xkb = XkbGetKeyboard(nxagentDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd);
if (xkb && xkb->geom) if (xkb && xkb->geom)
{ {
...@@ -1609,15 +1638,8 @@ void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, c ...@@ -1609,15 +1638,8 @@ void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, c
} }
} }
void nxagentKeycodeConversionSetup(void) void nxagentKeycodeConversionSetup(char * rules, char * model)
{ {
char *drules = NULL;
char *dmodel = NULL;
char *dlayout = NULL;
char *dvariant = NULL;
char *doptions = NULL;
unsigned int drulesLen;
if (nxagentOption(KeycodeConversion) == KeycodeConversionOff) if (nxagentOption(KeycodeConversion) == KeycodeConversionOff)
{ {
fprintf(stderr, "Info: Keycode conversion is off\n"); fprintf(stderr, "Info: Keycode conversion is off\n");
...@@ -1631,28 +1653,9 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1631,28 +1653,9 @@ void nxagentKeycodeConversionSetup(void)
return; return;
} }
nxagentKeycodeConversion = False; if (rules && model &&
(strcmp(rules, "evdev") == 0 ||
drulesLen = nxagentXkbGetNames(&drules, &dmodel, &dlayout, strcmp(model, "evdev") == 0))
&dvariant, &doptions);
#ifdef DEBUG
if (drulesLen != 0 && drules && dmodel)
{
fprintf(stderr, "%s: Remote: [rules='%s',model='%s',layout='%s',variant='%s',options='%s'].\n",
__func__, drules, dmodel, dlayout, dvariant, doptions);
}
else
{
fprintf(stderr, "%s: Failed to retrieve remote rules.\n", __func__);
}
#endif
nxagentWriteKeyboardFile(drulesLen, drules, dmodel, dlayout, dvariant, doptions);
if (drules && dmodel &&
(strcmp(drules, "evdev") == 0 ||
strcmp(dmodel, "evdev") == 0))
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: Activating KeyCode conversion.\n", __func__); fprintf(stderr, "%s: Activating KeyCode conversion.\n", __func__);
...@@ -1663,12 +1666,13 @@ void nxagentKeycodeConversionSetup(void) ...@@ -1663,12 +1666,13 @@ void nxagentKeycodeConversionSetup(void)
} }
else else
{ {
#ifdef DEBUG
fprintf(stderr, "%s: Deactivating KeyCode conversion.\n", __func__);
#endif
fprintf(stderr, "Info: Keycode conversion auto-determined as off\n"); fprintf(stderr, "Info: Keycode conversion auto-determined as off\n");
}
if (drules) nxagentKeycodeConversion = False;
{
XFree(drules);
} }
} }
...@@ -1683,7 +1687,21 @@ void nxagentResetKeycodeConversion(void) ...@@ -1683,7 +1687,21 @@ void nxagentResetKeycodeConversion(void)
if (result != 0) if (result != 0)
{ {
nxagentKeycodeConversionSetup(); char *drules = NULL;
char *dmodel = NULL;
char *dlayout = NULL;
char *dvariant = NULL;
char *doptions = NULL;
unsigned int drulesLen;
drulesLen = nxagentXkbGetNames(&drules, &dmodel, &dlayout,
&dvariant, &doptions);
if (drulesLen && drules && dmodel)
nxagentKeycodeConversionSetup(drules, dmodel);
if (drules)
XFree(drules);
} }
else else
{ {
......
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