Skip to content

Commit

Permalink
Screenshot: Add an 'type' option
Browse files Browse the repository at this point in the history
This option allows to select the type (screen, window, area) of screenshot
to be taken. Useful for apps that want to do the interactive parts
themselves but still allow the user these different types of screenshots.
This is only a hint, backends may not implement all of these.
  • Loading branch information
leolost2605 committed Aug 9, 2024
1 parent c8359ea commit acf0f6f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
13 changes: 12 additions & 1 deletion data/org.freedesktop.impl.portal.Screenshot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
This screenshot portal lets sandboxed applications request a screenshot.
This documentation describes version 2 of this interface.
This documentation describes version 3 of this interface.
-->
<interface name="org.freedesktop.impl.portal.Screenshot">
<!--
Expand All @@ -50,6 +50,17 @@
Hint whether the dialog should offer customization before taking a screenshot.
Defaults to no.
* ``type`` (``u``)
Hints what type of screenshot should be taken. May preselect the type if combined with interactive.
Default is 0. Accepted values are:
- ``0``: Entire screen (default)
- ``1``: A window to be selected by the user
- ``2``: An area to be selected by the user
**Since version 3.**
* ``permission_store_checked`` (``b``)
Hint whether the screenshot portal has checked the 'screenshot' permission for
Expand Down
13 changes: 12 additions & 1 deletion data/org.freedesktop.portal.Screenshot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
may involve adding it to the :ref:`Documents
portal<org.freedesktop.portal.Documents>`).
This documentation describes **version 2** of this interface.
This documentation describes **version 3** of this interface.
-->
<interface name="org.freedesktop.portal.Screenshot">
<!--
Expand Down Expand Up @@ -57,6 +57,17 @@
Hint whether the dialog should offer customization before taking a screenshot.
Default is no. **Since version 2.**
* ``type`` (``u``)
Hints what type of screenshot should be taken. May preselect the type if combined with interactive.
Default is 0. Accepted values are:
- ``0``: Entire screen (default)
- ``1``: A window to be selected by the user
- ``2``: An area to be selected by the user
**Since version 3.**
The following results get returned via the :ref:`org.freedesktop.portal.Request::Response`
signal:
Expand Down
22 changes: 21 additions & 1 deletion src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "config.h"

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
Expand Down Expand Up @@ -178,9 +179,28 @@ screenshot_done (GObject *source,
g_task_run_in_thread (task, send_response_in_thread_func);
}

static gboolean
validate_type (const char *key,
GVariant *value,
GVariant *options,
GError **error)
{
uint32_t type = g_variant_get_uint32 (value);

if (type > 2)
{
g_set_error (error, XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Invalid screenshot type: %x", type);
return FALSE;
}

return TRUE;
}

static XdpOptionKey screenshot_options[] = {
{ "modal", G_VARIANT_TYPE_BOOLEAN, NULL },
{ "interactive", G_VARIANT_TYPE_BOOLEAN, NULL }
{ "interactive", G_VARIANT_TYPE_BOOLEAN, NULL },
{ "type", G_VARIANT_TYPE_UINT32, validate_type }
};

static void
Expand Down

0 comments on commit acf0f6f

Please sign in to comment.