event.c
changeset 956 484245788760
parent 953 d7de5c7bdbe4
child 958 8b502be8b8e0
equal deleted inserted replaced
955:b2518e01f7e3 956:484245788760
     1 /* See LICENSE file for copyright and license details. */
     1 /* See LICENSE file for copyright and license details. */
     2 #include "dwm.h"
     2 #include "dwm.h"
     3 #include <stdio.h>
       
     4 #include <stdlib.h>
     3 #include <stdlib.h>
     5 #include <X11/keysym.h>
     4 #include <X11/keysym.h>
     6 #include <X11/Xatom.h>
     5 #include <X11/Xatom.h>
     7 #include <X11/Xutil.h>
     6 #include <X11/Xutil.h>
     8 
     7 
    12 	unsigned long mod;
    11 	unsigned long mod;
    13 	KeySym keysym;
    12 	KeySym keysym;
    14 	void (*func)(const char *arg);
    13 	void (*func)(const char *arg);
    15 	const char *arg;
    14 	const char *arg;
    16 } Key;
    15 } Key;
    17 
       
    18 KEYS
       
    19 
    16 
    20 #define CLEANMASK(mask)		(mask & ~(numlockmask | LockMask))
    17 #define CLEANMASK(mask)		(mask & ~(numlockmask | LockMask))
    21 #define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
    18 #define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
    22 
    19 
    23 static Client *
    20 static Client *
   110 	}
   107 	}
   111 }
   108 }
   112 
   109 
   113 static void
   110 static void
   114 buttonpress(XEvent *e) {
   111 buttonpress(XEvent *e) {
   115 	static char buf[32];
       
   116 	unsigned int i, x;
   112 	unsigned int i, x;
   117 	Client *c;
   113 	Client *c;
   118 	XButtonPressedEvent *ev = &e->xbutton;
   114 	XButtonPressedEvent *ev = &e->xbutton;
   119 
   115 
   120 	buf[0] = 0;
       
   121 	if(barwin == ev->window) {
   116 	if(barwin == ev->window) {
   122 		x = 0;
   117 		x = 0;
   123 		for(i = 0; i < ntags; i++) {
   118 		for(i = 0; i < ntags; i++) {
   124 			x += textw(tags[i]);
   119 			x += textw(tags[i]);
   125 			if(ev->x < x) {
   120 			if(ev->x < x) {
   126 				snprintf(buf, sizeof buf, "%d", i);
       
   127 				if(ev->button == Button1) {
   121 				if(ev->button == Button1) {
   128 					if(ev->state & MODKEY)
   122 					if(ev->state & MODKEY)
   129 						tag(buf);
   123 						tag(tags[i]);
   130 					else
   124 					else
   131 						view(buf);
   125 						view(tags[i]);
   132 				}
   126 				}
   133 				else if(ev->button == Button3) {
   127 				else if(ev->button == Button3) {
   134 					if(ev->state & MODKEY)
   128 					if(ev->state & MODKEY)
   135 						toggletag(buf);
   129 						toggletag(tags[i]);
   136 					else
   130 					else
   137 						toggleview(buf);
   131 						toggleview(tags[i]);
   138 				}
   132 				}
   139 				return;
   133 				return;
   140 			}
   134 			}
   141 		}
   135 		}
   142 		if((ev->x < x + blw) && ev->button == Button1)
   136 		if((ev->x < x + blw) && ev->button == Button1)
   255 	}
   249 	}
   256 }
   250 }
   257 
   251 
   258 static void
   252 static void
   259 keypress(XEvent *e) {
   253 keypress(XEvent *e) {
   260 	static unsigned int len = sizeof key / sizeof key[0];
   254 	KEYS
       
   255 	unsigned int len = sizeof key / sizeof key[0];
   261 	unsigned int i;
   256 	unsigned int i;
   262 	KeySym keysym;
   257 	KeySym keysym;
   263 	XKeyEvent *ev = &e->xkey;
   258 	XKeyEvent *ev = &e->xkey;
   264 
   259 
   265 	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
   260 	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
   360 	[UnmapNotify] = unmapnotify
   355 	[UnmapNotify] = unmapnotify
   361 };
   356 };
   362 
   357 
   363 void
   358 void
   364 grabkeys(void) {
   359 grabkeys(void) {
   365 	static unsigned int len = sizeof key / sizeof key[0];
   360 	KEYS
       
   361 	unsigned int len = sizeof key / sizeof key[0];
   366 	unsigned int i;
   362 	unsigned int i;
   367 	KeyCode code;
   363 	KeyCode code;
   368 
   364 
   369 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
   365 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
   370 	for(i = 0; i < len; i++) {
   366 	for(i = 0; i < len; i++) {