summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shapes.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/shapes.c b/shapes.c
index ef6345c..79cbf3f 100644
--- a/shapes.c
+++ b/shapes.c
@@ -2,6 +2,8 @@
#include <stdint.h>
#include <unistd.h>
#include <X11/Xlib.h>
+#include <X11/extensions/shape.h>
+#include <X11/Xutil.h>
int scr_width, scr_height;
@@ -23,10 +25,50 @@ reflect (uint64_t i, uint64_t size)
return i;
}
+#define OUTLINE_WIDTH 3
+
+void
+set_shape (Display *dpy, Window window, XRectangle *rect)
+{
+ if (rect->width > OUTLINE_WIDTH * 2 &&
+ rect->height > OUTLINE_WIDTH * 2)
+ {
+ XRectangle xrect;
+ Region inner_xregion;
+ Region outer_xregion;
+
+ inner_xregion = XCreateRegion ();
+ outer_xregion = XCreateRegion ();
+
+ xrect.x = 0;
+ xrect.y = 0;
+ xrect.width = rect->width;
+ xrect.height = rect->height;
+
+ XUnionRectWithRegion (&xrect, outer_xregion, outer_xregion);
+
+ xrect.x += OUTLINE_WIDTH;
+ xrect.y += OUTLINE_WIDTH;
+ xrect.width -= OUTLINE_WIDTH * 2;
+ xrect.height -= OUTLINE_WIDTH * 2;
+
+ XUnionRectWithRegion (&xrect, inner_xregion, inner_xregion);
+
+ XSubtractRegion (outer_xregion, inner_xregion, outer_xregion);
+
+ XShapeCombineRegion (dpy, window,
+ ShapeBounding, 0, 0, outer_xregion, ShapeSet);
+
+ XDestroyRegion (outer_xregion);
+ XDestroyRegion (inner_xregion);
+ }
+}
+
static void
update_window (Display *dpy)
{
uint32_t real_x, real_y, real_width, real_height;
+ XRectangle rect;
real_width = reflect (width, MAX_WIDTH) + MIN_WIDTH;
real_height = reflect (height, MAX_HEIGHT) + MIN_HEIGHT;
@@ -38,10 +80,18 @@ update_window (Display *dpy)
real_x = scr_width - real_width;
if (real_y + real_height >= scr_height)
real_y = scr_height - real_height;
-
+
XMoveResizeWindow (dpy, window, real_x, real_y,
real_width, real_height);
+ rect.x = real_x;
+ rect.y = real_y;
+ rect.width = real_width;
+ rect.height = real_height;
+
+ set_shape (dpy, window, &rect);
+
+
x += rand () % 20;
width += rand () % 20;
y += rand () % 20;