[X2Go-Commits] [nx-libs] 22/51: Keyboard.c: improve creation of keyboard config file

git-admin at x2go.org git-admin at x2go.org
Fri Feb 8 05:40:09 CET 2019


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository nx-libs.

commit 3b62184a1aaa3f8a66aab21c21d12162e7ba83df
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Sun Jul 23 02:03:58 2017 +0200

    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
---
 nx-X11/programs/Xserver/hw/nxagent/Keyboard.c | 44 +++++++++++++++++----------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
index dcb58de..9efafdf 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Keyboard.c
@@ -83,7 +83,7 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
 
 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 */
 
@@ -840,7 +840,7 @@ XkbError:
           }
           #endif
 
-          nxagentWriteKeyboardFile(remoteruleslen, remoterules, remotemodel, remotelayout, remotevariant, remoteoptions);
+          nxagentWriteKeyboardFile(remoterules, remotemodel, remotelayout, remotevariant, remoteoptions);
           nxagentKeycodeConversionSetup(remoterules, remotemodel);
 
           if (remoterules)
@@ -1588,10 +1588,32 @@ static int nxagentXkbGetNames(char **rules, char **model, char **layout,
   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();
     if (sessionpath)
     {
@@ -1605,18 +1627,8 @@ void nxagentWriteKeyboardFile(unsigned int ruleslen, char *rules, char *model, c
       free(sessionpath);
       if ((keyboard_file = fopen(keyboard_file_path, "w")))
       {
-        if (rules)
-          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);
+        writeKeyboardfileData(keyboard_file, rules, model, layout, variant, options);
+
         fclose(keyboard_file);
         fprintf(stderr, "Info: keyboard file created: '%s'\n", keyboard_file_path);
       }

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list