Commit a4ac2242 authored by Daniel Stone's avatar Daniel Stone Committed by Jamey Sharp

im: add Braille input method (#6296)

Bug #6296: Add a Braille input method.  (Samuel Thibault)
parent 90de1e2e
......@@ -21,7 +21,7 @@ AC_PROG_CC
XORG_PROG_RAWCPP
# Checks for pkg-config packages
PKG_CHECK_MODULES(XPROTO, xproto)
PKG_CHECK_MODULES(XPROTO, [xproto >= 7.0.6])
AC_SUBST(XPROTO_CFLAGS)
PKG_CHECK_MODULES(X11, xextproto xtrans xau xcmiscproto bigreqsproto)
......
......@@ -51,16 +51,43 @@ _XimLocalFilter(d, w, ev, client_data)
static char buf[256];
DefTree *p;
if( (ev->type != KeyPress)
|| (ev->xkey.keycode == 0)
|| (((Xim)ic->core.im)->private.local.top == (DefTree *)NULL) )
return(False);
if(ev->xkey.keycode == 0)
return (False);
XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL);
if(IsModifierKey(keysym))
return (False);
if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) {
if(ev->type == KeyPress) {
ic->private.local.brl_pressed |=
1<<(keysym-XK_braille_dot_1);
} else {
if(!ic->private.local.brl_committing
|| ev->xkey.time - ic->private.local.brl_release_start > 300) {
ic->private.local.brl_committing = ic->private.local.brl_pressed;
ic->private.local.brl_release_start = ev->xkey.time;
}
ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1));
if(!ic->private.local.brl_pressed) {
if(ic->private.local.brl_committing) {
ic->private.local.brl_committed =
ic->private.local.brl_committing;
ic->private.local.composed = NULL;
ev->type = KeyPress;
ev->xkey.keycode = 0;
_XPutBackEvent(d, ev);
}
}
}
return(True);
}
if( (ev->type != KeyPress)
|| (((Xim)ic->core.im)->private.local.top == (DefTree *)NULL) )
return(False);
for(p = ic->private.local.context; p; p = p->next) {
if(((ev->xkey.state & p->modifier_mask) == p->modifier) &&
(keysym == p->keysym)) {
......@@ -74,6 +101,7 @@ _XimLocalFilter(d, w, ev, client_data)
return(True);
} else { /* Terminate (reached to leaf) */
ic->private.local.composed = p;
ic->private.local.brl_committed = 0;
/* return back to client KeyPressEvent keycode == 0 */
ev->xkey.keycode = 0;
_XPutBackEvent(d, ev);
......
......@@ -87,7 +87,7 @@ _XimLocalSetFocus(
if (ic->core.focus_window)
_XRegisterFilterByType(ic->core.im->core.display,
ic->core.focus_window, KeyPress, KeyPress,
ic->core.focus_window, KeyPress, KeyRelease,
_XimLocalFilter, (XPointer)ic);
return;
}
......@@ -97,8 +97,11 @@ _XimLocalReset(
XIC xic)
{
Xic ic = (Xic)xic;
ic->private.local.composed = (DefTree *)NULL;
ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
ic->private.local.composed = (DefTree *)NULL;
ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
ic->private.local.brl_pressed = 0;
ic->private.local.brl_committing = 0;
ic->private.local.brl_committed = 0;
}
Private char *
......@@ -149,8 +152,11 @@ _XimLocalCreateIC(
ic->methods = &Local_ic_methods;
ic->core.im = im;
ic->private.local.context = ((Xim)im)->private.local.top;
ic->private.local.composed = (DefTree *)NULL;
ic->private.local.context = ((Xim)im)->private.local.top;
ic->private.local.composed = (DefTree *)NULL;
ic->private.local.brl_pressed = 0;
ic->private.local.brl_committing = 0;
ic->private.local.brl_committed = 0;
num = im->core.ic_num_resources;
len = sizeof(XIMResource) * num;
......
......@@ -42,6 +42,7 @@ PERFORMANCE OF THIS SOFTWARE.
#include <X11/Xutil.h>
#include "Xlibint.h"
#include "Xlcint.h"
#include "XlcPubI.h"
#include "Ximint.h"
Public int
......@@ -60,25 +61,43 @@ _XimLocalMbLookupString(xic, ev, buffer, bytes, keysym, status)
if(status) *status = XLookupNone;
return(0);
}
if(ev->keycode == 0 && ic->private.local.composed != NULL) { /* Composed Event */
ret = strlen(ic->private.local.composed->mb);
if(ret > bytes) {
if(status) *status = XBufferOverflow;
return(ret);
}
memcpy(buffer, ic->private.local.composed->mb, ret);
if(keysym) *keysym = ic->private.local.composed->ks;
if (ret > 0) {
if (keysym && *keysym != NoSymbol) {
if(ev->keycode == 0 &&
( (ic->private.local.composed != NULL)
||(ic->private.local.brl_committed != 0))) {
if (ic->private.local.brl_committed != 0) { /* Braille Event */
unsigned char pattern = ic->private.local.brl_committed;
char mb[XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max)];
ret = _Xlcwctomb(ic->core.im->core.lcd, mb, BRL_UC_ROW | pattern);
if(ret > bytes) {
if(status) *status = XBufferOverflow;
return(ret);
}
if(keysym) {
*keysym = XK_braille_blank | pattern;
if(status) *status = XLookupBoth;
} else {
} else
if(status) *status = XLookupChars;
memcpy(buffer, mb, ret);
} else { /* Composed Event */
ret = strlen(ic->private.local.composed->mb);
if(ret > bytes) {
if(status) *status = XBufferOverflow;
return(ret);
}
} else {
if(keysym && *keysym != NoSymbol) {
if(status) *status = XLookupKeySym;
memcpy(buffer, ic->private.local.composed->mb, ret);
if(keysym) *keysym = ic->private.local.composed->ks;
if (ret > 0) {
if (keysym && *keysym != NoSymbol) {
if(status) *status = XLookupBoth;
} else {
if(status) *status = XLookupChars;
}
} else {
if(status) *status = XLookupNone;
if(keysym && *keysym != NoSymbol) {
if(status) *status = XLookupKeySym;
} else {
if(status) *status = XLookupNone;
}
}
}
return (ret);
......@@ -119,26 +138,41 @@ _XimLocalWcLookupString(xic, ev, buffer, wlen, keysym, status)
if(status) *status = XLookupNone;
return(0);
}
if(ev->keycode == 0) { /* Composed Event */
ret = _Xwcslen(ic->private.local.composed->wc);
if(ret > wlen) {
if(status) *status = XBufferOverflow;
return (ret);
}
memcpy((char *)buffer, (char *)ic->private.local.composed->wc,
ret * sizeof(wchar_t));
if(keysym) *keysym = ic->private.local.composed->ks;
if (ret > 0) {
if (keysym && *keysym != NoSymbol) {
if(ev->keycode == 0) {
if (ic->private.local.brl_committed != 0) { /* Braille Event */
unsigned char pattern = ic->private.local.brl_committed;
ret = 1;
if (ret > wlen) {
if(status) *status = XBufferOverflow;
return (ret);
}
*buffer = BRL_UC_ROW | pattern;
if(keysym) {
*keysym = XK_braille_blank | pattern;
if(status) *status = XLookupBoth;
} else {
} else
if(status) *status = XLookupChars;
} else { /* Composed Event */
ret = _Xwcslen(ic->private.local.composed->wc);
if(ret > wlen) {
if(status) *status = XBufferOverflow;
return (ret);
}
} else {
if(keysym && *keysym != NoSymbol) {
if(status) *status = XLookupKeySym;
memcpy((char *)buffer, (char *)ic->private.local.composed->wc,
ret * sizeof(wchar_t));
if(keysym) *keysym = ic->private.local.composed->ks;
if (ret > 0) {
if (keysym && *keysym != NoSymbol) {
if(status) *status = XLookupBoth;
} else {
if(status) *status = XLookupChars;
}
} else {
if(status) *status = XLookupNone;
if(keysym && *keysym != NoSymbol) {
if(status) *status = XLookupKeySym;
} else {
if(status) *status = XLookupNone;
}
}
}
return (ret);
......@@ -179,25 +213,37 @@ _XimLocalUtf8LookupString(xic, ev, buffer, bytes, keysym, status)
if(status) *status = XLookupNone;
return(0);
}
if(ev->keycode == 0) { /* Composed Event */
ret = strlen(ic->private.local.composed->utf8);
if(ret > bytes) {
if(status) *status = XBufferOverflow;
return (ret);
}
memcpy(buffer, ic->private.local.composed->utf8, ret);
if(keysym) *keysym = ic->private.local.composed->ks;
if (ret > 0) {
if (keysym && *keysym != NoSymbol) {
if(status) *status = XLookupBoth;
} else {
if(status) *status = XLookupChars;
if(ev->keycode == 0) {
if (ic->private.local.brl_committed != 0) { /* Braille Event */
unsigned char pattern = ic->private.local.brl_committed;
ret = 3;
if (ret > bytes) {
if(status) *status = XBufferOverflow;
return (ret);
}
} else {
if(keysym && *keysym != NoSymbol) {
if(status) *status = XLookupKeySym;
buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f);
buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6);
buffer[2] = 0x80 | (pattern & 0x3f);
} else { /* Composed Event */
ret = strlen(ic->private.local.composed->utf8);
if(ret > bytes) {
if(status) *status = XBufferOverflow;
return (ret);
}
memcpy(buffer, ic->private.local.composed->utf8, ret);
if(keysym) *keysym = ic->private.local.composed->ks;
if (ret > 0) {
if (keysym && *keysym != NoSymbol) {
if(status) *status = XLookupBoth;
} else {
if(status) *status = XLookupChars;
}
} else {
if(status) *status = XLookupNone;
if(keysym && *keysym != NoSymbol) {
if(status) *status = XLookupKeySym;
} else {
if(status) *status = XLookupNone;
}
}
}
return (ret);
......
......@@ -2702,7 +2702,7 @@ _XimEncodeLocalTopValue(
if (flag) {
_XRegisterFilterByType(ic->core.im->core.display,
ic->core.focus_window,
KeyPress, KeyPress, _XimLocalFilter, (XPointer)ic);
KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic);
}
} else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
if (ic->core.client_window) {
......@@ -2713,7 +2713,7 @@ _XimEncodeLocalTopValue(
ic->core.focus_window = (Window)p->value;
if (flag) {
_XRegisterFilterByType(ic->core.im->core.display,
ic->core.focus_window, KeyPress, KeyPress,
ic->core.focus_window, KeyPress, KeyRelease,
_XimLocalFilter, (XPointer)ic);
}
} else
......
......@@ -49,7 +49,7 @@ static struct info {
KeySym val;
} info[KTNUM];
#define MIN_REHASH 10
#define MIN_REHASH 15
#define MATCHES 10
char tab[KTNUM];
......
......@@ -180,6 +180,8 @@ typedef struct _XimDefICValues {
#define XIM_FALSE False
#define XIM_OVERFLOW (-1)
#define BRL_UC_ROW 0x2800
/*
* Global symbols
*/
......
......@@ -84,5 +84,8 @@ typedef struct _XicLocalPrivateRec {
XIMResourceList ic_resources;
unsigned int ic_num_resources;
unsigned char brl_pressed, brl_committing, brl_committed;
Time brl_release_start;
} XicLocalPrivateRec;
#endif /* _XIMINTL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment