如何设置鼠标光标在X11在C应用程序 [英] How to set mouse cursor on X11 in a C application

查看:813
本文介绍了如何设置鼠标光标在X11在C应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已移植到Linux相当大,相当旧的C程序。我负责让鼠标光标正常工作,但有一些问题的。我是能够最需要我们的游标转换为使用由 XFontCursor <规定的标准光标/ A>使用类似:

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);

这是罚款,这有类似物在该XFontCursor提供(有用的)游标的极其有限的名单游标,但也有其他内置的,我想设置主题游标。例如,我希望能够设置光标bd_double_arrow(包括在每一个光标主题,是标准的对角线尺寸光标视窗)在我的应用程序,但你显然不能做到这一点与XCreateFontCursor。这似乎是pretty基本的,但对我的生活,我不能找到如何做任何说明。

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.

我只是想知道其他的X11应用程序是如何设置的游标,因为他们显然是从全球的主题,让他们不只是使用XCreateFontCursor。

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.

推荐答案

使用主题光标最简单的方法是使用Xcursor库。

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);

的名称是从 X11 / cursorfont.h中,SANS XC _ 标准光标名。如果主题有多余的游标,如 bd_double_arrow ,这些名称也可以使用(但不是所有的主题都有它们!)

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!)

如果主题不具备一些核心X光标的替代品,该库将回落到核心光标。

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

这篇关于如何设置鼠标光标在X11在C应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆