summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@l3000.localdomain>2011-04-07 01:03:10 -0400
committerSøren Sandmann Pedersen <ssp@l3000.localdomain>2011-04-07 01:03:10 -0400
commitbfbba498bdd7ec266d5b864382624cdb9d028e56 (patch)
tree8e281e8d51227c77c17ac65a0bc744cf25b1b15b
parente6b67a5d3b701daddfd93b8baf000a3696e2973b (diff)
window
-rw-r--r--shapes.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/shapes.c b/shapes.c
new file mode 100644
index 0000000..ef6345c
--- /dev/null
+++ b/shapes.c
@@ -0,0 +1,88 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+
+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;
+}
+
+static void
+update_window (Display *dpy)
+{
+ uint32_t real_x, real_y, real_width, real_height;
+
+ 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);
+
+ 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);
+}