Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent X11 Cursor Theme - Why does the X cursor appear in GTK+ subwindows?

I am using the transparent cursor theme trick (see http://obiltschnig.com/2010/08/14/hiding-the-gtkx11-mouse-cursor/) to hide the X11 cursor in a fullscreen Linux GTK+ application for a touchscreen-based device. I am basically running a WebKit GTK+-based application using the Xorg server with no window manager in fullscreen mode. Now, hiding the cursor by setting a transparent 1-pixel cursor default theme works quite well (see also: How do you hide the mouse pointer under Linux/X11?). However, as soon as the cursor is within a subwindow (e.g., an JavaScript alert window or a combobox/HTML ), the X cursor appears (and disappears again if the cursor is moved out of the window). Does anyone know why this is so? And is there a way to completely hide the cursor?

like image 584
Günter Obiltschnig Avatar asked Aug 16 '10 08:08

Günter Obiltschnig


People also ask

How do I change the cursor on my arch theme?

For user-specific configuration, create or edit ~/. icons/default/index. theme ; for system-wide configuration, one can edit /usr/share/icons/default/index. theme .

How do I change my gnome cursor?

After installing GNOME Tweaks, navigate to the top-left 'Activities' overview. Go to GNOME Tweaks and open it. Once you open GNOME Tweaks, go to the Appearance option from the left pane. Choose a different cursor theme from the drop-down menu.


1 Answers

“Why this is so?”

The main reason for that behaviour is because the XGrabPointer() function (see the Xlib Programming Manual), that actively grabs control of the pointer and returns GrabSuccess if the grab was successful. Further pointer events are reported only to the grabbing client. XGrabPointer() overrides any active pointer grab by this client.

int XGrabPointer(Display *display;
                 Window grab_window;
                 Bool owner_events;
                 unsigned int event_mask;
                 int pointer_mode, keyboard_mode;
                 Window confine_to;
                 Cursor cursor;
                 Time time);

If a cursor is specified, it is displayed regardless of what window the pointer is in. If None is specified, the normal cursor for that window is displayed when the pointer is in grab_window or one of its subwindows; otherwise, the cursor for grab_window is displayed.

“Is there a way to completely hide the cursor?”

I think you can override that behaviour with XUnDefineCursor and XUndefineCursor:

XUndefineCursor(Display *display;
                Window w);

Undoes the effect of a previous XDefineCursor() for the active window. When the pointer is in the window, the parent's cursor will be used. If you select a transparent pointer as the default pointer, and also use undefine the cursors of the subwindows, you should see no cursors at all. XUndefineCursor is equivalent to XDefineCursor when the cursor is set to None.

    display=XOpenDisplay(NULL)
    window = DefaultRootWindow(display);
    Cursor invisible_cursor;
    Pixmap no_pixmap;
    XColor black;
    static char nothing[] = { 0, 0, 0, 0, 0, 0, 0, 0 };

    no_pixmap = XCreateBitmapFromData(display, window, nothing, 8, 8);
    invisible_cursor = XCreatePixmapCursor(display,
                                           no_pixmap, no_pixmap,
                                           &black, &black, 0, 0);
    XDefineCursor(display, window, invisible_cursor);

Some Desktop such as KDE uses other methods to communicate with its windows, and may be that doesn't work anyway though.


Alternatively there is another program, unclutter, that removes the idle cursor from screen after a few seconds of inactivity. This hides the mouse pointer when it's not in use.

unclutter runs in the background of an X11 session and after a specified period of inactivity hides the cursor from display. When the cursor is moved its display is restored. Users may specify specific windows to be ignored by unclutter.

You can set the delay time to 0: unclutter -idle 0, and the mouse pointer will disappear at soon as you stop moving the cursor.

like image 182
J. A. Corbal Avatar answered Oct 01 '22 11:10

J. A. Corbal