diff options
author | corvid <corvid@lavabit.com> | 2011-06-23 19:24:11 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2011-06-23 19:24:11 +0000 |
commit | 70617461d5c20b5b362961feb6dba53368a98fbe (patch) | |
tree | 8ddfa829f1a2826636f011ca2c90cc8a09807584 | |
parent | 86ad9513a8d090501dd602b00b70fecc31eeaaa4 (diff) |
non-ASCII keybindings
Alexander Voigt has kindly done some testing, and it seems that this
makes bindings to most keys on a German keyboard possible -- except
those that need AltGr don't work yet.
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/keys.cc | 33 | ||||
-rw-r--r-- | src/utf8.cc | 5 | ||||
-rw-r--r-- | src/utf8.hh | 1 |
4 files changed, 28 insertions, 12 deletions
@@ -12,6 +12,7 @@ dillo-3.0 [not released yet] Patches: Jorge Arellano Cid +- Remove --enable-ansi configure option. - Limit saved cookie size. + - Allow binding to non-ASCII keys. Patches: corvid ----------------------------------------------------------------------------- diff --git a/src/keys.cc b/src/keys.cc index b00df190..8ec0978b 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -17,6 +17,7 @@ #include "dlib/dlib.h" #include "keys.hh" +#include "utf8.hh" #include "msg.h" /* @@ -172,20 +173,25 @@ KeysCommand_t Keys::getKeyCmd() { KeysCommand_t ret = KEYS_NOP; KeyBinding_t keyNode; - // We're only interested in some flags - keyNode.modifier = Fl::event_state() & - (FL_SHIFT | FL_CTRL | FL_ALT | FL_META); - - if (keyNode.modifier == FL_SHIFT && - ispunct(Fl::event_text()[0])) { - // Get key code for a shifted character - keyNode.key = Fl::event_text()[0]; - keyNode.modifier = 0; - } else { + + keyNode.modifier = Fl::event_state() & (FL_SHIFT | FL_CTRL |FL_ALT|FL_META); + if (iscntrl(Fl::event_text()[0])) { keyNode.key = Fl::event_key(); + } else { + const char *beyond = Fl::event_text() + Fl::event_length(); + keyNode.key = a_Utf8_decode(Fl::event_text(), beyond, NULL); + + /* BUG: The idea is to drop the modifiers if their use results in a + * different character (e.g., if shift-8 gives '*', drop the shift, + * but if ctrl-6 gives '6', keep the ctrl), but we have to compare a + * keysym with a Unicode codepoint, which only works for characters + * below U+0100 (those known to latin-1). + */ + if (keyNode.key != Fl::event_key()) + keyNode.modifier = 0; } - - _MSG("getKeyCmd: key=%d, mod=%d\n", keyNode.key, keyNode.modifier); + _MSG("getKeyCmd: evkey=0x%x evtext=\'%s\' key=0x%x, mod=0x%x\n", + Fl::event_key(), Fl::event_text(), keyNode.key, keyNode.modifier); void *data = dList_find_sorted(bindings, &keyNode, nodeByKeyCmp); if (data) ret = ((KeyBinding_t*)data)->cmd; @@ -311,6 +317,9 @@ void Keys::parseKey(char *key, char *commandName) // Get key code if (!key[1]) { keycode = *key; + } else if (a_Utf8_char_count(keystr, strlen(keystr)) == 1) { + const char *beyond = keystr + strlen(keystr); + keycode = a_Utf8_decode(keystr, beyond, NULL); } else if (key[0] == '0' && key[1] == 'x') { /* keysym. For details on values reported, see fltk's fltk/events.h */ keycode = strtol(key, NULL, 0x10); diff --git a/src/utf8.cc b/src/utf8.cc index a4a8504b..3d25f4f5 100644 --- a/src/utf8.cc +++ b/src/utf8.cc @@ -100,3 +100,8 @@ bool_t a_Utf8_combining_char(int unicode) (unicode >= 0x20d0 && unicode <= 0x20ff) || (unicode >= 0xfe20 && unicode <= 0xfe2f)); } + +int a_Utf8_char_count(const char *str, int len) +{ + return fl_utf_nb_char((const uchar_t*)str, len); +} diff --git a/src/utf8.hh b/src/utf8.hh index 4ded50b8..ce575118 100644 --- a/src/utf8.hh +++ b/src/utf8.hh @@ -24,6 +24,7 @@ int a_Utf8_encode(unsigned int ucs, char *buf); int a_Utf8_test(const char* src, unsigned int srclen); bool_t a_Utf8_ideographic(const char *s, const char *end, int *len); bool_t a_Utf8_combining_char(int unicode); +int a_Utf8_char_count(const char *str, int len); #ifdef __cplusplus } |