Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault if key event precedes kbd setup #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tmccombs
Copy link
Collaborator

Fixes: #123

@emersion
Copy link
Owner

TBH this sounds like a compositor bug. Can you post a WAYLAND_DEBUG=1 log?

The commit message has a typo: this is about the modifiers event, not the key event. We still segfault if we get a key event before a keymap event. If we want to merge this, maybe we should ignore key events before keymap.

@tmccombs
Copy link
Collaborator Author

Here's the WAYLAND_DEBUG=1 output:

[ 131999.607]  -> [email protected]_registry(new id wl_registry@2)
[ 131999.613]  -> [email protected](new id wl_callback@3)
[ 131999.648] [email protected]_id(3)
[ 131999.651] [email protected](1, "wl_shm", 1)
[ 131999.653]  -> [email protected](1, "wl_shm", 1, new id [unknown]@4)
[ 131999.655] [email protected](2, "wl_drm", 2)
[ 131999.657] [email protected](3, "zwp_linux_dmabuf_v1", 4)
[ 131999.659] [email protected](4, "wl_compositor", 5)
[ 131999.661]  -> [email protected](4, "wl_compositor", 4, new id [unknown]@5)
[ 131999.662] [email protected](5, "wl_subcompositor", 1)
[ 131999.664] [email protected](6, "wl_data_device_manager", 3)
[ 131999.666] [email protected](7, "zwlr_gamma_control_manager_v1", 1)
[ 131999.667] [email protected](8, "zxdg_output_manager_v1", 3)
[ 131999.669]  -> [email protected](8, "zxdg_output_manager_v1", 2, new id [unknown]@6)
[ 131999.672] [email protected](9, "org_kde_kwin_idle", 1)
[ 131999.673] [email protected](10, "ext_idle_notifier_v1", 1)
[ 131999.675] [email protected](11, "zwp_idle_inhibit_manager_v1", 1)
[ 131999.676] [email protected](12, "zwlr_layer_shell_v1", 4)
[ 131999.678]  -> [email protected](12, "zwlr_layer_shell_v1", 1, new id [unknown]@7)
[ 131999.680] [email protected](13, "xdg_wm_base", 2)
[ 131999.682] [email protected](14, "zwp_tablet_manager_v2", 1)
[ 131999.683] [email protected](15, "org_kde_kwin_server_decoration_manager", 1)
[ 131999.685] [email protected](16, "zxdg_decoration_manager_v1", 1)
[ 131999.686] [email protected](17, "zwp_relative_pointer_manager_v1", 1)
[ 131999.688] [email protected](18, "zwp_pointer_constraints_v1", 1)
[ 131999.690] [email protected](19, "wp_presentation", 1)
[ 131999.691] [email protected](20, "zwlr_output_manager_v1", 4)
[ 131999.693] [email protected](21, "zwlr_output_power_manager_v1", 1)
[ 131999.694] [email protected](22, "zwp_input_method_manager_v2", 1)
[ 131999.696] [email protected](23, "zwp_text_input_manager_v3", 1)
[ 131999.697] [email protected](24, "zwlr_foreign_toplevel_manager_v1", 3)
[ 131999.699] [email protected](25, "ext_session_lock_manager_v1", 1)
[ 131999.701] [email protected](26, "wp_drm_lease_device_v1", 1)
[ 131999.702] [email protected](27, "zwlr_export_dmabuf_manager_v1", 1)
[ 131999.704] [email protected](28, "zwlr_screencopy_manager_v1", 3)
[ 131999.706] [email protected](29, "zwlr_data_control_manager_v1", 2)
[ 131999.707] [email protected](30, "zwp_primary_selection_device_manager_v1", 1)
[ 131999.709] [email protected](31, "wp_viewporter", 1)
[ 131999.710] [email protected](32, "wp_single_pixel_buffer_manager_v1", 1)
[ 131999.712] [email protected](33, "zxdg_exporter_v1", 1)
[ 131999.713] [email protected](34, "zxdg_importer_v1", 1)
[ 131999.715] [email protected](35, "zxdg_exporter_v2", 1)
[ 131999.717] [email protected](36, "zxdg_importer_v2", 1)
[ 131999.718] [email protected](37, "xdg_activation_v1", 1)
[ 131999.720] [email protected](38, "zwp_virtual_keyboard_manager_v1", 1)
[ 131999.722] [email protected](39, "zwlr_virtual_pointer_manager_v1", 2)
[ 131999.723] [email protected](40, "zwlr_input_inhibit_manager_v1", 1)
[ 131999.725] [email protected](41, "zwp_keyboard_shortcuts_inhibit_manager_v1", 1)
[ 131999.727] [email protected](42, "wl_seat", 8)
[ 131999.729]  -> [email protected](42, "wl_seat", 1, new id [unknown]@8)
[ 131999.731] [email protected](43, "zwp_pointer_gestures_v1", 3)
[ 131999.733] [email protected](44, "wl_output", 4)
[ 131999.735]  -> [email protected](44, "wl_output", 3, new id [unknown]@9)
[ 131999.737] [email protected](45, "wl_output", 4)
[ 131999.739]  -> [email protected](45, "wl_output", 3, new id [unknown]@10)
[ 131999.741] [email protected](26163)
[ 131999.743]  -> [email protected]_surface(new id wl_surface@3)
[ 131999.746]  -> [email protected]_layer_surface(new id zwlr_layer_surface_v1@11, wl_surface@3, wl_output@10, 3, "selection")
[ 131999.749]  -> [email protected]_xdg_output(new id zxdg_output_v1@12, wl_output@10)
[ 131999.751]  -> [email protected]_anchor(15)
[ 131999.752]  -> [email protected]_keyboard_interactivity(1)
[ 131999.754]  -> [email protected]_exclusive_zone(-1)
[ 131999.756]  -> [email protected]()
[ 131999.768]  -> [email protected]_pool(new id wl_shm_pool@13, fd 5, 2304)
[ 131999.851]  -> [email protected](6912)
[ 131999.882]  -> [email protected](16128)
[ 131999.933]  -> [email protected](34560)
[ 132000.023]  -> [email protected](71424)
[ 132000.420]  -> [email protected](145152)
[ 132000.461]  -> [email protected](292608)
[ 132000.878]  -> [email protected](587520)
[ 132001.832]  -> [email protected](1177344)
[ 132006.430]  -> [email protected]_surface(new id wl_surface@14)
[ 132006.434]  -> [email protected]_layer_surface(new id zwlr_layer_surface_v1@15, wl_surface@14, wl_output@9, 3, "selection")
[ 132006.438]  -> [email protected]_xdg_output(new id zxdg_output_v1@16, wl_output@9)
[ 132006.440]  -> [email protected]_anchor(15)
[ 132006.442]  -> [email protected]_keyboard_interactivity(1)
[ 132006.444]  -> [email protected]_exclusive_zone(-1)
[ 132006.446]  -> [email protected]()
[ 132006.457]  -> [email protected]_pool(new id wl_shm_pool@17, fd 7, 2304)
[ 132006.521]  -> [email protected](6912)
[ 132006.549]  -> [email protected](16128)
[ 132006.593]  -> [email protected](34560)
[ 132006.674]  -> [email protected](71424)
[ 132007.039]  -> [email protected](145152)
[ 132007.083]  -> [email protected](292608)
[ 132007.502]  -> [email protected](587520)
[ 132008.427]  -> [email protected](1177344)
[ 132012.854]  -> [email protected](new id wl_callback@18)
[ 132013.003] [email protected]_id(18)
[ 132013.010] [email protected](3)
[ 132013.013]  -> [email protected]_pointer(new id wl_pointer@19)
[ 132013.016]  -> [email protected]_keyboard(new id wl_keyboard@20)
[ 132013.019] [email protected](0, 0, 480, 270, 0, "Samsung Electric Company", "S22C300", 0)
[ 132013.022] [email protected](1, 1920, 1080, 60000)
[ 132013.025] [email protected](1)
[ 132013.026] [email protected]()
[ 132013.028] [email protected](0, 0, 520, 320, 0, "Ancor Communications Inc", "VS24A", 0)
[ 132013.031] [email protected](1, 1920, 1200, 59950)
[ 132013.034] [email protected](1)
[ 132013.035] [email protected]()
[ 132013.037] [email protected]("DP-1")
[ 132013.039] [email protected]("Ancor Communications Inc VS24A E7LMQS031673 (DP-1 via DVI-D)")
[ 132013.041] [email protected]_position(0, 0)
[ 132013.043] [email protected]_size(1920, 1200)
[ 132013.045] [email protected]()
[ 132013.047] [email protected](26165, 1920, 1200)
[ 132013.050]  -> [email protected]_configure(26165)
[ 132013.074]  -> [email protected]_pool(new id wl_shm_pool@21, fd 7, 9216000)
[ 132013.078]  -> [email protected]_buffer(new id wl_buffer@22, 0, 1920, 1200, 7680, 0)
[ 132013.081]  -> [email protected]()
[ 132015.538]  -> [email protected](new id wl_callback@23)
[ 132015.541]  -> [email protected](wl_buffer@22, 0, 0)
[ 132015.544]  -> [email protected](0, 0, 1920, 1200)
[ 132015.546]  -> [email protected]_buffer_scale(1)
[ 132015.548]  -> [email protected]()
[ 132015.550] [email protected](26167, 1920, 1200)
[ 132015.552]  -> [email protected]_configure(26167)
[ 132015.566]  -> [email protected]_pool(new id wl_shm_pool@24, fd 8, 9216000)
[ 132015.569]  -> [email protected]_buffer(new id wl_buffer@25, 0, 1920, 1200, 7680, 0)
[ 132015.571]  -> [email protected]()
[ 132017.881]  -> [email protected](new id wl_callback@26)
[ 132017.884]  -> [email protected](wl_buffer@25, 0, 0)
[ 132017.886]  -> [email protected](0, 0, 1920, 1200)
[ 132017.888]  -> [email protected]_buffer_scale(1)
[ 132017.889]  -> [email protected]()
[ 132017.891] [email protected]("HDMI-A-1")
[ 132017.893] [email protected]("Samsung Electric Company S22C300 0x00007F35 (HDMI-A-1)")
[ 132017.895] [email protected]_position(1920, 100)
[ 132017.896] [email protected]_size(1920, 1080)
[ 132017.898] [email protected]()
[ 132017.900] [email protected](26169, 1920, 1080)
[ 132017.901]  -> [email protected]_configure(26169)
[ 132017.916]  -> [email protected]_pool(new id wl_shm_pool@27, fd 9, 8294400)
[ 132017.919]  -> [email protected]_buffer(new id wl_buffer@28, 0, 1920, 1080, 7680, 0)
[ 132017.921]  -> [email protected]()
[ 132019.970]  -> [email protected](new id wl_callback@29)
[ 132019.972]  -> [email protected](wl_buffer@28, 0, 0)
[ 132019.974]  -> [email protected](0, 0, 1920, 1080)
[ 132019.976]  -> [email protected]_buffer_scale(1)
[ 132019.977]  -> [email protected]()
[ 132019.979] [email protected](26171, 1920, 1080)
[ 132019.981]  -> [email protected]_configure(26171)
[ 132019.994]  -> [email protected]_pool(new id wl_shm_pool@30, fd 10, 8294400)
[ 132019.996]  -> [email protected]_buffer(new id wl_buffer@31, 0, 1920, 1080, 7680, 0)
[ 132019.998]  -> [email protected]()
[ 132022.226]  -> [email protected](new id wl_callback@32)
[ 132022.230]  -> [email protected](wl_buffer@31, 0, 0)
[ 132022.231]  -> [email protected](0, 0, 1920, 1080)
[ 132022.233]  -> [email protected]_buffer_scale(1)
[ 132022.235]  -> [email protected]()
[ 132022.237] [email protected](26171)
[ 132022.239]  -> [email protected]_surface(new id wl_surface@18)
[ 132029.109] [email protected]_id(21)
[ 132029.113] [email protected]_id(24)
[ 132029.115] [email protected]_id(27)
[ 132029.116] [email protected]_id(30)
[ 132029.119] [email protected]()
[ 132029.121] [email protected](26173, wl_surface@3, 1231.37890625, 635.94921875)
[ 132029.124]  -> [email protected]_buffer_scale(1)
[ 132029.127]  -> [email protected]_buffer(new id wl_buffer@30, 594432, 24, 24, 96, 0)
[ 132029.130]  -> [email protected](wl_buffer@30, 0, 0)
[ 132029.132]  -> [email protected]_cursor(26173, wl_surface@18, 11, 11)
[ 132029.134]  -> [email protected]()
[ 132029.136] [email protected](26175, 1920, 1200)
[ 132029.139]  -> [email protected]_configure(26175)
[ 132030.172]  -> [email protected](new id wl_callback@27)
[ 132030.175]  -> [email protected](wl_buffer@22, 0, 0)
[ 132030.177]  -> [email protected](0, 0, 1920, 1200)
[ 132030.179]  -> [email protected]_buffer_scale(1)
[ 132030.180]  -> [email protected]()
[ 132030.182] [email protected](26178, wl_surface@3, array[0])
[ 132030.186] [email protected](26179, 0, 0, 0, 0)
zsh: segmentation fault (core dumped)  WAYLAND_DEBUG=1 slurp

@tmccombs
Copy link
Collaborator Author

So it looks like we are getting a modifiers even (and an enter event) before we get a keymap event. That might be a bug in the compositor (this is sway 1.8.1). Although, from wayland.xml it doesn't sound like there is actually a requirement that th e keymap is sent before any modifier or key events. Although, it seems odd to send events in that order, since the application would either have to log the modifiers to be processed later, ignore the event, or assume a keymap before getting the keymap event.

Interestingly, on this branch this is the output I get with WAYLAND_DEBUG=1 (just the interesting bit):

[ 609019.154] [email protected](27607, wl_surface@3, array[0])
[ 609019.156] [email protected](27608, 0, 0, 0, 0)
[ 609019.159] [email protected]()
[ 609019.160] [email protected]()
[ 609019.162] [email protected](27610, 1920, 1080)
[ 609019.164]  -> [email protected]_configure(27610)
[ 609019.793]  -> [email protected](new id wl_callback@24)
[ 609019.796]  -> [email protected](wl_buffer@28, 0, 0)
[ 609019.798]  -> [email protected](0, 0, 1920, 1080)
[ 609019.799]  -> [email protected]_buffer_scale(1)
[ 609019.801]  -> [email protected]()
[ 609019.803] [email protected](27611, wl_surface@3)
[ 609019.805] [email protected](27612, wl_surface@14, array[0])
[ 609019.806] [email protected](27613, 0, 0, 0, 0)
[ 609019.808] [email protected]()
[ 609019.810] [email protected](11694817)
[ 609019.813] [email protected](11694817)
[ 609021.345] [email protected]()
[ 609021.347] [email protected]()
[ 609021.485] [email protected]_id(27)
[ 609021.487] [email protected]_id(26)
[ 609021.488] [email protected]_id(23)
[ 609021.489] [email protected](11694820)
[ 609021.491] [email protected](11694820)
[ 609021.492] [email protected](11694820)
[ 609024.977] [email protected](1, fd 5, 81930)
[ 609026.698] [email protected](27614, 0, 0, 16, 0)
[ 609026.704] [email protected](27615, 11694824, 28, 0)
[ 609028.274] [email protected]_id(24)
[ 609028.277] [email protected](11694827)
[ 610760.780] [email protected](27616, 11696560, 16, 1)
[ 610852.745] [email protected](27617, 11696652, 16, 0)
[ 611812.682] [email protected](27618, 11697612, 1, 1)

Notice that we do eventually get the keymap event before the actual key event, but keyboard focus enters one surface, leaves that surface, and enters another surface, before we get the keymap event, and each time it enters a surface, we get a modifiers event as well.

Make sure the keyboard has been initialized before using it in the key
press handler.
wochap added a commit to wochap/slurp that referenced this pull request Apr 24, 2024
@nekopsykose
Copy link

this still happens on sway master (interestingly only if i am running fcitx5; otherwise it does not happen). this mr fixes it.

for posterity my WAYLAND_DEBUG=1 of slurp:

log
[3952916.412]  -> [email protected]_registry(new id wl_registry@2)
[3952916.420]  -> [email protected](new id wl_callback@3)
[3952916.476] [email protected]_id(3)
[3952916.480] [email protected](1, "wl_shm", 1)
[3952916.483]  -> [email protected](1, "wl_shm", 1, new id [unknown]@4)
[3952916.486] [email protected](2, "zwp_linux_dmabuf_v1", 4)
[3952916.488] [email protected](3, "wl_drm", 2)
[3952916.491] [email protected](4, "wl_compositor", 6)
[3952916.494]  -> [email protected](4, "wl_compositor", 4, new id [unknown]@5)
[3952916.496] [email protected](5, "wl_subcompositor", 1)
[3952916.498] [email protected](6, "wl_data_device_manager", 3)
[3952916.500] [email protected](7, "zwlr_gamma_control_manager_v1", 1)
[3952916.502] [email protected](8, "zxdg_output_manager_v1", 3)
[3952916.504]  -> [email protected](8, "zxdg_output_manager_v1", 2, new id [unknown]@6)
[3952916.506] [email protected](9, "ext_idle_notifier_v1", 1)
[3952916.508] [email protected](10, "zwp_idle_inhibit_manager_v1", 1)
[3952916.510] [email protected](11, "zwlr_layer_shell_v1", 4)
[3952916.512]  -> [email protected](11, "zwlr_layer_shell_v1", 1, new id [unknown]@7)
[3952916.514] [email protected](12, "xdg_wm_base", 5)
[3952916.516] [email protected](13, "zwp_tablet_manager_v2", 1)
[3952916.518] [email protected](14, "org_kde_kwin_server_decoration_manager", 1)
[3952916.520] [email protected](15, "zxdg_decoration_manager_v1", 1)
[3952916.521] [email protected](16, "zwp_relative_pointer_manager_v1", 1)
[3952916.524] [email protected](17, "zwp_pointer_constraints_v1", 1)
[3952916.526] [email protected](18, "wp_presentation", 1)
[3952916.529] [email protected](19, "zwlr_output_manager_v1", 4)
[3952916.530] [email protected](20, "zwlr_output_power_manager_v1", 1)
[3952916.532] [email protected](21, "zwp_input_method_manager_v2", 1)
[3952916.534] [email protected](22, "zwp_text_input_manager_v3", 1)
[3952916.537] [email protected](23, "ext_foreign_toplevel_list_v1", 1)
[3952916.539] [email protected](24, "zwlr_foreign_toplevel_manager_v1", 3)
[3952916.541] [email protected](25, "ext_session_lock_manager_v1", 1)
[3952916.543] [email protected](26, "wp_drm_lease_device_v1", 1)
[3952916.545] [email protected](27, "zwlr_export_dmabuf_manager_v1", 1)
[3952916.547] [email protected](28, "zwlr_screencopy_manager_v1", 3)
[3952916.549] [email protected](29, "zwlr_data_control_manager_v1", 2)
[3952916.551] [email protected](30, "wp_security_context_manager_v1", 1)
[3952916.553] [email protected](31, "wp_viewporter", 1)
[3952916.555] [email protected](32, "wp_single_pixel_buffer_manager_v1", 1)
[3952916.556] [email protected](33, "wp_content_type_manager_v1", 1)
[3952916.558] [email protected](34, "wp_fractional_scale_manager_v1", 1)
[3952916.560] [email protected](35, "zxdg_exporter_v1", 1)
[3952916.562] [email protected](36, "zxdg_importer_v1", 1)
[3952916.564] [email protected](37, "zxdg_exporter_v2", 1)
[3952916.566] [email protected](38, "zxdg_importer_v2", 1)
[3952916.568] [email protected](39, "xdg_activation_v1", 1)
[3952916.570] [email protected](40, "wp_cursor_shape_manager_v1", 1)
[3952916.572] [email protected](41, "zwp_virtual_keyboard_manager_v1", 1)
[3952916.574] [email protected](42, "zwlr_virtual_pointer_manager_v1", 2)
[3952916.576] [email protected](43, "zwp_keyboard_shortcuts_inhibit_manager_v1", 1)
[3952916.578] [email protected](44, "zwp_pointer_gestures_v1", 3)
[3952916.579] [email protected](45, "ext_transient_seat_manager_v1", 1)
[3952916.581] [email protected](46, "wl_seat", 9)
[3952916.584]  -> [email protected](46, "wl_seat", 1, new id [unknown]@8)
[3952916.586] [email protected](48, "wl_output", 4)
[3952916.588]  -> [email protected](48, "wl_output", 3, new id [unknown]@9)
[3952916.593] [email protected](193809)
[3952916.596]  -> [email protected]_surface(new id wl_surface@3)
[3952916.598]  -> [email protected]_layer_surface(new id zwlr_layer_surface_v1@10, wl_surface@3, wl_output@9, 3, "selection")
[3952916.602]  -> [email protected]_xdg_output(new id zxdg_output_v1@11, wl_output@9)
[3952916.605]  -> [email protected]_anchor(15)
[3952916.607]  -> [email protected]_keyboard_interactivity(1)
[3952916.609]  -> [email protected]_exclusive_zone(-1)
[3952916.611]  -> [email protected]()
[3952916.613]  -> [email protected](new id wl_callback@12)
[3952916.711] [email protected]_id(12)
[3952916.716] [email protected](3)
[3952916.719]  -> [email protected]_pointer(new id wl_pointer@13)
[3952916.722]  -> [email protected]_keyboard(new id wl_keyboard@14)
[3952916.725] [email protected](0, 0, 700, 390, 1, "GIGA-BYTE TECHNOLOGY CO., LTD.", "M27Q", 0)
[3952916.730] [email protected](1, 2560, 1440, 169831)
[3952916.733] [email protected](1)
[3952916.735] [email protected]()
[3952916.737] [email protected]("DP-1")
[3952916.739] [email protected]("GIGA-BYTE TECHNOLOGY CO., LTD. M27Q 21240B002501 (DP-1)")
[3952916.741] [email protected]_position(0, 0)
[3952916.743] [email protected]_size(2560, 1440)
[3952916.744] [email protected]()
[3952916.746] [email protected](193812, 2560, 1440)
[3952916.748]  -> [email protected]_configure(193812)
[3952916.767]  -> [email protected]_pool(new id wl_shm_pool@15, fd 5, 14745600)
[3952916.770]  -> [email protected]_buffer(new id wl_buffer@16, 0, 2560, 1440, 10240, 0)
[3952916.773]  -> [email protected]()
[3952920.265]  -> [email protected](new id wl_callback@17)
[3952920.273]  -> [email protected](wl_buffer@16, 0, 0)
[3952920.277]  -> [email protected](0, 0, 2560, 1440)
[3952920.281]  -> [email protected]_buffer_scale(1)
[3952920.284]  -> [email protected]()
[3952920.287] [email protected](193812)
[3952920.306]  -> [email protected]_pool(new id wl_shm_pool@12, fd 6, 4096)
[3952920.550]  -> [email protected](12288)
[3952920.570]  -> [email protected](28672)
[3952920.587]  -> [email protected](61440)
[3952922.004]  -> [email protected](126976)
[3952922.043]  -> [email protected](258048)
[3952922.102]  -> [email protected](520192)
[3952923.075]  -> [email protected](1044480)
[3952926.149]  -> [email protected](2093056)
[3952930.086]  -> [email protected](4190208)
[3952938.874]  -> [email protected](8384512)
[3952956.020]  -> [email protected](16773120)
[3952982.701]  -> [email protected]_surface(new id wl_surface@18)
[3952984.983] [email protected]_id(15)
[3952984.989] [email protected](193826, wl_surface@3, array[0])
[3952984.995] [email protected](193827, 0, 0, 0, 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SegFault
3 participants