[hackers] [wmii] [menu] Grab keyboard sooner. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Thu, 16 Oct 2008 03:59:18 +0000 (UTC)

changeset: 2374:7112a13bd2ba
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Wed Oct 15 23:59:17 2008 -0400
files: cmd/menu/main.c cmd/menu/menu.c cmd/wmii.rc.rc cmd/wmii/x11.c rc/rc.wmii.rc
description:
[menu] Grab keyboard sooner.

diff -r 093bc132f974 -r 7112a13bd2ba cmd/menu/main.c
--- a/cmd/menu/main.c Wed Oct 15 23:15:42 2008 -0400
+++ b/cmd/menu/main.c Wed Oct 15 23:59:17 2008 -0400
@@ -247,6 +247,9 @@
 
         initdisplay();
 
+ xext_init();
+ menu_init();
+
         if(address && *address)
                 client = ixp_mount(address);
         else
@@ -267,9 +270,6 @@
         font = loadfont(readctl("font "));
         if(!font)
                 fatal("Can't load font %q", readctl("font "));
-
- xext_init();
- menu_init();
 
         inbuf = Bfdopen(0, OREAD);
         items = populate_list(inbuf, false);
diff -r 093bc132f974 -r 7112a13bd2ba cmd/menu/menu.c
--- a/cmd/menu/menu.c Wed Oct 15 23:15:42 2008 -0400
+++ b/cmd/menu/menu.c Wed Oct 15 23:59:17 2008 -0400
@@ -1,6 +1,7 @@
 #include "dat.h"
 #include <ctype.h>
 #include <string.h>
+#include <unistd.h>
 #include "fns.h"
 
 static Window* barwin;
@@ -28,16 +29,22 @@
 menu_init(void) {
         WinAttr wa;
 
- ltwidth = textwidth(font, "<");
-
         wa.override_redirect = 1;
         wa.background_pixmap = ParentRelative;
         wa.event_mask = ExposureMask | KeyPressMask;
- barwin = createwindow(&scr.root, Rect(0, 0, 1, 1), scr.depth, InputOutput,
+ barwin = createwindow(&scr.root, Rect(-1, -1, 1, 1), scr.depth, InputOutput,
                         &wa, CWOverrideRedirect
                            | CWBackPixmap
                            | CWEventMask);
         sethandler(barwin, &handlers);
+ mapwin(barwin);
+
+ int i = 0;
+ while(!grabkeyboard(barwin)) {
+ if(i++ > 1000)
+ fatal("can't grab keyboard");
+ usleep(1000);
+ }
 }
 
 static void
@@ -189,6 +196,8 @@
 
         USED(menu_unmap);
 
+ ltwidth = textwidth(font, "<");
+
         pad = (font->height & ~1)/2;
         height = font->height + 2;
 
@@ -205,11 +214,6 @@
         mapwin(barwin);
         raisewin(barwin);
         menu_draw();
- if(!grabkeyboard(barwin)) {
- exit(1);
- srv.running = false;
- result = 1;
- }
 }
 
 static void
diff -r 093bc132f974 -r 7112a13bd2ba cmd/wmii.rc.rc
--- a/cmd/wmii.rc.rc Wed Oct 15 23:15:42 2008 -0400
+++ b/cmd/wmii.rc.rc Wed Oct 15 23:59:17 2008 -0400
@@ -118,7 +118,8 @@
                         * = (wihack -tags `{wmiir read /tag/sel/ctl | sed 1q} $*) }
                 fn `{env | 9 sed -n 's/^fn#([^=]+).*/\1/p'}
                 mykeys=()
- eval exec $* & }
+ if(! ~ $* '')
+ eval exec $* & }
 }
 
 fn wi_getfuns {
diff -r 093bc132f974 -r 7112a13bd2ba cmd/wmii/x11.c
--- a/cmd/wmii/x11.c Wed Oct 15 23:15:42 2008 -0400
+++ b/cmd/wmii/x11.c Wed Oct 15 23:59:17 2008 -0400
@@ -973,7 +973,7 @@
 int
 grabkeyboard(Window *w) {
 
- return XGrabKeyboard(display, w->w, false /* owner events */,
+ return XGrabKeyboard(display, w->w, true /* owner events */,
                 GrabModeAsync, GrabModeAsync, CurrentTime
                 ) == GrabSuccess;
 }
diff -r 093bc132f974 -r 7112a13bd2ba rc/rc.wmii.rc
--- a/rc/rc.wmii.rc Wed Oct 15 23:15:42 2008 -0400
+++ b/rc/rc.wmii.rc Wed Oct 15 23:59:17 2008 -0400
@@ -217,7 +217,8 @@
 key $MODKEY-a || fn $key {
         Action `{wi_actions | wimenu -h $hist.action -n $histlen} &}
 key $MODKEY-p || fn $key {
- ifs=() { wi_runcmd `{wimenu -h $hist.prog -n $histlen <$progs_file} & }}
+ ifs=() { cmd = `{wimenu -h $hist.prog -n $histlen <$progs_file >[2]/dev/tty} }
+ wi_runcmd $cmd & }
 
 key $MODKEY-Return || fn $key {
         wi_runcmd $WMII_TERM &}
Received on Thu Oct 16 2008 - 03:59:18 UTC

This archive was generated by hypermail 2.2.0 : Thu Oct 16 2008 - 04:00:09 UTC