event.c (1910B)
1 /* Copyright ©2006-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include "dat.h" 5 #include <X11/keysym.h> 6 #include "fns.h" 7 8 void 9 debug_event(XEvent *e) { 10 Dprint(DEvent, "%E\n", e); 11 } 12 13 void 14 print_focus(const char *fn, Client *c, const char *to) { 15 Dprint(DFocus, "%s() disp.focus:\n", fn); 16 Dprint(DFocus, "\t%#C => %#C\n", disp.focus, c); 17 Dprint(DFocus, "\t%C => %s\n", disp.focus, to); 18 } 19 20 void 21 event_focusin(XFocusChangeEvent *ev) { 22 Window *w; 23 Client *c; 24 25 /* Yes, we're focusing in on nothing, here. */ 26 if(ev->detail == NotifyDetailNone) { 27 print_focus("focusin", &c_magic, "<magic[none]>"); 28 disp.focus = &c_magic; 29 setfocus(screen->barwin, RevertToParent); 30 return; 31 } 32 33 if(!((ev->detail == NotifyNonlinear) 34 ||(ev->detail == NotifyNonlinearVirtual) 35 ||(ev->detail == NotifyVirtual) 36 ||(ev->detail == NotifyInferior) 37 ||(ev->detail == NotifyAncestor))) 38 return; 39 if((ev->mode == NotifyWhileGrabbed) && (disp.hasgrab != &c_root)) 40 return; 41 42 if(ev->window == screen->barwin->xid) { 43 print_focus("focusin", nil, "<nil>"); 44 disp.focus = nil; 45 } 46 else if((w = findwin(ev->window))) 47 event_handle(w, focusin, ev); 48 else if(ev->mode == NotifyGrab) { 49 /* Some unmanaged window has grabbed focus */ 50 if((c = disp.focus)) { 51 print_focus("focusin", &c_magic, "<magic>"); 52 disp.focus = &c_magic; 53 if(c->sel) 54 frame_draw(c->sel); 55 } 56 } 57 } 58 59 void 60 event_focusout(XFocusChangeEvent *ev) { 61 XEvent me; 62 Window *w; 63 64 if(!((ev->detail == NotifyNonlinear) 65 ||(ev->detail == NotifyNonlinearVirtual) 66 ||(ev->detail == NotifyVirtual) 67 ||(ev->detail == NotifyInferior) 68 ||(ev->detail == NotifyAncestor))) 69 return; 70 if(ev->mode == NotifyUngrab) 71 disp.hasgrab = nil; 72 73 if((ev->mode == NotifyGrab) 74 && XCheckMaskEvent(display, KeyPressMask, &me)) 75 event_dispatch(&me); 76 else if((w = findwin(ev->window))) 77 event_handle(w, focusout, ev); 78 } 79