我想在Xorg中隐藏系统游标。
我使用xcb为Xorg编写X11应用程序,在某些情况下它会隐藏光标(比如"xbanish“或”un杂乱“)。我尝试过使用Xfixes:它在xlib中工作得很好,但是不适用于xcb。
我的xlib代码,它隐藏游标:
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
Display *conn = XOpenDisplay(NULL);
XFixesHideCursor(conn, DefaultRootWindow(conn));
Xflush(conn);我的xcb代码,它什么也不做:
#include <xcb/xcb.h>
#include <xcb/xfixes.h>
xcb_connection_t *conn = xcb_connect(NULL, NULL);
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
xcb_xfixes_hide_cursor(conn, screen->root);
xcb_flush(conn);我想了解为什么xcb的代码什么都不做,或者只是将光标隐藏在xcb中。
UPD
没有给我任何东西,它没有看到错误。但是我确信,xcb_xfixes_hide_cursor中有一个错误,因为这段代码给出了非空generic_error。
xcb_void_cookie_t cookie = xcb_xfixes_hide_cursor_checked(conn, screen->root);
xcb_generic_error_t *generic_error = xcb_request_check(conn, cookie);实际上,它给了我一个错误:
{
"error_code": 1,
"major_code": 138,
"minor_code": 29,
"sequence:": 2,
"full_sequence": 2
}我使用来自xcb错误的xcb_errors_get_name_for_minor_code和xcb_errors_get_name_for_major_code来了解任何关于错误的信息。它出现在xcb_xfixes_hide_cursor_checked内部。
发布于 2019-09-10 15:36:36
实际上,它给了我一个错误: { "error_code":1,"major_code":138,"minor_code":29,"sequence:":2,"full_sequence":2}
错误1是BadRequest / XCB_REQUEST。您会得到一个BadRequest错误,因为您没有初始化XFIXES扩展(=通知X11服务器您支持的版本)。
服务器中检查请求对客户端提供的版本是否有效的相关代码:2%3A1.20.4-1%2Fxfixes%2Fxfixes.c&line=150#L150
来自协议规范(2%3A1.20.4-1%2Fxfixes%2Fxfixes.c&line=150#L150):
4. Extension initialization
The client must negotiate the version of the extension before executing
extension requests. Behavior of the server is undefined otherwise.
QueryVersion
[...]因此,要回答您的问题:您需要先执行xcb_xfixes_query_version(c, 4, 0),然后才能执行HideCursor请求。
要回答您的第一个后续问题:Version4.0是引入HideCursor的版本。在协议规范中可以看到这一点,因为HideCursor是在"XFIXES版本4或更好“下记录的。
要回答您的第二个后续问题:XFixesHideCursor自动为您查询版本:1%3A5.0.3-1%2Fsrc%2FCursor.c&line=255#L250
此代码最后调用XFixesHideCursor -> XFixesFindDisplay -> XFixesExtAddDisplay,此函数查询版本:1%3A5.0.3-1%2Fsrc%2FXfixes.c&line=79#L79。
发布于 2019-09-08 22:56:34
一般而言,隐藏游标的最简单方法是将其更改为空游标。
xcb_void_cookie_t
xcb_create_glyph_cursor (xcb_connection_t *connection,
xcb_cursor_t cursorId,
xcb_font_t source_font, /* font for the source glyph */
xcb_font_t mask_font, /* font for the mask glyph or XCB_NONE */
uint16_t source_char, /* character glyph for the source */
uint16_t mask_char, /* character glyph for the mask */
uint16_t fore_red, /* red value for the foreground of the source */
uint16_t fore_green, /* green value for the foreground of the source */
uint16_t fore_blue, /* blue value for the foreground of the source */
uint16_t back_red, /* red value for the background of the source */
uint16_t back_green, /* green value for the background of the source */
uint16_t back_blue ); /* blue value for the background of the source */我们应该可以通过' '来表示source_char和mask_char。但是,我们需要传递一个普通字体,而不是光标字体,这样才能工作。
我发现显示和隐藏游标的旧想法有点问题。据我所知,API在现代窗口管理器中有些敏感。
https://stackoverflow.com/questions/57841785
复制相似问题