+static ptr_t x2ptr(XEvent *xe)
+{
+ XKeyEvent *xke = &xe->xkey;
+ return (ptr_t){xke->x, xke->y, xke->x_root, xke->y_root};
+}
+
+static Window getfocus(win_t *root, XEvent *xe)
+{
+ int revert;
+ Window focus = PointerRoot;
+ if (xe->type == KeyPress || xe->type == KeyRelease)
+ XGetInputFocus(root->sys->dpy, &focus, &revert);
+ if (focus == PointerRoot)
+ focus = xe->xkey.subwindow;
+ if (focus == None)
+ focus = xe->xkey.window;
+ return focus;
+}
+
+/* Strut functions
+ * Struts are spaces at the edges of the screen that are used by
+ * toolbars and statusbars such as dzen. */
+static int strut_copy(win_t *to, win_t *from, int scale)
+{
+ int left = from->sys->strut.left;
+ int right = from->sys->strut.right;
+ int top = from->sys->strut.top;
+ int bottom = from->sys->strut.bottom;
+ if (left == 0 && right == 0 && top == 0 && bottom == 0)
+ return 0;
+ to->x += scale*(left );
+ to->y += scale*(top );
+ to->w -= scale*(left+right);
+ to->h -= scale*(top+bottom);
+ to->sys->strut.left += scale*left;
+ to->sys->strut.right += scale*right;
+ to->sys->strut.top += scale*top;
+ to->sys->strut.bottom += scale*bottom;
+ return 1;
+}
+
+static int strut_add(win_t *root, win_t *win)
+{
+ /* Get X11 strut data */
+ Atom ret_type;
+ int ret_size;
+ unsigned long ret_items, bytes_left;
+ unsigned char *xdata;
+ int status = XGetWindowProperty(win->sys->dpy, win->sys->xid,
+ atoms[NET_STRUT], 0L, 4L, False, XA_CARDINAL,
+ &ret_type, &ret_size, &ret_items, &bytes_left, &xdata);
+ if (status != Success || ret_size != 32 || ret_items != 4)
+ return 0;
+
+ win->sys->strut.left = ((int*)xdata)[0];
+ win->sys->strut.right = ((int*)xdata)[1];
+ win->sys->strut.top = ((int*)xdata)[2];
+ win->sys->strut.bottom = ((int*)xdata)[3];
+ struts = list_insert(struts, win);
+ for (list_t *cur = screens; cur; cur = cur->next)
+ strut_copy(cur->data, win, 1);
+ return strut_copy(root, win, 1);
+}
+
+static int strut_del(win_t *root, win_t *win)
+{
+ list_t *lwin = list_find(struts, win);
+ if (lwin)
+ struts = list_remove(struts, lwin, 0);
+ for (list_t *cur = screens; cur; cur = cur->next)
+ strut_copy(cur->data, win, -1);
+ return strut_copy(root, win, -1);
+}
+
+#if 0
+static int is_fullscreen(win_t *win)