Commit 3b62184a authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Keyboard.c: improve creation of keyboard config file

It will now create better working config files. References: ArcticaProject/nx-libs#239 ArcticaProject/nx-libs#368
parent fb31220f
...@@ -83,7 +83,7 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout, ...@@ -83,7 +83,7 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
static void nxagentKeycodeConversionSetup(char *rules, char *model); static void nxagentKeycodeConversionSetup(char *rules, char *model);
void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, char *layout, char *variant, char *options); void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, char *variant, char *options);
#endif /* XKB */ #endif /* XKB */
...@@ -840,7 +840,7 @@ XkbError: ...@@ -840,7 +840,7 @@ XkbError:
} }
#endif #endif
nxagentWriteKeyboardFile(remoteruleslen, remoterules, remotemodel, remotelayout, remotevariant, remoteoptions); nxagentWriteKeyboardFile(remoterules, remotemodel, remotelayout, remotevariant, remoteoptions);
nxagentKeycodeConversionSetup(remoterules, remotemodel); nxagentKeycodeConversionSetup(remoterules, remotemodel);
if (remoterules) if (remoterules)
...@@ -1588,10 +1588,32 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout, ...@@ -1588,10 +1588,32 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
return n; return n;
} }
void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, char *layout, char *variant, char *options) void writeKeyboardfileData(FILE *out, char *rules, char *model, char *layout, char *variant, char *options)
{ {
if (ruleslen) /*
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 : "");
}
void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, char *variant, char *options)
{
if (rules && rules[0] != '\0')
{ {
#ifdef DEBUG
writeKeyboardfileData(stderr, rules, model, layout, variant, options);
#endif
char *sessionpath = nxagentGetSessionPath(); char *sessionpath = nxagentGetSessionPath();
if (sessionpath) if (sessionpath)
{ {
...@@ -1605,18 +1627,8 @@ void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, c ...@@ -1605,18 +1627,8 @@ void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, c
free(sessionpath); free(sessionpath);
if ((keyboard_file = fopen(keyboard_file_path, "w"))) if ((keyboard_file = fopen(keyboard_file_path, "w")))
{ {
if (rules) writeKeyboardfileData(keyboard_file, rules, model, layout, variant, options);
fprintf(keyboard_file, "rules=\"%s\"\n", rules[0] == '\0' ? "," : rules);
if (model)
fprintf(keyboard_file, "model=\"%s\"\n", model[0] == '\0' ? "," : model);
if (layout)
fprintf(keyboard_file, "layout=\"%s\"\n", layout[0] == '\0' ? "," : layout);
/* FIXME: this is not correct. We need to match the number of
comma separated values between variant and layout */
if (variant)
fprintf(keyboard_file, "variant=\"%s\"\n", variant[0] == '\0' ? "," : variant);
if (options)
fprintf(keyboard_file, "options=\"%s\"\n", options[0] == '\0' ? "," : options);
fclose(keyboard_file); fclose(keyboard_file);
fprintf(stderr, "Info: keyboard file created: '%s'\n", keyboard_file_path); fprintf(stderr, "Info: keyboard file created: '%s'\n", keyboard_file_path);
} }
......
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