linux - X11/XCB/Xlib : Copy root window to pixmap

标签 linux x11 xlib xserver xcb

我可以使用 xcb_image_get() 将根窗口的内容复制到客户端(即 CPU)内存中的 xcb_image_t(无论其 map 状态,尽管根窗口可能总是映射?)。例如:

xcb_image_t* xcb_img = xcb_image_get(xcb_connection, xcb_screen->root, 0, 0, xcb_screen->width_in_pixels, xcb_screen->height_in_pixels, 0x00ffffff, XCB_IMAGE_FORMAT_Z_PIXMAP);

现在根窗口的像素在xcb_img->data中。

但我试图将根窗口的内容复制到 xcb_pixmap_t(在服务器内存中),但它不起作用(调用无效 失败,但它返回垃圾,就好像窗口没有被映射一样):

  xcb_void_cookie_t    copy_cookie = xcb_copy_area_checked(xcb_connection, xcb_screen->root, xcb_pixmap, xcb_gc_null, 0, 0, 0, 0, xcb_screen->width_in_pixels, xcb_screen->height_in_pixels);
  xcb_generic_error_t* copy_error  = xcb_request_check(xcb_connection, copy_cookie);
  if(copy_error)
    exit(1);

但是,它适用于碰巧被映射的其他窗口(并且对于那些被其他窗口遮挡的窗口的子区域,从副本返回垃圾的意义上说,它会失败。)

我知道一个窗口需要被映射才能有有意义的内容。这让我认为根窗口从未被映射(或其他)。

All I want is to copy the contents of the display (ie. the pixels that are currently being shown in the physical display/monitor) to an xcb_pixmap_t (or, equivalently, to an Xlib Pixmap). How can I do this? (It works so easily for xcb_get_image()...)

最佳答案

您希望您的 GC 将 SubwindowMode 设置为 IncludeInferiors(默认为 ClipByChildren)。

来自X11协议(protocol)描述:

For ClipByChildren, both source and destination windows are additionally clipped by all viewable InputOutput children. For IncludeInferiors, neither source nor destination window is clipped by inferiors. This will result in including subwindow contents in the source and drawing through subwindow boundaries of the destination. The use of IncludeInferiors with a source or destination window of one depth with mapped inferiors of differing depth is not illegal, but the semantics is undefined by the core protocol.

https://www.x.org/releases/X11R7.5/doc/x11proto/proto.html

这意味着对于 ClipByChildren,您只是从用作源的窗口进行复制。如果窗口有子窗口,“那里”的像素不属于您用作源的窗口。因此,X11 假定您不需要这些像素。

关于linux - X11/XCB/Xlib : Copy root window to pixmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50957326/

相关文章:

cairo - 合成器如何在 X 上工作?

linux - 由于 'no permission',向 Hudson/build 授予权限失败

c++ - 读取 RSysLog tcp 消息

x11 - XSync - 丢弃参数是什么意思?

transparency - 如何创建位深度为 32 的窗口

c - xlib - 打印事件名称

linux - 在 linux 中不使用 "cat"命令读取大文件的内容

c - 无法理解 Linux 内核模块中 read_proc 的工作

c++ - 在 Linux 中确定程序是 GUI 还是控制台应用程序

在 Xlib 中点击透明窗口