xcb_get_image_reply 在另一个 workspace/desktop 上 window 失败

xcb_get_image_reply fails for window on another workspace/desktop

Ubuntu (xfce) 提供虚拟桌面又名工作区。我想获取放置在另一个虚拟桌面上的应用程序的屏幕截图。我成功创建了 xcb 连接,我可以通过标题找到 window 个应用程序。问题是 xcb_get_image_reply 失败了。我这样做:

    auto cookie = xcb_get_image(m_XCBConnection, XCB_IMAGE_FORMAT_Z_PIXMAP, m_XCBWindow, x, y, width, height, ~0);
    xcb_generic_error_t * err = nullptr;
    auto image = xcb_get_image_reply(m_XCBConnection, cookie, &err);

    // xcb_connection_has_error( m_XCBConnection ) returns no error

    if ( err ) {
        // here I have err->error_code == 8
        free( err );
    }

如果我理解正确 XCB errors encodings and general XCB errors explanation 我得到的错误描述为:

Match An InputOnly window is used as a DRAWABLE. In a graphics request, the GCONTEXT argument does not have the same root and depth as the destination DRAWABLE argument. Some argument (or pair of arguments) has the correct type and range, but it fails to match in some other way required by the request.

但是我不知道该怎么办。

注意:如果两个应用程序都在同一个虚拟桌面上,上述解决方案就可以正常工作。

引用自https://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.html#requests:GetImage

If the drawable is a window, the window must be viewable, [...] (or a Match error results).

因此,GetImage 请求失败,因为您要截屏的 window 不可见。 X11 服务器不会(真的)保留屏幕上可见内容之外的任何内容。其他所有内容都不会保存在任何地方。

I would like to get a screenshot of an application which is placed on another virtual desktop.

基本上:X11 无法做到这一点,除了切换到另一个虚拟桌面,等待(如何?)有问题的 window 重新绘制自己,然后抓取屏幕截图。