From ebe2a7027ac31e3cc40ad1907d59eebc3503e161 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 18 Oct 2008 12:29:23 -0400 Subject: [PATCH] Add root.c --- cmd/wmii/root.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 cmd/wmii/root.c diff --git a/cmd/wmii/root.c b/cmd/wmii/root.c new file mode 100644 index 00000000..4cdcc0db --- /dev/null +++ b/cmd/wmii/root.c @@ -0,0 +1,89 @@ +/* Copyright ©2008 Kris Maglione + * 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, +}; +