#include #include #include #include #include #include int scr_width, scr_height; uint64_t x, y, width, height; Window window; #define MIN_WIDTH 10 #define MIN_HEIGHT 10 #define MAX_WIDTH (800 - MIN_WIDTH) #define MAX_HEIGHT (800 - MIN_HEIGHT) static uint32_t reflect (uint64_t i, uint64_t size) { i = i % (size * 2); if (i >= size) i = size * 2 - i - 1; 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; real_x = reflect (x, scr_width); real_y = reflect (y, scr_height); if (real_x + real_width >= scr_width) 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; height += rand () % 20; XSync (dpy, False); } int main () { Display *dpy = XOpenDisplay (NULL); XSetWindowAttributes attr; attr.override_redirect = True; attr.background_pixel = 0; x = 10; y = 10; width = 400; height = 400; scr_width = DisplayWidth (dpy, 0); scr_height = DisplayHeight (dpy, 0); window = XCreateWindow ( dpy, DefaultRootWindow (dpy), x, y, width, height, 0, 0, InputOutput, DefaultVisual (dpy, 0), CWOverrideRedirect | CWBackPixel, &attr); XMapWindow (dpy, window); while (1) { update_window (dpy); usleep (10000); } XSync (dpy, False); sleep (10); }