Commit Graph

104 Commits

Author SHA1 Message Date
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
Simon Ser 6f873078d4 build: use dictionnary for features instead of configuration_data
This allows us to easily iterate on all features and only deal with
bools.
2021-02-15 16:32:33 +01:00
Rouven Czerwinski dd920f602e util: fix uuid support for freebsd
Fixes:
  FAILED: subprojects/wlroots/libwlroots.so.7.p/util_uuid.c.o
  cc -Isubprojects/wlroots/libwlroots.so.7.p -Isubprojects/wlroots -I../subprojects/wlroots -Isubprojects/wlroots/include -I../subprojects/wlroots/include -Isubprojects/wlroots/protocol -I../subprojects/wlroots/protocol -I/usr/local/include -I/usr/local/include/libepoll-shim -I/usr/local/include/libdrm -I/usr/local/include/pixman-1 -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c11 -g -DWLR_USE_UNSTABLE -Wundef -Wmissing-include-dirs -Wold-style-definition -Wpointer-arith -Winit-self -Wstrict-prototypes -Wendif-labels -Wstrict-aliasing=2 -Woverflow -Wmissing-prototypes -Wno-missing-braces -Wno-missing-field-initializers -Wno-unused-parameter '-DWLR_REL_SRC_DIR="../subprojects/wlroots/"' -Wno-missing-field-initializers -Wno-missing-braces -DHAS_LIBUUID=0 '-DICONDIR="/usr/local/share/icons"' -fPIC -pthread -D_THREAD_SAFE -MD -MQ subprojects/wlroots/libwlroots.so.7.p/util_uuid.c.o -MF subprojects/wlroots/libwlroots.so.7.p/util_uuid.c.o.d -o subprojects/wlroots/libwlroots.so.7.p/util_uuid.c.o -c ../subprojects/wlroots/util/uuid.c
  ../subprojects/wlroots/util/uuid.c:28:2: error: implicit declaration of function 'assert' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
          assert(strlen(str) + 1 == 37);
          ^
  ../subprojects/wlroots/util/uuid.c:28:2: error: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]
  ../subprojects/wlroots/util/uuid.c:29:25: error: sizeof on array function parameter will return size of 'char *' instead of 'char [static 37]' [-Werror,-Wsizeof-array-argument]
          memcpy(out, str, sizeof(out));
                                 ^
  ../subprojects/wlroots/util/uuid.c:15:25: note: declared here
  bool generate_uuid(char out[static 37]) {
                          ^
  ../subprojects/wlroots/util/uuid.c:29:26: error: 'memcpy' call operates on objects of type 'char' while the size is based on a different type 'char *' [-Werror,-Wsizeof-pointer-memaccess]
          memcpy(out, str, sizeof(out));
                 ~~~              ^~~
  ../subprojects/wlroots/util/uuid.c:29:26: note: did you mean to provide an explicit length?
          memcpy(out, str, sizeof(out));

Fixes #2616
2021-01-08 20:51:51 +01:00
Ilia Bozhinov 37602e153b types: add wlr_xdg_foreign_registry 2021-01-05 20:32:56 +01:00
Ilia Bozhinov bf4e2e0eac util: add support for generating UUIDs
Co-authored-by: Jason Francis <cycl0ps@tuta.io>
2021-01-05 20:32:56 +01:00
Simon Ser f0c1b32120 util/time: add timespec_from_nsec 2020-12-18 10:37:08 +01:00
Simon Ser 00ccb89288 util/region: add wlr_region_scale_xy 2020-06-17 09:10:54 -06:00
Tudor Brindus 363bf44a35 util/time: move `timespec_sub` to time utilities 2020-06-06 00:09:19 +02:00