X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=event.c;h=2e0b75fdf9c8a087db50ad5a01c3aa4a06f62a56;hb=c0705eeb65733e8c5091e47d5bdc701a0779a949;hp=604420dde6069145d53eac8386087d4d12d171a8;hpb=7696c89c90c926f6371b1ee3ec1b13dd2414aa40;p=dwm.git diff --git a/event.c b/event.c index 604420d..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,28 +35,101 @@ void (*handler[LASTEvent]) (XEvent *) = { [LeaveNotify] = leavenotify, [Expose] = expose, [KeyPress] = keypress, - [KeymapNotify] = keymapnotify, [MapRequest] = maprequest, [PropertyNotify] = propertynotify, [UnmapNotify] = unmapnotify }; -unsigned int -discard_events(long even_mask) +static void +mresize(Client *c) +{ + XEvent 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; - unsigned int n = 0; - while(XCheckMaskEvent(dpy, even_mask, &ev)) n++; - return n; + 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))) { + 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; @@ -60,7 +137,7 @@ buttonpress(XEvent *e) mmove(c); break; case Button2: - XLowerWindow(dpy, c->win); + lower(c); break; case Button3: mresize(c); @@ -78,6 +155,7 @@ configurerequest(XEvent *e) ev->value_mask &= ~CWSibling; if((c = getclient(ev->window))) { + gravitate(c, True); if(ev->value_mask & CWX) c->x = ev->x; if(ev->value_mask & CWY) @@ -86,6 +164,10 @@ configurerequest(XEvent *e) c->w = ev->width; if(ev->value_mask & CWHeight) c->h = ev->height; + if(ev->value_mask & CWBorderWidth) + c->border = 1; + gravitate(c, False); + resize(c, True); } wc.x = ev->x; @@ -122,10 +204,8 @@ enternotify(XEvent *e) if((c = getclient(ev->window))) focus(c); - else if(ev->window == root) { - sel_screen = True; - /*draw_frames();*/ - } + else if(ev->window == root) + issel = True; } static void @@ -133,10 +213,8 @@ leavenotify(XEvent *e) { XCrossingEvent *ev = &e->xcrossing; - if((ev->window == root) && !ev->same_screen) { - sel_screen = True; - /*draw_frames();*/ - } + if((ev->window == root) && !ev->same_screen) + issel = True; } static void @@ -146,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; @@ -182,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); } } }