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

Add support for the InputCapture portal #96

Merged
merged 4 commits into from
Oct 18, 2023

Conversation

whot
Copy link
Contributor

@whot whot commented Jun 2, 2022

For the corresponding Portal PR, please see flatpak/xdg-desktop-portal#714

This is a draft PR to add support for the input capture portal. Most of it is straightforward portal implementation but this portal does have a larger surface and more state than most, which raises a few questions:

  • XdpSession is re-used for input capture portals now too. This makes namespacing (or the lack thereof) slightly awkward, e.g. the activated signal on the session is instead inputcapture-activated to avoid future conflicts, which then requires the other signals to be namespaced too.
  • XdpInputCaptureSession now contains an XdpSession and the API is namespaced properly.
  • The enable/disable/release methods are paired with their respective _finish, but tbh this is of questionable value. Even if the portal keeps these as requests, I'd argue hiding this away here would make for better API - we can use the session signals to notify the caller out-of-band. Update June 06: these are method calls now
  • the pointer barriers and capture zones have their own GObjects with properties and little other functionality. This makes for slightly more sensible API but it also conflicts a bit with e.g. XdpSession which doesn't have properties but setters/getters only.
  • the Disabled signal is still missing here I just noticed
  • there's a dbusmock/pytest based test suite included. that won't run without patched dbus-python and dbusmock but it makes testing so much easier. specifically, it allows to test libportal without an existing implementation of the actual portal. Merged to main in test: add a pytest/dbusmock-based test suite #99, this is just the inputcapture tests now

The above are the larger topics, I'd appreciate a high-level review of the API and suggestions for where to go with this.

cc @jadahl

@whot whot force-pushed the wip/inputcapture branch 2 times, most recently from 31b8414 to 145192d Compare August 18, 2022 11:01
@whot whot force-pushed the wip/inputcapture branch 3 times, most recently from e0650f3 to b4ab8ed Compare August 30, 2022 05:34
@whot
Copy link
Contributor Author

whot commented Aug 30, 2022

if anyone is following along: the most recent changes from today change the implementation so that we have an API that creates and takes XdpInputCaptureSession objects. Inside that object is an XdpSession object that represents the session, it's exposed to the user on request via xdp_input_capture_session_get_session() so the user can e.g. subscribe to closed.

This is basically a working implementation of #112 (while not touching the RD/SC API) and should eventually allow us to create an InputCapture session from an existing XdpSession object, see flatpak/xdg-desktop-portal#864.

Copy link

@jadahl jadahl left a comment

Choose a reason for hiding this comment

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

Some light review so far only, looks good to me so far.

libportal/portal-private.h Outdated Show resolved Hide resolved
struct _XdpInputCaptureSession
{
GObject parent_instance;
XdpSession *parent_session; /* strong ref */
Copy link

Choose a reason for hiding this comment

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

IMO this approach to session object management makes more sense to me.

libportal/inputcapture.h Show resolved Hide resolved
libportal/inputcapture-pointerbarrier.c Outdated Show resolved Hide resolved
libportal/inputcapture.c Outdated Show resolved Hide resolved
libportal/inputcapture-pointerbarrier.c Outdated Show resolved Hide resolved
libportal/inputcapture-pointerbarrier.c Outdated Show resolved Hide resolved
libportal/inputcapture-private.h Outdated Show resolved Hide resolved
@whot
Copy link
Contributor Author

whot commented Sep 7, 2022

Just FTR, this now sits on top of #114 because I need both to work at the same time and juggling branches is annoying.

@whot
Copy link
Contributor Author

whot commented Aug 7, 2023

marking as ready, I stared at this for too long, I can no longer see any bugs...

@Conan-Kudo
Copy link
Contributor

What's keeping this from landing at this point? It seems to have been sitting in a ready state for a month now...

Copy link
Member

@GeorgesStavracas GeorgesStavracas left a comment

Choose a reason for hiding this comment

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

One small comment. LGTM otherwise.

libportal/inputcapture.h Outdated Show resolved Hide resolved
libportal/inputcapture-pointerbarrier.c Outdated Show resolved Hide resolved
libportal/inputcapture-zone.c Outdated Show resolved Hide resolved
libportal/inputcapture-zone.c Outdated Show resolved Hide resolved
libportal/inputcapture-pointerbarrier.c Outdated Show resolved Hide resolved
guint zone_set;
};

G_DEFINE_TYPE (XdpInputCaptureSession, xdp_input_capture_session, G_TYPE_OBJECT)
Copy link

Choose a reason for hiding this comment

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

Suggested change
G_DEFINE_TYPE (XdpInputCaptureSession, xdp_input_capture_session, G_TYPE_OBJECT)
G_DEFINE_FINAL_TYPE (XdpInputCaptureSession, xdp_input_capture_session, G_TYPE_OBJECT)

This way, people will get a warning if they try subclassing the type by using the instance/class sizes known to the type system.

Copy link

Choose a reason for hiding this comment

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

Done.

Copy link

Choose a reason for hiding this comment

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

Undone, sorry, that breaks the build (CI) with Ubuntu 20.04.

gboolean is_valid;
};

G_DEFINE_TYPE (XdpInputCaptureZone, xdp_input_capture_zone, G_TYPE_OBJECT)
Copy link

Choose a reason for hiding this comment

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

Suggested change
G_DEFINE_TYPE (XdpInputCaptureZone, xdp_input_capture_zone, G_TYPE_OBJECT)
G_DEFINE_FINAL_TYPE (XdpInputCaptureZone, xdp_input_capture_zone, G_TYPE_OBJECT)

This way, people using the type system to query the instance and class sizes in order to subclass this type will hit an assertion failure.

Copy link

Choose a reason for hiding this comment

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

Done as well.

Copy link

Choose a reason for hiding this comment

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

Undone, sorry, that breaks the build (CI) with Ubuntu 20.04.

libportal/inputcapture.c Outdated Show resolved Hide resolved
Comment on lines +285 to +286
if (call->cancelled_id)
{
g_signal_handler_disconnect (g_task_get_cancellable (call->task), call->cancelled_id);
call->cancelled_id = 0;
}
Copy link

Choose a reason for hiding this comment

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

Suggested change
if (call->cancelled_id)
{
g_signal_handler_disconnect (g_task_get_cancellable (call->task), call->cancelled_id);
call->cancelled_id = 0;
}
g_clear_signal_handler (&call->cancelled_id, g_task_get_cancellable (call->task));

Copy link

Choose a reason for hiding this comment

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

Done.

Copy link

Choose a reason for hiding this comment

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

Undone, sorry, that breaks the build (CI) with Ubuntu 20.04.

libportal/inputcapture.c Outdated Show resolved Hide resolved
@matthiasclasen
Copy link
Contributor

I had this on my list to look at today. Thanks for beating me to it, @ebassi

The Session is no longer unique to RemoteDesktop/ScreenCast and
shouldn't be treated as such. Let's split this out so we can use the
same object across other interfaces.

The session state is a bit more difficult since it is also related to
RD/SC only but it's more spaghettied in.
Disentangle the generic Session is-closed state from the
ScreenCast/RemoteDesktop-specific case.

The more detailed SessionState is specific to SC/RD - INITIAL and CLOSED
is generic enough that we can make it a generic API.
@@ -50,6 +50,7 @@ static void
xdp_session_finalize (GObject *object)
{
XdpSession *session = XDP_SESSION (object);
g_warning ("session finalize");
Copy link

Choose a reason for hiding this comment

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

Spurious warning.

Copy link

Choose a reason for hiding this comment

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

Removed

@ofourdan ofourdan force-pushed the wip/inputcapture branch 4 times, most recently from 52933d3 to 7371f61 Compare October 4, 2023 08:25
@ofourdan
Copy link

ofourdan commented Oct 4, 2023

Many thanks for the review!

I have applied the changes and forced push to @whot's branch now.

Please also note that I had to drop a few suggested changes at it was breaking the build on Ubuntu 20.04 for the CI (I suspect the version of Glib is older on that target).

@whot whot force-pushed the wip/inputcapture branch 3 times, most recently from b26f232 to 75e9aef Compare October 6, 2023 06:00
@whot
Copy link
Contributor Author

whot commented Oct 9, 2023

ftr, I fixed a buggy test case, but this branch should still be ready to go.

This patch adds a new XdpSession type for the input capture protocol as
well as as the methods provided by that portal to work on that session.

Two helper objects are available now too: XdpInputCaptureZone and
XdpInputCapturePointerBarrier
This also fixes the invocation of EmitSignalDetailed() which dated back
to an earlier version of that dbusmock feature. Since we never used it,
the wrong invocation got past the tests.
@whot
Copy link
Contributor Author

whot commented Oct 17, 2023

gentle ping for merging :)

@GeorgesStavracas GeorgesStavracas merged commit 1add346 into flatpak:main Oct 18, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants