[hackers] [wmii] [menu] Allow composed input. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sat, 31 Jul 2010 23:11:55 +0000 (UTC)

changeset: 2775:d811fa819bee
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Sat Jul 31 19:11:45 2010 -0400
files: cmd/menu/caret.c cmd/menu/main.c cmd/menu/menu.c include/stuff/x11.h lib/libstuff/x11/initdisplay.c
description:
[menu] Allow composed input.

diff -r 9de8efec7dc1 -r d811fa819bee cmd/menu/caret.c
--- a/cmd/menu/caret.c Sat Jul 31 16:20:51 2010 -0400
+++ b/cmd/menu/caret.c Sat Jul 31 19:11:45 2010 -0400
@@ -89,7 +89,7 @@
                         return p;
                 case CHAR:
                         if(p > end)
- return p-1;
+ return prev_rune(end, p, &r);
                         return end;
                 }
         }
diff -r 9de8efec7dc1 -r d811fa819bee cmd/menu/main.c
--- a/cmd/menu/main.c Sat Jul 31 16:20:51 2010 -0400
+++ b/cmd/menu/main.c Sat Jul 31 19:11:45 2010 -0400
@@ -186,7 +186,7 @@
         int i;
         long ndump;
 
- setlocale(LC_CTYPE, "");
+ setlocale(LC_ALL, "");
         fmtinstall('r', errfmt);
         quotefmtinstall();
 
diff -r 9de8efec7dc1 -r d811fa819bee cmd/menu/menu.c
--- a/cmd/menu/menu.c Sat Jul 31 16:20:51 2010 -0400
+++ b/cmd/menu/menu.c Sat Jul 31 19:11:45 2010 -0400
@@ -29,7 +29,13 @@
 
         wa.event_mask = ExposureMask | KeyPressMask;
         barwin = createwindow(&scr.root, Rect(-1, -1, 1, 1), scr.depth, InputOutput,
- &wa, CWEventMask);
+ &wa, CWEventMask);
+ if(scr.xim)
+ barwin->xic = XCreateIC(scr.xim,
+ XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
+ XNClientWindow, barwin->xid,
+ XNFocusWindow, barwin->xid,
+ nil);
 
         changeprop_long(barwin, Net("WM_WINDOW_TYPE"), "ATOM",
                         (long[]){ TYPE("MENU") }, 1);
@@ -262,29 +268,42 @@
         char **action, **p;
         char *key;
         char buf[32];
- int num;
+ int num, status;
         KeySym ksym;
 
- buf[0] = '\0';
- num = XLookupString(e, buf, sizeof buf, &ksym, 0);
- buf[num] = '\0';
- key = XKeysymToString(ksym);
- if(IsKeypadKey(ksym))
- if(ksym == XK_KP_Enter)
- ksym = XK_Return;
- else if(ksym >= XK_KP_0 && ksym <= XK_KP_9)
- ksym = (ksym - XK_KP_0) + XK_0;
-
- if(IsFunctionKey(ksym)
- || IsMiscFunctionKey(ksym)
- || IsKeypadKey(ksym)
- || IsPrivateKeypadKey(ksym)
- || IsPFKey(ksym))
+ if(XFilterEvent((XEvent*)e, w->xid))
                 return false;
 
- action = find_key(key, e->state);
- if(action == nil || action[0] == nil) {
+ status = XLookupBoth;
+ if(w->xic)
+ num = Xutf8LookupString(w->xic, e, buf, sizeof buf - 1, &ksym,
+ &status);
+ else
+ num = XLookupString(e, buf, sizeof buf - 1, &ksym, nil);
+
+ if(status != XLookupChars && status != XLookupKeySym && status != XLookupBoth)
+ return false;
+
+ if(status == XLookupKeySym || status == XLookupBoth) {
+ key = XKeysymToString(ksym);
+ if(IsKeypadKey(ksym))
+ if(ksym == XK_KP_Enter)
+ ksym = XK_Return;
+ else if(ksym >= XK_KP_0 && ksym <= XK_KP_9)
+ ksym = (ksym - XK_KP_0) + XK_0;
+
+ if(IsFunctionKey(ksym)
+ || IsMiscFunctionKey(ksym)
+ || IsKeypadKey(ksym)
+ || IsPrivateKeypadKey(ksym)
+ || IsPFKey(ksym))
+ return false;
+ action = find_key(key, e->state);
+ }
+
+ if(status == XLookupChars || action == nil || action[0] == nil) {
                 if(num && !iscntrl(buf[0])) {
+ buf[num] = '\0';
                         caret_insert(buf, false);
                         update_filter(true);
                         menu_draw();
diff -r 9de8efec7dc1 -r d811fa819bee include/stuff/x11.h
--- a/include/stuff/x11.h Sat Jul 31 16:20:51 2010 -0400
+++ b/include/stuff/x11.h Sat Jul 31 19:11:45 2010 -0400
@@ -146,6 +146,7 @@
 struct Window {
         int type;
         XID xid;
+ XIC xic;
         GC gc;
         Visual* visual;
         Colormap colormap;
@@ -202,6 +203,7 @@
         Rectangle rect;
         int depth;
         int fd;
+ XIM xim;
 };
 
 #ifdef VARARGCK
diff -r 9de8efec7dc1 -r d811fa819bee lib/libstuff/x11/initdisplay.c
--- a/lib/libstuff/x11/initdisplay.c Sat Jul 31 16:20:51 2010 -0400
+++ b/lib/libstuff/x11/initdisplay.c Sat Jul 31 19:11:45 2010 -0400
@@ -76,6 +76,8 @@
 
         scr.root.parent = &scr.root;
 
+ scr.xim = XOpenIM(display, nil, nil, nil);
+
         windowmap.bucket = wbucket;
         windowmap.nhash = nelem(wbucket);
         atommap.bucket = abucket;
Received on Sun Aug 01 2010 - 01:11:55 CEST

This archive was generated by hypermail 2.2.0 : Sun Aug 01 2010 - 01:12:04 CEST