Skip to content

Commit b949162

Browse files
committed
session: Communicate close reason to impl
This lets the impl differentiate between a session that's closing because the app voluntarily called `Close()`, or because the app disconnected from the bus / some other reason.
1 parent 38dd2c0 commit b949162

File tree

10 files changed

+65
-22
lines changed

10 files changed

+65
-22
lines changed

data/org.freedesktop.impl.portal.Session.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,51 @@
3131
object, which will stay alive for the duration of the session.
3232
3333
The portal can abort the interaction by calling
34-
org.freedesktop.impl.portal.Session.Close() on the Session object.
34+
org.freedesktop.impl.portal.Session.CloseEx() on the Session object.
35+
36+
This documentation describes version 2 of this interface.
3537
-->
3638
<interface name="org.freedesktop.impl.portal.Session">
3739

3840
<!--
3941
Close:
4042
4143
Close the session.
44+
45+
This method is deprecated since version 2 of this interface and will no
46+
longer by called by xdg-desktop-portal.
4247
-->
4348
<method name="Close">
4449
</method>
4550

51+
<!--
52+
CloseEx:
53+
@options: Vardict with optional further information
54+
55+
Close the session.
56+
57+
Supported keys in the @options vardict include:
58+
59+
* ``voluntary`` (``b``)
60+
61+
A boolean that indicates whether the app voluntarily called Close on
62+
the session. If false, the session was closed by the portal.
63+
64+
Since version 2.
65+
-->
66+
<method name="CloseEx">
67+
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
68+
<arg type="a{sv}" name="options" direction="in"/>
69+
</method>
70+
4671
<!--
4772
Closed:
4873
4974
The session was closed by the portal implementation.
5075
-->
5176
<signal name="Closed">
5277
</signal>
78+
5379
<property name="version" type="u" access="read"/>
5480
</interface>
5581
</node>

src/global-shortcuts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ session_created_cb (GObject *source_object,
212212
}
213213

214214
if (should_close_session)
215-
xdp_session_close (session, FALSE);
215+
xdp_session_close (session, FALSE, FALSE);
216216
}
217217

218218
static XdpOptionKey global_shortcuts_create_session_options[] = {

src/inhibit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ create_monitor_done (GObject *source_object,
397397
}
398398

399399
if (should_close_session)
400-
xdp_session_close (session, FALSE);
400+
xdp_session_close (session, FALSE, FALSE);
401401
}
402402

403403
static gboolean

src/input-capture.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ create_session_done (GObject *source_object,
199199
}
200200

201201
if (should_close_session)
202-
xdp_session_close (session, FALSE);
202+
xdp_session_close (session, FALSE, FALSE);
203203
}
204204

205205
static gboolean
@@ -346,7 +346,7 @@ get_zones_done (GObject *source_object,
346346

347347
if (should_close_session)
348348
{
349-
xdp_session_close (session, TRUE);
349+
xdp_session_close (session, TRUE, FALSE);
350350
}
351351
}
352352

@@ -501,7 +501,7 @@ set_pointer_barriers_done (GObject *source_object,
501501
}
502502

503503
if (should_close_session)
504-
xdp_session_close (session, TRUE);
504+
xdp_session_close (session, TRUE, FALSE);
505505
}
506506

507507
static XdpOptionKey input_capture_set_pointer_barriers_options[] = {

src/location.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ handle_create_session (XdpDbusLocation *object,
468468
if (!xdp_session_export (session, &error))
469469
{
470470
g_warning ("Failed to export session: %s", error->message);
471-
xdp_session_close (session, FALSE);
471+
xdp_session_close (session, FALSE, FALSE);
472472
}
473473
else
474474
{
@@ -635,7 +635,7 @@ handle_start_in_thread_func (GTask *task,
635635
if (response != 0)
636636
{
637637
g_debug ("closing session");
638-
xdp_session_close (session, FALSE);
638+
xdp_session_close (session, FALSE, FALSE);
639639
}
640640
}
641641

src/remote-desktop.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ create_session_done (GObject *source_object,
283283
}
284284

285285
if (should_close_session)
286-
xdp_session_close (session, FALSE);
286+
xdp_session_close (session, FALSE, FALSE);
287287
}
288288

289289
static gboolean
@@ -392,7 +392,7 @@ select_devices_done (GObject *source_object,
392392

393393
if (should_close_session)
394394
{
395-
xdp_session_close (session, TRUE);
395+
xdp_session_close (session, TRUE, FALSE);
396396
}
397397
else if (!session->closed)
398398
{
@@ -688,7 +688,7 @@ start_done (GObject *source_object,
688688

689689
if (should_close_session)
690690
{
691-
xdp_session_close (session, TRUE);
691+
xdp_session_close (session, TRUE, FALSE);
692692
}
693693
else if (!session->closed)
694694
{

src/screen-cast.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ create_session_done (GObject *source_object,
214214
}
215215

216216
if (should_close_session)
217-
xdp_session_close (session, FALSE);
217+
xdp_session_close (session, FALSE, FALSE);
218218
}
219219

220220
static gboolean
@@ -321,7 +321,7 @@ select_sources_done (GObject *source_object,
321321

322322
if (should_close_session)
323323
{
324-
xdp_session_close (session, TRUE);
324+
xdp_session_close (session, TRUE, FALSE);
325325
}
326326
else if (!session->closed)
327327
{
@@ -823,7 +823,7 @@ start_done (GObject *source_object,
823823

824824
if (should_close_session)
825825
{
826-
xdp_session_close (session, TRUE);
826+
xdp_session_close (session, TRUE, FALSE);
827827
}
828828
else if (!session->closed)
829829
{

src/usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ handle_create_session (XdpDbusUsb *object,
841841
if (!xdp_session_export (session, &error))
842842
{
843843
g_dbus_method_invocation_return_gerror (invocation, error);
844-
xdp_session_close (session, FALSE);
844+
xdp_session_close (session, FALSE, FALSE);
845845
return G_DBUS_METHOD_INVOCATION_HANDLED;
846846
}
847847

src/xdp-session.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ xdp_session_unregister (XdpSession *session)
169169

170170
void
171171
xdp_session_close (XdpSession *session,
172-
gboolean notify_closed)
172+
gboolean notify_closed,
173+
gboolean voluntary)
173174
{
174175
if (session->closed)
175176
return;
@@ -199,8 +200,23 @@ xdp_session_close (XdpSession *session,
199200
{
200201
g_autoptr(GError) error = NULL;
201202

202-
if (!xdp_dbus_impl_session_call_close_sync (session->impl_session,
203-
NULL, &error))
203+
if (xdp_dbus_impl_session_get_version (session->impl_session) >= 2)
204+
{
205+
g_auto(GVariantBuilder) options_builder =
206+
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
207+
208+
g_variant_builder_add (&options_builder, "{sv}", "voluntary",
209+
g_variant_new_boolean (voluntary));
210+
211+
xdp_dbus_impl_session_call_close_ex_sync (session->impl_session,
212+
g_variant_builder_end (&options_builder),
213+
NULL, &error);
214+
}
215+
else
216+
xdp_dbus_impl_session_call_close_sync (session->impl_session,
217+
NULL, &error);
218+
219+
if (error != NULL)
204220
g_warning ("Failed to close session implementation: %s",
205221
error->message);
206222

@@ -221,7 +237,7 @@ handle_close (XdpDbusSession *object,
221237

222238
SESSION_AUTOLOCK_UNREF (g_object_ref (session));
223239

224-
xdp_session_close (session, FALSE);
240+
xdp_session_close (session, FALSE, TRUE);
225241

226242
xdp_dbus_session_complete_close (object, invocation);
227243

@@ -263,7 +279,7 @@ close_sessions_in_thread_func (GTask *task,
263279
XdpSession *session = l->data;
264280

265281
SESSION_AUTOLOCK (session);
266-
xdp_session_close (session, FALSE);
282+
xdp_session_close (session, FALSE, FALSE);
267283
}
268284

269285
g_slist_free_full (list, g_object_unref);
@@ -288,7 +304,7 @@ on_closed (XdpDbusImplSession *object, GObject *data)
288304
SESSION_AUTOLOCK_UNREF (g_object_ref (session));
289305

290306
g_clear_object (&session->impl_session);
291-
xdp_session_close (session, TRUE);
307+
xdp_session_close (session, TRUE, FALSE);
292308
}
293309

294310
static gboolean

src/xdp-session.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ gboolean xdp_session_export (XdpSession *session,
8787
void close_sessions_for_sender (const char *sender);
8888

8989
void xdp_session_close (XdpSession *session,
90-
gboolean notify_close);
90+
gboolean notify_close,
91+
gboolean voluntary);
9192

9293
static inline void
9394
auto_session_unlock_unref_helper (XdpSession **session)

0 commit comments

Comments
 (0)