mirror of
git://git.proxmox.com/git/spiceterm.git
synced 2024-12-22 13:34:06 +03:00
implement unicode keysyms
This commit is contained in:
parent
7f3ff8c0e4
commit
c4d1da1490
2
Makefile
2
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 >$@
|
||||
|
64
input.c
64
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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user