How to override custom mouse cursor with Xcursor

rdesktopxcursorxorg

When I use rdesktop to connect to a Microsoft Windows server, the mouse cursor is set to a monochrome version of the Windows true-colour cursor. This ends up being a white arrow with no outline, so it's very difficult to see it over a white surface.

I don't want to change the cursor on the Windows machine, but my understanding of how Xcursor works is following:

When any cursor is set, it is looked up by filename (using a hash of the cursor image) so that if a match is found, that Xcursor is used instead of the original monochrome one.

My idea is that if I can supply this file and put a clearer cursor image in it (like the default arrow) then it will solve my problem by using the default arrow most of the time. Plus it will still allow rdesktop to change the cursor to something else (like a resize arrow) if the remote machine needs to.

  • How can I find out what hash to use for the rdesktop cursor image I am getting?
  • How can I map that hash to the normal arrow cursor in the theme I am using?

Best Answer

I have worked out how to do this. First, you have to set the XCURSOR_DISCOVER environment variable before running the program that is setting the mouse cursor, in my case, rdesktop:

$ XCURSOR_DISCOVER=1 rdesktop ...

This will then print out bitmaps and hashes of each cursor once only when they are set for the first time. Here is what it spat out when the default Windows cursor was set, which is the image I want to override:

Cursor image name: 24020000002800000528000084810000
...
Cursor image name: 7bf1cc07d310bf080118007e08fc30ff
...
Cursor hash 24020000002800000528000084810000 returns 0x0

When Xcursor looks for missing cursors, the search path includes ~/.icons/default/cursors so this is where we can place images for missing cursors.

$ mkdir -p ~/.icons/default/cursors

Now in here you just point any hash to an existing image. When an application tries to set the hash, that image will be used instead. In this case, we want the left_ptr image to be used (this is the default arrow) from the Vanilla-DMZ theme:

$ ln -s /usr/share/icons/Vanilla-DMZ/cursors/left_ptr ~/.icons/default/cursors/24020000002800000528000084810000

That's it! The change should be visible immediately.

Related Question