x11 - How to get mode name using XCB?
问题描述
In Xlib the structure XRRModeInfo
contains, aside from nameLength
field, the name
itself. But in XCB the corresponding structure xcb_randr_mode_info_t
only contains name_len
, and there seems to be no function to get actual name string.
I do see all the mode names in the string returned by xcb_randr_get_screen_resources_names()
, but they are all concatenated, and I don't know how to find the offset of a particular mode in this string.
So, how can I get the mode name using XCB?
解决方案
我确实在 xcb_randr_get_screen_resources_names() 返回的字符串中看到了所有模式名称,但它们都是串联的,我不知道如何在这个字符串中找到特定模式的偏移量。
您知道各个名称的长度,并且知道每个名称的长度,因此您只需计算字节数:
#include <stdio.h>
#include <xcb/randr.h>
int main()
{
xcb_connection_t *c = xcb_connect(NULL, NULL);
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
// TODO: Error handling
// TODO: Checking if the RandR extension is available
xcb_randr_get_screen_resources_reply_t *reply =
xcb_randr_get_screen_resources_reply(c,
xcb_randr_get_screen_resources(c, screen->root),
NULL);
xcb_randr_mode_info_iterator_t iter = xcb_randr_get_screen_resources_modes_iterator(reply);
uint8_t *names = xcb_randr_get_screen_resources_names(reply);
while (iter.rem) {
xcb_randr_mode_info_t *mode = iter.data;
printf("Mode %d has size %dx%d and name %.*s\n",
mode->id, mode->width, mode->height, mode->name_len, names);
names += mode->name_len;
xcb_randr_mode_info_next(&iter);
}
free(reply);
xcb_disconnect(c);
return 0;
}
推荐阅读
- javascript - Dropzone 接受的文件过滤器
- javascript - Vue Router中切换路由导致数据重复
- objective-c - 如何使用 obj-c 类实例删除快速非可选展开?
- python - 使用请求模块时出现 cookiejar 错误
- python - Python 和雪花游标正在添加额外的文本来更改表外键查询,从而导致找不到表本身
- html - Jquery find - 增加数量
- python - 执行 pip install open_excel 时出错
- sql - 将 PostgreSQL 查询重写为 clickhouse
- sql - 在 Laravel 中使用现有表进行会话
- javascript - OpenCV.js cannot convert "undefined" to int