tags:

views:

4250

answers:

3

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.

+7  A: 

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.

ephemient
Do you have a link on how to create this, enable it when the application starts and disable it when the application exits?
rck
It's easy to set the global cursor theme when X starts up, but to be able to manipulate other windows' cursors... that ability is not readily available. Why do you want to do this?
ephemient
Actually, come to think of it, I have control of all applications visible to the user, so I should be able to use XDefineCursor. Thanks.
rck
+3  A: 

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);
rck
+2  A: 

Here's a description how unclutter utility does it.

Eugene Morozov
Oh hey, that's pretty clever. I wouldn't have thought of that...
ephemient