diff --git a/cmd/menu/menu.c b/cmd/menu/menu.c index 12f0d42e..bc7c7bae 100644 --- a/cmd/menu/menu.c +++ b/cmd/menu/menu.c @@ -254,7 +254,7 @@ menu_show(void) { menu_draw(); } -static void +static bool kdown_event(Window *w, void *aux, XKeyEvent *e) { char **action, **p; char *key; @@ -276,7 +276,7 @@ kdown_event(Window *w, void *aux, XKeyEvent *e) { || 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 @@ kdown_event(Window *w, void *aux, XKeyEvent *e) { 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 --git a/cmd/strut/win.c b/cmd/strut/win.c index 8e85894e..b4810d22 100644 --- a/cmd/strut/win.c +++ b/cmd/strut/win.c @@ -79,20 +79,22 @@ restrut(Window *frame) { 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 --git a/cmd/tray/client.c b/cmd/tray/client.c index fc597aff..d88f5f0e 100644 --- a/cmd/tray/client.c +++ b/cmd/tray/client.c @@ -152,42 +152,47 @@ client_message(Client *c, long type, int format, ClientMessageData* data) { } } -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 --git a/cmd/tray/selection.c b/cmd/tray/selection.c index a5e71ead..41278d5c 100644 --- a/cmd/tray/selection.c +++ b/cmd/tray/selection.c @@ -94,16 +94,17 @@ selection_notify(Selection *s, XSelectionRequestEvent *ev, bool success) { sendevent(window(ev->requestor), false, 0L, ¬ify); } -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 @@ selectionclear_event(Window *w, void *aux, XSelectionClearEvent *ev) { 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 @@ selectionrequest_event(Window *w, void *aux, XSelectionRequestEvent *ev) { 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 --git a/cmd/tray/tray.c b/cmd/tray/tray.c index 2c1b301b..b55b48ab 100644 --- a/cmd/tray/tray.c +++ b/cmd/tray/tray.c @@ -221,7 +221,7 @@ tray_update(void) { tray_draw(tray.win->r); } -static void +static bool config_event(Window *w, void *aux, XConfigureEvent *ev) { USED(aux); @@ -239,19 +239,22 @@ config_event(Window *w, void *aux, XConfigureEvent *ev) { 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 @@ static Handlers handlers = { .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 --git a/cmd/tray/xembed.c b/cmd/tray/xembed.c index ff3fd234..e0f7fab0 100644 --- a/cmd/tray/xembed.c +++ b/cmd/tray/xembed.c @@ -92,16 +92,17 @@ xembed_sendmessage(XEmbed *xembed, long message, long detail, long data1, long d 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 @@ property_event(Window *w, void *aux, XPropertyEvent *ev) { 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 @@ reparent_event(Window *w, void *aux, XReparentEvent *ev) { xembed->flags = DEAD; xembed_disown(xembed); } + return false; } static Handlers handlers = { diff --git a/cmd/wmii/bar.c b/cmd/wmii/bar.c index 3c3c126f..cc170078 100644 --- a/cmd/wmii/bar.c +++ b/cmd/wmii/bar.c @@ -245,7 +245,7 @@ findbar(WMScreen *s, Point p) { return nil; } -static void +static bool bdown_event(Window *w, void *aux, XButtonPressedEvent *e) { WMScreen *s; Bar *b; @@ -258,9 +258,10 @@ bdown_event(Window *w, void *aux, XButtonPressedEvent *e) { 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 @@ bup_event(Window *w, void *aux, XButtonPressedEvent *e) { 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 @@ dndmotion_event(Window *w, void *aux, Point p) { 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 --git a/cmd/wmii/client.c b/cmd/wmii/client.c index dca76e69..adb5ba3f 100644 --- a/cmd/wmii/client.c +++ b/cmd/wmii/client.c @@ -783,7 +783,7 @@ updatemwm(Client *c) { } } -void +bool client_prop(Client *c, Atom a) { WinHints h; XWMHints *wmh; @@ -801,8 +801,7 @@ client_prop(Client *c, Atom a) { 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_prop(Client *c, Atom a) { 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 @@ configreq_event(Window *w, void *aux, XConfigureRequestEvent *e) { 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 @@ enter_event(Window *w, void *aux, XCrossingEvent *e) { 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 @@ focusin_event(Window *w, void *aux, XFocusChangeEvent *e) { 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 @@ focusout_event(Window *w, void *aux, XFocusChangeEvent *e) { 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 @@ unmap_event(Window *w, void *aux, XUnmapEvent *e) { 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 @@ map_event(Window *w, void *aux, XMapEvent *e) { 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 --git a/cmd/wmii/div.c b/cmd/wmii/div.c index fe48b159..fa5a6fcc 100644 --- a/cmd/wmii/div.c +++ b/cmd/wmii/div.c @@ -163,7 +163,7 @@ div_update_all(void) { } /* Div Handlers */ -static void +static bool bdown_event(Window *w, void *aux, XButtonEvent *e) { Divide *d; @@ -171,9 +171,10 @@ bdown_event(Window *w, void *aux, XButtonEvent *e) { 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 @@ expose_event(Window *w, void *aux, XExposeEvent *e) { d = aux; drawdiv(d); + return false; } static Handlers handlers = { diff --git a/cmd/wmii/event.c b/cmd/wmii/event.c index 8ffd338b..f7bb72ab 100644 --- a/cmd/wmii/event.c +++ b/cmd/wmii/event.c @@ -29,15 +29,6 @@ event_configurenotify(XConfigureEvent *ev) { event_handle(w, config, ev); } -void -event_clientmessage(XClientMessageEvent *ev) { - - if(ewmh_clientmessage(ev)) - return; - if(xdnd_clientmessage(ev)) - return; -} - void event_destroynotify(XDestroyWindowEvent *ev) { Window *w; diff --git a/cmd/wmii/ewmh.c b/cmd/wmii/ewmh.c index e8660f56..3e75ed49 100644 --- a/cmd/wmii/ewmh.c +++ b/cmd/wmii/ewmh.c @@ -10,6 +10,9 @@ Window *ewmhwin; 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 @@ ewmh_init(void) { 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_initclient(Client *c) { ewmh_getwinstate(c); ewmh_getstrut(c); ewmh_updateclientlist(); + pushhandler(&c->w, &client_handlers, c); } void @@ -144,6 +150,74 @@ ewmh_destroyclient(Client *c) { 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 @@ ewmh_pingclient(Client *c) { 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 @@ ewmh_prop(Client *c, Atom a) { 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 @@ ewmh_setstate(Client *c, Atom state, int action) { 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 @@ ewmh_clientmessage(XClientMessageEvent *e) { 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 @@ ewmh_clientmessage(XClientMessageEvent *e) { 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 --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h index dbd5d8bd..1d8ca86b 100644 --- a/cmd/wmii/fns.h +++ b/cmd/wmii/fns.h @@ -82,7 +82,7 @@ void client_kill(Client*, bool); 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_getwintype(Client*); 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* toutf8(const char*); char* toutf8n(const char*, size_t); /* xdnd.c */ -int xdnd_clientmessage(XClientMessageEvent*); void xdnd_initwindow(Window*); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c index b6e5d6f9..9b58a530 100644 --- a/cmd/wmii/frame.c +++ b/cmd/wmii/frame.c @@ -142,16 +142,17 @@ frame_restack(Frame *f, Frame *above) { } /* 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 @@ bdown_event(Window *w, void *aux, XButtonEvent *e) { 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 @@ enter_event(Window *w, void *aux, XCrossingEvent *e) { 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 @@ expose_event(Window *w, void *aux, XExposeEvent *e) { 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 --git a/cmd/wmii/layout.c b/cmd/wmii/layout.c index 5fb70c07..38542623 100644 --- a/cmd/wmii/layout.c +++ b/cmd/wmii/layout.c @@ -98,7 +98,7 @@ framedestroy(Framewin *f) { free(f); } -static void +static bool expose_event(Window *w, void *aux, XExposeEvent *e) { Rectangle r; Framewin *f; @@ -118,6 +118,7 @@ expose_event(Window *w, void *aux, XExposeEvent *e) { border(buf, insetrect(f->grabbox, -f->grabbox.min.x), 1, c->border); copyimage(w, r, buf, ZP); + return false; } static Handlers handlers = { diff --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c index 44195505..8319f709 100644 --- a/cmd/wmii/mouse.c +++ b/cmd/wmii/mouse.c @@ -28,11 +28,12 @@ quad_cursor(Align align) { } } -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 --git a/cmd/wmii/root.c b/cmd/wmii/root.c index f35742dc..ee64a2e9 100644 --- a/cmd/wmii/root.c +++ b/cmd/wmii/root.c @@ -23,45 +23,49 @@ root_init(void) { 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 @@ motion_event(Window *w, void *aux, XMotionEvent *e) { 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 --git a/cmd/wmii/xdnd.c b/cmd/wmii/xdnd.c index 92969e10..7d47b792 100644 --- a/cmd/wmii/xdnd.c +++ b/cmd/wmii/xdnd.c @@ -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 @@ struct Dnd { 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 @@ xdnd_clientmessage(XClientMessageEvent *e) { 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 @@ xdnd_clientmessage(XClientMessageEvent *e) { 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 --git a/include/stuff/x11.h b/include/stuff/x11.h index f2b5ddc0..77be6557 100644 --- a/include/stuff/x11.h +++ b/include/stuff/x11.h @@ -95,28 +95,28 @@ struct Font { 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 --git a/lib/libstuff/event/event.c b/lib/libstuff/event/event.c index 79f9b119..7a21e83f 100644 --- a/lib/libstuff/event/event.c +++ b/lib/libstuff/event/event.c @@ -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 @@ _event_handle(Window *w, ulong offset, XEvent *event) { 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