dwm-meillo

annotate dev.c @ 46:58307ad56ec1

added xlock command (I need it regularly)
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 12:19:10 +0200
parents a36f95a4841a
children ceff29af8c7b
rev   line source
garbeam@8 1 /*
garbeam@8 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@8 3 * See LICENSE file for license details.
garbeam@8 4 */
garbeam@8 5
garbeam@43 6 #include "dwm.h"
garbeam@8 7
garbeam@42 8 #include <stdlib.h>
garbeam@42 9 #include <string.h>
garbeam@42 10 #include <unistd.h>
garbeam@8 11 #include <X11/keysym.h>
garbeam@8 12
garbeam@31 13 /********** CUSTOMIZE **********/
garbeam@31 14
garbeam@33 15 const char *term[] = {
garbeam@44 16 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
garbeam@31 17 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
garbeam@14 18 };
garbeam@34 19 const char *browse[] = { "firefox", NULL };
garbeam@46 20 const char *xlock[] = { "xlock", NULL };
garbeam@14 21
garbeam@8 22 static Key key[] = {
garbeam@33 23 { Mod1Mask, XK_Return, (void (*)(void *))spawn, term },
garbeam@34 24 { Mod1Mask, XK_w, (void (*)(void *))spawn, browse },
garbeam@46 25 { Mod1Mask, XK_l, (void (*)(void *))spawn, xlock },
garbeam@27 26 { Mod1Mask, XK_k, sel, "prev" },
garbeam@27 27 { Mod1Mask, XK_j, sel, "next" },
garbeam@46 28 { Mod1Mask, XK_t, tiling, NULL },
garbeam@46 29 { Mod1Mask, XK_f, tiling, NULL },
garbeam@28 30 { Mod1Mask, XK_m, max, NULL },
garbeam@32 31 { Mod1Mask | ShiftMask, XK_c, ckill, NULL },
garbeam@27 32 { Mod1Mask | ShiftMask, XK_q, quit, NULL },
garbeam@8 33 };
garbeam@8 34
garbeam@31 35 /********** CUSTOMIZE **********/
garbeam@31 36
garbeam@8 37 void
garbeam@33 38 update_keys(void)
garbeam@8 39 {
garbeam@8 40 unsigned int i, len;
garbeam@8 41 KeyCode code;
garbeam@8 42
garbeam@8 43 len = sizeof(key) / sizeof(key[0]);
garbeam@8 44 for(i = 0; i < len; i++) {
garbeam@8 45 code = XKeysymToKeycode(dpy, key[i].keysym);
garbeam@8 46 XUngrabKey(dpy, code, key[i].mod, root);
garbeam@8 47 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
garbeam@8 48 }
garbeam@8 49 }
garbeam@9 50
garbeam@9 51 void
garbeam@9 52 keypress(XEvent *e)
garbeam@9 53 {
garbeam@9 54 XKeyEvent *ev = &e->xkey;
garbeam@9 55 unsigned int i, len;
garbeam@9 56 KeySym keysym;
garbeam@9 57
garbeam@9 58 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
garbeam@9 59 len = sizeof(key) / sizeof(key[0]);
garbeam@9 60 for(i = 0; i < len; i++)
garbeam@9 61 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
garbeam@9 62 if(key[i].func)
garbeam@14 63 key[i].func(key[i].aux);
garbeam@9 64 return;
garbeam@9 65 }
garbeam@9 66 }
garbeam@42 67
garbeam@42 68 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
garbeam@42 69 #define MouseMask (ButtonMask | PointerMotionMask)
garbeam@42 70
garbeam@42 71 void
garbeam@42 72 mresize(Client *c)
garbeam@42 73 {
garbeam@42 74 XEvent ev;
garbeam@42 75 int ocx, ocy;
garbeam@42 76
garbeam@42 77 ocx = c->x;
garbeam@42 78 ocy = c->y;
garbeam@42 79 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@42 80 None, cursor[CurResize], CurrentTime) != GrabSuccess)
garbeam@42 81 return;
garbeam@42 82 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
garbeam@42 83 for(;;) {
garbeam@42 84 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
garbeam@42 85 switch(ev.type) {
garbeam@42 86 default: break;
garbeam@42 87 case Expose:
garbeam@42 88 handler[Expose](&ev);
garbeam@42 89 break;
garbeam@42 90 case MotionNotify:
garbeam@42 91 XFlush(dpy);
garbeam@42 92 c->w = abs(ocx - ev.xmotion.x);
garbeam@42 93 c->h = abs(ocy - ev.xmotion.y);
garbeam@42 94 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
garbeam@42 95 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
garbeam@42 96 resize(c);
garbeam@42 97 break;
garbeam@42 98 case ButtonRelease:
garbeam@42 99 XUngrabPointer(dpy, CurrentTime);
garbeam@42 100 return;
garbeam@42 101 }
garbeam@42 102 }
garbeam@42 103 }
garbeam@42 104
garbeam@42 105 void
garbeam@42 106 mmove(Client *c)
garbeam@42 107 {
garbeam@42 108 XEvent ev;
garbeam@42 109 int x1, y1, ocx, ocy, di;
garbeam@42 110 unsigned int dui;
garbeam@42 111 Window dummy;
garbeam@42 112
garbeam@42 113 ocx = c->x;
garbeam@42 114 ocy = c->y;
garbeam@42 115 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@42 116 None, cursor[CurMove], CurrentTime) != GrabSuccess)
garbeam@42 117 return;
garbeam@42 118 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
garbeam@42 119 for(;;) {
garbeam@42 120 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
garbeam@42 121 switch (ev.type) {
garbeam@42 122 default: break;
garbeam@42 123 case Expose:
garbeam@42 124 handler[Expose](&ev);
garbeam@42 125 break;
garbeam@42 126 case MotionNotify:
garbeam@42 127 XFlush(dpy);
garbeam@42 128 c->x = ocx + (ev.xmotion.x - x1);
garbeam@42 129 c->y = ocy + (ev.xmotion.y - y1);
garbeam@42 130 resize(c);
garbeam@42 131 break;
garbeam@42 132 case ButtonRelease:
garbeam@42 133 XUngrabPointer(dpy, CurrentTime);
garbeam@42 134 return;
garbeam@42 135 }
garbeam@42 136 }
garbeam@42 137 }