Re: How can you get the current cursor/pointer in X windows?

8 views
Skip to first unread message

Spiros Bousbouras

unread,
May 6, 2019, 12:04:06 PM5/6/19
to
On Mon, 6 May 2019 15:30:09 +0000 (UTC)
john...@nowhere.co.uk wrote:
> Hello
>
> I need to get the current mouse cursor/pointer being displayed by the X server
> in a window but there doesn't seem to be an obvious way to do it in Xlib.
> XDefineCursor() sets it but there doesn't appear to be a way to get it.

[Crossposting to comp.windows.x]

XQueryPointer()

john...@nowhere.co.uk

unread,
May 6, 2019, 12:08:07 PM5/6/19
to
While that returns details about the pointer window and location it doesn't
return the glyph or bitmap currently being used for the pointer itself.

Winston

unread,
May 6, 2019, 2:15:25 PM5/6/19
to
john...@nowhere.co.uk originally asked:
>>> I need to get the current mouse cursor/pointer being displayed by
>>> the X server in a window but there doesn't seem to be an obvious way
>>> to do it in Xlib. XDefineCursor() sets it but there doesn't appear
>>> to be a way to get it.

and later added:
> [XQueryPointer] doesn't return the glyph or bitmap currently being
> used for the pointer itself.

I'm not seeing any standard way of retrieving that.

XSetWindowAttributes (and several X*Grab* functions) can set the cursor,
but XGetWindowAttributes doesn't return it.

About the only thing I found by `grep Cursor *.h */*.h` from X11 was

./extensions/Xfixes.h: XFixesGetCursorImage (Display *dpy);

which (I assume) only works when that extension is supported. To the
extent you want the cursor attribute of a particular window, though,
rather than (as its name suggests) the value of the cursor for the whole
display at that instant (when the pointer might not be in the window
you're interested in), the value might not be what you're seeking.

For an individual application, you could put "wrappers" around every
call that sets the Cursor, to save the value before doing the X
function.

That's about all I found.
-WBE

Scott Lurndal

unread,
May 6, 2019, 2:45:00 PM5/6/19
to
I wouldn't be suprised to find that the cursor pixmap is associated
with an Atom on the server - determining which may be useful.

john...@nowhere.co.uk

unread,
May 7, 2019, 3:58:28 AM5/7/19
to
On Mon, 06 May 2019 14:15:14 -0400
Winston <w...@UBEBLOCK.psr.com.invalid> wrote:
>john...@nowhere.co.uk originally asked:
>>>> I need to get the current mouse cursor/pointer being displayed by
>>>> the X server in a window but there doesn't seem to be an obvious way
>>>> to do it in Xlib. XDefineCursor() sets it but there doesn't appear
>>>> to be a way to get it.
>
>and later added:
>> [XQueryPointer] doesn't return the glyph or bitmap currently being
>> used for the pointer itself.
>
>I'm not seeing any standard way of retrieving that.
>
>XSetWindowAttributes (and several X*Grab* functions) can set the cursor,
>but XGetWindowAttributes doesn't return it.
>
>About the only thing I found by `grep Cursor *.h */*.h` from X11 was
>
>../extensions/Xfixes.h: XFixesGetCursorImage (Display *dpy);

Thanks. I've not heard of that extension but its on my system so I'm going
to give it a go.

In case anyone is wondering , I'm writing a program that changes the cursor
depending on what state its in, but when its reset I want to return it to
displaying whatever is the standard cursor for the system its running on.
Normally its an arrow, but sometimes its the X cursor and I imagine with some
WMs its something else entirely.

Reply all
Reply to author
Forward
0 new messages