How can I set the cursor for the root window (or any other window) in a python application using Xlib?
I have an instance of display
and window
(the root window).
Using the C bindings; I could use XDefineCursor with a cursor I have created with XCreatePixmapCursor. How do I do the same with the python bindings?
I want to be able to use a default cursor, or a custom cursor.
There are two things you want to keep in mind when you need to find the python-xlib equivalent of any libX11 function:
XCreatePixmapCursor()
translates topixmap.create_cursor()
.XDefineCursor()
, you'll see it's actually callingXChangeWindowAttributes()
, meaning you'll want to usewin.change_attributes()
in python-xlib.If you want to use
XCreateFontCursor()
to use a cursor from the cursor font, the second guideline again applies: It's callingXCreateGlyphCursor()
under the hood, which corresponds tofont.create_glyph_cursor()
.Putting all of that together, here's what you'll get:
If you're wondering about the significance of the
+1
in the call tofont.create_glyph_cursor()
, that's explained in the source code ofXCreateFontCursor()
.