【发布时间】:2021-04-08 23:04:09
【问题描述】:
有问题的代码类似于这个 SO 主题:Get X11 window caption height。链接指向用Xlib 代码回答。这个想法是获取窗口属性,即_NET_FRAME_EXTENTS。代码一直等到窗口管理器设置装饰尺寸。答案中的代码会跳过所有事件,直到属性返回。
基本上我对XCB 做同样的事情。我想知道我刚刚创建的窗户的装饰尺寸。我用XCB做的伪代码:
cookie = xcb_get_property(...)
reply = xcb_get_property_reply(..., cookie, ...)
if(NULL == reply){
/* fail */
}
if(reply->type != type){
/* fail */
}
prop_size = xcb_get_property_value_length(reply);
prop_val = xcb_get_property_value (reply);
if(0 == prop_size){
/* fail */
}
if(/* not failed */){
copy returned data here
print and return success.
}
if(/* failed */)
then wait for events and skip them
repeat the above untill success
问题是有时返回的值为零,有时值是正确的。从上面的代码可以看出,成功的条件是只有当类型匹配并且有一些数据被读取时。该请求使用 cookie 检查,因此,据我了解,回复属于该请求。在调用上述代码之前,我会映射窗口并刷新事件。
问题是,如何用XCB正确获取WM装饰?
【问题讨论】: