wmii

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

commit ebe2a7027ac31e3cc40ad1907d59eebc3503e161
parent 827af3ac7bef3c494fb5a92b62bd16e14e6eaf0a
Author: Kris Maglione <jg@suckless.org>
Date:   Sat, 18 Oct 2008 12:29:23 -0400

Add root.c

Diffstat:
cmd/wmii/root.c | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+), 0 deletions(-)

diff --git a/cmd/wmii/root.c b/cmd/wmii/root.c @@ -0,0 +1,89 @@ +/* Copyright ©2008 Kris Maglione <maglione.k at Gmail> + * See LICENSE file for license details. + */ +#include "dat.h" +#include "fns.h" + +static Handlers handlers; + +void +root_init(void) { + WinAttr wa; + + wa.event_mask = EnterWindowMask + | FocusChangeMask + | LeaveWindowMask + | PointerMotionMask + | SubstructureNotifyMask + | SubstructureRedirectMask; + wa.cursor = cursor[CurNormal]; + setwinattr(&scr.root, &wa, + CWEventMask + | CWCursor); + sethandler(&scr.root, &handlers); +} + +static void +enter_event(Window *w, XCrossingEvent *e) { + disp.sel = true; + frame_draw_all(); +} + +static void +leave_event(Window *w, XCrossingEvent *e) { + if(!e->same_screen) { + disp.sel = false; + frame_draw_all(); + } +} + +static void +focusin_event(Window *w, XFocusChangeEvent *e) { + if(e->mode == NotifyGrab) + disp.hasgrab = &c_root; +} + +static void +mapreq_event(Window *w, XMapRequestEvent *e) { + XWindowAttributes wa; + + if(!XGetWindowAttributes(display, e->window, &wa)) + return; + if(wa.override_redirect) { + /* Do I really want these? */ + /* Probably not. + XSelectInput(display, e->window, + PropertyChangeMask | StructureNotifyMask); + */ + return; + } + if(!win2client(e->window)) + client_create(e->window, &wa); +} + +static void +motion_event(Window *w, XMotionEvent *e) { + Rectangle r, r2; + + r = rectsetorigin(Rect(0, 0, 1, 1), Pt(e->x_root, e->y_root)); + r2 = constrain(r, 1); + if(!eqrect(r, r2)) + warppointer(r2.min); +} + +static void +kdown_event(Window *w, XKeyEvent *e) { + + e->state &= valid_mask; + kpress(w->w, e->state, (KeyCode)e->keycode); +} + +static Handlers handlers = { + .enter = enter_event, + .focusin = focusin_event, + .kdown = kdown_event, + .leave = leave_event, + .mapreq = mapreq_event, + .motion = motion_event, +}; +