gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:08:01 25 4
gpt4 key购买 nike

我可以使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com