Skip to content

Commit

Permalink
screenshot: Forward to modality to access dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Sodivad authored and GeorgesStavracas committed Jan 27, 2025
1 parent 1e1649d commit 93211fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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)
{
Expand Down
17 changes: 13 additions & 4 deletions tests/test_screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@pytest.fixture
def required_templates():
return {
"access": {},
"screenshot": {
"results": SCREENSHOT_DATA,
},
Expand All @@ -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,
Expand All @@ -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}},)
)
Expand Down

0 comments on commit 93211fb

Please sign in to comment.