Skip to content

Instantly share code, notes, and snippets.

@jvns jvns/bouncewm.c Secret
Created Dec 3, 2019

Embed
What would you like to do?
#include <X11/Xlib.h>
#include <unistd.h>
int main()
{
Window root;
Display * dpy;
XWindowAttributes attr;
XEvent ev;
if(!(dpy = XOpenDisplay(0x0))) return 1;
root = DefaultRootWindow(dpy);
XGrabButton(dpy, 1, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync,
GrabModeAsync, None, None);
int right = 1;
int up = 1;
int x = 0;
int y = 0;
for(;;)
{
XNextEvent(dpy, &ev);
if(ev.type == ButtonPress && ev.xbutton.subwindow != None)
{
XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
x = 40;
y = 40;
for(;;) {
XMoveWindow(dpy, ev.xbutton.subwindow, x, y);
XSync(dpy, 0);
if (x > 1280 - attr.width) {
right = 0;
} else if (x < 0) {
right = 1;
}
if (y < 0) {
up = 1;
} else if (y > 800 - attr.height) {
up = 0;
}
x += (right == 1) ? 8 : -6;
y += (up == 1) ? 6 : -4;
usleep(50 * 1000);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.