Last active
July 2, 2021 12:56
-
-
Save ghedo/963378 to your computer and use it in GitHub Desktop.
Utility to hide the mouse cursor and prevent screen blanking (http://blog.ghedini.me/post/2050358022/screensaver-inhibitor)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
} |
Maybe use XFixesHideCursor(dpy, win);
would be easier?
https://cgit.freedesktop.org/xorg/proto/fixesproto/plain/fixesproto.txt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Reminds me of http://xkcd.com/196/ :)