dwm-meillo

diff event.c @ 73:c2ddb9dbbd10

rearranged
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 22:33:38 +0200
parents e5fff8249705
children 5370ef170cc9
line diff
     1.1 --- a/event.c	Fri Jul 14 18:59:25 2006 +0200
     1.2 +++ b/event.c	Fri Jul 14 22:33:38 2006 +0200
     1.3 @@ -7,11 +7,15 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6  #include <string.h>
     1.7 +#include <unistd.h>
     1.8  #include <X11/keysym.h>
     1.9  #include <X11/Xatom.h>
    1.10  
    1.11  #include "dwm.h"
    1.12  
    1.13 +#define ButtonMask      (ButtonPressMask | ButtonReleaseMask)
    1.14 +#define MouseMask       (ButtonMask | PointerMotionMask)
    1.15 +
    1.16  /* local functions */
    1.17  static void buttonpress(XEvent *e);
    1.18  static void configurerequest(XEvent *e);
    1.19 @@ -19,7 +23,6 @@
    1.20  static void enternotify(XEvent *e);
    1.21  static void leavenotify(XEvent *e);
    1.22  static void expose(XEvent *e);
    1.23 -static void keymapnotify(XEvent *e);
    1.24  static void maprequest(XEvent *e);
    1.25  static void propertynotify(XEvent *e);
    1.26  static void unmapnotify(XEvent *e);
    1.27 @@ -32,21 +35,100 @@
    1.28  	[LeaveNotify] = leavenotify,
    1.29  	[Expose] = expose,
    1.30  	[KeyPress] = keypress,
    1.31 -	[KeymapNotify] = keymapnotify,
    1.32  	[MapRequest] = maprequest,
    1.33  	[PropertyNotify] = propertynotify,
    1.34  	[UnmapNotify] = unmapnotify
    1.35  };
    1.36  
    1.37  static void
    1.38 +mresize(Client *c)
    1.39 +{
    1.40 +	XEvent ev;
    1.41 +	int ocx, ocy;
    1.42 +
    1.43 +	ocx = c->x;
    1.44 +	ocy = c->y;
    1.45 +	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
    1.46 +				None, cursor[CurResize], CurrentTime) != GrabSuccess)
    1.47 +		return;
    1.48 +	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
    1.49 +	for(;;) {
    1.50 +		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
    1.51 +		switch(ev.type) {
    1.52 +		default: break;
    1.53 +		case Expose:
    1.54 +			handler[Expose](&ev);
    1.55 +			break;
    1.56 +		case MotionNotify:
    1.57 +			XFlush(dpy);
    1.58 +			c->w = abs(ocx - ev.xmotion.x);
    1.59 +			c->h = abs(ocy - ev.xmotion.y);
    1.60 +			c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
    1.61 +			c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
    1.62 +			resize(c, True);
    1.63 +			break;
    1.64 +		case ButtonRelease:
    1.65 +			XUngrabPointer(dpy, CurrentTime);
    1.66 +			return;
    1.67 +		}
    1.68 +	}
    1.69 +}
    1.70 +
    1.71 +static void
    1.72 +mmove(Client *c)
    1.73 +{
    1.74 +	XEvent ev;
    1.75 +	int x1, y1, ocx, ocy, di;
    1.76 +	unsigned int dui;
    1.77 +	Window dummy;
    1.78 +
    1.79 +	ocx = c->x;
    1.80 +	ocy = c->y;
    1.81 +	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
    1.82 +				None, cursor[CurMove], CurrentTime) != GrabSuccess)
    1.83 +		return;
    1.84 +	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
    1.85 +	for(;;) {
    1.86 +		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
    1.87 +		switch (ev.type) {
    1.88 +		default: break;
    1.89 +		case Expose:
    1.90 +			handler[Expose](&ev);
    1.91 +			break;
    1.92 +		case MotionNotify:
    1.93 +			XFlush(dpy);
    1.94 +			c->x = ocx + (ev.xmotion.x - x1);
    1.95 +			c->y = ocy + (ev.xmotion.y - y1);
    1.96 +			resize(c, False);
    1.97 +			break;
    1.98 +		case ButtonRelease:
    1.99 +			XUngrabPointer(dpy, CurrentTime);
   1.100 +			return;
   1.101 +		}
   1.102 +	}
   1.103 +}
   1.104 +
   1.105 +static void
   1.106  buttonpress(XEvent *e)
   1.107  {
   1.108 +	int x;
   1.109 +	Arg a;
   1.110  	XButtonPressedEvent *ev = &e->xbutton;
   1.111  	Client *c;
   1.112  
   1.113 -	if(barwin == ev->window)
   1.114 -		barclick(ev);
   1.115 +	if(barwin == ev->window) {
   1.116 +		x = (arrange == floating) ? textw("~") : 0;
   1.117 +		for(a.i = 0; a.i < TLast; a.i++) {
   1.118 +			x += textw(tags[a.i]);
   1.119 +			if(ev->x < x) {
   1.120 +				view(&a);
   1.121 +				break;
   1.122 +			}
   1.123 +		}
   1.124 +	}
   1.125  	else if((c = getclient(ev->window))) {
   1.126 +		if(arrange == tiling && !c->floating)
   1.127 +			return;
   1.128  		craise(c);
   1.129  		switch(ev->button) {
   1.130  		default:
   1.131 @@ -150,12 +232,6 @@
   1.132  }
   1.133  
   1.134  static void
   1.135 -keymapnotify(XEvent *e)
   1.136 -{
   1.137 -	update_keys();
   1.138 -}
   1.139 -
   1.140 -static void
   1.141  maprequest(XEvent *e)
   1.142  {
   1.143  	XMapRequestEvent *ev = &e->xmaprequest;