Commit Graph

50 Commits

Author SHA1 Message Date
Simon Ser 488a23c169 pointer: drop enum wlr_axis_orientation
Instead, use enum wl_pointer_axis from the Wayland protocol.
2024-02-28 16:39:18 +00:00
Simon Ser ec5263e6b7 pointer: drop enum wlr_axis_relative_direction
Instead, use enum wl_pointer_axis_relative_direction from the
Wayland protocol.
2024-02-28 16:39:18 +00:00
Simon Ser 812451cd8f pointer: use enum wl_pointer_button_state 2024-02-28 16:39:18 +00:00
Simon Ser 9f4cf242d9 pointer: drop enum wlr_axis_source
Instead, use enum wl_pointer_axis_source from the Wayland protocol.
2024-02-28 16:39:18 +00:00
Simon Ser 842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00
Simon Ser 00bb1b0f84 seat/pointer: add support for axis_relative_direction event 2024-01-23 08:37:29 +00:00
Kirill Primak 0f67580aab compositor: introduce wlr_surface_set_role_object() 2023-06-23 11:54:05 +00:00
Simon Ser 1e68e1f661 seat: fix keyboard/pointer/touch resource destroy
We need to always unlink the resource, even if it's already inert.
seat_client_destroy_*() may be called multiple times on the same
resource.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3638
2023-06-20 20:14:49 +00:00
Kirill Primak 753f3cc4fa compositor: add wlr_surface_role.no_object
This commit allows to make a role as not represented by an object,
which fixes calling role commit handlers for roles like cursor
surfaces.

Fixes: 099b9de752
2023-06-14 14:06:28 +00:00
Kirill Primak 2acc74a3db Clear input regions if they're ignored 2023-06-06 13:33:31 +03:00
Alexander Orzechowski d700bd2d7c wlr_seat_pointer: cursor surfaces are always mapped 2023-06-06 06:00:21 -04:00
Andri Yngvason 00489b11a0 seat: Provide dummy resources for inert seats 2023-04-18 08:29:30 +00:00
Andri Yngvason 3898bb482d seat: Let client manage its own resources
This makes seat_client resources inert when seats and/or input devices are
destroyed, rather than destroying the resources.

When the client calls e.g. wl_keyboard_release(), it's not expecting the
keyboard global to be already destroyed, so this results in an error such
as this:

    wl_display@1: error 0: invalid object 22
2023-04-18 08:29:30 +00:00
Guido Günther 8a56490229 seat/pointer: Initialize low_res_value
Fixes

    In file included from /usr/include/wayland-server-core.h:32,
                     from ../types/seat/wlr_seat_pointer.c:6:
    In function 'wl_fixed_from_double',
        inlined from 'wlr_seat_pointer_send_axis' at ../types/seat/wlr_seat_pointer.c:367:6:
    /usr/include/wayland-util.h:641:17: error: 'low_res_value' may be used uninitialized [-Werror=maybe-uninitialized]
      641 |         u.d = d + (3LL << (51 - 8));
          |               ~~^~~~~~~~~~~~~~~~~~~
    ../types/seat/wlr_seat_pointer.c: In function 'wlr_seat_pointer_send_axis':
    ../types/seat/wlr_seat_pointer.c:329:16: note: 'low_res_value' was declared here
      329 |         double low_res_value;
          |                ^~~~~~~~~~~~~
2022-11-24 22:37:52 +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
Quantum 30bf8a4303 seat/pointer: fix uninitialized variable warning
This results in the following warning, which in release mode causes an
error due to -Werror:

../types/seat/wlr_seat_pointer.c: In function ‘wlr_seat_pointer_send_axis’:
../types/seat/wlr_seat_pointer.c:344:25: error: ‘low_res_value_discrete’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  343 |   if (version < WL_POINTER_AXIS_VALUE120_SINCE_VERSION &&
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  344 |     value_discrete != 0 && low_res_value_discrete == 0) {
      |     ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
2022-07-28 02:25:31 -04:00
Kirill Primak 7298c42139 seat/pointer: rework sending axis events
This commit fixes:
- sending discrete scrolling events to multiple pointer resources
- sending events to clients which don't support wl_pointer.axis_discrete
2022-07-27 14:26:56 +00:00
José Expósito add44b3e2e seat: support low-resolution clients
When the client doesn't support high-resolution scroll, accumulate
deltas until we can notify a discrete event.

Some mice have a free spinning wheel, making possible to lock the wheel
when the accumulator value is not 0. To avoid synchronization issues
between the mouse wheel and the accumulators, store the last delta and
when the scroll direction changes, reset the accumulator.
2022-07-11 11:01:35 +02:00
José Expósito 40dc5121aa seat: support high-resolution clients
Upgrade the seat protocol to version 8 and handle clients that support
high-resolution scroll wheel events.

Since the backend already sends discrete values in the 120 range,
forwarding them is enough.
2022-07-11 11:01:35 +02:00
José Expósito 65c436407f pointer: transform low-res to high-res axis events
Currently, the "wlr_event_pointer_axis" event stores low-resolution
values in its "delta_discrete" field. Low-resolution values are always
multiples of one, i.e., 1 for one wheel detent, 2 for two wheel
detents, etc.

In order to simplify internal handling of events, always transform in
the backend from the low-resolution value into the high-resolution
value.

The transformation is performed by multiplying by 120. The 120 magic
number is used by the kernel and it is exposed to clients in the
"WLR_POINTER_AXIS_DISCRETE_STEP" constant.
2022-07-11 11:01:35 +02:00
Simon Zeni cfed039c9a types/wlr_input_device: move init and finish function to private API 2022-03-07 16:37:41 +00:00
Kirill Primak 617eb4fb93 surface: deprecate wlr_surface.h 2022-01-13 10:06:41 +00:00
David Rosca 31914928d2
seat: Only resend keyboard/pointer enter to focused clients
Otherwise it will send enter events to clients that already
have keyboard/pointer focus.
Notably Qt applications warns about this.
2021-12-14 08:23:53 +01:00
Tudor Brindus 033c9cab74 input/pointer: try harder to not send duplicate motion events
wl_fixed_t is a 32-bit data type, but our doubles are 64-bit. This meant
that two doubles that would map to the same wl_fixed_t could compare
unequal, and send a duplicate motion event.

Refs swaywm/sway#4632.
2021-08-07 09:04:12 +02:00
Vyivel a93b18dbd5 input/pointer: send axis source once per frame
Only one wl_pointer.axis_source event is permitted per frame, according
to the Wayland specification.

Fixes https://github.com/swaywm/wlroots/issues/2973
2021-07-19 12:00:31 +02:00
Kenny Levinsen 46d2f80c38 wlr_seat_pointer: Remove log on notify_button 2021-03-07 11:01:38 +01:00
Tudor Brindus a145430afa
input/pointer: add wlr_seat_pointer_wrap
It allows a compositor to do things like skip motion events on pointer
constraint unlock.

References: https://github.com/swaywm/sway/pull/5431
2020-07-15 19:31:13 +02:00
Thomas Hebb dcae6f1431 Allow keyboard and pointer grabs to hook clear_focus()
This is necessary for some grabs, which currently have no way of knowing
when the pointer/keyboard focus has left a surface. For example, without
this, a drag-and-drop grab can erroneously drop into a window that the
cursor is no longer over.

This is the plumbing needed to properly fix swaywm/sway#5220. The
existing fix, swaywm/sway#5222, relies on every grab's `enter()` hook
allowing a `NULL` surface. This is not guaranteed by the API and, in
fact, is not the case for the xdg-shell popup grab and results in a
crash when the cursor leaves a surface and does not immediately enter
another one while a popup is open (#2161).

This fix also adds an assertion to wlr_seat_pointer_notify_enter() that
ensures it's never called with a `NULL` surface. This will make Sway
crash much more until it fixes its usage of the API, so we should land
this at the same time as a fix in Sway (which I haven't posted yet).
2020-06-05 17:20:26 +02:00
Kenny Levinsen 5e0ef70cc0 seat: Create inert objects for missing capabilities
We should throw a protocol error if the relevant capability has never
existed when get_(pointer|keyboard|touch) is called. Otherwise, it
should succeed, even if the capability is not currently present.

This follows the spec, and avoids possible races with the client when
capabilities are lost.

Closes: https://github.com/swaywm/wlroots/issues/2227
2020-05-28 09:53:50 +02:00
Isaac Freund 1282c3b12f Send pointer enter/leave on capability change
This is more correct according to the protocol and fixes issues with
clients that wait for an enter event before processing pointer events.
2020-03-14 00:09:32 +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
Manuel Stoeckl edb30a6828 Implement serial validation for selection requests
This change tracks, for each wlr_seat_client, the most recent serial
numbers which were sent to the client. When the client makes a
selection request, wlroots now verifies that the serial number
associated with the selection request was actually provided to that
specific client. This ensures that the client that was most
recently interacted with always has priority for its copy selection
requests, and that no other clients can incorrectly use a larger serial
value and "steal" the role of having the copy selection.

Also, the code used to determine when a given selection is superseded
by a newer request uses < instead of <= to allow clients to make
multiple selection requests with the same serial number and have the
last one hold.

To limit memory use, a ring buffer is used to store runs of sequential
serial numbers, and all serial numbers earlier than the start of the
ring buffer are assumed to be valid. Faking very old serials is
unlikely to be disruptive.

Assuming all clients are correctly written, the only additional
constraint which this patch should impose is that serial numbers
are now bound to seats: clients may not receive a serial number
from an input event on one seat and then use that to request
copy-selection on another seat.
2019-06-30 15:01:05 -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
emersion 30d3426164 seat: add debug logs when validating grab serials
Makes it easier to debug when something goes wrong, e.g. button_count stuck
to 2 because the compositor ate a button release event.
2019-03-04 21:27:14 -07:00
Ian Fan 2e1dd4ae36 seat: fix remaining wlr_button_state enum rename 2019-03-01 21:49:04 +01:00
emersion e8f012c993 seat: only store serial if pressing a button
The grab serial can be used to start a pointer grab. A button pressed event
should be used for this purpose.

Thus, we should only save the grab serial if it's the first button pressed
event we send. This commit makes it so the serial is not saved if a button is
released while another button is still pressed.
2019-03-01 12:36:19 -07:00
emersion 2fde5c95d8 seat: use wlr_button_state enum instead of uint32_t 2019-03-01 12:36:03 -07:00
emersion 4135fafecd seat: guard against button count corruption
This is still a compositor bug, and bad events will be sent to clients. We'll
need to track each button separately to handle this in wlroots.
2019-02-28 23:00:57 -05:00
emersion 6291e84532
data-device: refactor wlr_drag 2019-02-20 18:42:29 +01:00
emersion d6de329d98
seat: don't send motion if pointer hasn't moved 2019-01-30 15:24:17 +01:00
emersion 5de26ad8ed
pointer: add a frame event
Frame events group logically connected pointer events. It makes sense to make
the backend responsible for sending frame events, since once the events are
split (ie. once the frame events are stripped) it's not easy to figure out
which events belongs to which frame again.

This is also how Weston handles frame events.

Fixes https://github.com/swaywm/wlroots/issues/1468
2019-01-26 11:04:05 +01:00
Las d446c53fe1 Make (wlr_)seat_client_from_pointer_resource public 2018-09-18 10:14:33 +02:00
Las 252bcce2f3 Add focus change event for seats 2018-09-18 10:14:33 +02:00
Markus Ongyerth 9a6f77fc2c tablet-v2: fix merge commits and test again
There were a few issues after rebase, that the merge algorithm didn't
throw at my face:

wlr_output did a check on the actual role, not a string anymore, so that
had to go to allow tablet-v2 to set cursor surfaces.
A few L_DEBUG/L_ERRORs were still around
There was a user-after-free in tablet-group free()ing, probably after
insufficient testing from a previous feedback pass
2018-07-14 10:29:22 +02:00
emersion 33db4263a0
surface: replace wlr_surface_set_role_committed with wlr_surface_role 2018-07-07 22:45:16 +01:00
emersion db84379242
Send axis source event 2018-05-12 13:53:21 +01:00
emersion 0b58579564
Add support for discrete axis values 2018-05-12 13:34:58 +01:00
emersion d136026a2c
seat: implement inert seat resources 2018-05-03 22:03:44 +01:00
emersion 2cff6dbd63
seat: split into multiple files 2018-05-03 10:30:47 +01:00