Instantly share code, notes, and snippets.

Embed
What would you like to do?
Utility to hide the mouse cursor and prevent screen blanking (http://blog.ghedini.me/post/2050358022/screensaver-inhibitor)
/*
* Utility to hide the mouse cursor and prevent screen blanking.
*
* Compile:
* $ cc -o movietime movie_time.c -lX11
*
* Usage:
* $ ./movietime
*
* Copyright (C) 2010 Alessandro Ghedini <alessandro@ghedini.me>
* --------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Alessandro Ghedini wrote this file. As long as you retain this
* notice you can do whatever you want with this stuff. If we
* meet some day, and you think this stuff is worth it, you can
* buy me a beer in return.
* --------------------------------------------------------------
*/
#include <unistd.h>
#include <X11/Xlib.h>
#define WAIT_FOR (5 * 60)
void hide_cursor(Display *dpy) {
GC gc;
XGCValues xgc = { .function = GXclear };
XColor color = { .pixel = 0, .red = 0, .flags = 0 };
Pixmap mask;
Cursor cursor;
Window root = DefaultRootWindow(dpy);
mask = XCreatePixmap(dpy, root, 1, 1, 1);
gc = XCreateGC(dpy, mask, GCFunction, &xgc);
XFillRectangle(dpy, mask, gc, 0, 0, 1, 1);
cursor = XCreatePixmapCursor(dpy, mask, mask, &color, &color, 0, 0);
XGrabPointer(
dpy, root, 0,
PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime
);
XFreePixmap(dpy, mask);
XFreeGC(dpy, gc);
}
void move_cursor(Display *dpy) {
int move_by = 1;
while (1) {
move_by -= move_by * 2;
sleep(WAIT_FOR);
XWarpPointer(dpy, None, None, 0, 0, 0, 0, 0, move_by);
XFlush(dpy);
}
}
int main(int argc, char *argv[]) {
Display *dpy = XOpenDisplay(NULL);
hide_cursor(dpy);
move_cursor(dpy);
XCloseDisplay(dpy);
return 0;
}
@archSeer

This comment has been minimized.

archSeer commented Jul 4, 2013

Nice! Reminds me of http://xkcd.com/196/ :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment