dwm-meillo

annotate event.c @ 55:fcbf7213d96f

continued with man page
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 08:34:38 +0200
parents 529901e6a227
children 1269bd127551
rev   line source
garbeam@5 1 /*
garbeam@5 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@5 3 * See LICENSE file for license details.
garbeam@5 4 */
garbeam@5 5
garbeam@5 6 #include <fcntl.h>
garbeam@5 7 #include <stdlib.h>
garbeam@5 8 #include <string.h>
garbeam@5 9 #include <X11/keysym.h>
garbeam@13 10 #include <X11/Xatom.h>
garbeam@5 11
garbeam@43 12 #include "dwm.h"
garbeam@5 13
garbeam@5 14 /* local functions */
garbeam@18 15 static void buttonpress(XEvent *e);
garbeam@5 16 static void configurerequest(XEvent *e);
garbeam@5 17 static void destroynotify(XEvent *e);
garbeam@5 18 static void enternotify(XEvent *e);
garbeam@5 19 static void leavenotify(XEvent *e);
garbeam@5 20 static void expose(XEvent *e);
garbeam@5 21 static void keymapnotify(XEvent *e);
garbeam@5 22 static void maprequest(XEvent *e);
garbeam@5 23 static void propertynotify(XEvent *e);
garbeam@5 24 static void unmapnotify(XEvent *e);
garbeam@5 25
garbeam@5 26 void (*handler[LASTEvent]) (XEvent *) = {
garbeam@18 27 [ButtonPress] = buttonpress,
garbeam@5 28 [ConfigureRequest] = configurerequest,
garbeam@5 29 [DestroyNotify] = destroynotify,
garbeam@5 30 [EnterNotify] = enternotify,
garbeam@5 31 [LeaveNotify] = leavenotify,
garbeam@5 32 [Expose] = expose,
garbeam@5 33 [KeyPress] = keypress,
garbeam@5 34 [KeymapNotify] = keymapnotify,
garbeam@5 35 [MapRequest] = maprequest,
garbeam@5 36 [PropertyNotify] = propertynotify,
garbeam@5 37 [UnmapNotify] = unmapnotify
garbeam@5 38 };
garbeam@5 39
garbeam@26 40 void
garbeam@18 41 discard_events(long even_mask)
garbeam@5 42 {
garbeam@5 43 XEvent ev;
garbeam@26 44 while(XCheckMaskEvent(dpy, even_mask, &ev));
garbeam@5 45 }
garbeam@5 46
garbeam@5 47 static void
garbeam@18 48 buttonpress(XEvent *e)
garbeam@18 49 {
garbeam@18 50 XButtonPressedEvent *ev = &e->xbutton;
garbeam@18 51 Client *c;
garbeam@18 52
garbeam@18 53 if((c = getclient(ev->window))) {
garbeam@32 54 craise(c);
garbeam@18 55 switch(ev->button) {
garbeam@18 56 default:
garbeam@18 57 break;
garbeam@18 58 case Button1:
garbeam@18 59 mmove(c);
garbeam@18 60 break;
garbeam@18 61 case Button2:
garbeam@26 62 lower(c);
garbeam@18 63 break;
garbeam@18 64 case Button3:
garbeam@18 65 mresize(c);
garbeam@18 66 break;
garbeam@18 67 }
garbeam@18 68 }
garbeam@18 69 }
garbeam@18 70
garbeam@18 71 static void
garbeam@5 72 configurerequest(XEvent *e)
garbeam@5 73 {
garbeam@5 74 XConfigureRequestEvent *ev = &e->xconfigurerequest;
garbeam@5 75 XWindowChanges wc;
garbeam@5 76 Client *c;
garbeam@5 77
garbeam@5 78 ev->value_mask &= ~CWSibling;
garbeam@18 79 if((c = getclient(ev->window))) {
garbeam@29 80 gravitate(c, True);
garbeam@5 81 if(ev->value_mask & CWX)
garbeam@20 82 c->x = ev->x;
garbeam@5 83 if(ev->value_mask & CWY)
garbeam@20 84 c->y = ev->y;
garbeam@5 85 if(ev->value_mask & CWWidth)
garbeam@20 86 c->w = ev->width;
garbeam@5 87 if(ev->value_mask & CWHeight)
garbeam@20 88 c->h = ev->height;
garbeam@29 89 if(ev->value_mask & CWBorderWidth)
garbeam@55 90 c->border = 1;
garbeam@29 91 gravitate(c, False);
garbeam@53 92 resize(c, True);
garbeam@5 93 }
garbeam@5 94
garbeam@5 95 wc.x = ev->x;
garbeam@5 96 wc.y = ev->y;
garbeam@5 97 wc.width = ev->width;
garbeam@5 98 wc.height = ev->height;
garbeam@25 99 wc.border_width = 1;
garbeam@5 100 wc.sibling = None;
garbeam@5 101 wc.stack_mode = Above;
garbeam@5 102 ev->value_mask &= ~CWStackMode;
garbeam@5 103 ev->value_mask |= CWBorderWidth;
garbeam@5 104 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
garbeam@5 105 XFlush(dpy);
garbeam@5 106 }
garbeam@5 107
garbeam@5 108 static void
garbeam@5 109 destroynotify(XEvent *e)
garbeam@5 110 {
garbeam@5 111 Client *c;
garbeam@5 112 XDestroyWindowEvent *ev = &e->xdestroywindow;
garbeam@5 113
garbeam@11 114 if((c = getclient(ev->window)))
garbeam@11 115 unmanage(c);
garbeam@5 116 }
garbeam@5 117
garbeam@5 118 static void
garbeam@5 119 enternotify(XEvent *e)
garbeam@5 120 {
garbeam@5 121 XCrossingEvent *ev = &e->xcrossing;
garbeam@5 122 Client *c;
garbeam@5 123
garbeam@5 124 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
garbeam@5 125 return;
garbeam@5 126
garbeam@13 127 if((c = getclient(ev->window)))
garbeam@13 128 focus(c);
garbeam@26 129 else if(ev->window == root)
garbeam@31 130 issel = True;
garbeam@5 131 }
garbeam@5 132
garbeam@5 133 static void
garbeam@5 134 leavenotify(XEvent *e)
garbeam@5 135 {
garbeam@5 136 XCrossingEvent *ev = &e->xcrossing;
garbeam@5 137
garbeam@26 138 if((ev->window == root) && !ev->same_screen)
garbeam@31 139 issel = True;
garbeam@5 140 }
garbeam@5 141
garbeam@5 142 static void
garbeam@5 143 expose(XEvent *e)
garbeam@5 144 {
garbeam@5 145 XExposeEvent *ev = &e->xexpose;
garbeam@21 146 Client *c;
garbeam@5 147
garbeam@5 148 if(ev->count == 0) {
garbeam@23 149 if((c = gettitle(ev->window)))
garbeam@21 150 draw_client(c);
garbeam@5 151 }
garbeam@5 152 }
garbeam@5 153
garbeam@5 154 static void
garbeam@5 155 keymapnotify(XEvent *e)
garbeam@5 156 {
garbeam@5 157 update_keys();
garbeam@5 158 }
garbeam@5 159
garbeam@5 160 static void
garbeam@5 161 maprequest(XEvent *e)
garbeam@5 162 {
garbeam@5 163 XMapRequestEvent *ev = &e->xmaprequest;
garbeam@5 164 static XWindowAttributes wa;
garbeam@5 165
garbeam@5 166 if(!XGetWindowAttributes(dpy, ev->window, &wa))
garbeam@5 167 return;
garbeam@5 168
garbeam@5 169 if(wa.override_redirect) {
garbeam@5 170 XSelectInput(dpy, ev->window,
garbeam@5 171 (StructureNotifyMask | PropertyChangeMask));
garbeam@5 172 return;
garbeam@5 173 }
garbeam@5 174
garbeam@10 175 if(!getclient(ev->window))
garbeam@10 176 manage(ev->window, &wa);
garbeam@5 177 }
garbeam@5 178
garbeam@5 179 static void
garbeam@5 180 propertynotify(XEvent *e)
garbeam@5 181 {
garbeam@5 182 XPropertyEvent *ev = &e->xproperty;
garbeam@53 183 Window trans;
garbeam@5 184 Client *c;
garbeam@5 185
garbeam@5 186 if(ev->state == PropertyDelete)
garbeam@5 187 return; /* ignore */
garbeam@5 188
garbeam@13 189 if((c = getclient(ev->window))) {
garbeam@30 190 if(ev->atom == wm_atom[WMProtocols]) {
garbeam@30 191 c->proto = win_proto(c->win);
garbeam@30 192 return;
garbeam@30 193 }
garbeam@13 194 switch (ev->atom) {
garbeam@13 195 default: break;
garbeam@13 196 case XA_WM_TRANSIENT_FOR:
garbeam@53 197 XGetTransientForHint(dpy, c->win, &trans);
garbeam@53 198 if(!c->floating && (c->floating = (trans != 0)))
garbeam@53 199 arrange(NULL);
garbeam@13 200 break;
garbeam@13 201 case XA_WM_NORMAL_HINTS:
garbeam@20 202 update_size(c);
garbeam@13 203 break;
garbeam@13 204 }
garbeam@13 205 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
garbeam@13 206 update_name(c);
garbeam@32 207 draw_client(c);
garbeam@13 208 }
garbeam@13 209 }
garbeam@5 210 }
garbeam@5 211
garbeam@5 212 static void
garbeam@5 213 unmapnotify(XEvent *e)
garbeam@5 214 {
garbeam@5 215 Client *c;
garbeam@5 216 XUnmapEvent *ev = &e->xunmap;
garbeam@5 217
garbeam@10 218 if((c = getclient(ev->window)))
garbeam@10 219 unmanage(c);
garbeam@5 220 }