Skip to content

Add xapp for Wallpaper and Screenshot in xfce-portals.conf

Follow-up to #181 (comment 79610)

According to my tests, only the Wallpaper and Screenshot interfaces deserve to be added to xfce-portals.conf for the time being.

They don't necessarily work as expected in all cases, for example Screenshot doesn't work in interactive mode and behaves as if in non-interactive mode instead of failing, which is debatable. And if we had our own implementation of these interfaces, we probably wouldn't use scripts or executables.

But since we don't implement our own backend and I don't think we plan to in the near future, I think it's worth adding them.

Here's a little program to test.
#include <glib.h>
#include <libportal/portal.h>

enum
{
  WALLPAPER,
  SCREENSHOT,
};
static gint interface = WALLPAPER;
static const gchar *image_uri = "file:///usr/share/backgrounds/xfce/xfce-shapes.svg";

static void
callback (GObject *source_object,
          GAsyncResult *res,
          gpointer loop)
{
  GError *error = NULL;

  switch (interface)
  {
    case WALLPAPER:
      if (!xdp_portal_set_wallpaper_finish (XDP_PORTAL (source_object), res, &error))
      {
        g_printerr ("set_wallpaper() failed: %s\n", error->message);
        g_error_free (error);
      }
      break;

    case SCREENSHOT:
      gchar *uri = xdp_portal_take_screenshot_finish (XDP_PORTAL (source_object), res, &error);
      if (uri == NULL)
      {
        g_printerr ("take_screenshot() failed: %s\n", error->message);
        g_error_free (error);
      }
      else
      {
        g_printerr ("take_screenshot() succeeded: %s\n", uri);
        g_free (uri);
      }
      break;

    default:
      g_warning ("Invalid interface");
  }

  g_main_loop_quit (loop);
  g_main_loop_unref (loop);
}

gint main (gint argc, gchar **argv)
{
  GMainLoop *loop = g_main_loop_new (NULL, FALSE);
  XdpPortal *portal = xdp_portal_new ();

  switch (interface)
  {
    case WALLPAPER:
      xdp_portal_set_wallpaper (portal, NULL, image_uri, XDP_WALLPAPER_FLAG_BACKGROUND, NULL, callback, loop);
      break;

    case SCREENSHOT:
      xdp_portal_take_screenshot (portal, NULL, XDP_SCREENSHOT_FLAG_INTERACTIVE, NULL, callback, loop);
      break;

    default:
      g_warning ("Invalid interface");
      return 1;
  }

  g_object_unref (portal);
  g_main_loop_run (loop);
}

To build it:

gcc ~/p.c -o ~/p $(pkg-config --cflags --libs libportal glib-2.0)

A bit of docs:

Wallpaper implementation:

Screenshot implementation:

Completes: d1f9afc0
Related: #181 (closed)

/cc @alexxcons @kelnos @andreldm

Merge request reports