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.
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(unsigned int ruleslen, char *rules, char *model, char *layout, char *variant, char *options);
......@@ -818,9 +818,38 @@ XkbError:
fprintf(stderr, "nxagentKeyboardProc: Init XKB extension.\n");
#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
nxagentKeycodeConversionSetup();
nxagentWriteKeyboardFile(drulesLen, drules, dmodel, dlayout, dvariant, doptions);
nxagentKeycodeConversionSetup(drules, dmodel);
if (drules)
{
XFree(drules);
}
}
xkb = XkbGetKeyboard(nxagentDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd);
if (xkb && xkb->geom)
{
......@@ -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)
{
fprintf(stderr, "Info: Keycode conversion is off\n");
......@@ -1631,28 +1653,9 @@ void nxagentKeycodeConversionSetup(void)
return;
}
nxagentKeycodeConversion = False;
drulesLen = nxagentXkbGetNames(&drules, &dmodel, &dlayout,
&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))
if (rules && model &&
(strcmp(rules, "evdev") == 0 ||
strcmp(model, "evdev") == 0))
{
#ifdef DEBUG
fprintf(stderr, "%s: Activating KeyCode conversion.\n", __func__);
......@@ -1663,12 +1666,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");
}
if (drules)
{
XFree(drules);
nxagentKeycodeConversion = False;
}
}
......@@ -1683,7 +1687,21 @@ void nxagentResetKeycodeConversion(void)
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
{
......
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