Commit graph

583 commits

Author SHA1 Message Date
Peter Hutterer
a5cc87c837 Purge the properties from the protocol
The primary use-case for these properties in libei itself was to send
some fixed information (pid, cmdline and conection type). In the portal
case, these can be obtained out-of-band via the portal. In the
non-portal case these can be obtained from the socket itself (fetch pid,
look up /proc/pid/cmdline) which is just as reliable as trusting
whatever libei sends.

The only other use-case for the properties was the activation id in the
InputCapture::Activated portal signal. This can be achieved with a
serial in the START_EMULATING event.
2023-02-09 11:48:29 +10:00
Peter Hutterer
479bda259a Purge libreis from the repo
libreis was intended for an intermediary to set some information that
the libei client cannot be entrusted with. In particular this was the
application name, the allowed capabilities, and some properties that -
once set - the client could no longer change (appid as probably the only
really useful one). The price for this was a rather complicated version
negotiation dance before the initial CONNECT request.

Now that we have a clear view of what's going to happen -
RemoteDesktop.ConnectToEIS and the InputCapture portal - there is no
longer any need for libreis. The extra information that libreis would've
sent is communicated out-of-band in both portals and are known to the
compositor at the time the connection is being established.

So we can simply drop this, it's no longer required and dropping it
makes the protocol significantly simpler anyway.
2023-02-09 11:48:28 +10:00
Peter Hutterer
8d7d6ca8b7 proto: drop the Packet message, replace with 4 byte prefix
We need some sort of length field to be able to know how long the next
message is. But for simplicity, we might as well just write that
explicitly on the wire instead of wrapping our messages into yet another
message. This makes the wire format slightly simpler since the first 4
bytes are now always the length, without the previous 0x0d prefix
caused by the protobuf encoding.

0x0d == (field number << 3) | wire_type == 1 << 3 | 5
(see https://protobuf.dev/programming-guides/encoding/#structure)
2023-02-09 11:47:45 +10:00
Peter Hutterer
3bcb6fe7f7 proto: drop the varint values, replace with fixed size ones
uint32 in protobuf is encoded as VARINT (roughly similar to UTF-8 but
for numbers). Thats useful when you're sending lots of messages over the
net but in our case having a simple fixed-size protocol message format
is better.
2023-02-09 11:47:45 +10:00
Peter Hutterer
cb46522425 meson.build: move tests to test/meson.build
This requires that we add the top-level directory to includes so the
tests can find the config.h file.
2023-02-09 11:42:11 +10:00
Peter Hutterer
dd32adb319 brei: drop the explicit src in a #include statement 2023-02-09 11:42:03 +10:00
Peter Hutterer
520c20904e meson.build: use proper include handling for the proto dir 2023-02-09 11:42:03 +10:00
Peter Hutterer
5ea229d261 meson.build: switch the src include dir to the proper meson way 2023-02-09 11:42:03 +10:00
Peter Hutterer
85dff28743 meson.build: switch the source file lists to use files() 2023-02-09 11:42:03 +10:00
Peter Hutterer
a8961420db test: fix compiler warning about possible loss of precision
Let's make this a float division then to keep the compiler happy
2023-02-07 13:34:29 +10:00
Peter Hutterer
f9d691e98b eis: don't allow connecting a disconnected client 2023-02-02 15:17:24 +10:00
Peter Hutterer
8bdfc8cf18 test: fix a test case's behavior
The default behaviour of a peck context is to handle the CONNECT event.
Let's disable that.

No effect on the test, the client cannot receive the connect event until
it's been accepted, but it's better form anyway.
2023-02-02 15:17:09 +10:00
Peter Hutterer
19c85e7ee1 ei: fix a typo 2023-02-02 15:16:56 +10:00
Peter Hutterer
f0aceb7a88 Add a gitignore file for the subprojects directory 2023-02-02 15:16:55 +10:00
Peter Hutterer
e515edafa5 ei: re-order a few arguments to match the order in the protocol
No functional changes
2023-02-01 12:52:34 +10:00
Peter Hutterer
affc464caa util-time: fix the us2ms function
Turns out this was converting in the wrong direction and the only call
site we had didn't notice/care.
2023-02-01 12:52:34 +10:00
Peter Hutterer
642e258ecb Format python files with black
And set up a gitlab ci job to check that
2023-02-01 11:48:53 +10:00
Peter Hutterer
857735fe7f gitlab-ci: add one more explanatory comment
Just so the CI is a bit easier to understand
2023-01-06 10:23:51 +10:00
Peter Hutterer
e02cb8a015 gitlab CI: replace meson-build.sh with a more generic one
Copied from libinput, also used by libevdev these days.
2023-01-06 10:04:01 +10:00
Peter Hutterer
fde1424a42 gitlab CI: move default_artefacts to the default build template
No point having this as a separate template when the default build
template controls how things are built...
2023-01-06 10:04:01 +10:00
Peter Hutterer
19b4320594 gitlab CI: switch the ci-fairy job to the fdo ci-fairy image 2023-01-06 10:04:01 +10:00
Peter Hutterer
c3b250ba2e gitlab CI: compress the file inclusion a bit
Just make it a bunch of files from a single project, rather than one
project each per file.
2023-01-06 09:56:12 +10:00
Peter Hutterer
42dbcf59c9 gitlab CI: drop the container clean stage
We don't have scheduled rebuilds so the containers build need to hang
around since they're almost certainly in use. Container expiry is
handled site-wide now anyway.
2023-01-06 09:56:12 +10:00
Peter Hutterer
528f6d4d4b gitlab CI: drop the reference to the forced container rebuild
Copy/paste from libinput where most of this came from, we've never had
forced container rebuilds in libei.
2023-01-06 09:17:50 +10:00
Peter Hutterer
c29b65eaf6 meson.build: add override_dependencies for all our libraries
This makes it easier to use libei as a subproject.
2022-12-12 09:07:24 +10:00
Peter Hutterer
7e058b3fa8 libei 0.4.1 2022-12-09 20:08:01 +10:00
Peter Hutterer
ddd704d6e8 libei 0.4 2022-12-09 13:32:29 +10:00
Olivier Fourdan
39f3ec007b liboeffis: protect from interrupted system calls
In various places, including the DBUS calls which can take some time, if
a SIGALRM triggers, the call will fail.

To prevent this from happening, use the wrappers when possible and make
sure to block the SIGALRM signal when issuing DBUS calls.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-08 12:37:46 +10:00
Olivier Fourdan
8bcbc53c0f ei: Use the signal protected wrappers
To prevent against unexpected interrupted system calls.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-08 12:37:46 +10:00
Peter Hutterer
1991b8f52d util: change the signal handler to a context-manager like macro
Change the signal-blocking helper to take a vararg list of signals to
block and provide a magic macro that works like python's context
manager, using  attribute(cleanup).

In our for loop we create a new struct with the old sigmask and a
boolean that's always true. We enter the body of the loop once and
set that boolean to false on the second run, i.e. we never do more than
one run. On loop exit, the destroy function for our struct restores the
previous signal mask.
2022-12-08 12:37:46 +10:00
Olivier Fourdan
0d3a398fee util: Add a wrapper for dup() and pipe2()
The wrappers take care of blocking the SIGALRM signal.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-08 12:37:46 +10:00
Olivier Fourdan
0ac9b1b02d util: Protect system calls against signals
Most system calls will fail if interrupted by a SIGALRM. Make sure we
block SIGALRM prior to do the syscall, and restore the set of signals
afterwards.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-08 12:37:46 +10:00
Olivier Fourdan
085f96c3bb util: Add block/release signals API
Add a couple of simple helper functions to block and releaset he SIGALRM
signal.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-08 12:37:46 +10:00
Peter Hutterer
eeefb3dc00 liboeffis is a wrapper library for the RemoteDesktop communication
libei used to have direct portal support code (see the git history) but:
- that code was a custom proposed portal that never went anywhere
- libei has slowly changed to be more an input event transport layer since
  it is now also used sending events *to* a libei context
- a number of libei users will never need the DBus code, either because they
  don't want it or because they talk Dbus themselves na ddon't need this
  abstraction.

Luckily, it's quite easy to move this into a separate library with a
simple API that does, effectively, the same trick as the old portal backend.
This API is aiming to be as simple as possible because the tools that
require anything more complex should talk to DBus directly.

An example tool that uses the API to retrieve an EIS fd over the
RemoteDesktop portal is included in this patch.

"Öffis" is a German word meaning public transport. It also sounds like the
French Œuf, the word for egg.

Co-authored-by: Olivier Fourdan <ofourdan@redhat.com>
2022-12-08 11:22:50 +10:00
Peter Hutterer
8fc654bfb0 Purge the portal code
The original idea here was that we would have an EmulatedInput portal
that allows the application to connect directly to the EIS
implementation to exchange input events - instead of ping-ponging DBus
events through the xdg-desktop-portal as the RemoteDesktop portal
requires.

This is no longer accurate, there are suggested PRs open to add
RemoteDesktop.ConnectToEIS to achieve the same through the existing
RemoteDesktop interface [1] and to add a new InputCapture portal
to allow for events to be sent to a libei receiver context [2].

The example EmulatedInput portal is thus superfluous and can be removed
from here.

We could switch the ei_setup_backend_portal() code to use RemoteDesktop
or InputCapture, depending on the context type, the utility of this is
questionable. Interaction with portals is complex, one needs to
implement the Session/Request interfaces correctly and in the case of
InputCapture also handle the complex zones/pointer barrier setup.
libportal does some of this (or it will, anyway) so it's more useful for
an application to use libportal and then just pass the received fd to
libei.

If there is a future need for this to be handled as part of libei, we
can (re)implement this, but for now it's best to just purge all of this.

[1] https://github.com/flatpak/xdg-desktop-portal/pull/762
[2] https://github.com/flatpak/xdg-desktop-portal/pull/714
2022-12-08 10:45:47 +10:00
Peter Hutterer
97254391dc README: swap to RemoteDesktop over the nonexistent EmulatedInput portal
At least for event replaying it looks like we'll go through the
RemoteDesktop portal instead of creating another one that doesn't
provide any additional benefits.

See https://github.com/flatpak/xdg-desktop-portal/pull/762
2022-12-08 10:45:34 +10:00
Peter Hutterer
903baf27ba CI: bump to latest ci-templates 2022-12-05 15:11:41 +10:00
Peter Hutterer
d741b3b7ce CI: bump to Fedora 37
Fedora 35 is EOL
2022-12-05 15:05:01 +10:00
Peter Hutterer
7713ad5ac5 CI: purge all references to the master branch 2022-12-05 15:05:01 +10:00
Peter Hutterer
260ae90d91 meson.build: fix an indentation issue 2022-12-05 14:52:47 +10:00
Peter Hutterer
d5b813d677 doc: fix a comment in util-mem.h 2022-12-01 18:56:18 +10:00
Peter Hutterer
9d5ec147a1 doc: fix a doxygen warning about a wrong parameter name 2022-12-01 18:56:18 +10:00
Peter Hutterer
06469e737b doc: fix two references to function calls 2022-11-29 15:25:07 +10:00
Olivier Fourdan
99b0eb4587 Fix absolute events filtering
When a device has multiple regions, ei_device_pointer_motion_absolute()
would walk all of the regions and bail out if the coordinates are
outside any region.

As a matter of facts, it means that an absolute event must fall within
all the device regions to succeed.

That doesn't seem right, it should be the opposite, the coordinates must
be within at least one region.

Fix the logic by reusing the existing ei_device_in_region() function.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2022-09-16 16:03:30 +02:00
Peter Hutterer
29da572dca proto: separate pre-connection properties into ConfigureProperty
This is primarily for namespacing: where a portal sets some properties
it needs to do so *before* the Connect event. By moving this out to a
different namespace we can separate this easier, avoiding a portal
accidentally sending a property event after it has already passed the fd
to the client.

Fixes #23
2022-09-07 10:07:56 +10:00
Peter Hutterer
bc78c24290 Fix some logging linebreak issues
One excessive linebreak, another one was missing.
2022-09-07 10:03:11 +10:00
Peter Hutterer
2d143904c2 proto: add versioned Configure transactions
The same socket is used for pre-connection configuration by a portal and
for the actual client that then uses the data. The portal and the client
may need different protocol versions *and* there may be different REIS
intermediaries.

So let's allow version negotiation for the configuration through
transactions: a REIS intermediary must start/finish a transaction with a
given version number.

This is only partially implemented in libreis right now: each API call
is wrapped in a transaction. Since we support version 1 only anyway,
there's no need to do anything but send our version down the wire. In
the future where we actually need to negotiate, libreis will need a
reis_dispatch() so we can wait for the server version to arrive, parse
it, etc. before sending ConfigureVersion down the wire. It's likely this
will never be needed.
2022-09-07 09:43:03 +10:00
Peter Hutterer
5535692ee0 proto: allow the client to set the protocol version
Let the client set the version number it wants on Connect. There is new
public API to query the client/server's version as set once the connect
finished (eis_client_get_version() and ei_get_version()) but there is
currently no public API for the client to select the version it actually
wants, other than whatever both support. IOW, it's not possible for the
client to say "I want version 8 but if that's not supported, use version
5".
2022-09-07 09:42:59 +10:00
Peter Hutterer
08a4ce4aac proto: add a version exchange prior to connect
Add a new protocol message "GetVersion" and the matching reply from the
server with "Version" that can be sent at any time. The server always
replies with the highest protocol version it supports, allowing the
client to choose the protocol version it wants.

These two messages also have a fixed string to make the protocol easy to
identify in hexdumps.

To avoid roundtrips on connection, libeis immediately sends the Version
message. Ideally and by the time the client actually starts, that
version is already available and we can continue without requiring a
full roundtrip.

This patch only adds the version exchange with the server, it does not
yet add the bits for the client to actually set the version.
2022-09-07 09:30:39 +10:00
Peter Hutterer
1592fdd57f Add a version macro for grepable version numbers
Makes it a lot easier than to grep for the lonely 1 or 2 in a codebase
somewhere.
2022-09-07 09:20:27 +10:00