nashaofu / xcap

XCap is a cross-platform screen capture library written in Rust. It supports Linux (X11, Wayland), MacOS, and Windows. XCap supports screenshot and video recording (to be implemented).

Home Page:https://docs.rs/xcap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ubuntu22.04在调用capture_area方法截图时弹出了系统自带的截图弹框

Selenium39 opened this issue · comments

在执行let image_result = screen.capture_area(top_left_x as i32, top_left_y as i32, rect_width, rect_height);这行代码时,弹出了系统自带的截图弹框,相同的代码在MacOS上无此问题,有什么解决办法吗?

Screenshot from 2023-09-22 11-23-34
Screenshot from 2023-09-22 11-31-39

https://github.com/nashaofu/screenshots-rs/blob/2dff55193d39611e10e0d0ae98eb7e935c232a9f/src/linux/wayland_screenshot.rs#L192C5-L192C31

https://github.com/nashaofu/screenshots-rs/blob/2dff55193d39611e10e0d0ae98eb7e935c232a9f/src/linux/wayland_screenshot.rs#L126C5-L126C5

明白了,原来是org_gnome_shell_screenshot执行失败后执行org_freedesktop_portal_screenshot请求截图时,会有一个系统的交互框。

org_gnome_shell_screenshot执行失败抛的异常为ScreenshotArea is not allowed

不过我还是不想要系统的这个交互框...

应该是wayland 的问题,这个目前没有啥好的办法避免,我也在寻找解决方案

One solution I can think of to fix this issue is to prioritize wlr instead of gnome, it sounds silly, but it could be useful

https://github.com/nashaofu/screenshots-rs/blob/2dff55193d39611e10e0d0ae98eb7e935c232a9f/src/linux/wayland_screenshot.rs#L192-L194

    wlr_screenshot(x, y, width, height)
        .or_else(|_| org_freedesktop_portal_screenshot(&conn, x, y, width, height))
        .or_else(|_| org_gnome_shell_screenshot(&conn, x, y, width, height))