Commit graph

105 commits

Author SHA1 Message Date
Peter Hutterer
5c017654e8 ei: always queue a disconnect event locally
In the case of a refused portal connection we get disconnected before we
had a chance to send the CONNECT message. This still needs to queue a
disconnect event and thus bubble back up to the caller.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-26 16:43:06 +10:00
Peter Hutterer
ed208f8374 ei: add an ei.connection.type property to be filled in automatically
Planned values: 'socket' and 'portal', the latter to be set by the
portal.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-26 12:47:07 +10:00
Peter Hutterer
1225bcb0e1 Add a property API for generic key/value exchanges
There is data that libei and the EIS implementation will want to
exchange that is not covered by the immediate API.

To avoid having to add APIs for all of these, let's provide a generic
property API that both server and client can use to exchange this info.

The property API provides read/write/delete permissions but those only
apply to the client, not the server. The idea is that a server can
create (or restrict) properties that the client can read but not modify
and/or delete. A special-case are properties filled in automatically by
libei: ei.application.pid and ei.application.cmdline. These could be
used by e.g. the portal implementation to match permissions.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-25 13:35:36 +10:00
Peter Hutterer
1bb5e103ab Split connect into an additional connect_done
This allows us to transmit extra information about the client before the
server has to decide on whether it wants to connect us.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-25 11:25:32 +10:00
Peter Hutterer
a03f547989 proto: add a start/stop emulating message pair
This effectively provides the EIS implementation with a notification
that the client will actually send events in the near future. To be used
by e.g. synergy-like clients when the pointer enters the logical screen
so that the EIS implementation can flash a warning or something.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-24 13:14:20 +10:00
Peter Hutterer
1884785a8a Add a scroll stop/cancel event
This allows a client to trigger kinetic scrolling (or prevent it).
For compositors implementing EIS, the only realistic scroll source is
continuous which allows for scroll stop events. So let's give the client
the opportunity to trigger those on demand.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-24 09:21:05 +10:00
Peter Hutterer
55594cd09c Add a frame event to logically group events together
Already present in e.g. libinput and wayland, this event allows us to
group several events together to denote them as a logical group.
Required for multi-touch but as we've learned with Wayland it's also
required to group other events (scroll events in the case of Wayland).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-24 09:21:05 +10:00
Peter Hutterer
6f70e97cce Implement key modifier mask events similar to Wayland
Since the server controls the keymap, and that keymap is likely merged
with some other device let's add the events so we notify the client of
things like numlock-is-down etc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-23 15:03:15 +10:00
Peter Hutterer
b08ec3cea4 ei: split event handling into its own source file
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-23 12:26:07 +10:00
Peter Hutterer
f8c2078bd3 ei: use a getter for ei_event_get_seat
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-23 12:26:07 +10:00
Peter Hutterer
fa7b624f93 Rename suspend to pause to indicate it's a "lighter" form of suspending
There's nothing in the protocol to modify the client device state from
the server, so a pause/resume cycle must leave the client with the
same(-ish) state. Pause is really just that, a short "no event now
please". Anything that would require e.g. modifying the device state by
releasing keys or buttons should result in the device being removed and
re-added.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-23 08:34:44 +10:00
Peter Hutterer
eaefaecdd0 eis: fix the seat assignment
We're using the upper bits for seats, just adding 1 clashes with the
device ids.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-17 16:08:26 +10:00
Peter Hutterer
86bac02026 ei: remove another layer of indirection before we hit the protocol
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-11 11:59:57 +10:00
Peter Hutterer
e3fd50bae7 ei: abstract the requests into an interface struct too
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-11 11:06:07 +10:00
Peter Hutterer
1a38bad756 proto: swap the ei message parsing for an interface struct
This gets rid of one layer of indirection with the struct message in
between - we can now call from the proto parser into the handling code
directly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-11 10:49:36 +10:00
Peter Hutterer
379f47b06b proto: split the keymap message out from the device added message
Same approach as used for the regions already, a separate (optional)
message.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-11 09:29:58 +10:00
Peter Hutterer
3abf13742a Restructure keymap handling to server-side only
This keeps most of the current structure but gets rid of client-side
keymaps (which have been broken since the server-side devices anyway).
The new approach: clients get a keymap (or NULL) from the server, if
they don't like it they will have to do transformation on their side.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-11 09:29:55 +10:00
Peter Hutterer
4ef359dc9b Fix a debug message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-11 09:09:08 +10:00
Peter Hutterer
59c4aef9d7 ei: drop pointer/touch width and height
Obsolete now that we have regions

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-11 09:09:08 +10:00
Peter Hutterer
6095a0d99f Add a physical scale factor for the regions
This isn't something that libei itself uses but clients like synergy
need to know about this to be able to map relative pointer motion from
one host into the right physical pixel on another host.

This is required for mutter in the x11-compat mode where a 4k screen is
logically twice the size of a 2k screen, despite having the same
physical size.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-07-23 15:06:01 +10:00
Peter Hutterer
56b82c2b8f Add DeviceRegions to replace the pointer/touch ranges
This is required for supporting synergy/barrier and similar clients.
Replacing the touch and pointer range we now have server-defined
rectangular regions that specify the active zones for this device.

For example, a dual-monitor EIS server would create two touch devices
with one region each for the respective monitors - libei-generated
touches would thus fall on the right area of the monitor. Or just one
device with one region if the second screen should be inaccessible.

A relative device may have multiple regions since it can reach all
screens in the layout.

This leaks the screen layout to libei but that is necessary for the
functionality to work. A libei client may need to control devices
through absolute coordinates and it needs to know where screen
transitions from one to the next screen happen:

  +-----------++----------------+
  |           ||                |
  |          B||Q               |
  |           |+----------------+
  |           |
  |          A|P
  +-----------+

In the above example, position P is unreachable and a client that
controls input on both screens must know that it cannot transition from
A to P but it can transition from B to Q.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-07-23 15:06:01 +10:00
Peter Hutterer
12b04fdeb0 Add a DeviceAddedDone message to the protocol
Similar to wayland's done message, this signals the end of the device
configuration.

Signed-off-by:	Peter Hutterer <peter.hutterer@who-t.net>
2021-07-23 14:26:38 +10:00
Peter Hutterer
926644e669 util: remove the need for a tmp argument in list_for_each_safe
With a bit of trickery, we can declare the tmp variable inside the for
loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-07-22 13:13:03 +10:00
Peter Hutterer
3e66c87e81 ei: make the device refcounting a bit easier to follow
Once a device is removed, it is moved to the seat's devices_removed
list and the seat's ref is dropped - meaning the seat no longer keeps
the device alive. Once the caller's refcounts drop, the device can be
destroyed.

The device still keeps the seat alive though through a ref.

Signed-off-by:	Peter Hutterer <peter.hutterer@who-t.net>
2021-07-21 11:02:54 +10:00
Peter Hutterer
2bb846696f Change to use server-created devices
This changes the protocol so that it is the EIS implementation that
creates devices within a seat.

A client now "binds" to a seat and the EIS implementation creates
devices matching the requested capabilities. A client can close a device
if it no longer wants those but otherwise everything (including pointer
ranges) is handled by the server.

This is one giant patch because changes at the protocol level cannot
easily be broken out into smaller patches. Some FIXMEs are left which
will be handled in follow-up patches, e.g. the keymap handling is
basically broken right now.

Fixes #7

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-07-21 11:02:54 +10:00
David Redondo
27e7823029 Implement support for scroll events
The interfaces were declared on both client and server  side but not
implemented.

Signed-off-by: David Redondo <kde@david-redondo.de>
2021-07-16 08:40:07 +02:00
Peter Hutterer
c317de742b libei: immediately remove devices added for a removed seat
Once the SEAT_REMOVED event has been processed, adding new devices is
pointless. But we do promise a DEVICE_REMOVED event for any device added with
ei_device_add(), so let's immediately queue an event and mark the device as
dead.

Since the SEAT_REMOVED event may still be pending in the queue (i.e. not yet
read by the client), we need to prepend the event to the queue. Note that
client that immediately add a device when a device is removed will cause
an infinite loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-29 14:10:47 +10:00
Peter Hutterer
f068ddf2a8 libei: only log the state when it changed
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-29 14:10:47 +10:00
Peter Hutterer
eef9c51df3 libei: fix the device/seat ref handling once again
Previously we didn't always clean up properly, especially where unexpected
removals happened. So the new approach is:
- the device always has a ref to the seat, we must not remove the seat until
  even not-yet-added devices are released
- the seat has a ref to the device *after* it was added. this is a circular
  ref so we need to make sure the device is manually removed from the seat
  so we can actually reach a refcount 1

This is made slightly more complicated by us calling ei_disconnect() whenever
we fail to write on the fd. The result is re-entrant functions that we need to
protect against inadvertent changes. The best option here is probably to mark
the context as degraded and clean up once we finished whatever we were really
doing - that's a larger rework though.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-29 11:28:29 +10:00
Peter Hutterer
683ff5cca0 Fix double device removal
Removing a seat could cause two device remove events to happen. Fix this by
splitting the removal up into two bits: removed by server and removed by
client. Only once both bits are set, remove the device.

This needs to happen in libei and libeis.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-27 11:35:06 +10:00
Peter Hutterer
0429ca2491 libei: print the device IDs as hex in the added/resumed/suspended debug logs
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-23 14:25:53 +10:00
Peter Hutterer
ab386f3cdb util: add an _unref_ cleanup + declaration function
To cut down on the boilerplate, an unref-able struct variable can now be
declared as
   _unref_(type) *name = NULL;
which is the equivalent of
   _cleanup_(type_unrefp) struct type *name = NULL;

Let's see how that style ends up reading.

This means we can get rid of the custom _cleanup_foo_ functions everywhere, no
need for all the extra #defines etc. A somewhat special case is systemd which
defines the various unrefp functions for us in the headers, so we can use them
directly.

OBJECT_IMPLEMENT_UNREF now also creates the unrefp function for this object -
this of course conflicts where DECLARE_UNREF_CLEANUP_FUNC is in scope. Not a
problem so far, let's see how we go.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-21 11:17:16 +10:00
Peter Hutterer
ff6633db97 libei: Improve function namespacing
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-21 10:47:47 +10:00
Peter Hutterer
93b96e42ad Add an EIS-controlled seat to the hierarchy
After CONNECT, the EIS implementation needs to add one or more seats. The
libei client can only create devices within those seats. This mirrors the
wayland hierarchy as well as the X.Org one.

The seat has a set of allowed capabilities, so the client knows ahead of time
when it may not be possible to create a specific device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-21 10:47:47 +10:00
Peter Hutterer
207cd5fd24 libei: rename added to device_added
Make space for a future seat_added/removed

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-21 10:10:16 +10:00
Peter Hutterer
937f9fd8c5 libei: add a bunch of log messages for client bugs
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-01 15:28:46 +10:00
Peter Hutterer
02efb19e2b libei: better logging of capabilities
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-10-01 15:28:46 +10:00
Peter Hutterer
40d7b3cade Add support for touch events
Client-side the approach is a managed touch object rather than passing the
touchid around. This is intentional, it allows for a stackable API in the
future if we need to add things like pressure or major/minor to it.

On the server side the touches are managed through the event object anyway, so
we don't need the same abstraction there.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-27 23:48:51 +00:00
Peter Hutterer
90d2b1b980 Add support for absolute pointer motion events
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 11:24:58 +10:00
Peter Hutterer
09ad65d5c6 Implement eis_device_set_name and get_name
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 11:21:46 +10:00
Peter Hutterer
eb40872770 Fix client-side removal of devices
Because events may be in-transit when a client removes the device, we need to
make this a full roundtrip to the server. Otherwise the client may assume a
device is removed, releases all references and then gets the original device
added event for that device. Better to have this as a round-trip instead.

This requires the server to call eis_device_disconnect() on the removed
notifications but we do so during eis_event_unref() anyway in case the server
forgets.

And it changes some of the API behaviors, so adjust the tests for that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 10:41:55 +10:00
Peter Hutterer
f27414d778 libei: move the event to string conversion to the top
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 10:32:26 +10:00
Peter Hutterer
423427c6da libei: better debugging of message types
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 10:32:03 +10:00
Peter Hutterer
297fb502f9 libei: remove ei_ prefix from the internal queue functions
An attempt to make things less confusing

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 10:32:03 +10:00
Peter Hutterer
fa179e8778 libei: rename a set of functions for clarity
It's getting too confusing without prefixing

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 10:32:02 +10:00
Peter Hutterer
ad87b67906 Move the CASE_RETURN_STRING macro to util-macros.h
No point redefining this everywhere

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-24 10:32:00 +10:00
Peter Hutterer
cc085b26f1 Print the event type name for debugging
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-23 09:47:44 +10:00
Peter Hutterer
31800cf870 util: make the OBJECT_IMPLEMENT_CREATE no longer static by default
Better for consistency with the other functions.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-15 23:23:51 +00:00
Peter Hutterer
6b3d9255cf libei: implement org.freedesktop.portal.EmulatedInput support
The current implementation of that portal has two methods: EmulateInput to
authenticate and Connect to get the fd to the EIS implementation. The portal
implementation is in charge of finding EIS and restricting it if need be.

This uses libsystemd because we can integrate that with epoll and our
libei_dispatch() method. GDBus requires a glib mainloop, so it's not really
suitable here. Given how simple this is anyway, it's easy to just do the DBus
bits in the caller and then hand the fd to ei_setup_backend_fd().

A eis-fake-portal is provided for testing, this "portal" can use the custom
portal bus name and connect the eis-demo-client to the eis-demo-server.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-25 13:35:18 +10:00
Peter Hutterer
17d396aaf1 Add size handling for the keymap
Just sending the fd isn't good enough, to mmap those we need the size argument
too.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-21 18:57:25 +10:00