Commit Graph

97 Commits

Author SHA1 Message Date
He Yong ac1232e576 tinywl: destroy wlr_renderer, wlr_allocator and wlr_cursor
Suggested-by: Alexander Bakker <ab@alexbakker.me>
Suggested-by: Simon Ser <contact@emersion.fr>
2024-03-14 10:07:56 +00:00
Simon Ser 7915a2ff59 tinywl: fix wlr_seat use-after-free on exit
When pressing the keybinding to shut down the compositor, the following
use-after-free is triggered:

    ==1165966==ERROR: AddressSanitizer: heap-use-after-free on address 0x51800000ade0 at pc 0x7fa6728b4531 bp 0x7ffe540a6aa0 sp 0x7ffe540a6a90
    READ of size 8 at 0x51800000ade0 thread T0
        #0 0x7fa6728b4530 in wlr_seat_set_keyboard ../types/seat/wlr_seat_keyboard.c:124
        #1 0x58a83fa7fd4e in keyboard_handle_key ../tinywl/tinywl.c:228
        #2 0x7fa673a1901d in wl_signal_emit_mutable (/usr/lib/libwayland-server.so.0+0xa01d) (BuildId: d943a6a6069d1b5293dad7c842d26ce407ebdd19)
        #3 0x7fa67295b4be in wlr_keyboard_notify_key ../types/wlr_keyboard.c:102
        #4 0x7fa67295c791 in wlr_keyboard_finish ../types/wlr_keyboard.c:165
        #5 0x7fa672848cb1 in destroy_wl_seat ../backend/wayland/seat.c:293
        #6 0x7fa672833dca in backend_destroy ../backend/wayland/backend.c:493
        #7 0x7fa6727b49e8 in wlr_backend_destroy ../backend/backend.c:67
        #8 0x7fa67282d334 in multi_backend_destroy ../backend/multi/backend.c:59
        #9 0x7fa67282da5a in handle_event_loop_destroy ../backend/multi/backend.c:110
        #10 0x7fa673a18b98 in wl_event_loop_destroy (/usr/lib/libwayland-server.so.0+0x9b98) (BuildId: d943a6a6069d1b5293dad7c842d26ce407ebdd19)
        #11 0x7fa673a1b43c in wl_display_destroy (/usr/lib/libwayland-server.so.0+0xc43c) (BuildId: d943a6a6069d1b5293dad7c842d26ce407ebdd19)
        #12 0x58a83fa8ada1 in main ../tinywl/tinywl.c:1068
        #13 0x7fa672043ccf  (/usr/lib/libc.so.6+0x25ccf) (BuildId: c0caa0b7709d3369ee575fcd7d7d0b0fc48733af)
        #14 0x7fa672043d89 in __libc_start_main (/usr/lib/libc.so.6+0x25d89) (BuildId: c0caa0b7709d3369ee575fcd7d7d0b0fc48733af)
        #15 0x58a83fa7e7c4 in _start (/home/simon/src/wlroots/build/tinywl/tinywl+0x167c4) (BuildId: 1febf2a5a18bda0f6b67377a132484061875e248)

    0x51800000ade0 is located 352 bytes inside of 880-byte region [0x51800000ac80,0x51800000aff0)
    freed by thread T0 here:
        #0 0x7fa6732dfdb2 in __interceptor_free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:52
        #1 0x7fa6728c6a1e in wlr_seat_destroy ../types/seat/wlr_seat.c:245
        #2 0x7fa6728c6a7a in handle_display_destroy ../types/seat/wlr_seat.c:251
        #3 0x7fa673a1b3c6 in wl_display_destroy (/usr/lib/libwayland-server.so.0+0xc3c6) (BuildId: d943a6a6069d1b5293dad7c842d26ce407ebdd19)

    previously allocated by thread T0 here:
        #0 0x7fa6732e0cc1 in __interceptor_calloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77
        #1 0x7fa6728c6a9d in wlr_seat_create ../types/seat/wlr_seat.c:255
        #2 0x58a83fa8a8d3 in main ../tinywl/tinywl.c:1024
        #3 0x7fa672043ccf  (/usr/lib/libc.so.6+0x25ccf) (BuildId: c0caa0b7709d3369ee575fcd7d7d0b0fc48733af)

This happens because the wlr_seat is destroyed before the
wlr_keyboard. Destroying the wlr_keyboard has the side effect of
implicitly releasing keys currently held down.

Explicitly destroying the wlr_backend before the wl_display fixes
this.

Suggested-by: Isaac Freund <ifreund@ifreund.xyz>
2024-03-04 12:50:14 +00:00
Simon Ser 812451cd8f pointer: use enum wl_pointer_button_state 2024-02-28 16:39:18 +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
Kirill Primak 811ca199c4 xdg-shell: drop automatic surface configuration
Compositors now are expected to wait for an initial commit by checking
wlr_xdg_surface.initial_commit on every surface commit and send
(schedule) configure events manually.
2024-02-06 13:48:00 +00:00
Simon Ser d1b39b5843 backend: take wl_event_loop instead of wl_display in wlr_backend_autocreate() 2024-01-25 15:05:36 +00:00
Simon Ser 00bb1b0f84 seat/pointer: add support for axis_relative_direction event 2024-01-23 08:37:29 +00:00
Kirill Primak ce89f49b7a tinywl: depend on the server xdg-shell header 2024-01-09 21:39:02 +03:00
Kirill Primak 425f5c07fb tinywl: check initialized instead of initial_commit
oops
2023-12-07 17:59:07 +03:00
Kirill Primak 1cc7ab3e29 tinywl: don't send configures to uninitialized xdg_surfaces 2023-12-07 12:43:39 +03:00
Kirill Primak c85838892d xdg-{shell,decoration}: improve events
This commit changes the behavior of `new_*` signals to better match
their names (see https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3608).
wlr_xdg_shell.events.new_surface is now emitted when an xdg_surface is
created, and wlr_xdg_shell.events.new_{toplevel,popup} events are
introduced to get notified when an xdg_{toplevel,popup} is created.
Same applies to
`wlr_xdg_decoration_manager_v1.events.new_toplevel_decoration`. As a
result, wlr_xdg_surface.added and wlr_xdg_toplevel_decoration_v1.added
are removed, as we no longer need to track whether the corresponding
event was emitted.

Additionally, this commit changes the behavior of
wlr_xdg_surface.events.destroy: it is now emitted when the xdg_surface
is destroyed, as the name suggests.
wlr_xdg_{toplevel,popup}.events.destroy events are added to get
notified when an xdg_{toplevel,popup} is destroyed.
2023-11-23 12:52:20 +00:00
Simon Ser 6a7463bb8e output-layout: take wl_display in constructor
The output layout creates and destroys wl_output globals. We will
soon need the wl_display to do so.
2023-11-23 11:39:25 +00:00
Simon Ser 3b4d7d2a92 build: bump version to 0.18.0-dev 2023-11-21 17:28:06 +01:00
Simon Ser fe53ec6937 tinywl: fix wlroots dependency constraint in Makefile 2023-11-21 17:22:02 +01:00
Kirill Primak 6cf0bb4b19 tinywl: don't use "I"/"my" in docs 2023-11-14 19:46:04 +03:00
Kirill Primak 73a387d3b6 tinywl: fix xdg_toplevel_destroy() docs 2023-11-14 19:40:26 +03:00
Simon Ser 73ab5246ea tinywl: stop using the word "view" to refer to toplevels
"View" has been cargo-culted from Weston. In Weston, a view is not
even necessarily a toplevel -- it's just a way to draw an arbitrary
somewhere (a surface may be painted at multiple locations
simultaneously). The Weston concept has been misunderstood and then
was carried over to rootston, Sway, and tinywl.

Let's just use the official Wayland wording instead.
2023-11-14 17:31:35 +01:00
Simon Ser 9e5d0f95f8 tinywl: fix crash when previously focused surface is not a toplevel
It can be e.g. a popup.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3754
2023-11-13 10:32:03 +01:00
Alexander Orzechowski 1b0694b794 treewide: Migrate from sizeof(struct) to sizeof(*pointer) where practical 2023-10-03 01:51:07 -04:00
Simon Ser 2926acf60d tinywl: set minimum wlroots version in Makefile 2023-09-01 00:28:55 +09:00
Rose Hudson f5917f0247 scene_output_layout: make output adding explicit
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3709
2023-08-22 11:53:28 +02:00
Kirill Primak 10ba8ebc70 Don't assume xdg_surface.{toplevel,popup} is non-NULL
This assumption will become incorrect with future commits.
2023-08-21 16:30:29 +00:00
Rose Hudson 214df8eda0 scene_output: optionally record and report timings 2023-07-10 09:57:02 +00:00
Simon Ser 9e6431dc3b tinywl: enable new outputs 2023-06-27 16:26:30 +00:00
Simon Ser be05097968 output: add wlr_output_state_init()
This changes the semantics of wlr_output_state. Instead of having
fields with uninitialized memory when missing from the committed
bitflag, all fields are always initialized (and maybe NULL/empty),
just like we do in wlr_surface_state. This reduces the chances of
footguns when reading a field, and removes the need to check for
the committed bitfield everywhere.

A new wlr_output_state_init() function takes care of initializing
the Pixman region.
2023-06-23 18:07:26 +00: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
Alexander Orzechowski 73ca1ea48a tinywl: Drop usage of wlr_output.pending 2023-06-13 09:19:51 +00:00
Kirill Primak b0437fc416 xdg-shell: use unified map logic 2023-06-02 17:26:18 +00:00
Alexander Orzechowski d5320e5f20 tinywl: Release everything before destroy
This makes -Db_sanatize=address happy.
2023-05-02 10:48:31 -04:00
Simon Ser 0bb574239d compositor: pass version in wlr_compositor_create
This allows wlroots to support newer versions of the interface
without breaking the API.
2023-04-14 17:07:26 +02:00
Kirill Primak 3a200aa279 tinywl: init server to zeros
This fixes e.g. accessing grabbed_view on a toplevel unmap if no
toplevel was grabbed before.
2023-03-04 17:01:11 +03:00
Alexander Orzechowski 7b32c25a4f wlr_scene: Rename wlr_scene_surface_from_buffer
This renames it to wlr_scene_surface_try_from_buffer to be more clear
that this function can return NULL. This is inline with the rest of
wlroots[1].

[1] https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3991
2023-02-04 02:57:42 -05:00
Simon Ser 711a1a3ed4 xdg-shell: convert to try_from
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/884
2023-02-01 20:12:49 +01:00
Simon Ser 3668c9d86c examples, tinywl: use "default" cursor instead of "left_ptr"
"left_ptr" is the X11 name, "default" is the cursor spec name.
2023-02-01 15:00:42 +01:00
Simon Ser 90d7bce994 tinywl: fix extra whitespace 2023-01-24 00:14:22 +01:00
Alexander Orzechowski e0b2bf2a6b tinywl: Nuke view->{x, y}
Instead use the scene node position.
2023-01-04 01:47:49 -05:00
Kirill Primak 825f1b2dc6 tinywl: handle wlr_output.events.request_state 2022-12-06 09:05:32 +00:00
Simon Ser 41b7acbab7 backend: return wlr_session in wlr_backend_autocreate() call
Up until now, wlr_backend_autocreate() created the wlr_session and
then stuffed it into struct wlr_multi_backend so that compositors
can grab it later.

This is an abuse of wlr_multi_backend and the wlr_backend API:
wlr_backend_get_session() and wlr_multi_backend.session only exist
to accomodate the needs of wlr_backend_autocreate(). What's more,
the DRM and libinput backends don't implement
wlr_backend_impl.get_session.

Instead, return the struct wlr_session to the compositor in the
wlr_backend_autocreate() call. wlr_backend_get_session() will be
removed in the next commit.
2022-11-15 21:16:25 +00:00
Kirill Primak b7623694ac tinywl: handle view unmap while grabbed
Fixes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3372
2022-11-07 20:09:25 +03:00
Simon Zeni 517ea218c6 tinywl: exit on backend, renderer or allocator creation failure 2022-06-28 13:43:36 +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
Alexander Orzechowski ccd0f85c2a wlr_scene: Only allow parenting on a wlr_scene_tree 2022-05-31 09:14:28 +00:00
Alexander Orzechowski 9eb71146ae wlr_scene: Refactor wlr_scene (the root element) to encase a wlr_scene_tree
Co-authored-by: Isaac Freund <mail@isaacfreund.com>
2022-05-31 09:14:28 +00:00
Kirill Primak 75d31509db tinywl: use xdg-shell v3 2022-05-27 13:31:30 +00:00
Alexander Orzechowski dc9bc5683a wlr_scene: Refactor wlr_scene_surface to be a helper on top of wlr_scene_buffer 2022-05-19 14:26:50 -04:00
Simon Ser 8fe3aa29da xdg-shell: specify version in wlr_xdg_shell_create
With protocol additions such as [1], compositors currently have no
way to opt out of the version upgrade. The protocol upgrade will
always be backwards-compatible but may require new compositor
features.

The status quo doesn't make it possible to ship a protocol addition
without breaking the wlroots API. This will be an issue for API
stabilization [2].

To address this, let compositors provide a maximum version in the
function creating the global. We need to support all previous versions
of the interface anyways because of older clients.

This mechanism works the same way as Wayland clients passing a version
in wl_global.bind.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3514
[2]: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/1008

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3397
2022-05-15 15:44:40 +00:00
Simon Ser fa9b61004b tinywl: don't crash when there is no keyboard
Running with WLR_BACKENDS=headless, there is no keyboard device.
Avoid crashes like so:

    ../tinywl/tinywl.c:136:2: runtime error: member access within null pointer of type 'struct wlr_keyboard'
    ../tinywl/tinywl.c:136:2: runtime error: member access within null pointer of type 'struct wlr_keyboard'
    AddressSanitizer:DEADLYSIGNAL
    =================================================================
    ==331107==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000120 (pc 0x556ed03e4e99 bp 0x7ffce834bc10 sp 0x7ffce834bbb0 T0)
    ==331107==The signal is caused by a READ memory access.
    ==331107==Hint: address points to the zero page.
        #0 0x556ed03e4e99 in focus_view ../tinywl/tinywl.c:136
        #1 0x556ed03eb3be in xdg_toplevel_map ../tinywl/tinywl.c:603
        #2 0x7f75d6f768db in wlr_signal_emit_safe ../util/signal.c:29
        #3 0x7f75d6e9cac7 in xdg_surface_role_commit ../types/xdg_shell/wlr_xdg_surface.c:315
        #4 0x7f75d6eb6944 in surface_commit_state ../types/wlr_compositor.c:466
        #5 0x7f75d6eb7b02 in surface_handle_commit ../types/wlr_compositor.c:523
        #6 0x7f75d5714d49  (/usr/lib/libffi.so.8+0x6d49)
        #7 0x7f75d5714266  (/usr/lib/libffi.so.8+0x6266)
        #8 0x7f75d68cb322  (/usr/lib/libwayland-server.so.0+0xd322)
        #9 0x7f75d68c65cb  (/usr/lib/libwayland-server.so.0+0x85cb)
        #10 0x7f75d68c91c9 in wl_event_loop_dispatch (/usr/lib/libwayland-server.so.0+0xb1c9)
        #11 0x7f75d68c6d36 in wl_display_run (/usr/lib/libwayland-server.so.0+0x8d36)
        #12 0x556ed03eef55 in main ../tinywl/tinywl.c:905
        #13 0x7f75d5d2330f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)
        #14 0x7f75d5d233c0 in __libc_start_main@GLIBC_2.2.5 (/usr/lib/libc.so.6+0x2d3c0)
        #15 0x556ed03e46e4 in _start (/home/simon/src/wlroots/build/tinywl/tinywl+0x136e4)
2022-05-10 16:37:21 +00:00
xiaoyaobing cb012c5cb5 tinywl/tinywl: clean up tinywl_output when wlr_output is gone
Add destroy event processing.

Fixes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3416
2022-05-06 20:05:17 +03:00
Kirill Primak dec2565f2b xdg-toplevel: don't schedule configures on state requests 2022-04-13 17:00:06 +00:00
Kirill Primak 578e5614d4 tinywl: remove outdated non-feature from README.md
Now that tinywl uses wlr_scene under the hood, damage tracking comes for
free.
2022-04-01 14:22:28 +00:00