How do I hide the mouse pointer under X11? I would like to use the built in libraries in order to do this and not something like SDL (SDL_ShowCursor(0)) or glut (glutSetCursor(GLUT_CURSOR_NONE)). Also, the mouse pointer should be hidden no matter the pointer location, not just in its own window.
You can create and set an invisible cursor theme. This trick is used by maemo, because it's rather pointless to have a cursor on a touchscreen device.
Sadly, the ability to change the global cursor theme at runtime is not uniform across X11 applications and toolkits. You can change the server resource Xcursor.theme
, and nobody will notice (generally it's only queried at startup); you can inform xsettings which only seems to affect Gtk+ programs; KDE uses some sort of communication through properties on the root window; etc.
At least changing the cursor for your own application is as easy as XDefineCursor, and if you do that on the root window, some applications might follow along.
I ended up using XDefineCursor like ephemient mentioned. The control application changed the default root window cursor and the other applications (which are under my control) inherited it.
Code specifics look like:
// Hide the cursor
if (NULL==(display=XOpenDisplay(NULL)))
{
printf("Unable to open NULL display\n");
exit(1);
}
window = DefaultRootWindow(display);
Cursor invisibleCursor;
Pixmap bitmapNoData;
XColor black;
static char noData[] = { 0,0,0,0,0,0,0,0 };
black.red = black.green = black.blue = 0;
bitmapNoData = XCreateBitmapFromData(display, window, noData, 8, 8);
invisibleCursor = XCreatePixmapCursor(display, bitmapNoData, bitmapNoData,
&black, &black, 0, 0);
XDefineCursor(display,window, invisibleCursor);
XFreeCursor(display, invisibleCursor);
In order to hide the cursor and then after I'm done
// Restore the X left facing cursor
Cursor cursor;
cursor=XCreateFontCursor(display,XC_left_ptr);
XDefineCursor(display, window, cursor);
XFreeCursor(display, cursor);
To restore X's left handed cursor (Since it's the root window and I don't want it to stay invisible. I'm not sure, but I might also be able to use
XUndefineCursor(display, window);