]> git.proxmox.com Git - spiceterm.git/commitdiff
implement unicode keysyms
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 29 Oct 2013 10:56:07 +0000 (11:56 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 29 Oct 2013 11:21:11 +0000 (12:21 +0100)
Makefile
input.c
spiceterm.c

index 47d39a597c5aea96f170560e924e56bfd308e75f..7c57421be00e597a4e67c56405cd211092f2f032 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ SOURCES=screen.c event_loop.c input.c spiceterm.c auth-pve.c
 all: ${PROGRAMS}
 
 spiceterm: ${SOURCES} ${HEADERS} spiceterm.c 
-       gcc -Werror -Wall -Wtype-limits ${SOURCES} -g -O2 -o $@ -lutil $(shell pkg-config --cflags gdk-3.0) $(shell pkg-config --cflags --libs gthread-2.0,spice-protocol,spice-server,gdk-3.0)
+       gcc -Werror -Wall -Wtype-limits ${SOURCES} -g -O2 -o $@ -lutil $(shell pkg-config) $(shell pkg-config --cflags --libs gthread-2.0,spice-protocol,spice-server)
 
 keysyms.h: genkeysym.pl
        ./genkeysym.pl >$@
diff --git a/input.c b/input.c
index 48f25760de8a1cb752069ddb10c9402f3c8920b3..fa3825fb6df0d9cd8e4cb959d5840784833eebb1 100644 (file)
--- a/input.c
+++ b/input.c
@@ -710,20 +710,28 @@ add_keymap_entry(guint8 mask, guint8 keycode, guint keysym, guint unicode)
     }
 }
 
-static void 
+
+static gboolean
 parse_keymap(const char *language)
 {
     char line[1024];
     int len;
-
-    printf("parse keymap %s\n", language);
+    static GRegex *uregex = NULL;
+    name2keysym_t tmap = { .keysym = 0, .unicode = 0 };
+    if (uregex == NULL) {
+        if (!(uregex = g_regex_new("^U\\+?[a-fA-F0-9]{4,6}$", 0, 0, NULL))) {
+            fprintf(stderr, "unable to compile regex\n");
+            return FALSE;
+        }
+    }
 
     char *filename = g_strdup_printf("/usr/share/kvm/keymaps/%s", language);
     FILE *f = fopen(filename, "r");
     g_free(filename);
     if (!f) {
        fprintf(stderr, "Could not read keymap file: '%s'\n", language);
-        return;
+        return FALSE;
     }
 
     for(;;) {
@@ -737,18 +745,33 @@ parse_keymap(const char *language)
        if (!strncmp(line, "map ", 4))
            continue;
        if (!strncmp(line, "include ", 8)) {
-           parse_keymap(line + 8);
+           if (!parse_keymap(line + 8))
+                return FALSE;
         } else {
-            printf("LINE: %s\n", line);
             char *tok = strtok(line, " ");
-            if (!tok) {
-                fprintf(stderr, "Warning: unknown keysym\n");
-                g_assert_not_reached();
-            }
+            if (!tok)
+                continue;
+
             const name2keysym_t *map = lookup_keysym(tok);
+            if (!map && g_regex_match(uregex, tok, 0, NULL)) {
+                char *hex = tok[1] == '+' ? tok + 2 : tok + 1;
+                long int uc = strtol(hex, NULL, 16);
+                if ((uc >= 0x0020 && uc <= 0x007e) ||
+                    (uc >= 0x00a0 && uc <= 0x00ff)) {
+                    // Latin 1
+                    tmap.keysym = uc;
+                    tmap.unicode = uc;
+                    map = &tmap;
+                   
+                } else if (uc >= 0x0100 && uc <= 0x010FFFF) {
+                    tmap.keysym = uc + 0x01000000;
+                    tmap.unicode = uc;
+                    map = &tmap;
+                }
+            }
             if (!map) {
                 fprintf(stderr, "Warning: unknown keysym '%s'\n", tok);
-                g_assert_not_reached();
+                continue;
             } 
 
             guint8 mask = 0;
@@ -765,23 +788,21 @@ parse_keymap(const char *language)
                 } else if (!strcmp(tok, "addupper")) {
                     addupper = TRUE;
                 } else if (!strcmp(tok, "inhibit")) {
-                    // fixme
+                    // ignore
                 } else if (!strcmp(tok, "localstate")) {
-                    //skip
+                    // ignore
                 } else {
                     char *endptr;
                     errno = 0;
                     keycode = strtol(tok, &endptr, 0);
                     if (errno != 0 || *endptr != '\0' || keycode >= 255) {
-                        printf("got unknown modifier '%s' %d\n", tok, keycode);
-                        g_assert_not_reached();
+                        fprintf(stderr, "got unknown modifier '%s' %d\n", 
+                                tok, keycode);
+                        continue;
                     }
-
                 }
             }
 
-            printf("got keycode %u ==> %02x:%d\n", map->keysym, mask, keycode);
-
             add_keymap_entry(mask, keycode, map->keysym, map->unicode);
             if (addupper) {
                 gchar uc = g_ascii_toupper(line[0]);
@@ -795,6 +816,8 @@ parse_keymap(const char *language)
             }
         }
     }
+
+    return TRUE;
 }
 
 spiceTerm *
@@ -804,7 +827,10 @@ spiceterm_create(uint32_t width, uint32_t height, SpiceTermOptions *opts)
     SpiceScreen *spice_screen = spice_screen_new(core, width, height, opts);
 
     keymap = g_hash_table_new(g_int_hash, g_int_equal);
-    parse_keymap(opts->keymap ?  opts->keymap : "en-us");
+    
+    if (!parse_keymap(opts->keymap ?  opts->keymap : "en-us")) {
+        return NULL;
+    }
 
     spice_screen->image_cache = g_hash_table_new(g_int_hash, g_int_equal);
 
index b27f3b2132445963739a1bf413fafb9101d72a20..be76107e32fb9dd600e5d879772b8ab791fb71e6 100644 (file)
@@ -51,8 +51,6 @@
 #include <spice/macros.h>
 #include <spice/qxl_dev.h>
 
-#include <gdk/gdkkeysyms.h>
-
 #include "event_loop.h"
 #include "translations.h"
 
@@ -1691,6 +1689,8 @@ main (int argc, char** argv)
     }
     
     spiceTerm *vt = spiceterm_create(744, 400, &opts);
+    if (!vt)
+        exit(-1);
 
     setlocale(LC_ALL, ""); // set from environment