[hackers] [wmii] Add root.c || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sat, 18 Oct 2008 16:29:24 +0000 (UTC)

changeset: 2388:ecfe0bf8aac8
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Oct 18 12:29:23 2008 -0400
files: cmd/wmii/root.c
description:
Add root.c

diff -r ac847b22405c -r ecfe0bf8aac8 cmd/wmii/root.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/root.c Sat Oct 18 12:29:23 2008 -0400
@@ -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,
+};
+
Received on Sat Oct 18 2008 - 16:29:24 UTC

This archive was generated by hypermail 2.2.0 : Sat Oct 18 2008 - 16:36:04 UTC