+#define REGION_WIN_BORDER 3
+/**
+ * Draw grabbing region window
+ *
+ * @param s x11_grab context
+ */
+static void
+x11grab_draw_region_win(struct x11_grab *s)
+{
+ Display *dpy = s->dpy;
+ int screen;
+ Window win = s->region_win;
+ GC gc;
+
+ screen = DefaultScreen(dpy);
+ gc = XCreateGC(dpy, win, 0, 0);
+ XSetForeground(dpy, gc, WhitePixel(dpy, screen));
+ XSetBackground(dpy, gc, BlackPixel(dpy, screen));
+ XSetLineAttributes(dpy, gc, REGION_WIN_BORDER, LineDoubleDash, 0, 0);
+ XDrawRectangle(dpy, win, gc,
+ 1, 1,
+ (s->width + REGION_WIN_BORDER * 2) - 1 * 2 - 1,
+ (s->height + REGION_WIN_BORDER * 2) - 1 * 2 - 1);
+ XFreeGC(dpy, gc);
+}
+
+/**
+ * Initialize grabbing region window
+ *
+ * @param s x11_grab context
+ */
+static void
+x11grab_region_win_init(struct x11_grab *s)
+{
+ Display *dpy = s->dpy;
+ int screen;
+ XSetWindowAttributes attribs;
+ XRectangle rect;
+
+ screen = DefaultScreen(dpy);
+ attribs.override_redirect = True;
+ s->region_win = XCreateWindow(dpy, RootWindow(dpy, screen),
+ s->x_off - REGION_WIN_BORDER,
+ s->y_off - REGION_WIN_BORDER,
+ s->width + REGION_WIN_BORDER * 2,
+ s->height + REGION_WIN_BORDER * 2,
+ 0, CopyFromParent,
+ InputOutput, CopyFromParent,
+ CWOverrideRedirect, &attribs);
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = s->width;
+ rect.height = s->height;
+ XShapeCombineRectangles(dpy, s->region_win,
+ ShapeBounding, REGION_WIN_BORDER, REGION_WIN_BORDER,
+ &rect, 1, ShapeSubtract, 0);
+ XMapWindow(dpy, s->region_win);
+ XSelectInput(dpy, s->region_win, ExposureMask | StructureNotifyMask);
+ x11grab_draw_region_win(s);
+}
+