wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

root.c (1769B)


      1 /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include "dat.h"
      5 #include "fns.h"
      6 
      7 static Handlers handlers;
      8 
      9 void
     10 root_init(void) {
     11 	WinAttr wa;
     12 
     13 	wa.cursor = cursor[CurNormal];
     14 	wa.event_mask = EnterWindowMask
     15 		      | FocusChangeMask
     16 		      | LeaveWindowMask
     17 		      | PointerMotionMask
     18 		      | SubstructureNotifyMask
     19 		      | SubstructureRedirectMask;
     20 	setwinattr(&scr.root, &wa, CWCursor
     21 			         | CWEventMask);
     22 	sethandler(&scr.root, &handlers);
     23 }
     24 
     25 static bool
     26 enter_event(Window *w, void *aux, XCrossingEvent *e) {
     27 	disp.sel = true;
     28 	frame_draw_all();
     29 	return false;
     30 }
     31 
     32 static bool
     33 leave_event(Window *w, void *aux, XCrossingEvent *e) {
     34 	if(!e->same_screen) {
     35 		disp.sel = false;
     36 		frame_draw_all();
     37 	}
     38 	return false;
     39 }
     40 
     41 static bool
     42 focusin_event(Window *w, void *aux, XFocusChangeEvent *e) {
     43 	if(e->mode == NotifyGrab)
     44 		disp.hasgrab = &c_root;
     45 	return false;
     46 }
     47 
     48 static bool
     49 mapreq_event(Window *w, void *aux, XMapRequestEvent *e) {
     50 	XWindowAttributes wa;
     51 
     52 	if(!XGetWindowAttributes(display, e->window, &wa) || wa.override_redirect)
     53 		return false;
     54 	if(!win2client(e->window))
     55 		client_create(e->window, &wa);
     56 	return false;
     57 }
     58 
     59 static bool
     60 motion_event(Window *w, void *aux, XMotionEvent *e) {
     61 	Rectangle r, r2;
     62 
     63 	r = rectsetorigin(Rect(0, 0, 1, 1), Pt(e->x_root, e->y_root));
     64 	r2 = constrain(r, 0);
     65 	if(!eqrect(r, r2))
     66 		warppointer(r2.min);
     67 	return false;
     68 }
     69 
     70 static bool
     71 kdown_event(Window *w, void *aux, XKeyEvent *e) {
     72 
     73 	e->state &= valid_mask;
     74 	kpress(w->xid, e->state, (KeyCode)e->keycode);
     75 	return false;
     76 }
     77 
     78 static Handlers handlers = {
     79 	.enter = enter_event,
     80 	.focusin = focusin_event,
     81 	.kdown = kdown_event,
     82 	.leave = leave_event,
     83 	.mapreq = mapreq_event,
     84 	.motion = motion_event,
     85 };
     86