garbeam@5: /* garbeam@5: * (C)opyright MMVI Anselm R. Garbe garbeam@5: * See LICENSE file for license details. garbeam@5: */ garbeam@5: garbeam@5: #include garbeam@5: #include garbeam@5: #include garbeam@5: #include garbeam@13: #include garbeam@5: garbeam@5: #include "wm.h" garbeam@5: garbeam@5: /* local functions */ garbeam@5: static void configurerequest(XEvent *e); garbeam@5: static void destroynotify(XEvent *e); garbeam@5: static void enternotify(XEvent *e); garbeam@5: static void leavenotify(XEvent *e); garbeam@5: static void expose(XEvent *e); garbeam@5: static void keymapnotify(XEvent *e); garbeam@5: static void maprequest(XEvent *e); garbeam@5: static void propertynotify(XEvent *e); garbeam@5: static void unmapnotify(XEvent *e); garbeam@5: garbeam@5: void (*handler[LASTEvent]) (XEvent *) = { garbeam@5: [ConfigureRequest] = configurerequest, garbeam@5: [DestroyNotify] = destroynotify, garbeam@5: [EnterNotify] = enternotify, garbeam@5: [LeaveNotify] = leavenotify, garbeam@5: [Expose] = expose, garbeam@5: [KeyPress] = keypress, garbeam@5: [KeymapNotify] = keymapnotify, garbeam@5: [MapRequest] = maprequest, garbeam@5: [PropertyNotify] = propertynotify, garbeam@5: [UnmapNotify] = unmapnotify garbeam@5: }; garbeam@5: garbeam@5: unsigned int garbeam@13: flush_events(long even_mask) garbeam@5: { garbeam@5: XEvent ev; garbeam@5: unsigned int n = 0; garbeam@5: while(XCheckMaskEvent(dpy, even_mask, &ev)) n++; garbeam@5: return n; garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: configurerequest(XEvent *e) garbeam@5: { garbeam@5: XConfigureRequestEvent *ev = &e->xconfigurerequest; garbeam@5: XWindowChanges wc; garbeam@5: Client *c; garbeam@5: garbeam@9: c = getclient(ev->window); garbeam@5: ev->value_mask &= ~CWSibling; garbeam@5: if(c) { garbeam@5: if(ev->value_mask & CWX) garbeam@9: c->r[RFloat].x = ev->x; garbeam@5: if(ev->value_mask & CWY) garbeam@9: c->r[RFloat].y = ev->y; garbeam@5: if(ev->value_mask & CWWidth) garbeam@9: c->r[RFloat].width = ev->width; garbeam@5: if(ev->value_mask & CWHeight) garbeam@9: c->r[RFloat].height = ev->height; garbeam@5: if(ev->value_mask & CWBorderWidth) garbeam@5: c->border = ev->border_width; garbeam@5: } garbeam@5: garbeam@5: wc.x = ev->x; garbeam@5: wc.y = ev->y; garbeam@5: wc.width = ev->width; garbeam@5: wc.height = ev->height; garbeam@5: wc.border_width = 0; garbeam@5: wc.sibling = None; garbeam@5: wc.stack_mode = Above; garbeam@5: ev->value_mask &= ~CWStackMode; garbeam@5: ev->value_mask |= CWBorderWidth; garbeam@5: XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); garbeam@5: XFlush(dpy); garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: destroynotify(XEvent *e) garbeam@5: { garbeam@5: Client *c; garbeam@5: XDestroyWindowEvent *ev = &e->xdestroywindow; garbeam@5: garbeam@11: if((c = getclient(ev->window))) garbeam@11: unmanage(c); garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: enternotify(XEvent *e) garbeam@5: { garbeam@5: XCrossingEvent *ev = &e->xcrossing; garbeam@5: Client *c; garbeam@5: garbeam@5: if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) garbeam@5: return; garbeam@5: garbeam@13: if((c = getclient(ev->window))) garbeam@13: focus(c); garbeam@5: else if(ev->window == root) { garbeam@5: sel_screen = True; garbeam@13: /*draw_frames();*/ garbeam@5: } garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: leavenotify(XEvent *e) garbeam@5: { garbeam@5: XCrossingEvent *ev = &e->xcrossing; garbeam@5: garbeam@5: if((ev->window == root) && !ev->same_screen) { garbeam@5: sel_screen = True; garbeam@5: /*draw_frames();*/ garbeam@5: } garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: expose(XEvent *e) garbeam@5: { garbeam@5: XExposeEvent *ev = &e->xexpose; garbeam@5: garbeam@5: if(ev->count == 0) { garbeam@5: if(ev->window == barwin) garbeam@5: draw_bar(); garbeam@5: } garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: keymapnotify(XEvent *e) garbeam@5: { garbeam@5: update_keys(); garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: maprequest(XEvent *e) garbeam@5: { garbeam@5: XMapRequestEvent *ev = &e->xmaprequest; garbeam@5: static XWindowAttributes wa; garbeam@5: garbeam@5: if(!XGetWindowAttributes(dpy, ev->window, &wa)) garbeam@5: return; garbeam@5: garbeam@5: if(wa.override_redirect) { garbeam@5: XSelectInput(dpy, ev->window, garbeam@5: (StructureNotifyMask | PropertyChangeMask)); garbeam@5: return; garbeam@5: } garbeam@5: garbeam@10: if(!getclient(ev->window)) garbeam@10: manage(ev->window, &wa); garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: propertynotify(XEvent *e) garbeam@5: { garbeam@5: XPropertyEvent *ev = &e->xproperty; garbeam@13: long msize; garbeam@5: Client *c; garbeam@5: garbeam@5: if(ev->state == PropertyDelete) garbeam@5: return; /* ignore */ garbeam@5: garbeam@13: if(ev->atom == wm_atom[WMProtocols]) { garbeam@13: c->proto = win_proto(c->win); garbeam@13: return; garbeam@13: } garbeam@13: if((c = getclient(ev->window))) { garbeam@13: switch (ev->atom) { garbeam@13: default: break; garbeam@13: case XA_WM_TRANSIENT_FOR: garbeam@13: XGetTransientForHint(dpy, c->win, &c->trans); garbeam@13: break; garbeam@13: case XA_WM_NORMAL_HINTS: garbeam@13: if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) garbeam@13: || !c->size.flags) garbeam@13: c->size.flags = PSize; garbeam@13: if(c->size.flags & PMinSize && c->size.flags & PMaxSize garbeam@13: && c->size.min_width == c->size.max_width garbeam@13: && c->size.min_height == c->size.max_height) garbeam@13: c->fixedsize = True; garbeam@13: else garbeam@13: c->fixedsize = False; garbeam@13: break; garbeam@13: } garbeam@13: if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { garbeam@13: update_name(c); garbeam@13: /*draw_frame(c->sel);*/ garbeam@13: } garbeam@13: } garbeam@5: } garbeam@5: garbeam@5: static void garbeam@5: unmapnotify(XEvent *e) garbeam@5: { garbeam@5: Client *c; garbeam@5: XUnmapEvent *ev = &e->xunmap; garbeam@5: garbeam@10: if((c = getclient(ev->window))) garbeam@10: unmanage(c); garbeam@5: }