Commit Graph

111 Commits

Author SHA1 Message Date
John Lindgren 3fc66d4525 util: fix non-linear behavior of wlr_box_closest_point()
Per comments in util/box.h, the width and height of a wlr_box are
exclusive; that is, for a 100x100 box at (0,0), the point (99,99) is
inside it while the point (100,100) is outside it.

Thus mathematically, there exists no single closest point to the
bottom-right corner of the box while remaining inside it. You can
construct an infinite series approaching the limit, such as {(99,99),
(99.9,99.9), (99.99,99.99)...}, but since the intervals are half-open,
there is no "last" point.

wlr_box_closest_point() must therefore define an arbitrary "closest"
point. For points below and to the right of the box, the current
implementation returns (box.x + width - 1, box.y + height - 1). Let's
continue to do this.

However, the current implementation is non-linear: with the example
100x100 box, it will return an input point of (99.9,99.9) unchanged, but
for an input point (100.1,100.1) the returned point will jump back to
(99.0,99.0).

In practice, this non-linearity results in strange behaviors when
driving the mouse cursor to a screen corner. On a 1920x1080 display for
example, driving the cursor quickly to the bottom-left corner results in
a position of exactly (0,1079). Continuing to slowly nudge the cursor
downward results in the position jumping between (0,1079) and other,
fractional coordinates such as (0,1079.88).

The fractional coordinates expose some client/toolkit-side bugs (which,
to be clear, should be fixed on the client side), but IMHO the wlroots
behavior is also inconsistent and wrong -- when I drive the mouse cursor
into the corner of the screen, it should come to a stop at a fixed
position, not jitter around.
2024-03-28 12:51:53 +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 efa706b769 util/log: drop unnecessary _XOPEN_SOURCE
snprintf() is actually ISO C99.

We still need POSIX for clock_gettime().
2024-02-15 15:20:14 +01:00
Simon Ser 2eb225236e util/transform: add wlr_output_transform_coords()
We hand-roll this in multiple places.
2023-11-23 11:07:34 +01:00
Simon Ser 9e702e9cfe util/transform: move over wl_output_transform helpers
These aren't really tied to wlr_output.
2023-11-23 11:03:57 +01:00
Manuel Stoeckl a3d22dbe97 xdg-toplevel: check that title provided actually is UTF-8
While the xdg-shell protocol requires this, it does not yet have
a dedicated error code for invalid titles; this commit makes
wlroots send a generic error instead.
2023-11-22 22:03:00 +03:00
Simon Ser 55be74ad86 util/token: rename TOKEN_STRLEN to TOKEN_SIZE
TOKEN_STRLEN is not actually the strlen() of the token. It's the
size taken by the token included the final zero byte.

Change the name to make this clearer, and remove unnecessary +1's.
2023-10-26 16:30:12 +00:00
Kirill Primak 2c33a1c2de util/addon: make wlr_addon_set_finish() safer
wl_list_for_each_safe() breaks if an item immediately after the current
one is removed, see
https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4358#note_2106260.
2023-10-08 11:06:09 +00:00
Manuel Stoeckl d180f4d9b3 util: add struct to track union of rectangles
The new struct rect_union is designed to make it easier to
efficiently accumulate a list of rectangles, and then operate
on an exact cover of their union.

Using rect_union, the times needed to added t rectangles, and then
compute their exact cover will be O(t), and something between Ω(t) and
O(t^2), depending on the rectangle arrangement. If one tries to do
the same by storing a pixman_region32_t and updating it with
pixman_region32_union_rect(), then total time needed would be between
Ω(t^2) and O(t^3), depending on the input. Without changing the public
API (data structure + rectangle ordering rules) for pixman_region32_t,
it is impossible to improve its worst case time.
2023-10-05 11:45:32 +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
Evyatar Stalinsky 21e96c459d util/log: fix buffer overflow 2023-06-29 15:58:56 +03:00
Rose Hudson bd834fe8d1 util: add timespec_to_nsec 2023-06-05 19:50:07 +00:00
Kirill Primak dc6402d153 util/box: transform empty boxes' origins
Not a huge fan of this, but changing this behavior would be a breaking change
to a stable API.

Fixes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3650
2023-05-24 08:55:15 +00:00
Kirill Primak 5f4a35290d util/box: always treat NULL boxes as empty 2023-05-23 21:08:22 +03:00
Kirill Primak 5d67bbde86 util/box: simplify empty box case in wlr_box_intersection() 2023-05-23 21:02:18 +03:00
Alexander Orzechowski d495fb8c04 wlr_{box, fbox}_equal: Consider empty boxes NULL 2023-05-23 17:57:16 +00:00
Alexander Orzechowski acaf57dcca wlr_{box, fbox}_equal: Handle NULL 2023-05-23 17:57:16 +00:00
Alexander Orzechowski 48a89179a3 addon: Remove extra newline from logging 2022-12-22 11:18:01 -05:00
Alexander Orzechowski 7a4fd9064c addon: Add more logging 2022-12-22 11:04:12 -05:00
Kirill Primak 884237e9af util/addon: ensure the set is empty after finish 2022-12-22 12:42:08 +03:00
Kirill Primak 8f58c060fd util/region: forbid "shrinking" a region with wlr_region_expand()
The logic isn't correct.
2022-12-09 16:46:36 +00:00
Simon Ser d72b4409ce util/env: make env_parse_switch() return a size_t
This function is guaranteed to never return a negative value.

This is important because we use arr[env_parse_switch(...)] in a
few places.
2022-12-06 16:14:18 +01:00
Kenny Levinsen bb0fd29252 addon: Allow NULL owner of addon
An owner is not always required or practical. Rather than have the user
set a bogus owner in these cases, allow the user to set a NULL owner.
2022-12-05 10:51:46 +01:00
Simon Ser 769cabbadf util/time: use int64_t return value for get_current_time_msec()
0xFFFFFFFF milliseconds is 4,294,967,295 ms so about 50 days.
A little bit too close for comfort.

Use int64_t instead of uint64_t to avoid C's implicit conversion
footguns in computations.
2022-11-25 16:15:29 +00:00
Simon Ser 9fd28d1e81 util/region: constify 2022-11-11 23:11:17 +00:00
Kirill Primak 7333a4602a util/set: overhaul 2022-08-29 13:48:42 +00:00
Kirill Primak 20c208d46a util/array: unclutter 2022-08-29 13:48:42 +00:00
Alexander Orzechowski 31a9fc1fb6 util: Introduce env helpers 2022-08-22 10:18:00 -04:00
Kenny Levinsen 724aa38fc2 util/array: Add array_realloc for wl_array
array_realloc will grow the array for the target size like wl_insert_add, but
will also shrink the array if the target size is sufficiently smaller than the
current allocation.
2022-08-19 19:38:33 +02:00
Alexander Orzechowski 346e524201 Remove wlr_signal_emit_safe 2022-08-18 07:16:16 -04:00
Alexander Orzechowski 1d08ef234e util/box: Introduce wlr_fbox_equal 2022-08-15 06:14:59 -04:00
Alexander Orzechowski 9f3bd64a33 util/box: Introduce wlr_box_equal 2022-08-15 06:14:28 -04:00
Simon Ser b89ed9015c util/global: fix memory leak on display destroy in wlr_global_destroy_safe
If the display is destroyed before wlr_global_destroy_safe's timer
fires, the struct destroy_global_data is leaked. This shouldn't cause
issues in practice because the timer will never fire, but makes it
harder to spot compositor memory leaks.
2022-06-07 18:18:11 +02:00
Steven Newbury ad06c12c89 util: Fix infinite loop in recursive function
When testing Xwayland multi-HiDPI support with Wine + SimCity4
I encountered a 100% CPU lockup from sway.  This turned out to be
triggering a bug in the wlroots pointer contraint code.

region_confine() contains multiple recursive calls where arguments
are modified and resubmitted to the function.  One of the calls
is however made using the original arguments, if/when this triggers
it results in the same codepath being followed each loop so the
condition always applies.

It makes much more sense if this was intended to apply the clamped
values x,y instead of the original x1,y1, and indeed this fixes the
infinite loop and results in correct behaviour.
2022-05-24 20:39:32 +00:00
Kirill Primak 4ac19e9f9c util/addon: avoid calling finish() twice
No functional change.
2022-05-23 11:11:38 +00:00
Simon Ser 19896e7fb6 util/shm: clear mode permission bits in allocate_shm_file_pair
This ensures the file cannot be re-opened with write permissions.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3429
2022-05-12 19:58:50 +02: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 Ser 54653b5d95 util/addon: fix public include
Everything in wlr/ is public and should be included via angle-bracket
include directives.
2022-04-26 09:43:10 +02:00
Simon Ser 4377b55292 util/global: remove wl_display arg from wlr_global_destroy_safe
Since [1], we can get the wl_display directly from the wl_global.

[1]: 2b22160fb6
2021-12-14 13:13:50 +00:00
Raphael Robatsch 4a8e681a5f util/token: don't leak /dev/urandom fd to children
Closes #3324.
2021-11-14 12:30:03 +01:00
Simon Ser fdc22449d6 util/box: introduce wlr_fbox_empty
Same as wlr_box_empty, but for wlr_fbox.
2021-09-22 10:45:39 -06:00
Simon Ser 55ca93469c util/shm: add allocate_shm_file_pair
This function behaves like allocate_shm_file, except it also
returns a read-only FD. This is useful to share the same segment
of memory with many Wayland clients.
2021-09-05 22:06:25 +02:00
Kirill Primak 664307f968 util/box: introduce wlr_fbox_transform()
A floating-point version of wlr_box_transform().
2021-08-24 10:36:06 +02:00
Kirill Primak 111d4eafd7 util/addon: find both by owner and impl
This allows to have multiple addons of different types with the same
owner.
2021-08-11 18:12:57 +02:00
Kirill Primak a6a80850b7 util: add wlr_addon 2021-08-10 19:15:48 +02:00
Dylan Araps e5063ef3a3 util/time: make NSEC_PER_SEC static
This fixes static linking with libseat.

Closes #3072
2021-07-28 09:01:59 +02:00
Simon Zeni e192d87731 move wlr_box from /types to /util 2021-07-06 21:43:17 +02:00
Simon Ser a6ed4ae308 util/array: add array_remove_at 2021-07-01 10:35:39 -04:00
Ryan Farley b29ac8fbac util/uuid: replace with util/token, remove libuuid
Use 128-bit hexadecimal string tokens generated with /dev/urandom
instead of UUIDs for xdg-foreign handles, removing the libuuid
dependency. Update readme and CI. Closes #2830.

build: remove xdg-foreign feature

With no external dependencies required, there's no reason not to always
build it. Remove WLR_HAS_XDG_FOREIGN as well.
2021-04-11 19:09:36 +02:00
Simon Ser 6721444114 build: simplify HAS_LIBUUID definition
We can just use to_int() instead of having two if branches.
2021-04-06 20:34:47 +02:00