aewl

annotate event.c @ 15:00d4d52b231f

removed unnecessary sel stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 18:19:01 +0200
parents ea9c08ec4b48
children 359b6e563b95
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@5 12 #include "wm.h"
garbeam@5 13
garbeam@5 14 /* local functions */
garbeam@5 15 static void configurerequest(XEvent *e);
garbeam@5 16 static void destroynotify(XEvent *e);
garbeam@5 17 static void enternotify(XEvent *e);
garbeam@5 18 static void leavenotify(XEvent *e);
garbeam@5 19 static void expose(XEvent *e);
garbeam@5 20 static void keymapnotify(XEvent *e);
garbeam@5 21 static void maprequest(XEvent *e);
garbeam@5 22 static void propertynotify(XEvent *e);
garbeam@5 23 static void unmapnotify(XEvent *e);
garbeam@5 24
garbeam@5 25 void (*handler[LASTEvent]) (XEvent *) = {
garbeam@5 26 [ConfigureRequest] = configurerequest,
garbeam@5 27 [DestroyNotify] = destroynotify,
garbeam@5 28 [EnterNotify] = enternotify,
garbeam@5 29 [LeaveNotify] = leavenotify,
garbeam@5 30 [Expose] = expose,
garbeam@5 31 [KeyPress] = keypress,
garbeam@5 32 [KeymapNotify] = keymapnotify,
garbeam@5 33 [MapRequest] = maprequest,
garbeam@5 34 [PropertyNotify] = propertynotify,
garbeam@5 35 [UnmapNotify] = unmapnotify
garbeam@5 36 };
garbeam@5 37
garbeam@5 38 unsigned int
garbeam@13 39 flush_events(long even_mask)
garbeam@5 40 {
garbeam@5 41 XEvent ev;
garbeam@5 42 unsigned int n = 0;
garbeam@5 43 while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
garbeam@5 44 return n;
garbeam@5 45 }
garbeam@5 46
garbeam@5 47 static void
garbeam@5 48 configurerequest(XEvent *e)
garbeam@5 49 {
garbeam@5 50 XConfigureRequestEvent *ev = &e->xconfigurerequest;
garbeam@5 51 XWindowChanges wc;
garbeam@5 52 Client *c;
garbeam@5 53
garbeam@9 54 c = getclient(ev->window);
garbeam@5 55 ev->value_mask &= ~CWSibling;
garbeam@5 56 if(c) {
garbeam@5 57 if(ev->value_mask & CWX)
garbeam@9 58 c->r[RFloat].x = ev->x;
garbeam@5 59 if(ev->value_mask & CWY)
garbeam@9 60 c->r[RFloat].y = ev->y;
garbeam@5 61 if(ev->value_mask & CWWidth)
garbeam@9 62 c->r[RFloat].width = ev->width;
garbeam@5 63 if(ev->value_mask & CWHeight)
garbeam@9 64 c->r[RFloat].height = ev->height;
garbeam@5 65 if(ev->value_mask & CWBorderWidth)
garbeam@5 66 c->border = ev->border_width;
garbeam@5 67 }
garbeam@5 68
garbeam@5 69 wc.x = ev->x;
garbeam@5 70 wc.y = ev->y;
garbeam@5 71 wc.width = ev->width;
garbeam@5 72 wc.height = ev->height;
garbeam@5 73 wc.border_width = 0;
garbeam@5 74 wc.sibling = None;
garbeam@5 75 wc.stack_mode = Above;
garbeam@5 76 ev->value_mask &= ~CWStackMode;
garbeam@5 77 ev->value_mask |= CWBorderWidth;
garbeam@5 78 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
garbeam@5 79 XFlush(dpy);
garbeam@5 80 }
garbeam@5 81
garbeam@5 82 static void
garbeam@5 83 destroynotify(XEvent *e)
garbeam@5 84 {
garbeam@5 85 Client *c;
garbeam@5 86 XDestroyWindowEvent *ev = &e->xdestroywindow;
garbeam@5 87
garbeam@11 88 if((c = getclient(ev->window)))
garbeam@11 89 unmanage(c);
garbeam@5 90 }
garbeam@5 91
garbeam@5 92 static void
garbeam@5 93 enternotify(XEvent *e)
garbeam@5 94 {
garbeam@5 95 XCrossingEvent *ev = &e->xcrossing;
garbeam@5 96 Client *c;
garbeam@5 97
garbeam@5 98 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
garbeam@5 99 return;
garbeam@5 100
garbeam@13 101 if((c = getclient(ev->window)))
garbeam@13 102 focus(c);
garbeam@5 103 else if(ev->window == root) {
garbeam@5 104 sel_screen = True;
garbeam@13 105 /*draw_frames();*/
garbeam@5 106 }
garbeam@5 107 }
garbeam@5 108
garbeam@5 109 static void
garbeam@5 110 leavenotify(XEvent *e)
garbeam@5 111 {
garbeam@5 112 XCrossingEvent *ev = &e->xcrossing;
garbeam@5 113
garbeam@5 114 if((ev->window == root) && !ev->same_screen) {
garbeam@5 115 sel_screen = True;
garbeam@5 116 /*draw_frames();*/
garbeam@5 117 }
garbeam@5 118 }
garbeam@5 119
garbeam@5 120 static void
garbeam@5 121 expose(XEvent *e)
garbeam@5 122 {
garbeam@5 123 XExposeEvent *ev = &e->xexpose;
garbeam@5 124
garbeam@5 125 if(ev->count == 0) {
garbeam@5 126 if(ev->window == barwin)
garbeam@5 127 draw_bar();
garbeam@5 128 }
garbeam@5 129 }
garbeam@5 130
garbeam@5 131 static void
garbeam@5 132 keymapnotify(XEvent *e)
garbeam@5 133 {
garbeam@5 134 update_keys();
garbeam@5 135 }
garbeam@5 136
garbeam@5 137 static void
garbeam@5 138 maprequest(XEvent *e)
garbeam@5 139 {
garbeam@5 140 XMapRequestEvent *ev = &e->xmaprequest;
garbeam@5 141 static XWindowAttributes wa;
garbeam@5 142
garbeam@5 143 if(!XGetWindowAttributes(dpy, ev->window, &wa))
garbeam@5 144 return;
garbeam@5 145
garbeam@5 146 if(wa.override_redirect) {
garbeam@5 147 XSelectInput(dpy, ev->window,
garbeam@5 148 (StructureNotifyMask | PropertyChangeMask));
garbeam@5 149 return;
garbeam@5 150 }
garbeam@5 151
garbeam@10 152 if(!getclient(ev->window))
garbeam@10 153 manage(ev->window, &wa);
garbeam@5 154 }
garbeam@5 155
garbeam@5 156 static void
garbeam@5 157 propertynotify(XEvent *e)
garbeam@5 158 {
garbeam@5 159 XPropertyEvent *ev = &e->xproperty;
garbeam@13 160 long msize;
garbeam@5 161 Client *c;
garbeam@5 162
garbeam@5 163 if(ev->state == PropertyDelete)
garbeam@5 164 return; /* ignore */
garbeam@5 165
garbeam@13 166 if(ev->atom == wm_atom[WMProtocols]) {
garbeam@13 167 c->proto = win_proto(c->win);
garbeam@13 168 return;
garbeam@13 169 }
garbeam@13 170 if((c = getclient(ev->window))) {
garbeam@13 171 switch (ev->atom) {
garbeam@13 172 default: break;
garbeam@13 173 case XA_WM_TRANSIENT_FOR:
garbeam@13 174 XGetTransientForHint(dpy, c->win, &c->trans);
garbeam@13 175 break;
garbeam@13 176 case XA_WM_NORMAL_HINTS:
garbeam@13 177 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
garbeam@13 178 || !c->size.flags)
garbeam@13 179 c->size.flags = PSize;
garbeam@13 180 if(c->size.flags & PMinSize && c->size.flags & PMaxSize
garbeam@13 181 && c->size.min_width == c->size.max_width
garbeam@13 182 && c->size.min_height == c->size.max_height)
garbeam@13 183 c->fixedsize = True;
garbeam@13 184 else
garbeam@13 185 c->fixedsize = False;
garbeam@13 186 break;
garbeam@13 187 }
garbeam@13 188 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
garbeam@13 189 update_name(c);
garbeam@13 190 /*draw_frame(c->sel);*/
garbeam@13 191 }
garbeam@13 192 }
garbeam@5 193 }
garbeam@5 194
garbeam@5 195 static void
garbeam@5 196 unmapnotify(XEvent *e)
garbeam@5 197 {
garbeam@5 198 Client *c;
garbeam@5 199 XUnmapEvent *ev = &e->xunmap;
garbeam@5 200
garbeam@10 201 if((c = getclient(ev->window)))
garbeam@10 202 unmanage(c);
garbeam@5 203 }