aewl

annotate event.c @ 72:d0eb0bb63c40

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