-2004-03-24 Bill Haneman <billh@gnome.org>
+2004-04-19 Bill Haneman <billh@gnome.org>
* configure.in: Revved to 1.5.1.
#include "deviceeventcontroller.h"
KeySym ucs2keysym (long ucs);
+long keysym2ucs(KeySym keysym);
#define CHECK_RELEASE_DELAY 20
#define BIT(c, x) (c[x/8]&(1<<(x%8)))
gunichar c;
cbuf[nbytes] = '\0'; /* OK since length is cbuf_bytes+1 */
key_event.event_string = CORBA_string_dup (cbuf);
- c = g_utf8_get_char_validated (cbuf, nbytes);
- if ((c > 0) && g_unichar_isprint (c))
+ c = keysym2ucs (keysym);
+ if (c > 0 && !g_unichar_iscntrl (c))
{
key_event.is_text = CORBA_TRUE;
/* incorrect for some composed chars? */
return ucs | 0x01000000;
}
+long keysym2ucs(KeySym keysym)
+{
+ int min = 0;
+ int max = sizeof(keysymtab) / sizeof(struct codepair) - 1;
+ int mid;
+
+ /* first check for Latin-1 characters (1:1 mapping) */
+ if ((keysym >= 0x0020 && keysym <= 0x007e) ||
+ (keysym >= 0x00a0 && keysym <= 0x00ff))
+ return (long) keysym;
+
+ /* also check for directly encoded 24-bit UCS characters */
+ if ((keysym & 0xff000000) == 0x01000000)
+ return keysym & 0x00ffffff;
+
+ /* binary search in table */
+ while (max >= min) {
+ mid = (min + max) / 2;
+ if (keysymtab[mid].keysym < keysym)
+ min = mid + 1;
+ else if (keysymtab[mid].keysym > keysym)
+ max = mid - 1;
+ else {
+ /* found it */
+ return keysymtab[mid].ucs;
+ }
+ }
+
+ /* no matching Unicode value found */
+ return -1;
+}