platform/upstream/wayland.git
2 years agobuild: bump to version 1.20.93 for the RC1 release 1.20.93
Simon Ser [Thu, 23 Jun 2022 19:59:18 +0000 (21:59 +0200)]
build: bump to version 1.20.93 for the RC1 release

2 years agoserver: warn about global filtering consistency
Simon Ser [Wed, 15 Jun 2022 08:37:18 +0000 (10:37 +0200)]
server: warn about global filtering consistency

The filtering needs to be static given a client and a global,
otherwise libwayland will misbehave.

Signed-off-by: Simon Ser <contact@emersion.fr>
References: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/241#note_1421888

2 years agoserver: add PID race condition disclaimer to wl_client_get_credentials
Simon Ser [Tue, 31 May 2022 17:23:38 +0000 (19:23 +0200)]
server: add PID race condition disclaimer to wl_client_get_credentials

PIDs are re-used and cannot be used to reliably check the identity of
a Wayland client.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agotests: add a test for dynamic filtered globals
Simon Ser [Thu, 12 May 2022 17:30:38 +0000 (19:30 +0200)]
tests: add a test for dynamic filtered globals

Ensure dynamically created and destroyed globals which are filtered
don't trigger any global/global_remove event.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agoserver: check visibility before sending global/global_remove
Simon Ser [Thu, 12 May 2022 17:29:11 +0000 (19:29 +0200)]
server: check visibility before sending global/global_remove

See the previous discussion at [1]: libwayland incorrectly skips
the visibility checks when sending global/global_remove events.
The check is only performed when a client performs a
wl_display.get_registry request.

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

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor/os-compatibility: handle EINTR gracefully
Olivier Fourdan [Mon, 30 May 2022 07:14:04 +0000 (09:14 +0200)]
cursor/os-compatibility: handle EINTR gracefully

If os_resize_anonymous_file() called from os_create_anonymous_file()
fails with EINTR (Interrupted system call), then the buffer allocation
fails.

To avoid that, retry posix_fallocate() on EINTR.

However, in the presence of an alarm, the interrupt may trigger
repeatedly and prevent a large posix_fallocate() to ever complete
successfully, so we need to first block SIGALRM to prevent this.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2 years agobuild: bump to version 1.20.92 for the beta release 1.20.92
Simon Ser [Thu, 9 Jun 2022 18:52:32 +0000 (20:52 +0200)]
build: bump to version 1.20.92 for the beta release

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agoclient: Lock display when setting a proxy event queue
Alexandros Frantzis [Thu, 26 May 2022 09:18:28 +0000 (12:18 +0300)]
client: Lock display when setting a proxy event queue

Assignments to a wl_proxy's queue member are currently not synchronized
with potential reads of that member during event reading/queuing.
Assuming atomic pointer value reads and writes (which is a reasonable
assumption), and using the documented best practices to handle event
queue changes, a queue change should still be safe to perform.

That being said, such implicitly atomic accesses are difficult to assess
for correctness, especially since they do not introduce memory barriers.

To make the code more obviously correct, and handle any potential races
we are not currently aware of, this commit updates wl_proxy_set_queue()
to set the proxy's event queue under the display lock (all other
proxy queue accesses are already done under the display lock).

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2 years agoclient: Document best practices for event queue changes
Alexandros Frantzis [Thu, 26 May 2022 09:05:15 +0000 (12:05 +0300)]
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>
2 years agoCheck that XDG base directories paths are absolute
Antonin Décimo [Fri, 11 Mar 2022 13:08:49 +0000 (14:08 +0100)]
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>
2 years agocursor/os-compatibility: fix trailing space
Simon Ser [Sat, 4 Jun 2022 20:58:50 +0000 (22:58 +0200)]
cursor/os-compatibility: fix trailing space

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor/os-compatibility: remove strcpy/strcat usage
Simon Ser [Sat, 4 Jun 2022 20:56:36 +0000 (22:56 +0200)]
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>
2 years agocursor: move xcursor_theme_inherits declarations at the top
Simon Ser [Fri, 27 May 2022 15:52:35 +0000 (17:52 +0200)]
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>
2 years agocursor: drop xcursor_add_path_elt
Simon Ser [Fri, 27 May 2022 15:49:10 +0000 (17:49 +0200)]
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>
2 years agocursor: drop unused XCursor comment declarations
Simon Ser [Fri, 27 May 2022 15:17:42 +0000 (17:17 +0200)]
cursor: drop unused XCursor comment declarations

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: fix indentation of xcursor_load_theme declaration
Simon Ser [Fri, 27 May 2022 15:16:17 +0000 (17:16 +0200)]
cursor: fix indentation of xcursor_load_theme declaration

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: simplify xcursor_library_path
Simon Ser [Fri, 27 May 2022 15:14:24 +0000 (17:14 +0200)]
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>
2 years agocursor: remove unnecessary ifs in xcursor_load_theme
Simon Ser [Fri, 27 May 2022 15:09:48 +0000 (17:09 +0200)]
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>
2 years agocursor: drop xcursor_images_set_name
Simon Ser [Fri, 27 May 2022 15:07:08 +0000 (17:07 +0200)]
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>
2 years agocursor: use getline instead of fgets
Simon Ser [Fri, 27 May 2022 14:54:49 +0000 (16:54 +0200)]
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>
2 years agocursor: remove unnecessary parentheses in load_all_cursors_from_dir
Simon Ser [Fri, 27 May 2022 14:03:16 +0000 (16:03 +0200)]
cursor: remove unnecessary parentheses in load_all_cursors_from_dir

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: remove xcursor_file_load_images wrapper
Simon Ser [Fri, 27 May 2022 14:01:42 +0000 (16:01 +0200)]
cursor: remove xcursor_file_load_images wrapper

It's just calling xcursor_xc_file_load_images.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: bump to version 1.20.91 for the alpha release 1.20.91
Simon Ser [Thu, 26 May 2022 18:15:35 +0000 (20:15 +0200)]
build: bump to version 1.20.91 for the alpha release

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agoMeson: Override wayland-scanner if it can be run
Xavier Claessens [Mon, 4 Apr 2022 13:34:33 +0000 (09:34 -0400)]
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>
2 years agoutil: fix code block language in docs
Simon Ser [Thu, 5 May 2022 10:18:16 +0000 (12:18 +0200)]
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>
2 years agocursor: rename local variables to snake case
Simon Ser [Thu, 21 Apr 2022 10:01:19 +0000 (12:01 +0200)]
cursor: rename local variables to snake case

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: drop xcursor_file abstraction
Simon Ser [Thu, 21 Apr 2022 09:57:31 +0000 (11:57 +0200)]
cursor: drop xcursor_file abstraction

Just use FILE * directly instead.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: refactor xcursor_theme_inherits
Simon Ser [Thu, 21 Apr 2022 09:53:24 +0000 (11:53 +0200)]
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>
2 years agocursor: convert macros to functions
Simon Ser [Thu, 21 Apr 2022 09:48:49 +0000 (11:48 +0200)]
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>
2 years agocursor: rename functions to snake case
Simon Ser [Thu, 21 Apr 2022 09:45:20 +0000 (11:45 +0200)]
cursor: rename functions to snake case

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: fix whitespace in function args definitions
Simon Ser [Thu, 21 Apr 2022 09:31:45 +0000 (11:31 +0200)]
cursor: fix whitespace in function args definitions

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: remove struct typedefs, rename to snake case
Simon Ser [Thu, 21 Apr 2022 09:29:08 +0000 (11:29 +0200)]
cursor: remove struct typedefs, rename to snake case

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: fix spacing around conditions and loops
Simon Ser [Thu, 21 Apr 2022 09:17:12 +0000 (11:17 +0200)]
cursor: fix spacing around conditions and loops

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: fix indentation
Simon Ser [Sun, 17 Apr 2022 15:40:55 +0000 (17:40 +0200)]
cursor: fix indentation

Use tabs.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: remove unnecessary if before free
Simon Ser [Sun, 17 Apr 2022 15:30:05 +0000 (17:30 +0200)]
cursor: remove unnecessary if before free

free(NULL) is valid and is a no-op.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: fix variable declaration style
Simon Ser [Sun, 17 Apr 2022 15:28:44 +0000 (17:28 +0200)]
cursor: fix variable declaration style

Use a single space between type and variable name.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: fix struct declaration style
Simon Ser [Sun, 17 Apr 2022 15:20:33 +0000 (17:20 +0200)]
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>
2 years agocursor: fix define style
Simon Ser [Sun, 17 Apr 2022 15:19:31 +0000 (17:19 +0200)]
cursor: fix define style

Don't use tabs, don't align.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: drop whitespace before parens in function calls
Simon Ser [Sun, 17 Apr 2022 15:10:53 +0000 (17:10 +0200)]
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>
2 years agocursor: drop XCURSOR_LIB_* defines
Simon Ser [Sun, 17 Apr 2022 15:02:49 +0000 (17:02 +0200)]
cursor: drop XCURSOR_LIB_* defines

These are unused.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: drop XcursorTrue and XcursorFalse
Simon Ser [Sun, 17 Apr 2022 15:01:18 +0000 (17:01 +0200)]
cursor: drop XcursorTrue and XcursorFalse

Just use <stdbool.h> instead.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: remove private Xcursor int typedefs
Simon Ser [Sun, 17 Apr 2022 14:57:15 +0000 (16:57 +0200)]
cursor: remove private Xcursor int typedefs

Just use the types directly instead.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agoserver: add wl_global_get_version
Simon Ser [Thu, 12 May 2022 17:01:26 +0000 (19:01 +0200)]
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>
2 years agoutil: Limit size of wl_map
Derek Foreman [Fri, 28 Jan 2022 19:18:37 +0000 (13:18 -0600)]
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>
2 years agodocs/publican: ensure output encoding is UTF-8
Simon Ser [Tue, 10 May 2022 15:21:11 +0000 (17:21 +0200)]
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>
2 years agobuild: sanity check options
Simon Ser [Thu, 5 May 2022 09:14:00 +0000 (11:14 +0200)]
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>
2 years agocursor: use MAP_FAILED instead of hardcoded constant
Simon Ser [Fri, 6 May 2022 19:57:24 +0000 (21:57 +0200)]
cursor: use MAP_FAILED instead of hardcoded constant

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agoRemove publish-doc
Simon Ser [Thu, 5 May 2022 09:24:11 +0000 (11:24 +0200)]
Remove publish-doc

We don't use this script anymore.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agowl_shell is not mandatory
Demi Marie Obenour [Tue, 5 Oct 2021 14:06:07 +0000 (10:06 -0400)]
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>
2 years agoos: drop unnecessary memcpy in wl_os_mremap_maymove
Simon Ser [Tue, 29 Mar 2022 08:16:17 +0000 (10:16 +0200)]
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>
2 years agoshm: Close file descriptors not needed
Olivier Fourdan [Mon, 10 Jan 2022 14:10:07 +0000 (15:10 +0100)]
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

2 years agoconnection: change clen type in build_cmsg to size_t
Sigrid Solveig Haflínudóttir [Tue, 29 Mar 2022 16:51:15 +0000 (18:51 +0200)]
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>
2 years agoconnection: fix asan report on sendmsg call
Sigrid Solveig Haflínudóttir [Tue, 29 Mar 2022 15:59:15 +0000 (17:59 +0200)]
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>
2 years agomeson: Use proper type for bools
illiliti [Sat, 2 Apr 2022 13:32:46 +0000 (16:32 +0300)]
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>
2 years agoserver: introduce wl_signal_emit_mutable
Simon Ser [Mon, 31 Jan 2022 22:09:26 +0000 (23:09 +0100)]
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>
2 years agoprotocol: add the wl_pointer.axis_value120 events
Peter Hutterer [Tue, 31 Mar 2020 03:47:04 +0000 (13:47 +1000)]
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>
2 years agoclient, server: handle wl_map_insert_new() failures
Aleksandr Mezin [Wed, 9 Feb 2022 00:26:18 +0000 (06:26 +0600)]
client, server: handle wl_map_insert_new() failures

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
2 years agoutil: set errno in wl_map_insert_at()
Aleksandr Mezin [Tue, 8 Feb 2022 23:36:11 +0000 (05:36 +0600)]
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>
2 years agoutil: set errno in wl_map_reserve_new()
Aleksandr Mezin [Tue, 8 Feb 2022 22:10:42 +0000 (04:10 +0600)]
util: set errno in wl_map_reserve_new()

And also fix wl_connection_demarshal() to pass through that errno.

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
2 years agoutil: always check result of wl_array_add()
Aleksandr Mezin [Wed, 26 Jan 2022 13:16:55 +0000 (19:16 +0600)]
util: always check result of wl_array_add()

Not checking the result of wl_array_add() can cause writes past the end of the
allocated buffer if realloc fails.

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
2 years agobuild: use get_variable(pkgconfig) instead of get_pkgconfig_variable()
Simon Ser [Tue, 8 Mar 2022 12:58:17 +0000 (13:58 +0100)]
build: use get_variable(pkgconfig) instead of get_pkgconfig_variable()

We don't get a warning for it yet, but get_pkgconfig_variable() is
deprecated.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: specify native arg in add_languages()
Simon Ser [Tue, 8 Mar 2022 12:57:23 +0000 (13:57 +0100)]
build: specify native arg in add_languages()

Fixes the following warning:

    WARNING: add_languages is missing native:, assuming languages are wanted for
    both host and build.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: use full_path() instead of path()
Simon Ser [Tue, 8 Mar 2022 12:56:32 +0000 (13:56 +0100)]
build: use full_path() instead of path()

Fixes the following warning:

    WARNING: Project targeting '>= 0.56.0' but tried to use feature deprecated
    since '0.55.0': ExternalProgram.path. use ExternalProgram.full_path() instead

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agoconnection: Make wl_closure_print output atomic
Alexander Irion [Mon, 7 Mar 2022 14:49:49 +0000 (15:49 +0100)]
connection: Make wl_closure_print output atomic

When multiple threads are used, output from different threads was intermixed in one line. That what breaking parsing of the log messages. Now, intermixing is prevented by using a memstream.

Signed-off-by: Alexander Irion <alexander_irion@mentor.com>
2 years agoprotocol: wl_shm.format events are actually sent after bind
Mikhail Gusarov [Sun, 20 Feb 2022 19:10:49 +0000 (20:10 +0100)]
protocol: wl_shm.format events are actually sent after bind

Protocol documentation mistakenly specified that wl_shm.format
events are sent at connection setup time, but that's impossible
(clients do not yet know ID of wl_shm object at the time) and
contradicts implementation in libwayland.

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
2 years agomeson: use absolute paths for doxygen stamp files
Simon Ser [Tue, 5 Jan 2021 11:07:13 +0000 (12:07 +0100)]
meson: use absolute paths for doxygen stamp files

The relative paths are incorrect when running as a subproject.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agomeson: use project build root for doxygen output
Simon Ser [Tue, 5 Jan 2021 11:05:11 +0000 (12:05 +0100)]
meson: use project build root for doxygen output

meson.build_root() returns the parent's build directory if Wayland is
a subproject. This fails with:

    error: tag OUTPUT_DIRECTORY: Output directory '<parent-build-dir>/doc/doxygen' does not exist and cannot be created

Instead, use meson.project_build_root(), which returns the subproject's
build directory.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agomeson: build requirement to 0.56.0
Simon Ser [Tue, 5 Jan 2021 11:10:58 +0000 (12:10 +0100)]
meson: build requirement to 0.56.0

meson.project_build_root() is only available with 0.56.0.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agocursor: Remove unused XcursorLibraryLoadImages() function
Vlad Zahorodnii [Thu, 27 Jan 2022 19:11:20 +0000 (21:11 +0200)]
cursor: Remove unused XcursorLibraryLoadImages() function

XcursorLibraryLoadImages() function is unused and not exported according to
objdump, so its removal should be an ABI compatible change.

Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
2 years agodisplay-test: Fix a race condition in test suite
Fergus Dall [Tue, 14 Dec 2021 23:31:41 +0000 (10:31 +1100)]
display-test: Fix a race condition in test suite

Several tests in this suite use setting and checking client.display_stopped (in
test-compositor.h) to synchronise between threads. This is a data race because
display_stopped is a non-atomic int. Fix this by making it an atomic_bool
instead. We don't need to change the access code because reads and writes are
sequentially consistent by default.

This can be reproduced (with both clang and gcc) by running
```
meson -Db_sanitize=thread build
cd build
ninja
meson test
```

Signed-off-by: Fergus Dall <sidereal@google.com>
2 years agoUse zalloc for structs
Simon Ser [Mon, 31 Jan 2022 21:23:30 +0000 (22:23 +0100)]
Use zalloc for structs

When allocating memory for structs, use zalloc instead of malloc.
This ensures the memory is zero-initialized, and reduces the risk
of forgetting to initialize all struct fields.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: explicitly set check arg in run_command()
Simon Ser [Wed, 2 Feb 2022 14:04:42 +0000 (15:04 +0100)]
build: explicitly set check arg in run_command()

Fixes the following warning:

    WARNING: You should add the boolean check kwarg to the run_command call.
             It currently defaults to false,
             but it will default to true in future releases of meson.
             See also: https://github.com/mesonbuild/meson/issues/9300

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agoprotocol: xkb_v1 is null-terminated
Julian Orth [Mon, 10 Jan 2022 16:31:07 +0000 (17:31 +0100)]
protocol: xkb_v1 is null-terminated

Closes #270

Signed-off-by: Julian Orth <ju.orth@gmail.com>
2 years agobuild: set c_std=c99
Simon Ser [Mon, 10 Jan 2022 13:54:02 +0000 (14:54 +0100)]
build: set c_std=c99

Set explicitly the C standard to use to make sure we don't use
features not available on our target platforms.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: don't rely on implicit GNU extensions
Simon Ser [Mon, 10 Jan 2022 13:51:55 +0000 (14:51 +0100)]
build: don't rely on implicit GNU extensions

Currently libwayland assumes GNU extensions will be available, but
doesn't define the C standard to use. Instead, let's unconditionally
enable POSIX extensions, and enable GNU extensions on a case-by-case
basis as needed.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agotests: use __typeof__ instead of typeof
Simon Ser [Mon, 10 Jan 2022 13:50:05 +0000 (14:50 +0100)]
tests: use __typeof__ instead of typeof

typeof is a GNU extension. Compiler extensions should be prefixed
with __ per the C standard.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: re-open main branch for regular development
Simon Ser [Mon, 10 Jan 2022 10:12:39 +0000 (11:12 +0100)]
build: re-open main branch for regular development

2 years agodoc: fix typo in wl_data_device.data_offer
shierote [Mon, 20 Dec 2021 12:25:23 +0000 (21:25 +0900)]
doc: fix typo in wl_data_device.data_offer

Signed-off-by: Taishi Eguchi <taishi2060@gmail.com>
2 years agotests: Fix tc_client_fd_leaks_exec test
Derek Foreman [Wed, 5 Jan 2022 22:20:49 +0000 (16:20 -0600)]
tests: Fix tc_client_fd_leaks_exec test

tc_client_fd_leaks and tc_client_fd_leaks_exec are currently the exact
same test. It seems clear from the name that the latter was intended to
spawn sanity_fd_leak_exec instead of sanity_fd_leak.

Fixes #121

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2 years agoprotocol: clarify wl_shm_pool.resize
Max Ihlenfeldt [Wed, 15 Dec 2021 17:14:56 +0000 (18:14 +0100)]
protocol: clarify wl_shm_pool.resize

Add a note that the request only changes the size of the memory mapping
and does not touch the mapped file.

Signed-off-by: Max Ihlenfeldt <mihlenfeldt@igalia.com>
2 years agodoc: Clarify that null terminator is included in string length
Mikhail Gusarov [Sat, 18 Dec 2021 13:19:41 +0000 (14:19 +0100)]
doc: Clarify that null terminator is included in string length

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
2 years agodoc: Clarify position of file descriptors in the stream
Mikhail Gusarov [Fri, 10 Dec 2021 11:44:44 +0000 (12:44 +0100)]
doc: Clarify position of file descriptors in the stream

The specification left the position and order of file
descriptors unspecified. Specify that

- order of file descriptors is maintained
- position of file descriptors is bounded, but loose

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
2 years agobuild: bump to version 1.20.0 for the official release duna_test tizen_work_20220121 tizen_work_20220124 upstream_bkup_20230216 upstream_work_20220121 upstream_work_20220124 upstream_work_20220208 1.20.0 upstream/1.20.0
Simon Ser [Thu, 9 Dec 2021 16:20:36 +0000 (17:20 +0100)]
build: bump to version 1.20.0 for the official release

2 years agomeson: override dependencies to ease use as subproject
Simon Ser [Tue, 7 Dec 2021 23:27:58 +0000 (00:27 +0100)]
meson: override dependencies to ease use as subproject

Make it easier to use Wayland as a Meson subproject by overriding
dependencies we define. This allows to easily build Wayland as a
subproject like so:

    subproject('wayland', required: false, default_options: ['documentation=false'])

After this statement, the wayland-* dependencies will use the subproject
instead of the system if available.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: bump to version 1.19.93 for the RC1 release 1.19.93
Simon Ser [Thu, 2 Dec 2021 19:50:58 +0000 (20:50 +0100)]
build: bump to version 1.19.93 for the RC1 release

2 years agobuild: bump to version 1.19.92 for the beta release 1.19.92
Simon Ser [Thu, 18 Nov 2021 15:30:09 +0000 (16:30 +0100)]
build: bump to version 1.19.92 for the beta release

2 years agoprotocol: clarify wl_data_offer::selection
Jan Grulich [Fri, 16 Jul 2021 11:35:37 +0000 (13:35 +0200)]
protocol: clarify wl_data_offer::selection

Clearly specify that switching focus within the same client
doesn't mean a new selection will be send.

Signed-off-by: Jan Grulich <jgrulich@redhat.com>
2 years agoprotocol: sync wl_shm.format with libdrm 2.4.108
Manuel Stoeckl [Fri, 12 Nov 2021 00:47:14 +0000 (19:47 -0500)]
protocol: sync wl_shm.format with libdrm 2.4.108

The four new formats added (all 16 bpc, RGB colorspace) are very useful
for applications providing high bit depth content and rendering their
buffers on CPU, as computations with 16 bit unsigned integers are often
more efficient than with the (half float, 10 bit) alternative formats.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2 years agobuild: bump to version 1.19.91 for the alpha release 1.19.91
Simon Ser [Thu, 4 Nov 2021 19:39:22 +0000 (20:39 +0100)]
build: bump to version 1.19.91 for the alpha release

2 years agowayland-shm: Check the size of sealed memory if ignoring SIGBUS handlers
Duncan McIntosh [Sun, 17 Oct 2021 00:28:34 +0000 (20:28 -0400)]
wayland-shm: Check the size of sealed memory if ignoring SIGBUS handlers

In 11623e8f, SIGBUS handlers aren't set if F_SEAL_SHRINK is configured on
the memory. This helps avoid setting up handlers with cooperative clients;
however, if an application gives an incorrect size, the compositor would
access it anyways, figuring SIGBUS is impossible, and crash.

This can be fixed by simply removing the seal-checking logic and always
setting the signal handler. However, it seems that fstat can give the size
of the memfd, so we can check that the size we were told is within the
region. Since it's sealed to shrinking, it must never be shrunk in future,
so we can really (hopefully) ignore SIGBUS.

I was worried that fstat wasn't supported for this, but shm_overview(7) does
mention that it is a possible use.

The best solution would likely be avoiding SIGBUS entirely with
MAP_NOSIGBUS, but that hasn't been merged yet and wouldn't help systems
without it (e.g. with older kernels).

A proof-of-concept of this crash is attached with the merge request. Running
it with this patch gives an invalid-shm error, which is correct.

Signed-off-by: Duncan McIntosh <duncan82013@live.ca>
2 years agoprotocol: wl_shm uses pre-multiplied alpha
Simon Ser [Sun, 31 Oct 2021 11:10:08 +0000 (12:10 +0100)]
protocol: wl_shm uses pre-multiplied alpha

Add a note about pre-multiplied alpha for all wl_shm formats.
Include an escape hatch in the spec to allow other protocol
extensions to override this.

Signed-off-by: Simon Ser <contact@emersion.fr>
Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/61

2 years agodebug: Fix printing of new ids
Derek Foreman [Tue, 24 Aug 2021 22:08:51 +0000 (17:08 -0500)]
debug: Fix printing of new ids

The client side closure traces have incorrect object ids for new server
generated objects. This is because create_proxies() overwrites the id in
'n' type arguments by storing a pointer to the actual object in the 'o'
field of the union.

Getting back to an id from this pointer requires accessing a structure
that isn't visible outside of wayland-client.c.

Add a function pointer to fish the correct value out of the argument and
pass it to wl_closure_print.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2 years agoprotocol: add wl_output.{name,description}
Simon Ser [Sun, 24 Jan 2021 11:26:53 +0000 (12:26 +0100)]
protocol: add wl_output.{name,description}

This is inspired from xdg-output-unstable-v1. This allows clients to
get the name and description without having to use xdg_output. This
should eventually allow us to restrict xdg_output to clients like
Xwayland.

The name is a unique non-persistent user-friendly string that can be
used to refer to an output. This can be used by Wayland clients to
refer to a specific wl_output (e.g. across processes or in CLI
arguments).

The description is a non-unique user-friendly string that can be
displayed to the user.

Signed-off-by: Simon Ser <contact@emersion.fr>
References: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/7

2 years agoprotocol: add note about wl_output.done in events
Simon Ser [Tue, 28 Sep 2021 13:36:14 +0000 (15:36 +0200)]
protocol: add note about wl_output.done in events

Mention that geometry, mode and scale wl_output events are followed
by a done event.

Signed-off-by: Simon Ser <contact@emersion.fr>
2 years agobuild: Include the Wayland minor version in libraries' ABI versions
Simon McVittie [Fri, 10 Sep 2021 17:32:00 +0000 (18:32 +0100)]
build: Include the Wayland minor version in libraries' ABI versions

The ABI of a shared library on Linux is given by a major version, which
is part of the SONAME and is incremented (rarely) on incompatible
changes, and a minor version, which is part of the basename of the
regular file to which the SONAME provides a symlink.

Until now, the ABI minor version was hard-coded, which means we can't
tell which of a pair of Wayland libraries is newer (and therefore
likely to have more symbols and/or fewer bugs).

libwayland-egl already had ABI major version 1, so we can use the
"marketing" version number as the ABI major.minor version number
directly, so Wayland 1.19.90 would produce
libwayland-egl.so.1 -> libwayland-egl.so.1.19.90.

libwayland-cursor and libwayland-server have ABI major version 0,
and OS distributions don't like it when there's a SONAME bump for no
good reason, so use their existing ABI major version together with
the "marketing" minor version:
libwayland-cursor.so.0 -> libwayland-cursor.so.0.19.90.

If the Wayland major version number is incremented to 2, we'll have to
rethink this, so add some error() to break the build if/when that
happens. Assuming that Wayland 2.0 would involve breaking changes,
the best way would probably to bump all the SONAMEs to
libwayland-foo.so.2.

Resolves: https://gitlab.freedesktop.org/wayland/wayland/-/issues/175
Signed-off-by: Simon McVittie <smcv@collabora.com>
2 years agoprotocol: Add wl_surface.offset
Jonas Ådahl [Mon, 22 Mar 2021 07:56:30 +0000 (08:56 +0100)]
protocol: Add wl_surface.offset

This is meant to address the issue where the call to 'wl_surface.attach'
is done by e.g. Vulkan, meaning applications cannot affect the values of
the offset passed as the x and y arguments.

The lack of ability to pass these is problematic when using the Vulkan
for e.g. drawing DND surfaces, as the buffer offset is used to implement
the drag icon hotspots.

Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/148
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
2 years agoclient: handle fcntl error on bad fd in wl_display_connect
Manuel Stoeckl [Sun, 1 Aug 2021 05:38:45 +0000 (01:38 -0400)]
client: handle fcntl error on bad fd in wl_display_connect

This makes wl_display_connect fail immediately instead of
succeeding when the integer provided by WAYLAND_SOCKET does
not refer to a valid file descriptor.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2 years agoserver: stop wl_display event loop from any context
Damian Hobson-Garcia [Tue, 31 Aug 2021 09:59:33 +0000 (18:59 +0900)]
server: stop wl_display event loop from any context

Calling wl_display_terminate() will exit the wl_display event loop
at the start of the next loop iteration.  This works fine when
wl_display_terminate() is called after the event loop wakes up
from polling on the added event sources.  If, however, it is
called before polling starts, the event loop will not exit until
one or more event sources trigger.  Depending on the types of event
sources, they may never trigger (or may not trigger for a long time),
so the event loop may never exit.

Add an extra event source to the wl_display event loop that will trigger
whenever wl_display_terminate() is called, so that the event loop will
always exit.

Fixes #201

Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
2 years agoprotocol: mention that buffers with alpha are assumed premultiplied
Matt Hoosier [Wed, 29 Sep 2021 14:41:34 +0000 (09:41 -0500)]
protocol: mention that buffers with alpha are assumed premultiplied

This turns out to be the default assumption by compositors, OpenGL, and the DRM
framework. Let's say it explicitly to avoid misinterpretation.

See https://lists.freedesktop.org/archives/wayland-devel/2021-September/041990.html.

Signed-off-by: Matt Hoosier <matt.hoosier@garmin.com>
2 years agoshm: Relax shm_pool_create_buffer() validity check
Olivier Fourdan [Thu, 16 Sep 2021 09:11:05 +0000 (11:11 +0200)]
shm: Relax shm_pool_create_buffer() validity check

shm_pool_create_buffer() can raise a false WL_SHM_ERROR_INVALID_STRIDE
error under some circumstances because of integer division.

Fix this by using a strict comparison operator instead of lower or
equal.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/235