X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=event.c;h=2e0b75fdf9c8a087db50ad5a01c3aa4a06f62a56;hb=c0705eeb65733e8c5091e47d5bdc701a0779a949;hp=93007dfc4607b5c3179457f0aea1de878a21cfda;hpb=2e836ecce1ba0629a6088b739c1092d27fccd72b;p=dwm.git diff --git a/event.c b/event.c index 93007df..2e0b75f 100644 --- a/event.c +++ b/event.c @@ -4,12 +4,17 @@ */ #include +#include #include #include +#include #include #include -#include "wm.h" +#include "dwm.h" + +#define ButtonMask (ButtonPressMask | ButtonReleaseMask) +#define MouseMask (ButtonMask | PointerMotionMask) /* local functions */ static void buttonpress(XEvent *e); @@ -18,7 +23,6 @@ static void destroynotify(XEvent *e); static void enternotify(XEvent *e); static void leavenotify(XEvent *e); static void expose(XEvent *e); -static void keymapnotify(XEvent *e); static void maprequest(XEvent *e); static void propertynotify(XEvent *e); static void unmapnotify(XEvent *e); @@ -31,27 +35,101 @@ void (*handler[LASTEvent]) (XEvent *) = { [LeaveNotify] = leavenotify, [Expose] = expose, [KeyPress] = keypress, - [KeymapNotify] = keymapnotify, [MapRequest] = maprequest, [PropertyNotify] = propertynotify, [UnmapNotify] = unmapnotify }; -void -discard_events(long even_mask) +static void +mresize(Client *c) { XEvent ev; - while(XCheckMaskEvent(dpy, even_mask, &ev)); + int ocx, ocy; + + ocx = c->x; + ocy = c->y; + if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, + None, cursor[CurResize], CurrentTime) != GrabSuccess) + return; + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); + for(;;) { + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); + switch(ev.type) { + default: break; + case Expose: + handler[Expose](&ev); + break; + case MotionNotify: + XFlush(dpy); + c->w = abs(ocx - ev.xmotion.x); + c->h = abs(ocy - ev.xmotion.y); + c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; + c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; + resize(c, True); + break; + case ButtonRelease: + XUngrabPointer(dpy, CurrentTime); + return; + } + } +} + +static void +mmove(Client *c) +{ + XEvent ev; + int x1, y1, ocx, ocy, di; + unsigned int dui; + Window dummy; + + ocx = c->x; + ocy = c->y; + if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, + None, cursor[CurMove], CurrentTime) != GrabSuccess) + return; + XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); + for(;;) { + XMaskEvent(dpy, MouseMask | ExposureMask, &ev); + switch (ev.type) { + default: break; + case Expose: + handler[Expose](&ev); + break; + case MotionNotify: + XFlush(dpy); + c->x = ocx + (ev.xmotion.x - x1); + c->y = ocy + (ev.xmotion.y - y1); + resize(c, False); + break; + case ButtonRelease: + XUngrabPointer(dpy, CurrentTime); + return; + } + } } static void buttonpress(XEvent *e) { + int x; + Arg a; XButtonPressedEvent *ev = &e->xbutton; Client *c; - if((c = getclient(ev->window))) { - raise(c); + if(barwin == ev->window) { + x = (arrange == floating) ? textw("~") : 0; + for(a.i = 0; a.i < TLast; a.i++) { + x += textw(tags[a.i]); + if(ev->x < x) { + view(&a); + break; + } + } + } + else if((c = getclient(ev->window))) { + if(arrange == tiling && !c->floating) + return; + higher(c); switch(ev->button) { default: break; @@ -87,8 +165,9 @@ configurerequest(XEvent *e) if(ev->value_mask & CWHeight) c->h = ev->height; if(ev->value_mask & CWBorderWidth) - c->border = ev->border_width; + c->border = 1; gravitate(c, False); + resize(c, True); } wc.x = ev->x; @@ -126,7 +205,7 @@ enternotify(XEvent *e) if((c = getclient(ev->window))) focus(c); else if(ev->window == root) - sel_screen = True; + issel = True; } static void @@ -135,7 +214,7 @@ leavenotify(XEvent *e) XCrossingEvent *ev = &e->xcrossing; if((ev->window == root) && !ev->same_screen) - sel_screen = True; + issel = True; } static void @@ -145,20 +224,14 @@ expose(XEvent *e) Client *c; if(ev->count == 0) { - if((c = gettitle(ev->window))) - draw_client(c); - else if(ev->window == barwin) - draw_bar(); + if(barwin == ev->window) + drawstatus(); + else if((c = gettitle(ev->window))) + drawtitle(c); } } static void -keymapnotify(XEvent *e) -{ - update_keys(); -} - -static void maprequest(XEvent *e) { XMapRequestEvent *ev = &e->xmaprequest; @@ -181,32 +254,31 @@ static void propertynotify(XEvent *e) { XPropertyEvent *ev = &e->xproperty; + Window trans; Client *c; if(ev->state == PropertyDelete) return; /* ignore */ - if(ev->atom == wm_atom[WMProtocols]) { - c->proto = win_proto(c->win); - return; - } if((c = getclient(ev->window))) { + if(ev->atom == wm_atom[WMProtocols]) { + c->proto = proto(c->win); + return; + } switch (ev->atom) { default: break; case XA_WM_TRANSIENT_FOR: - XGetTransientForHint(dpy, c->win, &c->trans); + XGetTransientForHint(dpy, c->win, &trans); + if(!c->floating && (c->floating = (trans != 0))) + arrange(NULL); break; - update_size(c); case XA_WM_NORMAL_HINTS: - update_size(c); + setsize(c); break; } if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { - update_name(c); - if(c == stack) - draw_bar(); - else - draw_client(c); + settitle(c); + drawtitle(c); } } }