dwm-meillo

diff dev.c @ 42:040a7074d23c

added dev.c instead of kb.c
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 10:34:55 +0200
parents kb.c@cd30cce52b78
children 989178822938
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dev.c	Thu Jul 13 10:34:55 2006 +0200
     1.3 @@ -0,0 +1,134 @@
     1.4 +/*
     1.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     1.6 + * See LICENSE file for license details.
     1.7 + */
     1.8 +
     1.9 +#include "wm.h"
    1.10 +
    1.11 +#include <stdlib.h>
    1.12 +#include <string.h>
    1.13 +#include <unistd.h>
    1.14 +#include <X11/keysym.h>
    1.15 +
    1.16 +/********** CUSTOMIZE **********/
    1.17 +
    1.18 +const char *term[] = { 
    1.19 +	"aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
    1.20 +	"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
    1.21 +};
    1.22 +const char *browse[] = { "firefox", NULL };
    1.23 +
    1.24 +static Key key[] = {
    1.25 +	{ Mod1Mask, XK_Return, (void (*)(void *))spawn, term },
    1.26 +	{ Mod1Mask, XK_w, (void (*)(void *))spawn, browse },
    1.27 +	{ Mod1Mask, XK_k, sel, "prev" }, 
    1.28 +	{ Mod1Mask, XK_j, sel, "next" }, 
    1.29 +	{ Mod1Mask, XK_space, toggle, NULL }, 
    1.30 +	{ Mod1Mask, XK_m, max, NULL }, 
    1.31 +	{ Mod1Mask | ShiftMask, XK_c, ckill, NULL }, 
    1.32 +	{ Mod1Mask | ShiftMask, XK_q, quit, NULL },
    1.33 +};
    1.34 +
    1.35 +/********** CUSTOMIZE **********/
    1.36 +
    1.37 +void
    1.38 +update_keys(void)
    1.39 +{
    1.40 +	unsigned int i, len;
    1.41 +	KeyCode code;
    1.42 +
    1.43 +	len = sizeof(key) / sizeof(key[0]);
    1.44 +	for(i = 0; i < len; i++) {
    1.45 +		code = XKeysymToKeycode(dpy, key[i].keysym);
    1.46 +		XUngrabKey(dpy, code, key[i].mod, root);
    1.47 +		XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
    1.48 +	}
    1.49 +}
    1.50 +
    1.51 +void
    1.52 +keypress(XEvent *e)
    1.53 +{
    1.54 +	XKeyEvent *ev = &e->xkey;
    1.55 +	unsigned int i, len;
    1.56 +	KeySym keysym;
    1.57 +
    1.58 +	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
    1.59 +	len = sizeof(key) / sizeof(key[0]);
    1.60 +	for(i = 0; i < len; i++)
    1.61 +		if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
    1.62 +			if(key[i].func)
    1.63 +				key[i].func(key[i].aux);
    1.64 +			return;
    1.65 +		}
    1.66 +}
    1.67 +
    1.68 +#define ButtonMask      (ButtonPressMask | ButtonReleaseMask)
    1.69 +#define MouseMask       (ButtonMask | PointerMotionMask)
    1.70 +
    1.71 +void
    1.72 +mresize(Client *c)
    1.73 +{
    1.74 +	XEvent ev;
    1.75 +	int ocx, ocy;
    1.76 +
    1.77 +	ocx = c->x;
    1.78 +	ocy = c->y;
    1.79 +	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
    1.80 +				None, cursor[CurResize], CurrentTime) != GrabSuccess)
    1.81 +		return;
    1.82 +	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
    1.83 +	for(;;) {
    1.84 +		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
    1.85 +		switch(ev.type) {
    1.86 +		default: break;
    1.87 +		case Expose:
    1.88 +			handler[Expose](&ev);
    1.89 +			break;
    1.90 +		case MotionNotify:
    1.91 +			XFlush(dpy);
    1.92 +			c->w = abs(ocx - ev.xmotion.x);
    1.93 +			c->h = abs(ocy - ev.xmotion.y);
    1.94 +			c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
    1.95 +			c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
    1.96 +			resize(c);
    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 +void
   1.106 +mmove(Client *c)
   1.107 +{
   1.108 +	XEvent ev;
   1.109 +	int x1, y1, ocx, ocy, di;
   1.110 +	unsigned int dui;
   1.111 +	Window dummy;
   1.112 +
   1.113 +	ocx = c->x;
   1.114 +	ocy = c->y;
   1.115 +	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
   1.116 +				None, cursor[CurMove], CurrentTime) != GrabSuccess)
   1.117 +		return;
   1.118 +	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
   1.119 +	for(;;) {
   1.120 +		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
   1.121 +		switch (ev.type) {
   1.122 +		default: break;
   1.123 +		case Expose:
   1.124 +			handler[Expose](&ev);
   1.125 +			break;
   1.126 +		case MotionNotify:
   1.127 +			XFlush(dpy);
   1.128 +			c->x = ocx + (ev.xmotion.x - x1);
   1.129 +			c->y = ocy + (ev.xmotion.y - y1);
   1.130 +			resize(c);
   1.131 +			break;
   1.132 +		case ButtonRelease:
   1.133 +			XUngrabPointer(dpy, CurrentTime);
   1.134 +			return;
   1.135 +		}
   1.136 +	}
   1.137 +}