如何使用 Xlib 设置 "arrow+watch" 鼠标光标?

How to set "arrow+watch" mouse cursor, using Xlib?

我注意到,使用 XCreateFontCursor 然后使用带有光标代码 XC_watch (150) 的 XDefineCursor 实际上将光标设置为不是丑陋的 Xlib 光标,而是默认的系统动画沙漏光标。

对我来说,这表明某些系统(window 管理器?)拦截 xlib 调用并透明地更改光标。

但是,如果未在 XLib 常量中定义,我如何通过这种方式将光标设置为 "arrow+hourglass" 光标?

您正在寻找的是 cursor themes(它扩展了 X cursor 字体的东西,并不总是以兼容的方式)。一些讨论:

这是用户级别(您可以在其中查看 动画光标)。 Xcursor library is used by the X server to override the older bitmap-cursor behavior to provide colors and other interesting image-related features. The documentation is ... poor, essentially requiring other developers to get most of the information by reading source-code (as I did in xterm — look for "XCursor").

这是指向源代码的指针:

http://cgit.freedesktop.org/xorg/lib/libXcursor/

存在从光标形状定义(数字)到光标主题提供的图像的映射。这似乎由 Xcursor 处理。查看 Xcursor.h 文件有此注释:

/*
 * This is the function called by Xlib when attempting to
 * load cursors from XCreateGlyphCursor.  The interface must
 * not change as Xlib loads 'libXcursor.so' instead of
 * a specific major version
 */

这表明 XcursorTryShapeCursor 函数参与将对 XCreateFontCursor 的调用转换为要加载的图像文件。

因此,用于满足Xlib 调用的图标文件由Xcursor 提供的图标主题管理。 XcursorSetTheme 可用于 select 替代光标主题,但除非已将原始丑陋的 X11 光标安装为主题,否则您无法通过这种方式获得内置光标。

但是,Xcursor 手册提到了 XCURSOR_PATH 环境变量。如果将其设置为没有光标主题的路径,则所有内容都默认为内置的丑陋光标。例如:env XCURSOR_PATH=/tmp ./test_application