简体   繁体   English

如何在 C 应用程序中在 X11 上设置鼠标光标

[英]How to set mouse cursor on X11 in a C application

I've got a rather large and rather old C application that has been ported to Linux.我有一个相当大且相当老的 C 应用程序,它已移植到 Linux。 I'm in charge of getting mouse cursors to work correctly, but having some issues.我负责让鼠标光标正常工作,但有一些问题。 I was able to convert most of the cursors we require to using the standard cursors provided by XFontCursor by using something like:我能够将我们需要的大多数游标转换为使用XFontCursor提供的标准游标,方法如下:

gCursorTable[waitCurs] = XCreateFontCursor(gDisplay, XC_watch);
...
XDefineCursor(gDisplay, WHostWindow(w), gCursorTable[cursor]);
XFlush(gDisplay);

This is fine for cursors which have analogs in the extremely limited list of (useful) cursors that XFontCursor provides, but there are other built in themed cursors that I'd like to set.这对于在 XFontCursor 提供的极其有限的(有用的)游标列表中具有类似物的游标来说很好,但是我想设置其他内置的主题游标。 For example, I'd like to be able to set the cursor to bd_double_arrow (which is included in every cursor theme and is the standard diagonal sizing cursor for windows) in my app, but you obviously can't do that with XCreateFontCursor.例如,我希望能够在我的应用程序中将光标设置为 bd_double_arrow(它包含在每个光标主题中,并且是 Windows 的标准对角线大小光标),但您显然无法使用 XCreateFontCursor 做到这一点。 This seems pretty basic, but for the life of me I can't find any description on how to do it.这看起来很基本,但对于我的生活,我找不到任何关于如何做到的描述。

I just want to know how other X11 apps are setting cursors, because they are obviously getting them from a global theme and not just using XCreateFontCursor.我只想知道其他 X11 应用程序是如何设置光标的,因为它们显然是从全局主题中获取的,而不仅仅是使用 XCreateFontCursor。

The easiest way to use themed cursors is with the Xcursor library.使用主题游标的最简单方法是使用 Xcursor 库。

#include <X11/Xcursor/Xcursor.h>
...
Cursor c = XcursorLibraryLoadCursor(dpy, "sb_v_double_arrow");
XDefineCursor (dpy, w, c);

The names are standard cursor names from X11/cursorfont.h , sans XC_ .名称是来自X11/cursorfont.h标准光标名称,无XC_ If the theme has extra cursors such as bd_double_arrow , these names can also be used (but not all themes have them!)如果主题有额外的光标,例如bd_double_arrow ,也可以使用这些名称(但并非所有主题都有!)

If a theme does not have a replacement for some core X cursor, the library will fall back to the core cursor.如果主题没有替代某些核心 X 光标,则库将回退到核心光标。

After clicking some links on that page: try XCreatePixmapCursor .单击该页面上的一些链接后:尝试XCreatePixmapCursor From its description, it looks like you can create any 2-color cursor you want.从它的描述来看,您似乎可以创建任何您想要的 2 色光标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM