Commit graph

2590 commits

Author SHA1 Message Date
Alexandros Frantzis
a8246a9f0f client: Document best practices for event queue changes
Document the proper way to deal with event queue changes, in order to
guarantee proper handing of all events which were queued before the
queue change takes effect, especially in multi-threaded setups.

Make a special note about queue changes of newly created proxies,
which require the use of a proxy wrapper for thread safety.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-06-09 18:38:53 +00:00
Antonin Décimo
9434e8d69f Check that XDG base directories paths are absolute
The [spec][1] reads:

> All paths set in these environment variables must be absolute. If an
> implementation encounters a relative path in any of these variables it should
> consider the path invalid and ignore it.

and

> If $XDG_DATA_HOME is either not set or empty, a default equal to
> $HOME/.local/share should be used.

Testing that the path is absolute also entails that is is non-empty.

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
2022-06-09 18:34:17 +00:00
Simon Ser
f710d01663 cursor/os-compatibility: fix trailing space
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-06-04 22:58:50 +02:00
Simon Ser
0297c2c47a cursor/os-compatibility: remove strcpy/strcat usage
These functions don't perform bounds checking, so they are easy to
misuse and complicate audits.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-06-04 22:58:47 +02:00
Simon Ser
355c8e885c cursor: move xcursor_theme_inherits declarations at the top
Per code style, declarations need to be at the start of the block.

And make l const while at it.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:12 +02:00
Simon Ser
dfe820efce cursor: drop xcursor_add_path_elt
Just use snprintf instead. It doesn't really matter if we have
some duplicate slashes in filenames.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:12 +02:00
Simon Ser
ccca002691 cursor: drop unused XCursor comment declarations
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:12 +02:00
Simon Ser
1cb728246b cursor: fix indentation of xcursor_load_theme declaration
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:12 +02:00
Simon Ser
7a399383fc cursor: simplify xcursor_library_path
- Use early returns
- De-duplicate XDG_DATA_HOME code-paths
- Don't crash on allocation failure
- Use size_t when appropriate
- Fix indentation

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:11 +02:00
Simon Ser
f33356742e cursor: remove unnecessary ifs in xcursor_load_theme
load_all_cursors_from_dir and xcursor_theme_inherits already have
the NULL checks we want.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:11 +02:00
Simon Ser
6c49a8f7e5 cursor: drop xcursor_images_set_name
We don't ever need to set the name multiple times for a single
struct xcursor_images, so we can just set the field directly. Also
replace the hand-rolled logic with strdup.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:11 +02:00
Simon Ser
6cf5e8f932 cursor: use getline instead of fgets
This avoids storing 8KiB on the stack, and removes the line length
limit.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:11 +02:00
Simon Ser
0b8793ab0c cursor: remove unnecessary parentheses in load_all_cursors_from_dir
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 22:41:10 +02:00
Simon Ser
c2a150f7c2 cursor: remove xcursor_file_load_images wrapper
It's just calling xcursor_xc_file_load_images.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-27 16:01:42 +02:00
Simon Ser
73d4d2410e build: bump to version 1.20.91 for the alpha release
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-26 20:15:35 +02:00
Xavier Claessens
24244f26bf Meson: Override wayland-scanner if it can be run
This allows projects to use Wayland as a Meson subproject and get the
wayland-scanner executable when doing find_program('wayland-scanner').

Signed-off-by: Xavier Claessens <xavier.claessens@collabora.com>
2022-05-24 14:09:33 +00:00
Simon Ser
5e4253ed50 util: fix code block language in docs
Without {.xml}, Doxygen interprets the code as C. See [1] for
details.

[1]: https://www.doxygen.nl/manual/commands.html#cmdcode

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 10:13:46 +00:00
Simon Ser
93b61fde1f cursor: rename local variables to snake case
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
cf9065dfb8 cursor: drop xcursor_file abstraction
Just use FILE * directly instead.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
245d30ecb8 cursor: refactor xcursor_theme_inherits
Use early returns and breaks to avoid dealing with very long
indentation lines.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
963014459c cursor: convert macros to functions
Improves readability since there's no need for so many parentheses
anymore, adds type safety. The compiler will inline the function
automatically as necessary.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
bcfcd49232 cursor: rename functions to snake case
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
3c12a7a1be cursor: fix whitespace in function args definitions
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
a46d8be4e1 cursor: remove struct typedefs, rename to snake case
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
21394fd5f7 cursor: fix spacing around conditions and loops
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
315126d3bd cursor: fix indentation
Use tabs.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
450bb7c145 cursor: remove unnecessary if before free
free(NULL) is valid and is a no-op.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
92e758834c cursor: fix variable declaration style
Use a single space between type and variable name.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
b0a4e63351 cursor: fix struct declaration style
Use tabs for indentation, don't use tabs to align field names.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
329be63d6b cursor: fix define style
Don't use tabs, don't align.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
5f5f1da691 cursor: drop whitespace before parens in function calls
This is in line with the rest of the Wayland code style.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
13d4ae01cb cursor: drop XCURSOR_LIB_* defines
These are unused.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
7658cff241 cursor: drop XcursorTrue and XcursorFalse
Just use <stdbool.h> instead.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
4ea5ad1d11 cursor: remove private Xcursor int typedefs
Just use the types directly instead.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:59:05 +00:00
Simon Ser
d01868413f server: add wl_global_get_version
Add a helper to check the advertised version of a global. This can
be handy when checking whether a compositor feature is supported,
instead of having to store the version passed to wl_global_create
separately.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-23 08:53:19 +00:00
Derek Foreman
b19488c715 util: Limit size of wl_map
Since server IDs are basically indistinguishable from really big client
IDs at many points in the source, it's theoretically possible to overflow
a map and either overflow server IDs into the client ID space, or grow
client IDs into the server ID space. This would currently take a massive
amount of RAM, but the definition of massive changes yearly.

Prevent this by placing a ridiculous but arbitrary upper bound on the
number of items we can put in a map: 0xF00000, somewhere over 15 million.
This should satisfy pathological clients without restriction, but stays
well clear of the 0xFF000000 transition point between server and client
IDs. It will still take an improbable amount of RAM to hit this, and a
client could still exhaust all RAM in this way, but our goal is to prevent
overflow and undefined behaviour.

Fixes #224

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-05-16 14:39:21 +00:00
Simon Ser
f7ca2c65f3 docs/publican: ensure output encoding is UTF-8
Without this, DocBook picks the output encoding and on some setups
we end up with ISO-8859-1. Tested by booting a fresh Alpine VM,
verifying that the generated HTML is using the incorrect charset,
applying the patch, and verifying that the generated HTML is fixed.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-11 07:21:14 +00:00
Simon Ser
9402afc353 build: sanity check options
Fail when tests/documentation is enabled without libraries. Fail
when neither scanner nor libraries is enabled, because we don't
build anything in that case.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-10 14:02:51 +00:00
Simon Ser
2dcc35af81 cursor: use MAP_FAILED instead of hardcoded constant
Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-06 21:57:24 +02:00
Simon Ser
04efea1727 Remove publish-doc
We don't use this script anymore.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-05 11:24:11 +02:00
Demi Marie Obenour
1078ee4993 wl_shell is not mandatory
Even though it is part of wayland.xml, wl_shell is not mandatory for
compositors to implement, and may be removed in a future version.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
2022-04-11 23:04:26 +00:00
Simon Ser
ff972f85b2 os: drop unnecessary memcpy in wl_os_mremap_maymove
FreeBSD doesn't support mremap [1], so we have a fallback
implementation based on munmap+mmap. We memcpy from the old memory
region to the new one, however this is unnecessary because the new
mapping references the same file as the old one.

Use msync to make sure any pending write is flushed to the underlying
file before we map the new region.

[1]: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=59912

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-04-11 09:21:53 +00:00
Olivier Fourdan
6c424e9d4c shm: Close file descriptors not needed
Commit 5a981ee8 implemented a fallback path for platforms which do not
support mremap() such as FreeBSD.

To do so, the file descriptor for the mmap() is not closed immediately
but instead kept as long as the pool exists.

That induces more file descriptors kept open for longer, which in turn
may cause problems as wl_shm may be using a lot of file descriptors,
especially with Xwayland which can create a lot of pixmaps on behalf of
its X11 clients.

For platforms where mremap() is available, keeping those file
descriptors opened is a bit of a waste and may cause exhaustion of file
descriptors sooner that before commit 5a981ee8.

Only keep the mmap() file descriptor open on platforms which do not
implement mremap()  and close it immediately as before on others.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1283
2022-04-05 10:42:03 +00:00
Sigrid Solveig Haflínudóttir
2bcc27ff36 connection: change clen type in build_cmsg to size_t
To avoid implicit conversion since msg_control's type is size_t.

Signed-off-by: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
2022-04-03 16:17:40 +00:00
Sigrid Solveig Haflínudóttir
d066c4bd4e connection: fix asan report on sendmsg call
Initialiaze the entire msghdr struct to 0 before use.

Example of the report fixed with this change:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==20035==ERROR: AddressSanitizer: SEGV on unknown address 0x2dad4dbffffa0d (pc 0x0055555c7488 bp 0x007fffffc760 sp 0x007fffffc760 T0)
==20035==The signal is caused by a READ memory access.
    #0 0x55555c7488 in read_msghdr(void*, __sanitizer::__sanitizer_msghdr*, long) (/home/ftrvx/w/_/uxn/bin/uxnemu+0x77488)
    #1 0x55555c810c in sendmsg (/home/ftrvx/w/_/uxn/bin/uxnemu+0x7810c)
    #2 0x7ff7f2db20 in wl_connection_flush /home/ftrvx/q/wayland/build/../src/connection.c:315:10
    #3 0x7ff7f2d014 in wl_display_flush /home/ftrvx/q/wayland/build/../src/wayland-client.c:2154:9
    #4 0x7ff7e80bc0  (/lib/libSDL2-2.0.so.0+0x104bc0)
    #5 0x7ff7e523b0  (/lib/libSDL2-2.0.so.0+0xd63b0)
    #6 0x7ff7e534e4  (/lib/libSDL2-2.0.so.0+0xd74e4)
    #7 0x7ff7e535e8  (/lib/libSDL2-2.0.so.0+0xd75e8)
    #8 0x7ff7daad54  (/lib/libSDL2-2.0.so.0+0x2ed54)
    #9 0x7ff7dab130  (/lib/libSDL2-2.0.so.0+0x2f130)
    #10 0x555565bb40 in main /home/ftrvx/w/_/uxn/src/uxnemu.c:519:2
    #11 0x7ff7f62484 in libc_start_main_stage2 /builddir/musl-1.1.24/src/env/__libc_start_main.c:94:2

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/ftrvx/w/_/uxn/bin/uxnemu+0x77488) in read_msghdr(void*, __sanitizer::__sanitizer_msghdr*, long)
==20035==ABORTING

Signed-off-by: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
2022-04-03 16:17:40 +00:00
illiliti
de57106c94 meson: Use proper type for bools
Fix invalid usage of bools which violates official meson specification and thus
breaks muon, an implementation of meson written in C.

Signed-off-by: illiliti <illiliti@protonmail.com>
2022-04-02 17:04:08 +03:00
Simon Ser
962aefda42 server: introduce wl_signal_emit_mutable
wl_signal_emit doesn't handle well situations where a listener removes
another listener. This can happen in practice: wlroots and Weston [1]
both have private helpers to workaround this defect.

wl_signal_emit can't be fixed without breaking the API. Instead,
introduce a new function. Callers need to make sure to always remove
listeners when they are free'd.

[1]: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/457

Signed-off-by: Simon Ser <contact@emersion.fr>
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2022-03-28 19:06:16 +00:00
Peter Hutterer
868eb99eb0 protocol: add the wl_pointer.axis_value120 events
These events are for high-resolution wheels. Each logical wheel click
represents an axis value120 value of 120, fractions of a wheel click an
integer fraction thereof. The new event replaces
wl_pointer.axis_discrete for wl_pointer versions 8 and above.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-03-28 17:31:27 +00:00
Aleksandr Mezin
79c84ed3f1 client, server: handle wl_map_insert_new() failures
Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
2022-03-25 09:43:53 +00:00
Aleksandr Mezin
884d5fe3ab util: set errno in wl_map_insert_at()
And add errno checks in callers, where it seems to be necessary.

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
2022-03-25 09:43:53 +00:00