Commit Graph

122 Commits

Author SHA1 Message Date
Isaac Freund b821be5749
input-device: unconfuse tablet naming
WLR_INPUT_DEVICE_TABLET_TOOL is renamed to WLR_INPUT_DEVICE_TABLET

The input device corresponds to wlr_tablet, not wlr_tablet_tool.
2024-02-29 16:09:07 +01:00
Simon Ser 889150f866 cursor: use switch for input device type
Slightly improves the code style.
2024-02-29 14:03:55 +01: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
Kirill Primak 56cc25185d cursor: fix and simplify region mapping
Fixes: 4462f5dcb3
2024-02-01 14:42:00 +00:00
Simon Ser d7ac8c0cc1 cursor: drop unnecessary commented code
This is unused.
2023-12-12 19:39:33 +00:00
Simon Ser 7ef62cc995 cursor: fix initial cursor position for new outputs
The fresh new wlr_output_cursor is positioned at (0, 0).

Call wlr_output_cursor_move() after creating the wlr_output_cursor
to fix this.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3777
2023-12-12 19:39:33 +00:00
Simon Ser 78836298ef cursor: send surface scale events
wlr_cursor is responsible for sending enter/leave events, but
doesn't send fractional-scale-v1 and wl_surface.preferred_buffer_scale
events. This is not an easy thing to do from a compositor, so let's
just do it in wlr_cursor itself.
2023-12-04 15:39:04 +00:00
Simon Ser d61ec694b3 output: take wl_event_loop in wlr_output_init()
We don't need the whole wl_display here anymore. The wl_event_loop
is enough.
2023-11-23 11:39:25 +00:00
Simon Ser 22df8d3847 cursor: log missing XCursor
Log a debug message when the XCursor theme is missing a cursor.
Eases debugging.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3746
2023-10-31 13:37:00 +00:00
sunzhguy dbf20b0ad3 wlr_cursor: update cursor when output enable and transform changed
Signed-off-by: zhoulei <zhoulei@kylinos.cn>
Signed-off-by: sunzhguy <sunzhigang1@kylinos.cn>
2023-10-31 01:29:02 -04:00
Alexander Orzechowski 5fb0007e02 output_event_commit: Remove committed and buffer
The newly introduced state struct can be used to retrieve this.
2023-10-06 10:06:01 +00:00
Alexander Orzechowski 1b0694b794 treewide: Migrate from sizeof(struct) to sizeof(*pointer) where practical 2023-10-03 01:51:07 -04:00
Kirill Primak a09d649439 docs: replace the less commonly used "::" with "." 2023-10-02 22:10:16 +03:00
Alexander Orzechowski c044aef5f0 cursor: Unset cursor if texture upload failed
We need to make sure cursor_output_cursor_update() will clear the old
texture references through all code paths.
2023-10-02 06:08:10 +00:00
Alexander Orzechowski 7ef2c0a506 cursor: Remove dead code
This conditional would never fire because `cursor_output_cursor_reset_image`
nulls the previous xcursor.
2023-10-02 06:08:10 +00:00
Alexander Orzechowski 00dcc68e16 cursor: Unset cursor image when there is not available xcursor theme
This fixes a crash in the case where the last cursor was a client surface
cursor but then transitioned into a server managed xcursor that isn't
available. Because the logic would return early before, we would continue
to reference a texture pointer belonging to a client surface but would
otherwise disassociate with it (we wouldn't clear the cursor if the surface
is destroyed) resulting an an eventual UAF.

Let's just make the cursor invisible if we don't know what to show. It's
compositor policy if they want to show a default.

Co-authored-by: Scott Moreau <oreaus@gmail.com>
Fixes: #3686
2023-10-02 06:08:10 +00:00
JiDe Zhang 73db481037 wlr_output: update cursor when scale changed
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3699
2023-08-03 02:13:00 +00:00
JiDe Zhang 61903ed66b wlr_output_cursor: assert renderer isn't NULL
When a wlr_output add to wlr_output_layout, wlr_cursor will create
wlr_buffer of xcursor for the wlr_output, this behavior depends
wlr_renderer of wlr_output, using assert to ensure renderer is
initialized before wlr_output_layout_add and wlr_cursor_set_buffer/
wlr_cursor_set_xcursor.
2023-08-03 02:13:00 +00:00
Simon Ser 000081db19 cursor, output: apply viewport to cursor
Instead of passing the scale, pass the source and destination
boxes.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3676
2023-07-17 14:55:22 +00: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
Simon Ser f8d70fbece cursor: remove usage of wlr_output_cursor_set_image()
Stop using wlr_output_cursor_set_image() because it's getting
dropped. Instead, use wlr_output_cursor_set_buffer().

This mirrors what wlr_output_cursor_set_image() is doing
under-the-hood.
2023-07-03 09:45:34 +02:00
Simon Ser 0fc532f8de cursor: remove wlr_cursor_set_image()
Superseded by wlr_cursor_set_buffer().
2023-07-02 22:42:37 +00:00
Simon Ser 71c87ff4b8 cursor: add wlr_cursor_set_buffer()
A saner replacement for wlr_cursor_set_image():

- Takes a wlr_buffer instead of numerous parameters and a hardcoded
  format.
- The scale is not used to filter outputs.
- A ref to the buffer is kept to apply it to new outputs.
2023-07-02 22:42:37 +00:00
Simon Ser bb91787b5f cursor: stop using set_image() in wlr_cursor_unset_image()
set_image() will go away.
2023-07-02 22:42:37 +00:00
Simon Ser 53b07b5b72 cursor: set image for new outputs
When an output is added to wlr_cursor, update its cursor image.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/2119
2023-06-30 17:24:44 +00:00
Simon Ser d5581e42d4 cursor: add cursor_update_outputs()
Sets the cursor image for each output depending on the wlr_cursor
state.
2023-06-30 17:24:44 +00:00
Simon Ser d1d6cd9008 cursor: keep track of XCursor manager and name
Will be useful to apply the current cursor to new outputs.
2023-06-30 17:24:44 +00:00
Simon Ser 69c44de22f cursor: track surface globally, instead of per-output
Most of the surface-related state does not need to be per-output.
Move it to wlr_cursor_state.
2023-06-30 17:24:44 +00:00
Simon Ser c46fabe45c cursor: use wlr_cursor_unset_image() in wlr_cursor_set_surface() 2023-06-30 17:24:44 +00:00
Simon Ser f0b8a68654 cursor: store wlr_cursor inline in wlr_cursor_state
Removes one allocation, makes this a bit more consistent with the
rest of wlroots.
2023-06-30 17:24:44 +00:00
Simon Ser d59749aa44 cursor: add support for animated XCursor 2023-06-22 14:55:32 +02:00
Simon Ser 220402b717 cursor: add wlr_cursor_unset_image()
It's pretty awkward to call wlr_cursor_set_image() with 6 zeroes.
Hide that awkwardness in wlroots.
2023-06-15 18:40:33 +02:00
Simon Ser da04b066ea cursor: add wlr_cursor_set_xcursor()
This keeps track of the last set XCursor. If it hasn't changed,
skip the texture upload.

In the future, support for animated XCursors can be added.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3436
2023-06-15 18:28:43 +02:00
Simon Ser 6e8fb5509f cursor: only reset the cursor when the surface changes
If the set_cursor request is used with the same surface, don't call
cursor_output_cursor_reset_image(). That function sends
wl_surface.leave and can cause an infinite feedback loop with some
clients (submitting a LoDPI cursor when the surface leaves an HiDPI
output).

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3669
2023-06-12 12:42:31 +00:00
Kirill Primak 31d958f70a cursor: fix applying hotspot offset
"On surface.attach requests to the pointer surface, hotspot_x and
hotspot_y are _decremented_ by the x and y parameters passed to the
request."
2023-06-07 10:35:49 +03:00
Simon Ser 09c87cec3f cursor: fix wl_pointer.set_cursor hotspot updates
A client might update the cursor with the same wl_surface as
before, but with a different hotspot. Don't ignore such updates.

Fixes: 9c9e3f6263 ("cursor: ignore wlr_cursor_set_surface() with same surface")
2023-06-02 22:33:40 +00:00
Simon Ser 6668c822b3 cursor: unset wlr_output_cursor.texture on surface destroy
When the surface is destroyed, its current wlr_texture is about to
get destroyed as well. Reset wlr_output_cursor.texture to prevent
use-after-free.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3652
2023-06-02 16:27:54 +00:00
Simon Ser 9c9e3f6263 cursor: ignore wlr_cursor_set_surface() with same surface
Avoids damaging the output and rendering the cursor again if it
hasn't changed.
2023-06-02 16:27:54 +00:00
Alexander Orzechowski 18139f4d87 wlr_cursor: Don't multiply hotspot by scale^2
We are already multiplying in output_cursor_set_texture
2023-05-08 09:17:22 +00:00
Alexander Orzechowski 47a250ae12 wlr_cursor: Consider surface state when setting new cursor surface
Found by inspection
2023-05-06 20:55:11 +00:00
Simon Ser 78afce5e2d cursor: add surface handling
Only rely on wlr_output_cursor_set_texture(), because
wlr_output_cursor_set_surface() will get dropped.
2023-05-06 17:48:56 +00:00
John Lindgren 68c8cef38e cursor: Don't warp to (0,0) when last output is disconnected
There doesn't appear to be any good reason to warp the cursor to
the top-left corner when all outputs are disconnected; it's no more
valid than any other (x,y) point in that case.

The real-world case here is a user with a single external monitor
turning it off (which apparently counts as disconnected depending
on the connection type/hardware).  For that user, it's desirable to
have the cursor remain in its original location when the monitor
is turned back on.
2022-09-21 14:25:09 -04:00
John Lindgren 5417a182e5 cursor: Add a more general check for infinite/NaN cursor position
It should be considered a bug if a compositor sets a non-finite
cursor position, so fail loudly (in debug builds) if that happens.

The existing check in wlr_cursor_warp_closest() is now redundant,
and would silently hide such bugs, so remove it.
2022-09-21 14:25:09 -04:00
Kirill Primak 4462f5dcb3 cursor: avoid uninitialized wlr_box fields 2022-08-30 19:26:20 +03:00
Alexander Orzechowski ef4baea0e2 Use wl_signal_emit_mutable 2022-08-18 07:16:16 -04:00
Kenny Levinsen 03dc7e2df5 wlr_{keyboard,pointer,touch}: Update event docs
Events used by our input devices were recently renamed from wlr_event_* to
wlr_*_event, but the documentation and a single point of use was not updated
accordingly.

Regressed by: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3484
2022-06-28 09:50:30 +00: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 Zeni aaf787ee56 types/wlr_touch: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni e732c5c895 types/wlr_tablet_tool: uniformize events name 2022-03-17 18:16:14 +00:00
Simon Zeni bd6c000d14 types/wlr_pointer: uniformize events name 2022-03-17 18:16:14 +00:00