开发者

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 m开发者_运维技巧anager 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?


“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.


If a child window sets a cursor then it will have that cursor instead of the one set on the parent window. The window manager normally sets the root window cursor, but if an app changes the cursor it would override that.

A GTK app would normally set the cursor theme cursors, but maybe the lack of an xsettings manager or other normal desktop environment setup is causing a problem. See if running gnome-settings-manager fixes it and if so you could try to replicate its functionality.

You could also look into XFixesHideCursor(), as long as you can rely on an X server with that extension it might solve the problem nicely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜