How to set mouse cursor on X11 in a C application

余生长醉 提交于 2019-12-10 10:15:53

问题


I've got a rather large and rather old C application that has been ported to 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:

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. 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. 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.


回答1:


The easiest way to use themed cursors is with the Xcursor library.

#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_. If the theme has extra cursors such as bd_double_arrow, these names can also be used (but not all themes have them!)

If a theme does not have a replacement for some core X cursor, the library will fall back to the core cursor.




回答2:


After clicking some links on that page: try XCreatePixmapCursor. From its description, it looks like you can create any 2-color cursor you want.



来源:https://stackoverflow.com/questions/18857125/how-to-set-mouse-cursor-on-x11-in-a-c-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!