Commit graph

75 commits

Author SHA1 Message Date
Paul Cercueil
220df2aa0f
Add more POSIX compliance macros to fix uClibc support
- Add POSIX 1993.09 compliance macro in source files that use
  "struct timespec";
- Add POSIX 2001.12 compliance macro in source files that use
  "struct sigaction" and the SA_SIGINFO macro, or the fchmod()
  function;
- Add POSIX 2008.09 compliance macro in source files that use the
  getline() function.

These compliance macros are enough for wlroots to compile with the
git-master version of uClibc-ng.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
2024-02-12 17:41:45 +01:00
Isaac Freund
7129eaa1f2 keyboard: fix type of wlr_keyboard_modifiers.group
This isn't a breaking change since both of these typedefs are uint32_t
but this should make things a bit less confusing for readers.
2024-01-17 11:00:52 +03:00
Simon Ser
7a9f8d8d6b Use struct initializers instead of memset()
This is a bit more type-safe.
2023-07-07 17:31:11 +02:00
Kirill Primak
75293d5fb0 keyboard: use the new data in wlr_keyboard_set_keymap()
Fixes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3647
2023-05-18 08:39:24 +03:00
Simon Ser
e2647c5151 keyboard: add support for resetting the keymap 2023-05-17 22:08:34 +00:00
Simon Ser
e725f234d7 keyboard: don't change current keymap on wlr_keyboard_set_keymap() error
This function was unsetting the keymap on error. Instead, let's
leave the current keymap untouched on error.
2023-05-17 22:08:34 +00:00
xiliuya
7f6d646e0a keyboard: only update LEDs when changed 2022-12-14 17:51:06 +01:00
Kirill Primak
20c208d46a util/array: unclutter 2022-08-29 13:48:42 +00:00
Alexander Orzechowski
ef4baea0e2 Use wl_signal_emit_mutable 2022-08-18 07:16:16 -04:00
Isaac Freund
91943a68a6 wlr_input_device: remove anon union field
This union is unnecessary since the recent input device refactor and can
now be replaced by wlr_*_from_input_device() functions.
2022-06-21 18:42:07 +00:00
Simon Ser
6c350799b2 Zero-initialize structs in init functions
Ensures there is no field left to its previous undefined value after
calling an init function.
2022-04-28 10:09:50 +02:00
Simon Zeni
9a17200446 types/wlr_keyboard: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni
eae8952e17 types/wlr_keyboard: remove destroy event
The destroy event from the base wlr_input_device must be used
2022-03-11 20:02:21 +00:00
Simon Zeni
cfed039c9a types/wlr_input_device: move init and finish function to private API 2022-03-07 16:37:41 +00:00
Simon Zeni
7dc4a3ecd7 interface/wlr_keyboard: rework destroy sequence
The destroy member in wlr_keyboard_impl has been removed. The function
`wlr_keyboard_finish` has been introduce to clean up the resources owned by a
wlr_keyboard.

`wlr_input_device_destroy` no longer destroys the wlr_keyboard, attempting to
destroy a wlr_keyboard will result in a no-op.

The field `name` has been added to the wlr_keyboard_impl to be able to identify
a given wlr_keyboard device.
2022-03-07 16:37:41 +00:00
Simon Zeni
e279266f71 interfaces: remove wlr_input_device_impl 2022-02-22 14:23:46 -05:00
Simon Zeni
a1978b1299 types/wlr_keyboard: add base wlr_input_device
wlr_keyboard owns its base wlr_input_device. It will be initialized when the
keyboard is initialized, and finished when the keyboard is destroyed.
2022-02-21 17:11:32 +00:00
Simon Ser
62924cc523 keyboard: add wlr_keyboard.keymap_fd
This exposes a read-only FD with the keymap.
2021-09-05 22:06:25 +02:00
Isaac Freund
7693f61d81 Replace wlr_key_state with wl_keyboard_key_state
There's no reason to have duplicate enums
2020-11-11 10:58:38 +01:00
Brian Ashworth
32148808ad wlr_keyboard_group: introduce enter and leave
This introduces the enter and leave events for wlr_keyboard_group.

The enter event is emitted when a keyboard is added to the group while a
key is pressed that is not pressed by any other keyboard in the group.
The data is a wl_array of the pressed key codes unique to the keyboard
that should now be considered pressed.

Similarly the leave event is emitted when a keyboard is removed from the
group while at least one key is pressed that is not pressed by any other
keyboard in the group. The data is a wl_array of the pressed key codes
unique to the keyboard that should now be considered released.

The purpose of these events are to allow the compositor to update its
state to avoid corruption. Additionally, for the leave event, the
focused surface may have been notified of a key press for some or all of
the key codes and needs to be notified of a key release to avoid state
corruption.

These were previously emitted as normal key events, but they are not
normal key events. There is no actual key press or release associated
with the events. It's purely for state keeping purposes. Emitting them
as separate events allows the compositor to handle them differently.
Since these are purely for state keeping purposes and are not associated
with an actual key being pressed or released, bindings should not be
triggered as a result of these events.
2020-05-31 17:28:18 -04:00
Tudor Brindus
064f64dbf7 input/keyboard: expose keymap matching helper
sway needs this logic too, and currently ships a version that has fallen
behind in terms of bugfixes (b1a63bc).
2020-05-07 23:10:03 -04:00
Isaac Freund
8707a9b7ec Return false on wlr_keyboard_set_keymap() failure
This allows users of the library to handle or ignore the error as they
see fit.
2020-03-24 00:22:50 +01:00
Simon Ser
16f22940d9 keyboard: emit key events without keymap
Sometimes compositors don't need an XKB keymap at all, they just handle
raw keycodes. Emit key events even if no keymap is set.
2019-12-01 10:25:50 -05:00
Brian Ashworth
f2d3b1000f Introduce wlr_keyboard_group
A wlr_keyboard_group allows for multiple keyboard devices to be
combined into one logical keyboard. Each keyboard device can only be
added to one keyboard group. This helps with the situation where one
physical keyboard is exposed as multiple keyboard devices. It is up to
the compositors on how they group keyboards together, if at all.

Since a wlr_keyboard_group is one logical keyboard, the keys are a set.
This means that if a key is pressed on multiple keyboard devices, the
key event will only be emitted once, but the internal state will count
the number of devices that the key is pressed on. Likewise, the key
release will not be emitted until the key is released from all devices.
If the compositor wants access to which keys are pressed and released
on each keyboard device, the events for those devices can be listened
to, as they currently are, in addition to the group keyboard's events.

Also, all keyboard devices in the group must share the same keymap. If
the keymap's differ, the keyboard device will not be able to be added
to the group. Once in the group, if the keymap or effective layout for
one keyboard device changes, it will be synced to all keyboard devices
in the group. The repeat info and keyboard modifiers are also synced
2019-11-05 20:05:49 +01:00
Simon Ser
ca45f4490c Remove all wayland-server.h includes
The documentation for wayland-server.h says:

> Use of this header file is discouraged. Prefer including
> wayland-server-core.h instead, which does not include the server protocol
> header and as such only defines the library PI, excluding the deprecated API
> below.

Replacing wayland-server.h with wayland-server-core.h allows us to drop the
WL_HIDE_DEPRECATED declaration.
2019-07-27 15:49:32 -04:00
Ashkan Kiani
06a13203dd Use a set to track pointer button state.
In addition to `button_count`, we keep track of the current buttons
pressed just as in `wlr_keyboard`.

Add `set_add` and `set_remove` to assist with this. These functions can
only be used with values greater than 0 (such as the button/key masks
for keyboards and pointers).

Partially addresses:
- https://github.com/swaywm/wlroots/issues/1716
- https://github.com/swaywm/wlroots/issues/1593
2019-06-16 00:59:53 +03:00
random human
40a43003a1
Send unique keymap file descriptors
To prevent wl_keyboard keymap being written to by clients, use a unique
file descriptor for each wl_keyboard resource.

Reference: weston, commit 76829fc4eaea329d2a525c3978271e13bd76c078
2018-09-18 13:58:36 +05:30
Markus Ongyerth
74ca2f8fcf Another round of feedback from acrisci 2018-07-14 09:52:34 +02:00
emersion
7cbef15206
util: add wlr_ prefix to log symbols 2018-07-09 22:49:54 +01:00
Dominique Martinet
efef54ccf5 wlr_keyboard: fix mmap leak + logic on close for keymap_fd
mmap leak found through static analysis
2018-06-30 11:38:21 +09:00
emersion
f8e0a03451
backend/x11: correctly destroy input devices 2018-04-28 12:55:36 +01:00
emersion
79da4c175e
backend/headless: remove useless destructor 2018-04-28 12:48:05 +01:00
Markus Ongyerth
c8ccb1bef3 reorder xkb state handling in wlr_keyboard
wlr_keyboard manages the xkb-common state of the compositor.
It used to update the state, update the modifiers, then notify the
compositor.
When [Shift_L] was pressed and released, this resulted in an event chain:
  Modifiers: Shift
  Key: Shift_L (Pressed)

  Modifiers:
  Key: Shift_L (Release)

The xkb-docs state that the state should be updated *after* the key was
handled [1], to prevent the new state from influencing the actual key
generated.

To achieve this, the event to the compositor is emitted, *before*
wlroots handles the xkb and internal keyboard state.

With this patch applied, the emitted events ill be:
  Modifiers:
  Key: Shift_L (Pressed)

  Modifiers: Shift
  Key: Shift_L (Release)

[1] https://xkbcommon.org/doc/current/group__state.html#gac554aa20743a621692c1a744a05e06ce
2018-04-18 11:54:59 +02:00
Drew DeVault
1d9be89e2d
Revert "ELF Visibility" 2018-02-19 18:01:27 -05:00
Scott Anderson
86269052eb Explicitly export EFL symbols 2018-02-19 14:26:40 +13:00
emersion
c2e1474010
Reformat all #include directives 2018-02-12 21:29:23 +01:00
emersion
36ead80cd1
Make wlr_signal_emit_safe private 2018-02-12 19:52:47 +01:00
emersion
5e58d46cc1
Add wlr_signal_emit_safe 2018-02-12 09:12:31 +01:00
Guido Günther
1633b8d793 wlr_keyboard: use correct printf format string for keymap_size
keymap_size is a size_t. Otherwise the build fails on arm like

../types/wlr_keyboard.c: In function 'wlr_keyboard_set_keymap':
../include/wlr/util/log.h:34:17: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t {aka unsigned int}' [-Werror=format=]
  _wlr_log(verb, "[%s:%d] " fmt, _strip_path(__FILE__), __LINE__, ##__VA_ARGS__)
                 ^
../types/wlr_keyboard.c:218:3: note: in expansion of macro 'wlr_log'
   wlr_log(L_ERROR, "creating a keymap file for %lu bytes failed", kb->keymap_size);
   ^~~~~~~
../types/wlr_keyboard.c:218:50: note: format string is defined here
   wlr_log(L_ERROR, "creating a keymap file for %lu bytes failed", kb->keymap_size);
                                                ~~^
                                                %u
2018-01-27 12:23:26 +01:00
Tony Crisci
b6f29e87e8 dont use pointer for modifiers 2018-01-17 08:31:15 -05:00
Tony Crisci
9765232096 update xkb state on layout change 2018-01-06 09:36:57 -05:00
Tony Crisci
ca0f456d6c wlr-keyboard set layout error handling 2018-01-06 09:06:19 -05:00
Tony Crisci
0ef2df21f2 compositor modifier hook 2018-01-05 07:00:50 -05:00
Tony Crisci
e8b810ce3e keep track of number of keycodes pressed 2017-12-27 18:58:43 -05:00
Tony Crisci
c838679393 fix memory leaks 2017-12-18 14:53:24 -05:00
Tony Crisci
20327d82cb Merge branch 'master' into keyboard-fixes 2017-12-18 10:04:27 -05:00
Tony Crisci
37c83d5c6d misc keyboard fixes 2017-12-18 09:59:59 -05:00
emersion
2c31cac116
Do not segfault when loading an unknown keymap 2017-12-18 15:11:05 +01:00
emersion
a3c0f97810
Make keyboard repeat info configurable 2017-12-08 17:03:05 +01:00
emersion
bb79ada49f
Fix a bunch of mistakes detected with scan-build 2017-11-16 10:30:54 +01:00