[hackers] [wmii] Allow chained event handlers. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Fri, 28 May 2010 00:49:24 +0000 (UTC)

changeset: 2658:bbef798778a3
user: Kris Maglione <kris_AT_suckless.org>
date: Thu May 27 18:57:08 2010 -0400
files: cmd/menu/menu.c cmd/strut/win.c cmd/tray/client.c cmd/tray/selection.c cmd/tray/tray.c cmd/tray/xembed.c cmd/wmii/bar.c cmd/wmii/client.c cmd/wmii/div.c cmd/wmii/event.c cmd/wmii/ewmh.c cmd/wmii/fns.h cmd/wmii/frame.c cmd/wmii/layout.c cmd/wmii/mouse.c cmd/wmii/root.c cmd/wmii/xdnd.c include/stuff/x11.h lib/libstuff/event/event.c
description:
Allow chained event handlers.

diff -r 87818ee68036 -r bbef798778a3 cmd/menu/menu.c
--- a/cmd/menu/menu.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/menu/menu.c Thu May 27 18:57:08 2010 -0400
@@ -254,7 +254,7 @@
         menu_draw();
 }
 
-static void
+static bool
 kdown_event(Window *w, void *aux, XKeyEvent *e) {
         char **action, **p;
         char *key;
@@ -276,7 +276,7 @@
         || IsKeypadKey(ksym)
         || IsPrivateKeypadKey(ksym)
         || IsPFKey(ksym))
- return;
+ return false;
 
         action = find_key(key, e->state);
         if(action == nil || action[0] == nil) {
@@ -328,13 +328,15 @@
                         break;
                 }
         }
+ return false;
 }
 
-static void
+static bool
 expose_event(Window *w, void *aux, XExposeEvent *e) {
 
         USED(w);
         menu_draw();
+ return false;
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/strut/win.c
--- a/cmd/strut/win.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/strut/win.c Thu May 27 18:57:08 2010 -0400
@@ -79,20 +79,22 @@
         ewmh_setstrut(frame->aux, strut);
 }
 
-static void
+static bool
 config_event(Window *frame, void *aux, XConfigureEvent *ev) {
 
         frame->r = rectaddpt(Rect(ev->x, ev->y, ev->width, ev->height),
                              Pt(ev->border_width, ev->border_width));
         restrut(frame);
+ return false;
 }
 
-static void
+static bool
 destroy_event(Window *w, void *aux, XDestroyWindowEvent *ev) {
 
         USED(ev);
         sethandler(w, nil);
         event_looprunning = windowmap.nmemb > 0;
+ return false;
 }
 
 Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/tray/client.c
--- a/cmd/tray/client.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/tray/client.c Thu May 27 18:57:08 2010 -0400
@@ -152,42 +152,47 @@
         }
 }
 
-static void
+static bool
 config_event(Window *w, void *aux, XConfigureEvent *e) {
         Client *c;
 
         c = aux;
         if(false)
                 movewin(c->indicator, addpt(w->r.min, Pt(1, 1)));
+ return false;
 }
 
-static void
+static bool
 configreq_event(Window *w, void *aux, XConfigureRequestEvent *e) {
 
         Dprint("configreq_event(%W)\n", w);
         /* This seems, sadly, to be necessary. */
         tray_update();
+ return false;
 }
 
-static void
+static bool
 map_event(Window *w, void *aux, XMapEvent *e) {
 
         Dprint("client map_event(%W)\n", w);
         w->mapped = true;
         tray_update();
+ return false;
 }
 
-static void
+static bool
 unmap_event(Window *w, void *aux, XUnmapEvent *e) {
 
         Dprint("client map_event(%W)\n", w);
         tray_update();
+ return false;
 }
 
-static void
+static bool
 reparent_event(Window *w, void *aux, XReparentEvent *e) {
 
         Dprint("client reparent_event(%W)\n", w);
+ return false;
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/tray/selection.c
--- a/cmd/tray/selection.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/tray/selection.c Thu May 27 18:57:08 2010 -0400
@@ -94,16 +94,17 @@
         sendevent(window(ev->requestor), false, 0L, &notify);
 }
 
-static void
+static bool
 message_event(Window *w, void *aux, XClientMessageEvent *ev) {
         Selection *s;
 
         s = aux;
         if(s->message)
                 s->message(s, ev);
+ return false;
 }
 
-static void
+static bool
 selectionclear_event(Window *w, void *aux, XSelectionClearEvent *ev) {
         Selection *s;
 
@@ -111,9 +112,10 @@
         s = aux;
         s->time_end = ev->time;
         selection_release(s);
+ return false;
 }
 
-static void
+static bool
 selectionrequest_event(Window *w, void *aux, XSelectionRequestEvent *ev) {
         Selection *s;
 
@@ -127,13 +129,14 @@
                                  XGetAtomName(display, ev->property), "TIMESTAMP",
                                  &s->time_start, 1);
                 selection_notify(s, ev, true);
- return;
+ return false;
         }
 
         if(s->request)
                 s->request(s, ev);
         else
                 selection_notify(s, ev, false);
+ return false;
 }
 
 static Handlers selection_handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/tray/tray.c
--- a/cmd/tray/tray.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/tray/tray.c Thu May 27 18:57:08 2010 -0400
@@ -221,7 +221,7 @@
         tray_draw(tray.win->r);
 }
 
-static void
+static bool
 config_event(Window *w, void *aux, XConfigureEvent *ev) {
 
         USED(aux);
@@ -239,19 +239,22 @@
                                  Pt(ev->border_width, ev->border_width));
                 restrut(w, tray.orientation);
         }
+ return false;
 }
 
-static void
+static bool
 expose_event(Window *w, void *aux, XExposeEvent *ev) {
 
         USED(w, aux, ev);
         tray_draw(tray.win->r);
+ return false;
 }
 
-static void
+static bool
 message_event(Window *w, void *aux, XClientMessageEvent *ev) {
 
         Dprint("tray_message: %s\n", XGetAtomName(display, ev->message_type));
+ return false;
 }
 
 static Handlers handlers = {
@@ -260,12 +263,13 @@
         .expose = expose_event,
 };
 
-static void
+static bool
 property_event(Window *w, void *aux, XPropertyEvent *ev) {
         if(ev->atom == NET("CURRENT_DESKTOP"))
                 tray_resize(tray.r);
         Debug if(ev->atom == NET("CURRENT_DESKTOP"))
                 print("property_event(_NET_CURRENT_DESKTOP)\n");
+ return false;
 }
 
 static Handlers root_handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/tray/xembed.c
--- a/cmd/tray/xembed.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/tray/xembed.c Thu May 27 18:57:08 2010 -0400
@@ -92,16 +92,17 @@
         traperrors(false);
 }
 
-static void
+static bool
 destroy_event(Window *w, void *aux, XDestroyWindowEvent *ev) {
         XEmbed *xembed;
 
         xembed = aux;
         xembed->flags = DEAD;
         xembed_disown(xembed);
+ return false;
 }
 
-static void
+static bool
 property_event(Window *w, void *aux, XPropertyEvent *ev) {
         XEmbed *xembed;
 
@@ -110,9 +111,10 @@
         xembed = aux;
         if(ev->atom == xatom("_XEMBED_INFO"))
                 xembed_updateinfo(xembed);
+ return false;
 }
 
-static void
+static bool
 reparent_event(Window *w, void *aux, XReparentEvent *ev) {
         XEmbed *xembed;
 
@@ -121,6 +123,7 @@
                 xembed->flags = DEAD;
                 xembed_disown(xembed);
         }
+ return false;
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/bar.c
--- a/cmd/wmii/bar.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/bar.c Thu May 27 18:57:08 2010 -0400
@@ -245,7 +245,7 @@
         return nil;
 }
 
-static void
+static bool
 bdown_event(Window *w, void *aux, XButtonPressedEvent *e) {
         WMScreen *s;
         Bar *b;
@@ -258,9 +258,10 @@
         b = findbar(s, Pt(e->x, e->y));
         if(b)
                 event("%sBarMouseDown %d %s\n", barside[b->bar], e->button, b->name);
+ return false;
 }
 
-static void
+static bool
 bup_event(Window *w, void *aux, XButtonPressedEvent *e) {
         WMScreen *s;
         Bar *b;
@@ -269,6 +270,7 @@
         b = findbar(s, Pt(e->x, e->y));
         if(b)
                 event("%sBarClick %d %s\n", barside[b->bar], e->button, b->name);
+ return false;
 }
 
 static Rectangle
@@ -285,10 +287,11 @@
         return ZR;
 }
 
-static void
+static bool
 expose_event(Window *w, void *aux, XExposeEvent *e) {
         USED(w, e);
         bar_draw(aux);
+ return false;
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/client.c
--- a/cmd/wmii/client.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/client.c Thu May 27 18:57:08 2010 -0400
@@ -783,7 +783,7 @@
         }
 }
 
-void
+bool
 client_prop(Client *c, Atom a) {
         WinHints h;
         XWMHints *wmh;
@@ -801,8 +801,7 @@
         else
         switch (a) {
         default:
- ewmh_prop(c, a);
- break;
+ return true;
         case XA_WM_TRANSIENT_FOR:
                 XGetTransientForHint(display, c->w.xid, &c->trans);
                 break;
@@ -838,10 +837,11 @@
                 client_updatename(c);
                 break;
         }
+ return false;
 }
 
 /* Handlers */
-static void
+static bool
 configreq_event(Window *w, void *aux, XConfigureRequestEvent *e) {
         Rectangle r, cr;
         Client *c;
@@ -873,16 +873,18 @@
                 c->sel->floatr = r;
                 client_configure(c);
         }
+ return false;
 }
 
-static void
+static bool
 destroy_event(Window *w, void *aux, XDestroyWindowEvent *e) {
         USED(w, e);
 
         client_destroy(aux);
+ return false;
 }
 
-static void
+static bool
 enter_event(Window *w, void *aux, XCrossingEvent *e) {
         Client *c;
         
@@ -896,9 +898,10 @@
                 client_setcursor(c, cursor[CurNormal]);
         }else
                 Dprint(DFocus, "enter_notify(%#C[NotifyInferior]%s)\n", c, c->name);
+ return false;
 }
 
-static void
+static bool
 focusin_event(Window *w, void *aux, XFocusChangeEvent *e) {
         Client *c, *old;
 
@@ -916,9 +919,10 @@
                 if(c->sel)
                         frame_draw(c->sel);
         }
+ return false;
 }
 
-static void
+static bool
 focusout_event(Window *w, void *aux, XFocusChangeEvent *e) {
         Client *c;
 
@@ -932,9 +936,10 @@
                 if(c->sel)
                         frame_draw(c->sel);
         }
+ return false;
 }
 
-static void
+static bool
 unmap_event(Window *w, void *aux, XUnmapEvent *e) {
         Client *c;
         
@@ -942,9 +947,10 @@
         if(!e->send_event)
                 c->unmapped--;
         client_destroy(c);
+ return false;
 }
 
-static void
+static bool
 map_event(Window *w, void *aux, XMapEvent *e) {
         Client *c;
 
@@ -953,17 +959,15 @@
         c = aux;
         if(c == selclient())
                 client_focus(c);
+ return false;
 }
 
-static void
+static bool
 property_event(Window *w, void *aux, XPropertyEvent *e) {
- Client *c;
 
         if(e->state == PropertyDelete) /* FIXME */
- return;
-
- c = aux;
- client_prop(c, e->atom);
+ return true;
+ return client_prop(aux, e->atom);
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/div.c
--- a/cmd/wmii/div.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/div.c Thu May 27 18:57:08 2010 -0400
@@ -163,7 +163,7 @@
 }
 
 /* Div Handlers */
-static void
+static bool
 bdown_event(Window *w, void *aux, XButtonEvent *e) {
         Divide *d;
 
@@ -171,9 +171,10 @@
         
         d = aux;
         mouse_resizecol(d);
+ return false;
 }
 
-static void
+static bool
 expose_event(Window *w, void *aux, XExposeEvent *e) {
         Divide *d;
         
@@ -181,6 +182,7 @@
         
         d = aux;
         drawdiv(d);
+ return false;
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/event.c
--- a/cmd/wmii/event.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/event.c Thu May 27 18:57:08 2010 -0400
@@ -30,15 +30,6 @@
 }
 
 void
-event_clientmessage(XClientMessageEvent *ev) {
-
- if(ewmh_clientmessage(ev))
- return;
- if(xdnd_clientmessage(ev))
- return;
-}
-
-void
 event_destroynotify(XDestroyWindowEvent *ev) {
         Window *w;
         Client *c;
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/ewmh.c
--- a/cmd/wmii/ewmh.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/ewmh.c Thu May 27 18:57:08 2010 -0400
@@ -10,6 +10,9 @@
 static void ewmh_getwinstate(Client*);
 static void ewmh_setstate(Client*, Atom, int);
 
+static Handlers client_handlers;
+static Handlers root_handlers;
+
 #define Net(x) ("_NET_" x)
 #define Action(x) Net("WM_ACTION_" x)
 #define State(x) Net("WM_STATE_" x)
@@ -37,6 +40,8 @@
         changeprop_long(&scr.root, Net("DESKTOP_VIEWPORT"), "CARDINAL",
                 zz, 2);
 
+ pushhandler(&scr.root, &root_handlers, nil);
+
         long supported[] = {
                 /* Misc */
                 NET("SUPPORTED"),
@@ -129,6 +134,7 @@
         ewmh_getwinstate(c);
         ewmh_getstrut(c);
         ewmh_updateclientlist();
+ pushhandler(&c->w, &client_handlers, c);
 }
 
 void
@@ -144,6 +150,74 @@
         free(c->strut);
 }
 
+static bool
+event_client_clientmessage(Window *w, void *aux, XClientMessageEvent *e) {
+ Client *c;
+ ulong *l;
+ ulong msg;
+ int action;
+
+ c = aux;
+ l = (ulong*)e->data.l;
+ msg = e->message_type;
+ Dprint(DEwmh, "ClientMessage: %A\n", msg);
+
+ if(msg == NET("WM_STATE")) {
+ enum {
+ StateUnset,
+ StateSet,
+ StateToggle,
+ };
+ if(e->format != 32)
+ return false;
+
+ switch(l[0]) {
+ case StateUnset: action = Off; break;
+ case StateSet: action = On; break;
+ case StateToggle: action = Toggle; break;
+ default: return false;
+ }
+
+ Dprint(DEwmh, "\tAction: %s\n", TOGGLE(action));
+ ewmh_setstate(c, l[1], action);
+ ewmh_setstate(c, l[2], action);
+ return false;
+ }else
+ if(msg == NET("ACTIVE_WINDOW")) {
+ if(e->format != 32)
+ return false;
+
+ Dprint(DEwmh, "\tsource: %ld\n", l[0]);
+ Dprint(DEwmh, "\twindow: 0x%lx\n", e->window);
+ Dprint(DEwmh, "\tclient: %C\n", c);
+ if(l[0] == SourceClient && abs(event_xtime - l[1]) > 5000)
+ return false;
+ if(l[0] == SourceClient || l[0] == SourcePager)
+ focus(c, true);
+ return false;
+ }else
+ if(msg == NET("CLOSE_WINDOW")) {
+ if(e->format != 32)
+ return false;
+ Dprint(DEwmh, "\tsource: %ld\n", l[0]);
+ Dprint(DEwmh, "\twindow: 0x%lx\n", e->window);
+ client_kill(c, true);
+ return false;
+ }
+
+ return false;
+}
+
+static bool
+event_client_property(Window *w, void *aux, XPropertyEvent *e) {
+ return ewmh_prop(aux, e->atom);
+}
+
+static Handlers client_handlers = {
+ .message = event_client_clientmessage,
+ .property = event_client_property,
+};
+
 static void
 pingtimeout(long id, void *v) {
         Client *c;
@@ -171,7 +245,7 @@
         e->timer = ixp_settimer(&srv, PingTime, pingtimeout, c);
 }
 
-int
+bool
 ewmh_prop(Client *c, Atom a) {
         if(a == NET("WM_WINDOW_TYPE"))
                 ewmh_getwintype(c);
@@ -179,8 +253,8 @@
         if(a == NET("WM_STRUT_PARTIAL"))
                 ewmh_getstrut(c);
         else
- return 0;
- return 1;
+ return true;
+ return false;
 }
 
 typedef struct Prop Prop;
@@ -335,70 +409,21 @@
                 client_seturgent(c, action, UrgClient);
 }
 
-int
-ewmh_clientmessage(XClientMessageEvent *e) {
+static bool
+event_root_clientmessage(Window *w, void *aux, XClientMessageEvent *e) {
         Client *c;
         View *v;
         ulong *l;
         ulong msg;
- int action, i;
+ int i;
 
         l = (ulong*)e->data.l;
         msg = e->message_type;
         Dprint(DEwmh, "ClientMessage: %A\n", msg);
 
- if(msg == NET("WM_STATE")) {
- enum {
- StateUnset,
- StateSet,
- StateToggle,
- };
- if(e->format != 32)
- return -1;
- c = win2client(e->window);
- if(c == nil)
- return 0;
- switch(l[0]) {
- case StateUnset: action = Off; break;
- case StateSet: action = On; break;
- case StateToggle: action = Toggle; break;
- default: return -1;
- }
- Dprint(DEwmh, "\tAction: %s\n", TOGGLE(action));
- ewmh_setstate(c, l[1], action);
- ewmh_setstate(c, l[2], action);
- return 1;
- }else
- if(msg == NET("ACTIVE_WINDOW")) {
- if(e->format != 32)
- return -1;
- Dprint(DEwmh, "\tsource: %ld\n", l[0]);
- Dprint(DEwmh, "\twindow: 0x%lx\n", e->window);
- c = win2client(e->window);
- if(c == nil)
- return 1;
- Dprint(DEwmh, "\tclient: %C\n", c);
- if(l[0] == SourceClient && abs(event_xtime - l[1]) > 5000)
- return 1;
- if(l[0] != SourceClient && l[0] != SourcePager)
- return 1;
- focus(c, true);
- return 1;
- }else
- if(msg == NET("CLOSE_WINDOW")) {
- if(e->format != 32)
- return -1;
- Dprint(DEwmh, "\tsource: %ld\n", l[0]);
- Dprint(DEwmh, "\twindow: 0x%lx\n", e->window);
- c = win2client(e->window);
- if(c == nil)
- return 1;
- client_kill(c, true);
- return 1;
- }else
         if(msg == NET("CURRENT_DESKTOP")) {
                 if(e->format != 32)
- return -1;
+ return false;
                 for(v=view, i=l[0]; v; v=v->next, i--)
                         if(i == 0)
                                 break;
@@ -406,14 +431,14 @@
                 if(i == 0)
                         view_select(v->name);
                 return 1;
- }else
+ }
         if(msg == xatom("WM_PROTOCOLS")) {
                 if(e->format != 32)
- return 0;
+ return false;
                 Dprint(DEwmh, "\t%A\n", l[0]);
                 if(l[0] == NET("WM_PING")) {
                         if(e->window != scr.root.xid)
- return -1;
+ return false;
                         c = win2client(l[2]);
                         if(c == nil)
                                 return 1;
@@ -424,13 +449,19 @@
                                 ixp_unsettimer(&srv, c->w.ewmh.timer);
                         c->w.ewmh.timer = 0;
                         c->w.ewmh.ping = 0;
- return 1;
+ return false;
                 }
+ return false;
         }
 
- return 0;
+ return false;
 }
 
+static Handlers root_handlers = {
+ .message = event_root_clientmessage,
+};
+
+
 void
 ewmh_framesize(Client *c) {
         Rectangle r;
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/fns.h Thu May 27 18:57:08 2010 -0400
@@ -82,7 +82,7 @@
 void client_manage(Client*);
 void client_map(Client*);
 void client_message(Client*, char*, long);
-void client_prop(Client*, Atom);
+bool client_prop(Client*, Atom);
 void client_reparent(Client*, Window*, Point);
 void client_resize(Client*, Rectangle);
 void client_setcursor(Client*, Cursor);
@@ -142,7 +142,7 @@
 void ewmh_init(void);
 void ewmh_initclient(Client*);
 void ewmh_pingclient(Client*);
-int ewmh_prop(Client*, Atom);
+bool ewmh_prop(Client*, Atom);
 long ewmh_protocols(Window*);
 void ewmh_updateclient(Client*);
 void ewmh_updateclientlist(void);
@@ -278,6 +278,5 @@
 char* toutf8n(const char*, size_t);
 
 /* xdnd.c */
-int xdnd_clientmessage(XClientMessageEvent*);
 void xdnd_initwindow(Window*);
 
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/frame.c Thu May 27 18:57:08 2010 -0400
@@ -142,16 +142,17 @@
 }
 
 /* Handlers */
-static void
+static bool
 bup_event(Window *w, void *aux, XButtonEvent *e) {
         if((e->state & def.mod) != def.mod)
                 XAllowEvents(display, ReplayPointer, e->time);
         else
                 XUngrabPointer(display, e->time);
         event("ClientClick %#C %d\n", aux, e->button);
+ return false;
 }
 
-static void
+static bool
 bdown_event(Window *w, void *aux, XButtonEvent *e) {
         Frame *f;
         Client *c;
@@ -200,15 +201,17 @@
                         event("ClientMouseDown %#C %d\n", f->client, e->button);
                 }
         }
+ return false;
 }
 
-static void
+static bool
 config_event(Window *w, void *aux, XConfigureEvent *e) {
 
         USED(w, e);
+ return false;
 }
 
-static void
+static bool
 enter_event(Window *w, void *aux, XCrossingEvent *e) {
         Client *c;
         Frame *f;
@@ -224,9 +227,10 @@
                         focus(f->client, false);
         }
         mouse_checkresize(f, Pt(e->x, e->y), false);
+ return false;
 }
 
-static void
+static bool
 expose_event(Window *w, void *aux, XExposeEvent *e) {
         Client *c;
 
@@ -238,14 +242,16 @@
         else
                 fprint(2, "Badness: Expose event on a client frame which shouldn't be visible: %#C\n",
                         c);
+ return false;
 }
 
-static void
+static bool
 motion_event(Window *w, void *aux, XMotionEvent *e) {
         Client *c;
         
         c = aux;
         mouse_checkresize(c->sel, Pt(e->x, e->y), false);
+ return false;
 }
 
 Handlers framehandler = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/layout.c
--- a/cmd/wmii/layout.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/layout.c Thu May 27 18:57:08 2010 -0400
@@ -98,7 +98,7 @@
         free(f);
 }
 
-static void
+static bool
 expose_event(Window *w, void *aux, XExposeEvent *e) {
         Rectangle r;
         Framewin *f;
@@ -118,6 +118,7 @@
         border(buf, insetrect(f->grabbox, -f->grabbox.min.x), 1, c->border);
 
         copyimage(w, r, buf, ZP);
+ return false;
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/mouse.c Thu May 27 18:57:08 2010 -0400
@@ -28,11 +28,12 @@
         }
 }
 
-static void
+static bool
 cwin_expose(Window *w, void *aux, XExposeEvent *e) {
 
         fill(w, rectsubpt(w->r, w->r.min), def.focuscolor.bg);
         fill(w, w->r, def.focuscolor.bg);
+ return false;
 }
 
 static Handlers chandler = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/root.c
--- a/cmd/wmii/root.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/root.c Thu May 27 18:57:08 2010 -0400
@@ -23,45 +23,49 @@
         sethandler(&scr.root, &handlers);
 }
 
-static void
+static bool
 enter_event(Window *w, void *aux, XCrossingEvent *e) {
         disp.sel = true;
         frame_draw_all();
+ return false;
 }
 
-static void
+static bool
 leave_event(Window *w, void *aux, XCrossingEvent *e) {
         if(!e->same_screen) {
                 disp.sel = false;
                 frame_draw_all();
         }
+ return false;
 }
 
-static void
+static bool
 focusin_event(Window *w, void *aux, XFocusChangeEvent *e) {
         if(e->mode == NotifyGrab)
                 disp.hasgrab = &c_root;
+ return false;
 }
 
-static void
+static bool
 mapreq_event(Window *w, void *aux, XMapRequestEvent *e) {
         XWindowAttributes wa;
 
         if(!XGetWindowAttributes(display, e->window, &wa))
- return;
+ return false;
         if(wa.override_redirect) {
                 /* Do I really want these? */
                 /* Probably not.
                 XSelectInput(display, e->window,
                          PropertyChangeMask | StructureNotifyMask);
                 */
- return;
+ return false;
         }
         if(!win2client(e->window))
                 client_create(e->window, &wa);
+ return false;
 }
 
-static void
+static bool
 motion_event(Window *w, void *aux, XMotionEvent *e) {
         Rectangle r, r2;
 
@@ -69,13 +73,15 @@
         r2 = constrain(r, 0);
         if(!eqrect(r, r2))
                 warppointer(r2.min);
+ return false;
 }
 
-static void
+static bool
 kdown_event(Window *w, void *aux, XKeyEvent *e) {
 
         e->state &= valid_mask;
         kpress(w->xid, e->state, (KeyCode)e->keycode);
+ return false;
 }
 
 static Handlers handlers = {
diff -r 87818ee68036 -r bbef798778a3 cmd/wmii/xdnd.c
--- a/cmd/wmii/xdnd.c Thu May 27 18:05:27 2010 -0400
+++ b/cmd/wmii/xdnd.c Thu May 27 18:57:08 2010 -0400
@@ -4,12 +4,15 @@
 #include "dat.h"
 #include "fns.h"
 
+static Handlers handlers;
+
 void
 xdnd_initwindow(Window *w) {
         long l;
 
         l = 3; /* They are insane. Why is this an ATOM?! */
         changeprop_long(w, "XdndAware", "ATOM", &l, 1);
+ pushhandler(w, &handlers, nil);
 }
 
 typedef struct Dnd Dnd;
@@ -18,9 +21,8 @@
         Rectangle r;
 };
 
-int
-xdnd_clientmessage(XClientMessageEvent *e) {
- Window *w;
+static bool
+clientmessage_event(Window *w, void *aux, XClientMessageEvent *e) {
         Dnd *dnd;
         long *l;
         Rectangle r;
@@ -35,34 +37,28 @@
 
         if(msg == xatom("XdndEnter")) {
                 if(e->format != 32)
- return -1;
- w = findwin(e->window);
- if(w) {
- if(w->dnd == nil)
- w->dnd = emallocz(sizeof *dnd);
- dnd = w->dnd;
- dnd->source = l[0];
- dnd->r = ZR;
- }
- return 1;
+ return false;
+ if(w->dnd == nil)
+ w->dnd = emallocz(sizeof *dnd);
+ dnd = w->dnd;
+ dnd->source = l[0];
+ dnd->r = ZR;
+ return false;
         }else
         if(msg == xatom("XdndLeave")) {
                 if(e->format != 32)
- return -1;
- w = findwin(e->window);
- if(w && w->dnd) {
+ return false;
+ if(w->dnd) {
                         free(w->dnd);
                         w->dnd = nil;
                 }
- return 1;
+ return false;
         }else
         if(msg == xatom("XdndPosition")) {
                 if(e->format != 32)
- return -1;
+ return false;
                 r = ZR;
- w = findwin(e->window);
- if(w)
- dnd = w->dnd;
+ dnd = w->dnd;
                 if(dnd) {
                         p.x = (ulong)l[2] >> 16;
                         p.y = (ulong)l[2] & 0xffff;
@@ -80,9 +76,13 @@
                 pos = (r.min.x<<16) | r.min.y;
                 siz = (Dx(r)<<16) | Dy(r);
                 sendmessage(window(l[0]), "XdndStatus", e->window, 0, pos, siz, 0);
- return 1;
+ return false;
         }
 
- return 0;
+ return true;
 }
 
+static Handlers handlers = {
+ .message = clientmessage_event
+};
+
diff -r 87818ee68036 -r bbef798778a3 include/stuff/x11.h
--- a/include/stuff/x11.h Thu May 27 18:05:27 2010 -0400
+++ b/include/stuff/x11.h Thu May 27 18:57:08 2010 -0400
@@ -95,28 +95,28 @@
 
 struct Handlers {
         Rectangle (*dndmotion)(Window*, void*, Point);
- void (*bdown)(Window*, void*, XButtonEvent*);
- void (*bup)(Window*, void*, XButtonEvent*);
- void (*config)(Window*, void*, XConfigureEvent*);
- void (*configreq)(Window*, void*, XConfigureRequestEvent*);
- void (*destroy)(Window*, void*, XDestroyWindowEvent*);
- void (*enter)(Window*, void*, XCrossingEvent*);
- void (*expose)(Window*, void*, XExposeEvent*);
- void (*focusin)(Window*, void*, XFocusChangeEvent*);
- void (*focusout)(Window*, void*, XFocusChangeEvent*);
- void (*kdown)(Window*, void*, XKeyEvent*);
- void (*kup)(Window*, void*, XKeyEvent*);
- void (*leave)(Window*, void*, XCrossingEvent*);
- void (*map)(Window*, void*, XMapEvent*);
- void (*mapreq)(Window*, void*, XMapRequestEvent*);
- void (*message)(Window*, void*, XClientMessageEvent*);
- void (*motion)(Window*, void*, XMotionEvent*);
- void (*property)(Window*, void*, XPropertyEvent*);
- void (*reparent)(Window*, void*, XReparentEvent*);
- void (*selection)(Window*, void*, XSelectionEvent*);
- void (*selectionclear)(Window*, void*, XSelectionClearEvent*);
- void (*selectionrequest)(Window*, void*, XSelectionRequestEvent*);
- void (*unmap)(Window*, void*, XUnmapEvent*);
+ bool (*bdown)(Window*, void*, XButtonEvent*);
+ bool (*bup)(Window*, void*, XButtonEvent*);
+ bool (*config)(Window*, void*, XConfigureEvent*);
+ bool (*configreq)(Window*, void*, XConfigureRequestEvent*);
+ bool (*destroy)(Window*, void*, XDestroyWindowEvent*);
+ bool (*enter)(Window*, void*, XCrossingEvent*);
+ bool (*expose)(Window*, void*, XExposeEvent*);
+ bool (*focusin)(Window*, void*, XFocusChangeEvent*);
+ bool (*focusout)(Window*, void*, XFocusChangeEvent*);
+ bool (*kdown)(Window*, void*, XKeyEvent*);
+ bool (*kup)(Window*, void*, XKeyEvent*);
+ bool (*leave)(Window*, void*, XCrossingEvent*);
+ bool (*map)(Window*, void*, XMapEvent*);
+ bool (*mapreq)(Window*, void*, XMapRequestEvent*);
+ bool (*message)(Window*, void*, XClientMessageEvent*);
+ bool (*motion)(Window*, void*, XMotionEvent*);
+ bool (*property)(Window*, void*, XPropertyEvent*);
+ bool (*reparent)(Window*, void*, XReparentEvent*);
+ bool (*selection)(Window*, void*, XSelectionEvent*);
+ bool (*selectionclear)(Window*, void*, XSelectionClearEvent*);
+ bool (*selectionrequest)(Window*, void*, XSelectionRequestEvent*);
+ bool (*unmap)(Window*, void*, XUnmapEvent*);
 };
 
 struct HandlersLink {
diff -r 87818ee68036 -r bbef798778a3 lib/libstuff/event/event.c
--- a/lib/libstuff/event/event.c Thu May 27 18:05:27 2010 -0400
+++ b/lib/libstuff/event/event.c Thu May 27 18:57:08 2010 -0400
@@ -3,7 +3,7 @@
  */
 #include "event.h"
 
-typedef void (*Handler)(Window*, void*, XEvent*);
+typedef bool (*Handler)(Window*, void*, XEvent*);
 void (*event_debug)(XEvent*);
 long event_xtime;
 bool event_looprunning;
@@ -37,16 +37,14 @@
         Handler f;
         HandlersLink *l;
 
- if(w->handler && (f = structmember(w->handler, Handler, offset))) {
- f(w, w->aux, event);
- return;
- }
- for(l=w->handler_link; l; l=l->next) {
- if(f = structmember(l->handler, Handler, offset)) {
- f(w, l->aux, event);
+ if(w->handler && (f = structmember(w->handler, Handler, offset)))
+ if(!f(w, w->aux, event))
                         return;
- }
- }
+
+ for(l=w->handler_link; l; l=l->next)
+ if((f = structmember(l->handler, Handler, offset)))
+ if(!f(w, l->aux, event))
+ return;
 }
 
 void
Received on Fri May 28 2010 - 00:49:24 UTC

This archive was generated by hypermail 2.2.0 : Fri May 28 2010 - 01:00:08 UTC