【问题标题】:Get width and height from `xcb_get_geometry_reply()`从 `xcb_get_geometry_reply()` 获取宽度和高度
【发布时间】:2023-04-09 15:07:02
【问题描述】:

我正在尝试通过 XCB 检索根窗口的大小,以便创建一个该大小的窗口。

我可以使用xcb_get_geometry_reply() 来获取几何图形,但如何将其转换为uint16_t 以便将其传递给xcb_create_window()(作为宽度和高度)?

【问题讨论】:

  • ...你到底在问什么?我对“如何将其转换为uint16_t 数组”感到非常困惑。您为什么要尝试获取数组,而仅创建数组有什么问题?请注意,xcb_create_window 的参数 7 和 8 分别是 widthheight。不涉及数组。
  • 我很抱歉。我已经改写了我的问题。
  • 啊,好的。现在我明白你的意思了。很抱歉没有早点理解,也没有理由道歉。

标签: c xorg xcb


【解决方案1】:

来自this page

就像我们可以设置窗口的各种属性一样,我们也可以要求 X 服务器提供这些属性的当前值。例如,我们可以检查一个窗口在屏幕上的位置,它的当前大小是多少,它是否被映射等等。包含这些信息的结构是

typedef struct {
    uint8_t      response_type;
    uint8_t      depth;         /* depth of the window */
    uint16_t     sequence;
    uint32_t     length;
    xcb_window_t root;          /* Id of the root window *>
    int16_t      x;             /* X coordinate of the window's location */
    int16_t      y;             /* Y coordinate of the window's location */
    uint16_t     width;         /* Width of the window */
    uint16_t     height;        /* Height of the window */
    uint16_t     border_width;  /* Width of the window's border */
 } xcb_get_geometry_reply_t;

因此,只需使用geomtry->widthgeomtry->height 访问宽度/高度

【讨论】:

    猜你喜欢
    • 2017-12-26
    • 1970-01-01
    • 2019-12-26
    • 2017-02-02
    • 2014-07-15
    • 1970-01-01
    • 2012-10-10
    • 2021-06-30
    • 2010-11-18
    相关资源
    最近更新 更多