sway icon indicating copy to clipboard operation
sway copied to clipboard

For layer-shell, wl_surface::enter events are not delivered until the next resize event

Open WhyNotHugo opened this issue 1 year ago • 2 comments

Please read the following before submitting:

Please fill out the following:

  • Sway Version:

541e6e260c2df0346b421cacfaf4ce5d204c49ba

  • Debug Log: https://paste.sr.ht/~whynothugo/45bb7a80e980d8b10ad745727c1c905e12fafbe0

  • Configuration File: exec shotman --capture output

  • Stack Trace: n/a

  • Description:

shotman creates a layer-shell surface on each output, covering the entire output with transparent overlay. It waits for awl_surface::enter event in order to determine the currently active output.

This worked okay with the previous stable release of sway. Currently, however, the wl_surface::enter is not delivered. If I resize some other window, then the event is delivered.

You can use shotman to reproduce this. It does a lot more stuff, but there's the output with WAYLAND_DEBUG=1:

[1708085678.207815] -> [email protected]_registry (wl_registry@2)
[1708085678.207839] -> [email protected] (wl_callback@3)
[1708085678.208210] <- [email protected], (1, Some("wl_shm"), 1)
[1708085678.208235] <- [email protected], (2, Some("zwp_linux_dmabuf_v1"), 4)
[1708085678.208255] <- [email protected], (3, Some("wl_compositor"), 6)
[1708085678.208273] <- [email protected], (4, Some("wl_subcompositor"), 1)
[1708085678.208295] <- [email protected], (5, Some("wl_data_device_manager"), 3)
[1708085678.208317] <- [email protected], (6, Some("zwlr_gamma_control_manager_v1"), 1)
[1708085678.208344] <- [email protected], (7, Some("zxdg_output_manager_v1"), 3)
[1708085678.208366] <- [email protected], (8, Some("ext_idle_notifier_v1"), 1)
[1708085678.208392] <- [email protected], (9, Some("zwp_idle_inhibit_manager_v1"), 1)
[1708085678.208420] <- [email protected], (10, Some("zwlr_layer_shell_v1"), 4)
[1708085678.208442] <- [email protected], (11, Some("xdg_wm_base"), 2)
[1708085678.208463] <- [email protected], (12, Some("zwp_tablet_manager_v2"), 1)
[1708085678.208488] <- [email protected], (13, Some("org_kde_kwin_server_decoration_manager"), 1)
[1708085678.208521] <- [email protected], (14, Some("zxdg_decoration_manager_v1"), 1)
[1708085678.208554] <- [email protected], (15, Some("zwp_relative_pointer_manager_v1"), 1)
[1708085678.208583] <- [email protected], (16, Some("zwp_pointer_constraints_v1"), 1)
[1708085678.208610] <- [email protected], (17, Some("wp_presentation"), 1)
[1708085678.208633] <- [email protected], (18, Some("zwlr_output_manager_v1"), 4)
[1708085678.208657] <- [email protected], (19, Some("zwlr_output_power_manager_v1"), 1)
[1708085678.208686] <- [email protected], (20, Some("zwp_input_method_manager_v2"), 1)
[1708085678.208708] <- [email protected], (21, Some("zwp_text_input_manager_v3"), 1)
[1708085678.208732] <- [email protected], (22, Some("zwlr_foreign_toplevel_manager_v1"), 3)
[1708085678.208761] <- [email protected], (23, Some("ext_session_lock_manager_v1"), 1)
[1708085678.208788] <- [email protected], (24, Some("wp_drm_lease_device_v1"), 1)
[1708085678.208810] <- [email protected], (25, Some("zwlr_export_dmabuf_manager_v1"), 1)
[1708085678.208836] <- [email protected], (26, Some("zwlr_screencopy_manager_v1"), 3)
[1708085678.208867] <- [email protected], (27, Some("zwlr_data_control_manager_v1"), 2)
[1708085678.208900] <- [email protected], (28, Some("wp_security_context_manager_v1"), 1)
[1708085678.208929] <- [email protected], (29, Some("wp_viewporter"), 1)
[1708085678.208949] <- [email protected], (30, Some("wp_single_pixel_buffer_manager_v1"), 1)
[1708085678.208979] <- [email protected], (31, Some("wp_content_type_manager_v1"), 1)
[1708085678.209007] <- [email protected], (32, Some("wp_fractional_scale_manager_v1"), 1)
[1708085678.209036] <- [email protected], (33, Some("zxdg_exporter_v1"), 1)
[1708085678.209061] <- [email protected], (34, Some("zxdg_importer_v1"), 1)
[1708085678.209082] <- [email protected], (35, Some("zxdg_exporter_v2"), 1)
[1708085678.209104] <- [email protected], (36, Some("zxdg_importer_v2"), 1)
[1708085678.209121] <- [email protected], (37, Some("xdg_activation_v1"), 1)
[1708085678.209138] <- [email protected], (38, Some("wp_cursor_shape_manager_v1"), 1)
[1708085678.209159] <- [email protected], (39, Some("zwp_virtual_keyboard_manager_v1"), 1)
[1708085678.209182] <- [email protected], (40, Some("zwlr_virtual_pointer_manager_v1"), 2)
[1708085678.209209] <- [email protected], (41, Some("zwp_keyboard_shortcuts_inhibit_manager_v1"), 1)
[1708085678.209242] <- [email protected], (42, Some("zwp_pointer_gestures_v1"), 3)
[1708085678.209268] <- [email protected], (43, Some("wl_seat"), 9)
[1708085678.209286] <- [email protected], (45, Some("zwp_primary_selection_device_manager_v1"), 1)
[1708085678.209319] <- [email protected], (46, Some("wl_output"), 4)
[1708085678.209338] <- [email protected], (53, Some("wl_output"), 4)
[1708085678.209358] <- [email protected], (135328)
[1708085678.209366] <- [email protected]_id, (3)
[1708085678.209412] -> [email protected] (1, Some("wl_shm"), 1, wl_shm@3)
[1708085678.209435] -> [email protected] (26, Some("zwlr_screencopy_manager_v1"), 3, zwlr_screencopy_manager_v1@4)
[1708085678.209467] -> [email protected] (29, Some("wp_viewporter"), 1, wp_viewporter@5)
[1708085678.209491] -> [email protected] (43, Some("wl_seat"), 7, wl_seat@6)
[1708085678.209513] -> [email protected] (5, Some("wl_data_device_manager"), 3, wl_data_device_manager@7)
[1708085678.209543] -> [email protected] (30, Some("wp_single_pixel_buffer_manager_v1"), 1, wp_single_pixel_buffer_manager_v1@8)
[1708085678.209576] -> [email protected] (10, Some("zwlr_layer_shell_v1"), 4, zwlr_layer_shell_v1@9)
[1708085678.209604] -> [email protected] (4, Some("wl_subcompositor"), 1, wl_subcompositor@10)
[1708085678.209627] -> [email protected] (3, Some("wl_compositor"), 4, wl_compositor@11)
[1708085678.209651] -> [email protected]_surface (wl_surface@12)
[1708085678.209662] -> [email protected]_surface (wl_surface@13)
[1708085678.209672] -> [email protected]_surface (wl_surface@14)
[1708085678.209683] -> [email protected] (32, Some("wp_fractional_scale_manager_v1"), 1, wp_fractional_scale_manager_v1@15)
[1708085678.209717] -> [email protected]_fractional_scale (wp_fractional_scale_v1@16, wl_surface@13)
[1708085678.209734] -> [email protected]_subsurface (wl_subsurface@17, wl_surface@14, wl_surface@13)
[1708085678.209756] -> [email protected]_layer_surface (zwlr_layer_surface_v1@18, wl_surface@12, <anonymous>@0, 0, Some("shotman"))
[1708085678.209780] -> [email protected]_layer_surface (zwlr_layer_surface_v1@19, wl_surface@13, <anonymous>@0, 3, Some("shotman"))
[1708085678.209802] -> [email protected]_anchor (5)
[1708085678.209812] -> [email protected]_keyboard_interactivity (0)
[1708085678.209821] -> [email protected]_size (1, 1)
[1708085678.209832] -> [email protected] ()
[1708085678.209930] -> [email protected]_viewport (wp_viewport@20, wl_surface@13)
[1708085678.209944] -> [email protected]_viewport (wp_viewport@21, wl_surface@14)
[1708085678.209959] -> [email protected]_u32_rgba_buffer (wl_buffer@22, 0, 0, 0, 0)
[1708085678.209983] -> [email protected] (46, Some("wl_output"), 4, wl_output@23)
[1708085678.210004] -> [email protected] (53, Some("wl_output"), 4, wl_output@24)
[1708085678.210025] -> [email protected] (7, Some("zxdg_output_manager_v1"), 3, zxdg_output_manager_v1@25)
[1708085678.210055] -> [email protected]_xdg_output (zxdg_output_v1@26, wl_output@23)
[1708085678.210071] -> [email protected]_xdg_output (zxdg_output_v1@27, wl_output@24)
[1708085678.210255] <- [email protected], (0)
[1708085678.210267] <- [email protected], (1)
[1708085678.210278] <- [email protected], (875709016)
[1708085678.210288] <- [email protected], (875708993)
[1708085678.210298] <- [email protected], (875710274)
[1708085678.210308] <- [email protected], (842094674)
[1708085678.210317] <- [email protected], (842088786)
[1708085678.210325] <- [email protected], (892426322)
[1708085678.210335] <- [email protected], (892420434)
[1708085678.210345] <- [email protected], (909199186)
[1708085678.210353] <- [email protected], (808665688)
[1708085678.210362] <- [email protected], (808665665)
[1708085678.210370] <- [email protected], (1211384408)
[1708085678.210379] <- [email protected], (1211384385)
[1708085678.210386] <- [email protected], (942948952)
[1708085678.210395] <- [email protected], (942948929)
[1708085678.210404] <- [email protected], (Some("seat0"))
[1708085678.210418] <- [email protected], (7)
[1708085678.210426] <- [email protected], (135330, 1, 1)
[1708085678.210440] <- [email protected], (0, 0, 800, 340, 0, Some("Ancor Communications Inc"), Some("ROG PG348Q"), 0)
[1708085678.210475] <- [email protected], (1, 3440, 1440, 59973)
[1708085678.210486] <- [email protected], (2)
[1708085678.210494] <- [email protected], (Some("DP-1"))
[1708085678.210505] <- [email protected], (Some("Ancor Communications Inc ROG PG348Q #ASMuhJCcVsHd (DP-1)"))
[1708085678.210545] <- [email protected], ()
[1708085678.210554] <- [email protected], (0, 0, 310, 170, 0, Some("ASUSTek COMPUTER INC"), Some("ASUS PA148"), 0)
[1708085678.210589] <- [email protected], (1, 1920, 1080, 60000)
[1708085678.210600] <- [email protected], (2)
[1708085678.210610] <- [email protected], (Some("HDMI-A-1"))
[1708085678.210623] <- [email protected], (Some("ASUSTek COMPUTER INC ASUS PA148 R3LMTF047543 (HDMI-A-1)"))
[1708085678.210659] <- [email protected], ()
[1708085678.210665] <- [email protected], (Some("DP-1"))
[1708085678.210679] <- [email protected], (Some("Ancor Communications Inc ROG PG348Q #ASMuhJCcVsHd (DP-1)"))
[1708085678.210719] <- [email protected]_position, (0, 0)
[1708085678.210728] <- [email protected]_size, (2074, 868)
[1708085678.210738] <- [email protected], ()
[1708085678.210745] <- [email protected], (Some("HDMI-A-1"))
[1708085678.210758] <- [email protected], (Some("ASUSTek COMPUTER INC ASUS PA148 R3LMTF047543 (HDMI-A-1)"))
[1708085678.210795] <- [email protected]_position, (1920, 1080)
[1708085678.210804] <- [email protected]_size, (1157, 651)
[1708085678.210814] <- [email protected], ()
[1708085678.213422] -> [email protected]_keyboard (wl_keyboard@28)
[1708085678.213435] -> [email protected]_pointer (wl_pointer@29)
[1708085678.213447] -> [email protected]_configure (135330)
[1708085678.213455] -> [email protected] (wl_buffer@22, 0, 0)
[1708085678.213466] -> [email protected] ()
[1708085678.213620] <- [email protected], (1, 9, 66413)
[1708085678.213633] <- [email protected]_info, (25, 600)
[1708085678.213644] <- [email protected], (135336, 1, 1)
[1708085678.213659] <- [email protected], ()
[1708085678.215369] -> [email protected]_configure (135336)
[1708085678.215383] -> [email protected] (wl_buffer@22, 0, 0)
[1708085678.215394] -> [email protected] ()
[1708085678.215404] -> [email protected] ()
[1708085678.215440] <- [email protected], ()
[1708085678.215449] <- [email protected]_id, (22)

-- I resize another window at this point --

[1708085680.471696] <- [email protected], (wl_output@23)
[1708085680.471753] -> [email protected]_output (zwlr_screencopy_frame_v1@22, 1, wl_output@23)
[1708085680.471775] -> [email protected] ()
[1708085680.471787] -> [email protected] ()
[1708085680.472079] <- [email protected], (875709016, 3440, 1440, 13760)
[1708085680.472093] <- [email protected]_dmabuf, (875713112, 3440, 1440)
[1708085680.472105] <- [email protected]_done, ()
[1708085680.472113] <- [email protected]_id, (18)
[1708085680.472123] <- [email protected]_id, (12)
[1708085680.472148] -> [email protected]_pool (wl_shm_pool@12, 9, 19814400)
[1708085680.472170] -> [email protected]_buffer (wl_buffer@18, 0, 3440, 1440, 13760, 875709016)
[1708085680.472187] -> [email protected] ()
[1708085680.472200] -> [email protected] (wl_buffer@18)
[1708085680.497022] <- [email protected]_id, (12)
[1708085680.497041] <- [email protected], (0)
[1708085680.497058] <- [email protected], (0, 127235, 500407936)
[1708085680.497068] <- [email protected], ()
[1708085680.497155] -> [email protected] (wl_buffer@18, 0, 0)
[1708085680.497172] -> [email protected] ()
[1708085680.497182] -> [email protected]_keyboard_interactivity (1)
[1708085680.497427] -> [email protected]_size (832, 351)
[1708085680.497438] -> [email protected] ()
[1708085680.497449] -> [email protected] ()
[1708085680.497756] <- [email protected]_id, (22)
[1708085680.497765] <- [email protected], (135377, 832, 351)
[1708085680.497776] <- [email protected]_id, (18)
[1708085680.497788] -> [email protected]_configure (135377)
[src/main.rs:638:9] "render window" = "render window"
[1708085680.497804] -> [email protected]_margin (72, 72, 72, 72)
[1708085680.497817] -> [email protected]_size (832, 351)
[1708085680.497829] -> [email protected]_position (2, 2)
[1708085680.497842] -> [email protected]_destination (828, 347)
[1708085680.497852] -> [email protected] ()
[1708085680.497859] -> [email protected] ()
[1708085680.497873] -> [email protected]_u32_rgba_buffer (wl_buffer@12, 2147483647, 2147483647, 2147483647, 4294967295)
[1708085680.497891] -> [email protected] (wl_buffer@12, 0, 0)
[1708085680.497905] -> [email protected]_buffer (0, 0, 1, 1)
[1708085680.497917] -> [email protected]_destination (832, 351)
[1708085680.497928] -> [email protected] ()
[1708085680.497935] -> [email protected] ()
[1708085680.497975] <- [email protected], (135383, 832, 351)
[1708085680.497984] <- [email protected]_id, (12)
[1708085680.497994] -> [email protected]_configure (135383)
[...]

WhyNotHugo avatar Feb 16 '24 12:02 WhyNotHugo

I believe this also results in the preferred_scale events on layer surfaces being delayed.

danieldg avatar Feb 19 '24 14:02 danieldg

I cannot change the position of my displays using a bind. Is this related? I am on sway 1.8.1 (the one fedora ships). I dont know what I'm looking at and I don't want to make a redundant issue.

a73s avatar Feb 23 '24 06:02 a73s

@a73s your issue is entirely unrelated

WhyNotHugo avatar Mar 10 '24 11:03 WhyNotHugo

I debugged this issue tonight. I know what's going on. I don't really have a good idea on how to solve it but expect a fix soon.

Nefsen402 avatar Mar 12 '24 05:03 Nefsen402

I lied, I came up with a fix: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4600

Nefsen402 avatar Mar 12 '24 05:03 Nefsen402

The linked wlroots MR has been merged.

vyivel avatar Mar 12 '24 14:03 vyivel

With the same reproduction steps, sway now segfaults instead.

WhyNotHugo avatar Mar 12 '24 15:03 WhyNotHugo

Debug output: https://paste.sr.ht/blob/7eb51cff3474e52a99b313573bc8e5b49d8e78f8

WhyNotHugo avatar Mar 12 '24 15:03 WhyNotHugo

Fallback one earlier commit. A bad MR was merged

Nefsen402 avatar Mar 12 '24 15:03 Nefsen402

Yeah, see https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4602

emersion avatar Mar 12 '24 15:03 emersion

Testing with sway 2e951163c5a5f24fe9cf7ee348e56b09719a99a9 and wlroots 2d97935e82fe942cf146068d5ed99c2a06547df9, I still see this issue.

It's also still present in the latest master version of both.

WhyNotHugo avatar May 07 '24 14:05 WhyNotHugo

I'm still seeing this issue on current master (sway version 1.10-dev-40ca4150b (Jun 10 2024, branch 'master')).

My original code destroy'ed the buffer immediately after attaching it. I've removed that code that destroys the buffer but it doesn't seem to be the culprit here.

WhyNotHugo avatar Jul 11 '24 14:07 WhyNotHugo

I found an important factor: my layer shell is rendered in background layer.

When I create and commit a layer shell in zwlr_layer_shell_v1::layer::background, it doesn't receive an wl_surface::enter event until some other window changes size.

When I create and commit a layer shell in zwlr_layer_shell_v1::layer::overlay, it receives the wl_surface::enter event immediately.

WhyNotHugo avatar Jul 28 '24 19:07 WhyNotHugo

I tested creating the layer shell with layer::background on an empty workspace, and it receives the wl_surface::enter event immediately.

I think that this issue is only reproducible if the layer shell is not visible.

WhyNotHugo avatar Jul 28 '24 19:07 WhyNotHugo

If the layer shell is not visible, then we don't need to send the enter event. The wayland protocol allows this.

Nefsen402 avatar Jul 28 '24 21:07 Nefsen402

Based on the wording of wl_surface::enter that sounds correct.

I guess that I was relying on non-standard behaviour.

WhyNotHugo avatar Jul 29 '24 07:07 WhyNotHugo

wlroots scene will only have the surface enter an output if that surface is at all visible on that output. That means that if the surface is completely obscured by an application, the enter event will never fire. This is true for all surfaces including layer shell ones. The wayland spec allows this. Changing the size of applications will make scene momentarily believe that the layer shell surface is visible because scene mutations are not atomic.

Nefsen402 avatar Jul 29 '24 07:07 Nefsen402

I've fixed the related code on my client. Thanks for the guidance.

WhyNotHugo avatar Jul 29 '24 07:07 WhyNotHugo