From 93211fb4f4209b2f03f2ecd95a4d7104225b0395 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Thu, 23 Jan 2025 09:52:54 +0100 Subject: [PATCH] screenshot: Forward to modality to access dialog --- src/screenshot.c | 6 ++++++ tests/test_screenshot.py | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/screenshot.c b/src/screenshot.c index ffb48fc63..40d092e21 100644 --- a/src/screenshot.c +++ b/src/screenshot.c @@ -204,6 +204,7 @@ handle_screenshot_in_thread_func (GTask *task, GVariant *options; gboolean permission_store_checked = FALSE; gboolean interactive; + gboolean modal; const char *parent_window; const char *app_id; @@ -221,6 +222,9 @@ handle_screenshot_in_thread_func (GTask *task, if (!g_variant_lookup (options, "interactive", "b", &interactive)) interactive = FALSE; + if (!g_variant_lookup (options, "modal", "b", &modal)) + modal = TRUE; + if (!interactive && permission != XDP_PERMISSION_YES) { g_autoptr(GVariant) access_results = NULL; @@ -243,6 +247,8 @@ handle_screenshot_in_thread_func (GTask *task, "grant_label", g_variant_new_string (_("Allow"))); g_variant_builder_add (&access_opt_builder, "{sv}", "icon", g_variant_new_string ("applets-screenshooter-symbolic")); + g_variant_builder_add (&access_opt_builder, "{sv}", + "modal", g_variant_new_boolean (modal)); if (g_strcmp0 (app_id, "") != 0) { diff --git a/tests/test_screenshot.py b/tests/test_screenshot.py index a9dd78318..d0b2999be 100644 --- a/tests/test_screenshot.py +++ b/tests/test_screenshot.py @@ -21,6 +21,7 @@ @pytest.fixture def required_templates(): return { + "access": {}, "screenshot": { "results": SCREENSHOT_DATA, }, @@ -31,13 +32,12 @@ class TestScreenshot: def test_version(self, portals, dbus_con): xdp.check_version(dbus_con, "Screenshot", 2) - def test_screenshot_basic(self, portals, dbus_con, app_id): + @pytest.mark.parametrize("modal", [True, False]) + @pytest.mark.parametrize("interactive", [True, False]) + def test_screenshot_basic(self, portals, dbus_con, app_id, modal, interactive): screenshot_intf = xdp.get_portal_iface(dbus_con, "Screenshot") mock_intf = xdp.get_mock_iface(dbus_con) - modal = True - interactive = True - request = xdp.Request(dbus_con, screenshot_intf) options = { "modal": modal, @@ -62,6 +62,15 @@ def test_screenshot_basic(self, portals, dbus_con, app_id): assert args[3]["modal"] == modal assert args[3]["interactive"] == interactive + # check that args were forwarded to access portal correctly + if not interactive: + method_calls = mock_intf.GetMethodCalls("AccessDialog") + assert len(method_calls) > 0 + _, args = method_calls[-1] + assert args[1] == app_id + assert args[2] == "" # parent window + assert args[6]["modal"] == modal + @pytest.mark.parametrize( "template_params", ({"screenshot": {"expect-close": True}},) )