Commit Graph

1781 Commits

Author SHA1 Message Date
Isaac Freund a819c512ec foreign-toplevel: send enter if needed on output bind
Currently the output enter event is never sent if the client has not
yet bound the output, which happens every time the compositor creates a
new output.

To fix this, listen for the output bind event and inform clients as
if needed.

(cherry picked from commit 1bd0ea3a809bdba092ef051120bb6d32f79c0ffb)
2022-02-03 22:15:39 +01:00
Alexander Orzechowski c4824b680a xdg-foreign: Fix crash on destroy of degenerate surface
I am running a custom compiled version of chromium with a patch to get
it up and running on sway git at the moment, and in that development
build I compiled there is a bug where the browser will crash if you
try to open a file select dialog. When this crash happens, chromium will
not close, but instead will remain open and impossible to close unless
you send a SIGKILL signal to the process. However, sway will crash to
tty when you send the SIGKILL.

I have a hunch that when chromium is opening the file select dialog
it is creating some sort of a xdg toplevel surface. But it freezes
before it fully initializes the surface. When the SIGKILL signal is
given, sway/wlroots will try to free the xdg_toplevel surface but
because it hasn't fully initialized due to the frozen window, it
segfaults.

Don't be fooled by the assert, the assert is not firing, the surface
pointer is indeed NULL here.

* thread #1, name = 'sway', stop reason = signal SIGSEGV: invalid address (fault address: 0x28)
    frame #0: 0x00007ffff78b9041 libwlroots.so.11`wlr_xdg_toplevel_set_parent(surface=0x0000000000000000, parent=0x0000000000000000) at wlr_xdg_toplevel.c:159:37
   156
   157 	void wlr_xdg_toplevel_set_parent(struct wlr_xdg_surface *surface,
   158 			struct wlr_xdg_surface *parent) {
-> 159 		assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
   160 		assert(!parent || parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
   161
   162 		if (surface->toplevel->parent) {
(lldb) up
error: sway {0x0003442a}: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x67) attribute, but range extraction failed (invalid range list offset 0x67), please file a bug and attach the file at the start of this error message
error: sway {0x0003442a}: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x67) attribute, but range extraction failed (invalid range list offset 0x67), please file a bug and attach the file at the start of this error message
frame #1: 0x00007ffff78e176e libwlroots.so.11`destroy_imported(imported=0x000055555626d570) at wlr_xdg_foreign_v1.c:154:3
   151 		wl_list_for_each_safe(child, child_tmp, &imported->children, link) {
   152 			struct wlr_xdg_surface *xdg_child =
   153 				wlr_xdg_surface_from_wlr_surface(child->surface);
-> 154 			wlr_xdg_toplevel_set_parent(xdg_child, NULL);
   155 		}
   156
   157 		wl_list_remove(&imported->exported_destroyed.link);
(lldb) up
frame #2: 0x00007ffff78e1b9d libwlroots.so.11`xdg_imported_handle_resource_destroy(resource=0x00005555562555a0) at wlr_xdg_foreign_v1.c:280:2
   277 			struct wl_resource *resource) {
   278 		struct wlr_xdg_imported_v1 *imported = xdg_imported_from_resource(resource);
   279 		if (!imported) {
-> 280 			return;
   281 		}
   282
   283 		destroy_imported(imported);
(lldb) up
frame #3: 0x00007ffff794989a libwayland-server.so.0`___lldb_unnamed_symbol211 + 154
libwayland-server.so.0`___lldb_unnamed_symbol211:
->  0x7ffff794989a <+154>: andl   $0x1, %r13d
    0x7ffff794989e <+158>: je     0x7ffff79498b0            ; <+176>
    0x7ffff79498a0 <+160>: addq   $0x8, %rsp
    0x7ffff79498a4 <+164>: movl   $0x1, %eax
(lldb) up
frame #4: 0x00007ffff794fec0 libwayland-server.so.0`___lldb_unnamed_symbol290 + 64
libwayland-server.so.0`___lldb_unnamed_symbol290:
->  0x7ffff794fec0 <+64>: cmpl   $0x1, %eax
    0x7ffff794fec3 <+67>: jne    0x7ffff794fed3            ; <+83>
    0x7ffff794fec5 <+69>: addq   $0x8, %rbx
    0x7ffff794fec9 <+73>: cmpq   %rbx, %r13
(lldb) up
frame #5: 0x00007ffff79503e0 libwayland-server.so.0`___lldb_unnamed_symbol300 + 32
libwayland-server.so.0`___lldb_unnamed_symbol300:
->  0x7ffff79503e0 <+32>: cmpl   $0x1, %eax
    0x7ffff79503e3 <+35>: je     0x7ffff79503f0            ; <+48>
    0x7ffff79503e5 <+37>: popq   %rbx
    0x7ffff79503e6 <+38>: popq   %r12
(lldb) up
frame #6: 0x00007ffff794a30e libwayland-server.so.0`wl_client_destroy + 126
libwayland-server.so.0`wl_client_destroy:
->  0x7ffff794a30e <+126>: movq   %r12, %rdi
    0x7ffff794a311 <+129>: callq  0x7ffff7950150            ; ___lldb_unnamed_symbol293
    0x7ffff794a317 <+135>: movq   0x8(%rbp), %rdi
    0x7ffff794a31b <+139>: callq  *0xdc77(%rip)
(lldb) up
frame #7: 0x00007ffff794a3f7 libwayland-server.so.0`___lldb_unnamed_symbol214 + 119
libwayland-server.so.0`___lldb_unnamed_symbol214:
->  0x7ffff794a3f7 <+119>: movq   0x28(%rsp), %rax
    0x7ffff794a3fc <+124>: subq   %fs:0x28, %rax
    0x7ffff794a405 <+133>: jne    0x7ffff794a727            ; <+935>
    0x7ffff794a40b <+139>: addq   $0x38, %rsp
(lldb) up
frame #8: 0x00007ffff794d1ca libwayland-server.so.0`wl_event_loop_dispatch + 202
libwayland-server.so.0`wl_event_loop_dispatch:
->  0x7ffff794d1ca <+202>: addq   $0xc, %r15
    0x7ffff794d1ce <+206>: cmpq   %r15, %rbp
    0x7ffff794d1d1 <+209>: jne    0x7ffff794d1b8            ; <+184>
    0x7ffff794d1d3 <+211>: movq   0x8(%rsp), %rcx
(lldb) up
frame #9: 0x00007ffff794ad37 libwayland-server.so.0`wl_display_run + 39
libwayland-server.so.0`wl_display_run:
->  0x7ffff794ad37 <+39>: movl   0x8(%rbx), %eax
    0x7ffff794ad3a <+42>: testl  %eax, %eax
    0x7ffff794ad3c <+44>: jne    0x7ffff794ad20            ; <+16>
    0x7ffff794ad3e <+46>: popq   %rbx
(lldb) up
frame #10: 0x000055555557689a sway`server_run(server=0x00005555555f26c0) at server.c:307:2
   304 			wlr_backend_destroy(server->backend);
   305 			return false;
   306 		}
-> 307
   308 		return true;
   309 	}
   310
(lldb) up
frame #11: 0x0000555555575a93 sway`main(argc=3, argv=0x00007fffffffe978) at main.c:431:2
   428 			swaynag_show(&config->swaynag_config_errors);
   429 		}
   430
-> 431 		server_run(&server);
   432
   433 	shutdown:
   434 		sway_log(SWAY_INFO, "Shutting down sway");

(cherry picked from commit cddc1c1bd9f796709c50f4bbb300788edd42fd4f)
2022-02-02 20:29:44 +01:00
Simon Ser ec3780e6ea scene: try to import buffers as textures before rendering
The wlroots APIs currently don't allow importing/uploading a buffer
during rendering operations. Scene-graph buffer nodes need to turn
their wlr_buffer into a wlr_texture at some point. It's not always
possible to do so at wlr_scene_buffer creation time because the
scene-graph may have zero outputs at this point, thus no way to
grab a wlr_renderer.

Instead, add scene-graph buffers to a pending list and try to import
them in wlr_scene_output_commit.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3354
(cherry picked from commit 3db1bcbe641b407b9f5c9e5d0a012b45aa2c6cb7)
2022-02-02 20:28:27 +01:00
Kirill Primak 68c5fa340d subsurface: unlock cached state on commit if desynced
wl_subsurface::set_desync description states: "If cached state exists when
wl_surface.commit is called in desynchronized mode, the pending state is
added to the cached state, and applied as a whole."

This commit reintroduces an implementation of said behavior, previously
removed in 7daf6da9ac05be2cb74c0983e3caee0b21db75d4.

Strictly speaking, this logic isn't fully correct, as the cached state
and the pending state are applied individually instead, if the cached
state isn't locked by anything else. However, the end result is still
the same.

This commit fixes the issue with Firefox permission popups.

(cherry picked from commit 77951968dc9df7214c04c33f4905a9a7aa92f60c)
2022-02-02 20:27:49 +01:00
Kirill Primak 304c61307a compositor: damage the whole buffer on viewport src change
wp_viewporter protocol doesn't seem to say anything about damage, but
Firefox assumes that wp_viewport::set_source alone is enough to damage
the whole surface, and that assumption kinda makes sense, so let's do
that.

(cherry picked from commit da2491d4163e1d8e627d00c8ae594c7f8003472e)
2022-02-02 20:25:28 +01:00
Tadeo Kondrak b0fee56974 input_method_v2: improve mapping detection
Detect NULL commits before the surface is actually committed, allowing
the surface to be properly damaged on unmap.

(cherry picked from commit 5091118bed82394de5a151d658e895bb44059b61)
2022-02-02 20:25:24 +01:00
Kirill Primak 7dde2b66d6 scene/subsurface_tree: fix handling subsurface destruction
This commit renames map/unmap listeners to clarify that they handle
subsurface events, and ensures the node is always destroyed before
the subsurface.

Without this patch, wl_list_remove() would operate on listener links in
already freed memory. glibc is usually lenient to bugs like this, but
musl isn't.

(cherry picked from commit 83ab5055fd36bd0f8a0106257e45d8ed303636d8)
2022-02-02 20:08:20 +01:00
Simon Ser df945b665c scene: schedule an output frame on wl_surface.frame
Some clients (e.g. mpv, Firefox) request a new wl_surface.frame
callback without damaging their surface. When this happens,
schedule a new output frame.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3350
(cherry picked from commit 812951f5bc47f502429406e49f4e24f377b7799b)
2022-02-02 20:07:39 +01:00
Stacy Harper 8e566f716c layer-shell: don't set committed flag if the property didn't change
This fixes configure loop in Sway when clients re-send same properties
on every configure event.

Original issue: https://todo.sr.ht/~mil/sxmo-tickets/413
2021-12-15 16:24:33 +03:00
Isaac Freund 07ccc6e0b3
scene: add wlr_scene_set_presentation()
This helper automates sending presentation feedback to clients based on
the primary output of scene surfaces.
2021-12-14 21:34:02 +01: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
Guido Günther 4c59f7d46a xdg-activation: Allow to submit tokens
Allows the compositor to submit tokens to the pool of
currently active tokens. This can be useful when the
launcher doesn't use or support xdg-activation-v1 by
itself - e.g. when it is X11 based or use gtk_shell1.
2021-12-14 12:01:46 +01:00
David Rosca 31914928d2
seat: Only resend keyboard/pointer enter to focused clients
Otherwise it will send enter events to clients that already
have keyboard/pointer focus.
Notably Qt applications warns about this.
2021-12-14 08:23:53 +01:00
Isaac Freund 1c3e0816f3
scene: fix wlr_scene_send_frame_done() API
This doesn't work if scene outputs are not used as the primary output of
scene surfaces will always be NULL.

Therefore, take a wlr_scene_output instead of separate wlr_scene and
wlr_output arguments and rename the function to
wlr_scene_output_send_frame_done().

The actual behavior of the function is unchanged.
2021-12-13 17:26:22 +01:00
Isaac Freund fecde72be3 scene: add wlr_scene_send_frame_done() 2021-12-13 15:21:05 +00:00
Isaac Freund fb1f613510 scene: add primary output to wlr_scene_surface
This allows compositors to avoid sending multiple frame done events
to a surface that is rendered on multiple outputs at once. This may
also be used in the same way for presentation feedback.
2021-12-13 15:21:05 +00:00
Isaac Freund 0215dffba5 scene: send surface enter/leave output events
Co-authored-by: Simon Ser <contact@emersion.fr>
2021-12-13 15:21:05 +00:00
Simon Ser e3fefda023 output: add support for protocol interface version 4
Two new events are added: name and description. The name is
immutable. The description can be updated on-the-fly.
2021-12-13 12:06:16 +00:00
Kirill Primak 0fcc842291 subsurface: don't add to parent list immediately 2021-12-09 18:26:56 +00:00
Kirill Primak 7964bdae76 surface: fix non-buffer damage handling
This commit fixes the way the damage that doesn't come directly from the
client is handled.
2021-12-09 18:26:56 +00:00
Kirill Primak df7d280343 subsurface: apply position change at the right moment
Subsurface position is considered to be a part of the parent surface's
state, therefore it should be modified when the parent is committed.
2021-12-09 18:26:56 +00:00
Kirill Primak f463ca669a subsurface: simplify and fix parent commit handling 2021-12-09 18:26:56 +00:00
Simon Ser 36a2b19485 output: introduce wlr_output_set_name
wlroots picks names for all outputs, but it might be desirable for
compositor to override it.

For instance, Sway will use a headless output as a fallback in
case no outputs are connected. Sway wants to clearly label the
fallback output as such and label "real" headless outputs starting
from HEADLESS-1.
2021-12-09 15:46:46 +01:00
Simon Ser c50c4fc5cc linux-dmabuf-v1: add per-surface feedback 2021-12-07 15:18:19 +01:00
Simon Ser 1d8340754b linux-dmabuf-v1: implement v4
Implement a basic version of linux-dmabuf-unstable-v1 version 4.
Only default hints are implemented.

The new wlr_linux_dmabuf_feedback_v1 data structure will allow
compositors to define their own custom hints in the future. This
data structure makes it easy to describe feedback metadata.

It's converted to a "compiled" form suitable for marshalling over
the Wayland socket via feedback_compile.
2021-12-07 15:18:16 +01:00
Kirill Primak c9f3c2b4f7 surface: fix damage transformation 2021-12-06 15:37:36 +00:00
tiosgz ca1af8119c Fix wlr_scene_node_lower_to_bottom
Before this commit, it would keep the node at the top or make it second-
topmost.
2021-12-04 22:22:56 +00:00
Simon Ser efeb8346cf output: drop front_buffer
This lets backends immediately release committed buffers if they
want to.
2021-12-03 14:56:17 +00:00
Simon Ser 45069fb623 screencopy-v1: use wlr_output_event_commit.buffer 2021-12-03 14:56:17 +00:00
Simon Ser 60b7267e18 export-dmabuf-v1: use wlr_output_event_commit.buffer 2021-12-03 14:56:17 +00:00
Simon Ser f016eca97c output: add wlr_output_event_commit.buffer
This allows output commit listeners to access the newly committed
buffer. Currently wlr_output.front_buffer is used but it'll get
removed in the next commit.
2021-12-03 14:56:17 +00:00
Simon Ser 0d32118a80 output: fix modifier stripping
DRM formats with an empty modifier list are invalid. Instead of
emptying the list, reduce it to { INVALID }.

Add a check to make sure the renderer and backend support implicit
modifiers, so that we don't fallback on e.g. Vulkan.

Closes: https://github.com/swaywm/sway/issues/6692
2021-12-02 14:31:16 +00:00
Simon Ser ba974a4e9f scene: add wlr_scene_get_scene_output
This allows getting a wlr_scene_output from a wlr_output. Since an
output can only be added once to a scene-graph there's no ambiguity.

This is useful for compositors using wlr_scene_attach_output_layout:
the output layout integration automatically creates a scene-graph
output for each wlr_output added to the layout.
2021-11-30 20:16:24 +00:00
Simon Zeni dd84c5a1cc types/wlr_drm_lease_v1: add NULL check to drm lease resource destroy 2021-11-30 19:59:55 +00:00
Simon Ser 697a1cd0f5 output: add wlr_output_get_primary_formats
This allows compositors to get primary formats without manually
calling wlr_output_impl.get_primary_formats.

For example, the Sway patch for linux-dmabuf feedback [1] needs
this.

[1]: https://github.com/swaywm/sway/pull/6313
2021-11-30 20:49:33 +01:00
Simon Ser 2540de494e output: don't leave dangling cursor_front_buffer
Sometimes we were calling wlr_output_impl.set_cursor with a NULL
buffer, but we weren't clearing wlr_output.cursor_front_buffer.
Avoid leaving a dangling buffer behind.

Introduce a helper function output_set_hardware_cursor which calls
wlr_output_impl.set_cursor and keeps cursor_front_buffer in sync.
2021-11-30 18:32:48 +00:00
Simon Ser 456b971099 output: destroy swapchain when disabled
This avoids consuming GPU memory when an output is disabled.
2021-11-30 18:32:48 +00:00
Rouven Czerwinski 6bfb930aa7 linux-dmabuf-v1: fix implicit check
The implicit check to filter out LINEAR for dmabuf checked for INVALID
twice instead of checking for INVALID & LINEAR. Fix this.

Fixes: d37eb5c2ea ("linux-dmabuf-v1: filter out LINEAR if implicit")
Reported-by: Dawid Czeluśniak <czelusniakdawid@gmail.com>
2021-11-29 17:44:34 +01:00
John Lindgren bff5b2c559 Insert new outputs at the end of the list
This prevents auto-configuring a new output from changing the
position of existing outputs.

(v2: simplify insert-at-end logic)
2021-11-29 13:14:31 +00:00
Jonathan Wong 0fb479ca61 Added whitespace between "output" and "(not" 2021-11-28 16:56:09 +00:00
Rouven Czerwinski d37eb5c2ea linux-dmabuf-v1: filter out LINEAR if implicit
If only INVALID and LINEAR are valid modifiers, we need to filter out
LINEAR since Xwayland won't be able to allocate a BO with the explicit
linear modifier on hardware that does not support explicit modifiers.
The addition of LINEAR is an internal implementation detail which
simplifies the wlroots architecture for now.

Evntually Xwayland should be fixed to filter out modifiers that are not
supported by the GBM implementation, see [1]. This could be done by
querying EGL for the supported modifiers.

[1]: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1166
2021-11-27 19:32:25 +01:00
Simon Ser 254ab890e7 scene: add support for viewporter
If the surface has a source box set, use that.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3172
2021-11-26 19:31:19 +00:00
Simon Ser affe9eda57 Require INVALID for implicit format modifiers
See [1] for the motivation.

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/75
2021-11-26 16:40:53 +00:00
Simon Ser 585a908a01 scene: add wlr_scene_xdg_surface_create
This allows compositors to easily add an xdg_surface to the
scene-graph while retaining the ability to unconstraint popups
and decide their final position.

Compositors can handle new popups with the wlr_xdg_shell.new_surface
event, get the parent scene-graph node via wlr_xdg_popup.parent.data,
create a new scene-graph node via wlr_scene_xdg_surface_tree_create,
and unconstraint the popup if they want to.
2021-11-25 18:53:12 +01:00
Isaac Freund c9ba9e82b6
wlr_drag: emit destroy after wl_data_device.leave 2021-11-22 22:43:39 +01:00
Simon Ser 3d73b899ff linux-dmabuf-v1: hide wlr_linux_buffer_params_v1
The parameters are used when the client is in the process of
building a buffer. There's no reason why this internal
implementation detail should be exposed in our public header.
2021-11-22 10:32:55 +01:00
Simon Ser 6bb8973309 drm-lease-v1: listen to lease destroy event 2021-11-19 16:06:07 +00:00
Simon Ser 86f5ecf468 backend/drm: introduce wlr_drm_lease
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3183
2021-11-19 16:06:07 +00:00
Manuel Stoeckl d0bb7df630 output: remove XRGB8888 cursor fallback format
All graphics drivers supporting cursor planes support ARGB8888,
the default cursor format, so this fallback is almost certainly
unused.

Essentially all cursor themes use alpha transparency to make it
clearer where relative to the screen content the cursor hotspot is.
It is better to fall back to a slightly slower software cursor than
it is to fall back to the opaque square that is a hardware cursor
without an alpha channel.
2021-11-19 15:51:46 +00:00
Manuel Stoeckl e879d566bb output: Add function to set preferred render format
This change introduces new double buffered state to the wlr_output,
corresponding to the buffer format to render to.

The format being rendered to does not control the bit depth of colors
being sent to the display; it does generally determine the format with
which screenshot data is provided. The DRM backend _may_ sent higher
bit depths if the render format depth is increased, but hardware and
other limitations may apply.
2021-11-19 15:51:46 +00:00