我怎样才能在Wayland上截屏?Wayland、上截屏

2023-09-03 10:35:28 作者:二着二着就疯了

现在我需要开发一个插件,可以在Ubuntu、CentOS和Fedora上截屏。我试着用Xlib编写它。它可以在Ubuntu和CentOS上运行,但Fedora使用的是Wayland,我开发的插件无法运行。

Gnome截图可以在这些平台上运行,但我看了他的源代码后发现,它可以通过调用其他进程来实现截图,这对我来说是很难学习的。

如何使用 Windows 10 的内置截屏工具

有什么办法可以在Wayland Engine上截屏吗?

推荐答案

我是使用dbus获得的,以下是轻量级代码:

    method_name = "Screenshot";
    method_params = g_variant_new ("(bbs)",
                                     TRUE,
                                     FALSE, /* flash */
                                     filename);

    connection = g_application_get_dbus_connection (g_application_get_default ());
    g_dbus_connection_call_sync (connection,
                               "org.gnome.Shell.Screenshot",
                               "/org/gnome/Shell/Screenshot",
                               "org.gnome.Shell.Screenshot",
                               method_name,
                               method_params,
                               NULL,
                               G_DBUS_CALL_FLAGS_NONE,
                               -1,
                               NULL,
                               &error);