mirror of
git://git.proxmox.com/git/spiceterm.git
synced 2025-08-22 10:17:06 +00: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}
|
all: ${PROGRAMS}
|
||||||
|
|
||||||
spiceterm: ${SOURCES} ${HEADERS} spiceterm.c
|
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
|
keysyms.h: genkeysym.pl
|
||||||
./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)
|
parse_keymap(const char *language)
|
||||||
{
|
{
|
||||||
char line[1024];
|
char line[1024];
|
||||||
int len;
|
int len;
|
||||||
|
static GRegex *uregex = NULL;
|
||||||
|
name2keysym_t tmap = { .keysym = 0, .unicode = 0 };
|
||||||
|
|
||||||
printf("parse keymap %s\n", language);
|
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);
|
char *filename = g_strdup_printf("/usr/share/kvm/keymaps/%s", language);
|
||||||
FILE *f = fopen(filename, "r");
|
FILE *f = fopen(filename, "r");
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(stderr, "Could not read keymap file: '%s'\n", language);
|
fprintf(stderr, "Could not read keymap file: '%s'\n", language);
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
@ -737,18 +745,33 @@ parse_keymap(const char *language)
|
|||||||
if (!strncmp(line, "map ", 4))
|
if (!strncmp(line, "map ", 4))
|
||||||
continue;
|
continue;
|
||||||
if (!strncmp(line, "include ", 8)) {
|
if (!strncmp(line, "include ", 8)) {
|
||||||
parse_keymap(line + 8);
|
if (!parse_keymap(line + 8))
|
||||||
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
printf("LINE: %s\n", line);
|
|
||||||
char *tok = strtok(line, " ");
|
char *tok = strtok(line, " ");
|
||||||
if (!tok) {
|
if (!tok)
|
||||||
fprintf(stderr, "Warning: unknown keysym\n");
|
continue;
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
const name2keysym_t *map = lookup_keysym(tok);
|
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) {
|
if (!map) {
|
||||||
fprintf(stderr, "Warning: unknown keysym '%s'\n", tok);
|
fprintf(stderr, "Warning: unknown keysym '%s'\n", tok);
|
||||||
g_assert_not_reached();
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
guint8 mask = 0;
|
guint8 mask = 0;
|
||||||
@ -765,22 +788,20 @@ parse_keymap(const char *language)
|
|||||||
} else if (!strcmp(tok, "addupper")) {
|
} else if (!strcmp(tok, "addupper")) {
|
||||||
addupper = TRUE;
|
addupper = TRUE;
|
||||||
} else if (!strcmp(tok, "inhibit")) {
|
} else if (!strcmp(tok, "inhibit")) {
|
||||||
// fixme
|
// ignore
|
||||||
} else if (!strcmp(tok, "localstate")) {
|
} else if (!strcmp(tok, "localstate")) {
|
||||||
//skip
|
// ignore
|
||||||
} else {
|
} else {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
keycode = strtol(tok, &endptr, 0);
|
keycode = strtol(tok, &endptr, 0);
|
||||||
if (errno != 0 || *endptr != '\0' || keycode >= 255) {
|
if (errno != 0 || *endptr != '\0' || keycode >= 255) {
|
||||||
printf("got unknown modifier '%s' %d\n", tok, keycode);
|
fprintf(stderr, "got unknown modifier '%s' %d\n",
|
||||||
g_assert_not_reached();
|
tok, keycode);
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("got keycode %u ==> %02x:%d\n", map->keysym, mask, keycode);
|
|
||||||
|
|
||||||
add_keymap_entry(mask, keycode, map->keysym, map->unicode);
|
add_keymap_entry(mask, keycode, map->keysym, map->unicode);
|
||||||
if (addupper) {
|
if (addupper) {
|
||||||
@ -795,6 +816,8 @@ parse_keymap(const char *language)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
spiceTerm *
|
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);
|
SpiceScreen *spice_screen = spice_screen_new(core, width, height, opts);
|
||||||
|
|
||||||
keymap = g_hash_table_new(g_int_hash, g_int_equal);
|
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);
|
spice_screen->image_cache = g_hash_table_new(g_int_hash, g_int_equal);
|
||||||
|
|
||||||
|
@ -51,8 +51,6 @@
|
|||||||
#include <spice/macros.h>
|
#include <spice/macros.h>
|
||||||
#include <spice/qxl_dev.h>
|
#include <spice/qxl_dev.h>
|
||||||
|
|
||||||
#include <gdk/gdkkeysyms.h>
|
|
||||||
|
|
||||||
#include "event_loop.h"
|
#include "event_loop.h"
|
||||||
#include "translations.h"
|
#include "translations.h"
|
||||||
|
|
||||||
@ -1691,6 +1689,8 @@ main (int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
spiceTerm *vt = spiceterm_create(744, 400, &opts);
|
spiceTerm *vt = spiceterm_create(744, 400, &opts);
|
||||||
|
if (!vt)
|
||||||
|
exit(-1);
|
||||||
|
|
||||||
setlocale(LC_ALL, ""); // set from environment
|
setlocale(LC_ALL, ""); // set from environment
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user