Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshot: Allow selecting the type of screenshot #1415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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``)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think type is not very descriptive, because many parts of D-Bus and GLib and etc already use "type" for other things. When it comes to screenshots, I feel like mode fits better. What do you think?


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
21 changes: 20 additions & 1 deletion src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,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)
{
guint32 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: %u", 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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
{ "type", G_VARIANT_TYPE_UINT32, validate_type }
{ "type", G_VARIANT_TYPE_UINT32, validate_type },

};

static void
Expand Down
Loading