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: Forward to modality to access dialog #1599

Merged
merged 2 commits into from
Jan 27, 2025
Merged
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
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
3 changes: 3 additions & 0 deletions tests/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def export(self, close_callback: Optional[Callable] = None):
self._close_callback = close_callback
return self

def unexport(self):
Sodivad marked this conversation as resolved.
Show resolved Hide resolved
self.mock.RemoveObject(self.handle)

def __str__(self):
return f"ImplRequest {self.handle}"

Expand Down
5 changes: 3 additions & 2 deletions tests/templates/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def closed_callback():
logger.debug(f"AccessDialog Close() response {response}")
cb_success(response.response, response.results)

def reply_callback():
def reply_callback(request):
response = Response(self.response, {})
logger.debug(f"AccessDialog with response {response}")
request.unexport()
Sodivad marked this conversation as resolved.
Show resolved Hide resolved
cb_success(response.response, response.results)

request = ImplRequest(self, BUS_NAME, handle)
Expand All @@ -65,7 +66,7 @@ def reply_callback():
request.export()

logger.debug(f"scheduling delay of {self.delay}")
GLib.timeout_add(self.delay, reply_callback)
GLib.timeout_add(self.delay, reply_callback, request)
except Exception as e:
logger.critical(e)
cb_error(e)
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
Loading