Commit graph

550 commits

Author SHA1 Message Date
Peter Hutterer
708aed6402 Export the event names through helper functions
Approximately every user of libei(s) will want something like this for
easier debugging, converting the numeric event type into something that
can be printed into the debug logs.

Let's provide this here so this doesn't need to be duplicated.
2023-05-22 02:39:08 +00:00
Jan Beich
708d0f57e8 util: silence warnings when memfd_create is missing
src/util-memfile.c:55:1: warning: unused function 'memfile_create' [-Wunused-function]
OBJECT_IMPLEMENT_CREATE(memfile);
^
src/util-object.h:164:16: note: expanded from macro 'OBJECT_IMPLEMENT_CREATE'
struct type_ * type_##_create(struct object *parent) { \
               ^
<scratch space>:133:1: note: expanded from here
memfile_create
^

test/test-ei-device.c:37:1: warning: unused function 'memfile_unrefp' [-Wunused-function]
DEFINE_TRIVIAL_CLEANUP_FUNC(struct memfile *, memfile_unref);
^
src/util-mem.h:56:21: note: expanded from macro 'DEFINE_TRIVIAL_CLEANUP_FUNC'
        static inline void _func##p(_type *_p) {                \
                           ^
<scratch space>:159:1: note: expanded from here
memfile_unrefp
^
2023-05-21 09:04:16 +00:00
Jan Beich
e27f039b32 brei: silence warnings on 32-bit architectures
src/brei-shared.c:231:16: warning: comparison of integers of different signs: 'int' and 'uint32_t' (aka 'unsigned int') [-Wsign-compare]
                        if (end - p < len32) {
                            ~~~~~~~ ^ ~~~~~
src/brei-shared.c:233:76: warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
                                                       "Invalid string length %u, only %li bytes remaining", s->len, (end - p) * 4);
                                                                                       ~~~                           ^~~~~~~~~~~~~
                                                                                       %i

Co-authored-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-21 09:04:16 +00:00
Peter Hutterer
3aed761f3d eis: don't log a warning for a disconnecting client that's disconnected
A client that does ei_disconnect() sends out the 'disconnect' protocol
message before closing the fd. On the libeis side, this will cause a
Connection error when reading past that message. Logging that as error
looks bad when this is normal behavior.

The 'disconnect' protocol message changes the client into the
REQUEST_DISCONNECT state. If we get a transport error when the client is
in that state, don't log an error - the client wanted to be disconnected
anyway and even if it's a legitimate socket failure there isn't anything
we can do about it anyway.
2023-05-19 05:10:58 +00:00
Peter Hutterer
e21f14d69f Log a connection error before disconnecting
This makes the debug logs easier to read - previously we'd get an error
and disconnect. That causes unwinding of the state internally
(including lots of debug messages) and then eventually the actual error
that caused the disconnect.

Reshuffle this, so we see the "Connection error" first before all the
unwiding of the state, making it easier to spot what caused the actual
error.
2023-05-19 05:10:58 +00:00
Jan Beich
27ff400bc2 meson: allow selecting sd-bus library via option
Roughly based on https://github.com/swaywm/sway/commit/fdbe98512a71

Co-authored-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-18 22:55:18 +00:00
Peter Hutterer
fe2abeda9d eis: drop declaration for eis_client_has_capability()
The implementation of this was removed in 408a3a94
2023-05-18 22:03:27 +00:00
Jan Beich
cc046f1f67 util: avoid /proc on BSDs (but keep for tests)
/proc is removed on OpenBSD, deprecated on FreeBSD or may not contain
Linux-style nodes.

Not mounted:

  test_cmdline_as_str                  [ ERROR ]
  Error: src/util-strings.c:483: assertion failed: fd >= 0 (-1 >= 0)

Mounted but only has /proc/curproc instead of /proc/self:

  test_cmdline_as_str                  [ ERROR ]
  Error: child killed by signal 11
2023-05-18 05:11:55 +00:00
Jan Beich
c7517b2737 liboeffis: expand sd_bus_close_unref for basu compatibility
ld: error: undefined symbol: sd_bus_close_unref
>>> referenced by liboeffis.c:116 (src/liboeffis.c:116)
>>>               liboeffis.c.o:(oeffis_destroy) in archive src/liboeffis.a

See also https://github.com/systemd/systemd/commit/bd62b7448623
2023-05-18 05:11:55 +00:00
Jan Beich
2a2c4cdd49 meson: depend on elogind or basu if systemd is missing
systemd isn't portable to non-Linux. However, sd-bus API was extracted
into a standalone library that works on BSDs.
2023-05-18 04:25:44 +00:00
Jan Beich
35e7ad9717 meson: depend on epoll-shim for BSDs
src/util-sources.c:29:10: fatal error: 'sys/epoll.h' file not found
 #include <sys/epoll.h>
          ^~~~~~~~~~~~~

ld: error: undefined symbol: epoll_ctl
>>> referenced by util-sources.c:76 (src/util-sources.c:76)
>>>               libutil.a.p/util-sources.c.o:(source_remove) in archive src/libutil.a
>>> referenced by util-sources.c:200 (src/util-sources.c:200)
>>>               libutil.a.p/util-sources.c.o:(sink_add_source) in archive src/libutil.a

ld: error: undefined symbol: epoll_create1
>>> referenced by util-sources.c:152 (src/util-sources.c:152)
>>>               libutil.a.p/util-sources.c.o:(sink_new) in archive src/libutil.a

ld: error: undefined symbol: epoll_wait
>>> referenced by util-sources.c:169 (src/util-sources.c:169)
>>>               libutil.a.p/util-sources.c.o:(sink_dispatch) in archive src/libutil.a
2023-05-18 04:15:36 +00:00
Jan Beich
53482faa57 meson: depend on math library for BSDs
ld: error: undefined symbol: __isnormal
>>> referenced by util-strings.h:243 (src/util-strings.h:243)
>>>               test/unit-tests-utils.p/.._src_util-strings.c.o:(xatod)
2023-05-18 04:15:36 +00:00
Peter Hutterer
3b8ce3dca1 Drop a few unused unref functions
Fixes 'warning: unused function 'ei_device_unrefp' [-Wunused-function]'
and friends.
2023-05-18 14:03:26 +10:00
Peter Hutterer
7015fa6ad0 brei: move the object_id_t typedefs to the brei-proto.h header
It's not the perfect place but here it does the least harm and it fixes
the noisy compiler warnings:
'warning: redefinition of typedef 'object_id_t' is a C11 feature [-Wtypedef-redefinition]'

Fixes #31
2023-05-18 14:03:26 +10:00
Peter Hutterer
e0a6c75cb4 protocol: widen the callback_data arg for ping/sync to 64bit
The only invocations we have right now of these callbacks ignore the
argument or force it to zero. But in the future we may have an interface
that requires a callback and that interface may need to store a
timestamp or object ID in this argument - so let's make sure we have
enough space for that.
2023-05-16 15:09:47 +10:00
Peter Hutterer
cdab45a9f4 ei: drop unused ei_insert_device_removed_event()
Unused since 2bb846696f "Change to use server-created devices"
2023-05-16 11:47:01 +10:00
Peter Hutterer
3e47f544c2 ei: drop ei_seat_bind_capability() and the unbind equivalent
This function is almost always wrong, very few clients will want to bind
to a single capability. Having this function means clients will use it to
bind caps one-by-one, causing the EIS implementation to create (an later
destroy) devices with capabilities that are about to be bound again anyway.
Better to have an API that encourages clients to bind all at once.

EIS implementation could avoid this by using a pingpong roundtrip in
response to a bind call, but removing this API is likely going to have
the same utility.
2023-05-10 12:25:40 +10:00
Peter Hutterer
95a5cebabb meson.build: list if oeffis is built in the summary 2023-05-10 12:10:40 +10:00
Peter Hutterer
333e98a191 doc/api: add some more high-level overview to the libei page 2023-05-10 11:36:51 +10:00
Peter Hutterer
8302b1ddac doc/api: add the unicode icons for a splash of color
Sometimes it's good to focus on the important issues in life.
2023-05-10 11:36:51 +10:00
Peter Hutterer
e130c9aeb1 meson.build: add soname versions to the generated libraries
Our soname tracks the library version, even though on Linux only the
first number is actually being used. The rest is just to make it easier
for tools to find the right version. So let's do that.

And until the 1.0 version is out and our library ABI is stable, hardcode
to 1.0.0

This commit also moves the header define up for better grouping.
2023-05-09 00:52:43 +00:00
Peter Hutterer
40ba30da82 meson.build: install our headers into a versioned subfolder
This makes it possible to have multiple (incompatible) versions
installed simultaneously.

Any incompatible version requires us bumping the major version, so our
headers are simply installed into the hardcoded libei-1.0 subdir.

This also changes the pkgconfig names to include the API version, so
it's now `pkgconfig --cflags libei-1.0`.
2023-05-08 14:33:50 +10:00
Peter Hutterer
61d97269ab ei: fix capability checks for sending events
Fixes da37da1308
2023-05-08 14:08:32 +10:00
Peter Hutterer
408a3a9462 eis: drop the vestiges of client restrictions
Leftover from 479bda259a (and possibly
others). This dates back to when a client could have restrictions
configured on the same fd. This is now all out-of-band (portals!) so the
compositor knows what the client is allowed to set up anyway.

No need for this (read-only) API here.
2023-05-08 13:38:40 +10:00
Peter Hutterer
f56a9000c0 eis: split up the API docs into smaller categories
See c076c48336 for the libei change,
mostly copy-pasted after that anyway.
2023-05-08 13:30:36 +10:00
Peter Hutterer
08efdee83d eis: remove a misleading paragraph from the docs
The 99% use-case for receiver clients is probably going to be capturing
logical input, not physical input.
2023-05-08 13:03:15 +10:00
Peter Hutterer
b3c202af23 ei: tighten the event type checks
Require exact event types, not just approximate ones. It's always a bug
to call any of these functions for an event type that's something else.
2023-05-08 12:49:40 +10:00
Peter Hutterer
c076c48336 doc: split the libei doxygen API into multiple submodules
The API is quite long now, so let's split it up into multiple logical
groups. The main page is now roughly graspable, with seats, devices,
regions and keymaps in submodules.

The sender and receiver APIs are also grouped into two separate APIs -
anyone implementing either doesn't need the other, it just messes things
up.
2023-05-05 14:05:30 +10:00
Peter Hutterer
5bb6e80ded doc: some minor doxygen updates 2023-05-05 14:05:30 +10:00
Peter Hutterer
aa866c5a92 Add a few more doxygen comments 2023-05-05 14:05:30 +10:00
Peter Hutterer
e6954b76d3 eis: change the API to match the protocol interfaces closer
Same as the corresponding ei change a few commits ago, this one does all
the EIS renaming in the same manner.

As with the libei changes, an EIS implementation must now handle the
EIS_DEVICE_CAP_BUTTON and EI_DEVICE_CAP_SCROLL capabilities. In
virtually all cases, clients will likely expect that a device with the
pointer or absolute pointer capabilities will also have button and
scroll capabilities.
2023-05-05 14:04:17 +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
d21726965b doc: move the sentinel attribute to unconfuse doxygen
The compiler doesn't care, doxygen apprently does.
2023-04-27 14:42:25 +10:00
Peter Hutterer
97a7a3e360 doc: fix two obsolete API comments 2023-04-27 14:42:22 +10:00
Peter Hutterer
f6cd949472 test: cast the varargs to the right data size
Fixes the test suite issues on 32 bit. Only needed for the 64 bit
arguments, but let's do the 32 bit as well for solidarity and
readability.

Fixes #30
2023-04-26 12:18:58 +10:00
Peter Hutterer
9c5c3c890f ei: de-duplicate ei_seat_unbind_capability
ei_seat_unbind_capabilities does the same, so let's use that.
2023-04-14 10:52:39 +10:00
Peter Hutterer
cf74cfeb1e ei: fix ei_seat_unbind_capabilities
Simplify the code a little but more importantly: if we get down to zero
capabilities close the devices - just like we do in
ei_seat_unbind_capability.
2023-04-14 10:51:40 +10: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
Salman Malik
a438e46e18 config: Make memfd_create optional
`memfd_create` doesn't seem to be supported on
all platforms (e.g. ubuntu 18 has trouble with it).
Even though, I was able to substitute `memfd_create`
with a direct system call, I was not able to get
the `MFD_CLOXEC` flag (from fcntl.h) working cleanly
(there were redefinitions/conflicts for other
structures when trying to use <linux/*> headers).
Making it optional for time being till we have
figured out how to make it work broadly.
2023-03-28 11:24:06 +00:00
Salman Malik
150ac5b4ac src/meson.build: Switch shared_library => library
This is the recommendation from meson documentation. The default
option is still to create a shared library but doing it this
way gives users an opportunity to create either a shared, static
or both type of libraries by setting up the meson build appropriately.

Here is the result with the default setup:

$ meson setup . _build
$ meson compile -C _build
$ find _build | egrep "(\.so|\.a)$"

_build/subprojects/munit/libmunit.so
_build/test/libunittest.a
_build/test/libeierpecken.a
_build/src/libei.so
_build/src/liboeffis.so
_build/src/libutil.a
_build/src/libeis.so

And here it is with the overridden flag:

_build/subprojects/munit/libmunit.a
_build/test/libunittest.a
_build/test/libeierpecken.a
_build/src/libei.a
_build/src/libeis.a
_build/src/liboeffis.a
_build/src/libutil.a

$ meson setup . _build  --default-library=static
$ meson compile -C _build
$ find _build | egrep "(\.so|\.a)$"
2023-03-15 00:47:15 +00:00
Peter Hutterer
8954d96227 Remove empty trailing newlines from all files 2023-03-13 08:52:08 +10:00
Peter Hutterer
d936e3e822 meson: make the header files variables to use within other meson files 2023-03-07 13:17:12 +10:00
Peter Hutterer
30aab5179e Merge branch 'main' into wip/drop-protobuf 2023-03-07 12:55:18 +10:00
Peter Hutterer
7810be8a80 meson: split into separate meson.build files for src/tools 2023-03-07 11:10:06 +10:00
Peter Hutterer
c350ac2ee3 src: pass the headerfile as jinja extra data
This removes another special handling of the C bindings from the
scanner.
2023-03-03 11:38:40 +10:00
Peter Hutterer
5f9bfe7b7b client: drop seats when destroying the client
This *should* have happened when the client got disconnected but in some
race conditions a seat may be added after the client gets disconnected.
Reproducible (sometimes) by test_invalid_object_id with the
eis-demo-server:
- client connects, sends invalid object ID, gets disconnected
- server sees CONNECTED, adds a seat, then sees DISCONNECTED and drops
  the client.

From the demo-server's POV the seat is handled by the client, so it
expects the client to destroy it.
2023-03-03 11:27:01 +10:00