Commit graph

114 commits

Author SHA1 Message Date
Peter Hutterer
2821282dc9 libei: include math.h for fmod
For correctness only, looks like math.h is already pulled in from
elsewhere anyway.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/362>
2025-11-03 15:27:38 +10:00
Jonas Ådahl
ee27dd5c92 ei-device: Don't leak fd when receiving the keymap
The ei_keymap dups the file descriptor, so lets close the one we
received from the demarshaller.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/334>
2025-05-22 22:43:35 +02:00
Peter Hutterer
247a3d49d7 ei: print the sequence number on error for a start_emulating event
This may help debugging which sequence triggered an error.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/330>
2025-05-02 05:39:52 +00:00
Peter Hutterer
b1c1c5d579 Add the ei_touchscreen.cancel event and ei_touch_cancel()
In the protocol it's a new request/event that is sent instead of the
touch up event.

In the library this is implemented as ei_touch_cancel() which
transparently sends cancel() or up depending on the EIS implementation
support. This is mirrored for the EIS implementation.

Where touch cancel is received as an event it is presented
as EI_EVENT_TOUCH_UP with an ei_event_touch_is_cancel() flag to
check if it was a cancel. This is required for backwards compatbility,
we cannot replace the TOUCH_UP event with a TOUCH_CANCEL event without
breaking existing callers. To add a new event type we would need clients
announcing support for those event types but that's an effort that's
better postponed until we have a stronger need for it (see #68).

Closes #60

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/308>
2024-12-17 15:12:56 +10:00
Peter Hutterer
0cf12a889d eis: remove pending events on eis_device_remove()
This fixes a memleak caused by anything having a device ref when
ei_device_remove() is called. This can happen e.g. if there is a pending
event that hasn't been flushed with a ei_device.frame yet.

Example Sequence:
- client sends an event, event is queued to pending with a ref to the
  device
- next event causes a client disconnect, queuing an emulated seat bind
  of 0
- server calls eis_device_remove()
- client calls eis_device_unref()

One ref is still held in the pending event that was never visible to the
server, preventing the device from being freed.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/317>
2024-12-06 16:48:48 +10:00
Peter Hutterer
80bbcc67ed libei: fix an error message, spurious 'd'
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/312>
2024-11-29 12:27:48 +10:00
Peter Hutterer
a424458f03 Devices without regions pass coordinates as-is
If a device doesn't have a region (e.g. physical device) the answer to
"is this in the region" is always yes.

Closes #56
2024-07-25 01:17:39 +00:00
Peter Hutterer
0f81114544 Fix region check for devices with multiple regions
Use the ei(s)_device_in_region() to check for any region.

Closes #56
2024-07-25 01:17:39 +00:00
Peter Hutterer
38132d6fc5 ei: improve debug messages for keymap failures
Let's be more informative about what failed.

Fixes #48
2023-11-09 12:55:56 +10:00
Alban Browaeys
4929aeae61 Fix duplicate negation in log message
The test is meant for "not emulating", not "not not emulating".
2023-09-14 02:01:04 +02:00
Peter Hutterer
76652350cc Add a mapping_id to the regions
This allows a caller to match up a region with other data, e.g. in the
remote desktop case the same mapping_id can be assigned to the pipewire
stream that represents that output.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-08-30 09:18:26 +10:00
Peter Hutterer
7ddd70e9d8 Add ei_device_get_region_at() to obtain a region for a point
Helper function so clients don't need to loop through the regions to
find the matching one.
2023-08-29 11:39:20 +10:00
Peter Hutterer
868a16df85 ei: ei_device_get_width/height need to be public APIs 2023-05-31 01:06:32 +00:00
Peter Hutterer
3ef22c8ed0 Log a bug if a client tries to send a discrete value 1
Discrete values are multiples of 120 and it's unlikely the device to be
emulated is *that* precise, so let's assume it's a bug and the client
wasn't aware of the 120-multiple requirement.
2023-05-30 11:14:57 +10:00
Peter Hutterer
c99f4ffa2c libei: check incoming objects' version for correctness
If the server sends a protocol version higher than we support, fail.
2023-05-26 19:16:15 +10:00
Peter Hutterer
61d97269ab ei: fix capability checks for sending events
Fixes da37da1308
2023-05-08 14:08:32 +10:00
Peter Hutterer
da37da1308 ei: change the API to match the protocol interfaces closer
Now that the protocol interfaces are more fine-grained, let's match this
with the C API too.

This is just a rename of things so that in general
ei_pointer_*foo now becomes ei_foo*.

A few notable renames for better readability here:
- ei_device_scroll_delta (because scroll_scroll is awkward)
- ei_event_scroll_get_dx/dy and
  ei_event_scroll_get_discrete_dx/dy to indicate the delta-ness

Beyond that, clients must ensure to check/bind to the new
EI_DEVICE_CAP_BUTTON and EI_DEVICE_CAP_SCROLL capabilities to be able
to send button or scroll events.

Note that this API now allows for an EIS implementation to send a device
that only has a button or a scroll cap. Or a pointer cap without
buttons, etc. It's up to the clients how to handle such devices
(probably: ignore them).
2023-05-05 14:02:33 +10:00
Peter Hutterer
a902d5dbd8 protocol: replace the capabilities enum with an interface list
Previously we had ei_seat.capabilities and ei_device.capabilities,
both referring to the same enum. The seat caps were used to bind,
the device caps were used to announce capabilities.

The device caps were already mostly superfluous as the information
they carried was implicitly available by the set of interfaces
the device announced - if the device has a keyboard interface
it must also have the keyboard capability.

So let's drop the separate enum and make the capabilities
the set of supported interfaces. In the device we can drop the
event directly and just send the interface list. In the seat
we have a capability event that sends each *possible* interface
with a custom-assigned mask. The client can then use that mask
to bind to the capability as before.

For example:
   <- ei_seat.capability(0x1, "ei_pointer")
   <- ei_seat.capability(0x4, "ei_keyboard")
   <- ei_seat.capability(0x8, "ei_touchscreen")
   <- ei_seat.done()
   -> ei_seat.bind(0x4 | 0x8)  # bind to keyboard and touchscreen
   <- ei_seat.device()
   -> ei_device.interface("ei_keyboard")
   -> ei_device.interface("ei_touchscreen")
   <- ei_device.done()

In the generated bindings we simply use the interface index
to generate the masks, but the protocol at least states that
the mask may not be constant.

Because the button/scroll interfaces are not exposed by the C API, some
of the handling is a bit awkward since we need to use both depending
whether we have pointer/pointer_absolute selected.

Fixes #28

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-02 05:53:25 +00:00
Peter Hutterer
bf88b34918 Split the ei_pointer interface up into its components
Split the ei_pointer protocol interface into ei_pointer,
ei_pointer_absolute, ei_scroll and ei_button.

This gets rid of the slightly awkward pointer vs pointer absolute
handling. Those were two different capabilities but tied to the same
interface.

Plus it paves the way for devices that are keyboards with scroll
buttons, etc.
2023-05-02 05:53:25 +00:00
Peter Hutterer
a157cbfa42 Rename an internal struct to scroll_state
To avoid future name clashes.
2023-05-02 05:53:25 +00:00
Peter Hutterer
5aad9fd777 scanner: add the protocol name so we can compile some #defines
The protocol name on an interface is a fixed string that is part of
the ABI since it's used in a few messages (e.g.
ei_handshake.interface_version). To avoid typos, let's expose that
string in the scanner and #define it in the generated sources.
2023-04-06 13:57:20 +10:00
Peter Hutterer
5b1b5aec1a proto: replace pointer/keyboard/touchscreen with a generic "interface" event
Since these events are merely notifications of a single object, we can make
this more generic. This allows us to introduce future capabilities without
having to bump the seat.
2023-04-06 13:57:18 +10:00
Peter Hutterer
1a64b4963d Check incoming ids for validity
In libei we just check the range is correct.
In libeis we also check that the client is monotonically increasing the
id.
2023-03-03 11:27:01 +10:00
Peter Hutterer
ba51f434a6 proto: switch object ids to 64 bits 2023-03-03 11:27:01 +10:00
Peter Hutterer
0ef1bb95d4 ei: remove obsolete device->id 2023-03-03 11:27:01 +10:00
Peter Hutterer
b309798bf1 Switch object ids to use the object_id_t typedef 2023-03-03 11:27:01 +10:00
Peter Hutterer
8ea6b81f40 Change the ei_device_capability values to match the protocol
In the protocol this is a bitmask, let's make it the same in the
interface to avoid confusion in the implementation.
2023-03-03 11:27:01 +10:00
Peter Hutterer
38dc5dc72f proto: shift the capabilities down by one
These were previously (1 << cap) for convenience but that results in the
capability mask on the wire starting at 2 - which is a bit awkward.

Lets shift them down by one so we start the mask at 1.
2023-03-03 11:27:01 +10:00
Jonas Ådahl
eecf69af48 protocol: Make timestamps a single 64 bit argument
With 64 bit integers on the wire, we don't need to split timestamps in
milliseconds and microsecond parts.
2023-03-03 11:27:01 +10:00
Peter Hutterer
d319c3a725 protocol: rename "type" arguments and events
Type is a reserved keyword in many languages, let's make this easier for
those.
2023-03-03 11:27:01 +10:00
Peter Hutterer
658a861c2a proto: add a serial number to the modifiers event 2023-03-03 11:27:01 +10:00
Peter Hutterer
e5b37dedc8 protocol: add serial numbers to the various destroy events
This should allow EIS to track whether events that were sent before or
after a destruction of a resource.
2023-03-03 11:27:01 +10:00
Peter Hutterer
1c9ce9b680 Add serial numbers to the protocol
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-03-03 11:27:01 +10:00
Peter Hutterer
83b4902d9f ei: error out if we're in the wrong device state for emulating 2023-03-03 11:22:09 +10:00
Peter Hutterer
d698ed2f75 ei: remove some indirection from device events
Now that we only have one nice hook as entry point for those events,
let's move (and harden) the code there.
2023-03-03 11:22:09 +10:00
Peter Hutterer
8a2dd03a3f ei: reject a device with capabilities unknown to us
Untested because we cannot really trigger this code path with libeis.
2023-03-03 11:22:09 +10:00
Peter Hutterer
1a21c4854b ei: better protocol checking for invalid messages 2023-03-03 11:22:09 +10:00
Peter Hutterer
e67a0a7777 brei: add the brei_result object and bubble it up as error case
Add a new simple object "brei_result" that maps to the protocol-type
reason + explanation. That object is now returned instead of the errno,
giving us better debugging options.

This changes the dispatcher functions from returning an int to returning
a brei_result instead (default NULL for success). A helper function for
converting a neg errno to a result is provided for convenience for now,
eventually all these paths should deal with things correctly.
2023-03-03 11:22:08 +10:00
Peter Hutterer
23433d3aff protocol: move the keymap into the keyboard interface 2023-03-03 11:21:26 +10:00
Peter Hutterer
4d9ca1796d protocol: move pointer/keyboard/touch into separate interfaces
This allows us to have a device support multiple interfaces and evolve
those interfaces individually, e.g. add things to the keyboard interface
without having to bump the touchscreen interface.

Note that due to a name clash with the existing struct ei_touch public
API the protocol interface is named touchscreen.
2023-03-03 11:21:26 +10:00
Peter Hutterer
964bb76c60 protocol: move the frame event into the device interface 2023-03-03 11:21:26 +10:00
Peter Hutterer
3fc1bdf07a protocol: move start/stop emulating into the device 2023-03-03 11:21:26 +10:00
Peter Hutterer
fadc1853c9 protocol: add the ei_device interface
Sitting nested below the ei_seat, the client gets a notification for a
device through the ei_seat.device event.
2023-03-03 11:21:26 +10:00
Peter Hutterer
ba55bef917 Add ei/eis getters for the device id 2023-03-03 11:20:42 +10:00
Peter Hutterer
866a754223 ei: implement ei_device_get_width/height 2023-02-20 15:42:56 +10:00
Peter Hutterer
ff9830c122 Add a sequence number to START_EMULATING
This makes it easier to correlate a particular input transaction
(whether there are events or not) with out-of-band information like the
planned portal InputCapture::Activated signal's "activation-id".
2023-02-09 11:48:29 +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
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
37467881e6 Drop the trailing newline from the log messages
Punt this job to the caller, any structured logging handler doesn't need
them anyway and it makes handling of messages more awkward.

For our default log handlers (fprintf) we can just append them
ourselves.

Fixes #19
2022-08-11 10:09:27 +10:00
Peter Hutterer
48bf74a5b9 Add a pending event queue for incoming device events
Incoming device events are now added to a device-internal queue. Once
the frame event comes in, that queue is shuffled over to the main event
queue. For libei/the EIS implementation this means that device events
are seen only once the frame event appears from the sender (or it is
emulated by other means).
2022-05-17 15:31:20 +10:00