diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-04-07 09:59:26 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-04-07 09:59:26 -0400 |
commit | e1efd9ce6dbaa1c02e95bc491cbdc770528a8caf (patch) | |
tree | 0325b0bef21539d41292e8e7e492f7d6c6583833 | |
parent | bfbba498bdd7ec266d5b864382624cdb9d028e56 (diff) |
-rw-r--r-- | shapes.c | 52 |
1 files changed, 51 insertions, 1 deletions
@@ -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; |