首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用XCB获取窗口标题

用XCB获取窗口标题
EN

Stack Overflow用户
提问于 2016-01-25 21:16:55
回答 1查看 2K关注 0票数 4

我正试图在焦点中获取有关窗口的信息。我似乎从xcb_get_input_focus_reply_t->focus获得了一个正确的窗口id :对于Eclipse (56623164),它保持不变,对于焦点中的任何其他窗口也是相同的。但是,对于XCB_ATOM_WM_NAME,值长度始终为0。

缩短代码

代码语言:javascript
复制
cookie = xcb_get_property(c, 0, fr->focus, XCB_ATOM_WM_NAME,
            XCB_ATOM_STRING, 0, 0);
if ((reply = xcb_get_property_reply(c, cookie, NULL))) {
    int len = xcb_get_property_value_length(reply);
    if (len == 0) {
        printf("Zero Length\n");
        free(reply);
        return;
    }
    printf("WM_NAME is %.*s\n", len, (char*) xcb_get_property_value(reply));
}

Eclipse调试器

代码语言:javascript
复制
reply xcb_get_property_reply_t * 0x60bd40
    response_type uint8_t            1 '\001'
    format        uint8_t            0 '\0'
    sequence      uint16_t           2
    length        uint32_t           0
    type          xcb_atom_t         0
    bytes_after   uint32_t           0
    value_len     uint32_t           0
    pad0          unsigned char [12] 0x60bd54   

没有错误(我传递并检查了一个xcb_generic_error_t)。你知道什么会出错吗?也许我应该用Xlib代替..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-18 04:49:17

这段代码适用于我,它是js-ctype中的,但是您可以忽略这个部分,并将其用于API使用:

代码语言:javascript
复制
var win = aXcbWindowT;
// console.log('win:', win);

var req_title = ostypes.API('xcb_get_property')(ostypes.HELPER.cachedXCBConn(), 0, win, ostypes.CONST.XCB_ATOM_WM_NAME, ostypes.CONST.XCB_ATOM_STRING, 0, 100); // `100` means it will get 100*4 so 400 bytes, so that 400 char, so `rez_title.bytes_after` should be `0` but i can loop till it comes out to be 0
var rez_title = ostypes.API('xcb_get_property_reply')(ostypes.HELPER.cachedXCBConn(), req_title, null);
// console.log('rez_title:', rez_title);

var title_len = ostypes.API('xcb_get_property_value_length')(rez_title); // length is not null terminated so "Console - chrome://nativeshot/content/resources/scripts/MainWorker.js?0.01966718940939427" will be length of `88`, this matches `rez_title.length` but the docs recommend to use this call to get the value, i dont know why
console.log('title_len:', title_len, 'rez_title.contents.length:', rez_title.contents.length); // i think `rez_title.contents.length` is the actual length DIVIDED by 4, and rez_title_len is not dividied by 4

var title_buf = ostypes.API('xcb_get_property_value')(rez_title); // "title_len: 89 rez_title.contents.length: 23" for test case of "Console - chrome://nativeshot/content/resources/scripts/MainWorker.js?0.01966718940939427"
// console.log('title_buf:', title_buf);

var title = ctypes.cast(title_buf, ctypes.char.array(title_len).ptr).contents.readString();
console.log('title:', title);

ostypes.API('free')(rez_title);

return title;

不过,有时xcb_get_input_focus_reply_t->focus返回的内容并不是可以执行操作的窗口。我发现有时它没有标题,但是如果您使用xcb_query_tree,您可以发现它的父窗口可能有一个标题:

代码语言:javascript
复制
    var req_query = ostypes.API('xcb_query_tree')(ostypes.HELPER.cachedXCBConn(), win);
    var rez_query = ostypes.API('xcb_query_tree_reply')(ostypes.HELPER.cachedXCBConn(), req_query, null);
    console.log('rez_query.contents:', rez_query.contents);
    if (root === -1) {
        root = rez_query.contents.root;
    }
    win = rez_query.contents.parent; // this win should have the title
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35002526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档