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

Games under Wayland/SDL receive keyboard events when mouse focus changes in and out #1198

Closed
jwangac opened this issue Dec 6, 2024 · 4 comments

Comments

@jwangac
Copy link

jwangac commented Dec 6, 2024

Summary

以窗口模式运行 Moonlight(串流软件)和 Factorio(异星工厂)时,在鼠标移动或在游戏和其他窗口之间切换焦点时,游戏窗口获得焦点时会产生 Ctrl、Alt、Shift 键的按下事件,表现为游戏认为这些键被长按。当游戏窗口失去焦点时,则会产生这些键的弹起事件。

在 Ctrl、Alt、Shift 中,哪些键会被触发没有发现规律,但 Ctrl 的频率最高,Alt 和 Shift 很少出现。

运行 killall fcitx5 或者卸载 fcitx5,可以解决这一问题。

故障演示视频如下。

record.mp4

Steps to Reproduce

  1. 运行环境为 Debian testing / Sway 1.9 (禁用XWayland);
  2. 运行Moonlight(来自Flathub)或异星工厂;
  3. 在窗口间切换焦点、新建窗口、关闭窗口以触发此问题。

Expected Behavior

正确时的SDL事件:

移入鼠标,SDL程序获得焦点:

00:01:19 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=79973 windowid=2 event=SDL_WINDOWEVENT_FOCUS_GAINED data1=0 data2=0)
00:01:19 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
00:01:19 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
00:01:19 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=79973 windowid=2 event=SDL_WINDOWEVENT_ENTER data1=0 data2=0)

移出鼠标,SDL程序失去焦点:

00:01:26 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=86232 windowid=2 event=SDL_WINDOWEVENT_LEAVE data1=0 data2=0)
00:01:26 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=86241 windowid=2 event=SDL_WINDOWEVENT_FOCUS_LOST data1=0 data2=0)

错误时的SDL事件:

移入鼠标,SDL程序获得焦点,并认为Ctrl键按下:

00:00:33 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=33986 windowid=2 event=SDL_WINDOWEVENT_FOCUS_GAINED data1=0 data2=0)
00:00:33 - SDL Info (0): SDL EVENT: SDL_KEYDOWN (timestamp=33986 windowid=2 state=pressed repeat=false scancode=224 keycode=1073742048 mod=4160)
00:00:33 - SDL Info (0): SDL EVENT: SDL_KEYDOWN (timestamp=33986 windowid=2 state=pressed repeat=false scancode=228 keycode=1073742052 mod=4288)
00:00:33 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
00:00:33 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
00:00:33 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=33986 windowid=2 event=SDL_WINDOWEVENT_ENTER data1=0 data2=0)

移出鼠标,SDL程序失去焦点,并认为Ctrl键弹起:

00:00:39 - SDL Info (0): SDL EVENT: SDL_KEYUP (timestamp=39392 windowid=2 state=released repeat=false scancode=224 keycode=1073742048 mod=128)
00:00:39 - SDL Info (0): SDL EVENT: SDL_KEYUP (timestamp=39392 windowid=2 state=released repeat=false scancode=228 keycode=1073742052 mod=0)
00:00:39 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=39392 windowid=2 event=SDL_WINDOWEVENT_FOCUS_LOST data1=0 data2=0)
00:00:39 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=39392 windowid=2 event=SDL_WINDOWEVENT_LEAVE data1=0 data2=0)

Output of fcitx5-diagnose command

fcitx5-diagnose.log

@wengxt
Copy link
Member

wengxt commented Dec 6, 2024

用 WAYLAND_DEBUG=1 启动你说的这些程序和 fcitx5 看看

顺便推荐你试试 kde 或者更新 sway 到 1.10 看看

@jwangac
Copy link
Author

jwangac commented Dec 6, 2024

用 WAYLAND_DEBUG=1 启动你说的这些程序和 fcitx5 看看

顺便推荐你试试 kde 或者更新 sway 到 1.10 看看

感谢回复,更新sway到1.10仍然有此问题。

加上WAYLAND_DEBUG=1启动后,完整日志见wayland.txt

移入鼠标时的片段:

[2206097.844] wl_keyboard@30.enter(1377, wl_surface@45, array[12])
00:00:09 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=9532 windowid=2 event=SDL_WINDOWEVENT_FOCUS_GAINED data1=0 data2=0)
[2206097.911]  -> wl_display@1.sync(new id wl_callback@229)
00:00:09 - SDL Info (0): SDL EVENT: SDL_KEYDOWN (timestamp=9532 windowid=2 state=pressed repeat=false scancode=228 keycode=1073742052 mod=128)
00:00:09 - SDL Info (0): SDL EVENT: SDL_KEYDOWN (timestamp=9532 windowid=2 state=pressed repeat=true scancode=228 keycode=1073742052 mod=128)
00:00:09 - SDL Info (0): SDL EVENT: SDL_KEYDOWN (timestamp=9532 windowid=2 state=pressed repeat=true scancode=228 keycode=1073742052 mod=128)
[2206097.946] wl_keyboard@30.modifiers(1378, 0, 0, 0, 0)
[2206097.959] wl_data_device@21.data_offer(new id wl_data_offer@4278190080)
[2206097.961] wl_data_offer@4278190080.offer("text/plain;charset=utf-8")
[2206097.969] wl_data_offer@4278190080.offer("text/plain")
[2206097.970] wl_data_offer@4278190080.offer("TEXT")
[2206097.972] wl_data_offer@4278190080.offer("STRING")
[2206097.973] wl_data_offer@4278190080.offer("UTF8_STRING")
[2206097.980] wl_data_device@21.selection(wl_data_offer@4278190080)
[2206097.982]  -> wl_data_offer@4278190081.destroy()
00:00:09 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
[2206097.994] zwp_primary_selection_device_v1@25.selection(nil)
00:00:09 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
[2206098.000] zwp_text_input_v3@22.enter(wl_surface@45)
[2206098.002] wl_pointer@28.enter(1380, wl_surface@45, 620.65625000, 548.99218750)
00:00:09 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=9532 windowid=2 event=SDL_WINDOWEVENT_ENTER data1=0 data2=0)

移出鼠标时的片段:

[2206419.946] wl_keyboard@30.leave(1382, wl_surface@45)
00:00:09 - SDL Info (0): SDL EVENT: SDL_KEYUP (timestamp=9855 windowid=2 state=released repeat=false scancode=228 keycode=1073742052 mod=0)
[2206420.018]  -> wl_display@1.sync(new id wl_callback@260)
00:00:09 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=9855 windowid=2 event=SDL_WINDOWEVENT_FOCUS_LOST data1=0 data2=0)
[2206420.049] zwp_text_input_v3@22.leave(wl_surface@45)
[2206420.053] wl_pointer@28.leave(1387, wl_surface@45)
00:00:09 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=9855 windowid=2 event=SDL_WINDOWEVENT_LEAVE data1=0 data2=0)

关闭fcitx5,解决此问题后的日志如下。

移入鼠标时的片段:

[2626606.923] wl_keyboard@30.enter(3058, wl_surface@45, array[0])
00:00:16 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=16329 windowid=2 event=SDL_WINDOWEVENT_FOCUS_GAINED data1=0 data2=0)
[2626607.087]  -> wl_display@1.sync(new id wl_callback@246)
[2626607.104] wl_keyboard@30.modifiers(3059, 0, 0, 0, 0)
[2626607.110] wl_data_device@21.data_offer(new id wl_data_offer@4278190082)
[2626607.115] wl_data_offer@4278190082.offer("text/plain;charset=utf-8")
[2626607.117] wl_data_offer@4278190082.offer("UTF8_STRING")
[2626607.119] wl_data_offer@4278190082.offer("COMPOUND_TEXT")
[2626607.120] wl_data_offer@4278190082.offer("TEXT")
[2626607.124] wl_data_offer@4278190082.offer("text/plain")
[2626607.126] wl_data_offer@4278190082.offer("STRING")
[2626607.127] wl_data_offer@4278190082.offer("SAVE_TARGETS")
[2626607.129] wl_data_device@21.selection(wl_data_offer@4278190082)
[2626607.133]  -> wl_data_offer@4278190080.destroy()
00:00:16 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
[2626607.147] zwp_primary_selection_device_v1@25.data_offer(new id zwp_primary_selection_offer_v1@4278190083)
[2626607.151] zwp_primary_selection_offer_v1@4278190083.offer("text/plain;charset=utf-8")
[2626607.153] zwp_primary_selection_offer_v1@4278190083.offer("UTF8_STRING")
[2626607.154] zwp_primary_selection_offer_v1@4278190083.offer("COMPOUND_TEXT")
[2626607.156] zwp_primary_selection_offer_v1@4278190083.offer("TEXT")
[2626607.159] zwp_primary_selection_offer_v1@4278190083.offer("text/plain")
[2626607.160] zwp_primary_selection_offer_v1@4278190083.offer("STRING")
[2626607.162] zwp_primary_selection_device_v1@25.selection(zwp_primary_selection_offer_v1@4278190083)
[2626607.164]  -> zwp_primary_selection_offer_v1@4278190081.destroy()
00:00:16 - SDL Info (0): SDL EVENT: SDL_CLIPBOARDUPDATE
[2626607.175] wl_pointer@28.enter(3060, wl_surface@45, 11.81640625, 475.00390625)
00:00:16 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=16329 windowid=2 event=SDL_WINDOWEVENT_ENTER data1=0 data2=0)

移出鼠标时的片段:

[2626994.621] wl_keyboard@30.leave(3065, wl_surface@45)
00:00:16 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=16717 windowid=2 event=SDL_WINDOWEVENT_FOCUS_LOST data1=0 data2=0)
[2626994.679]  -> wl_display@1.sync(new id wl_callback@289)
[2626994.690] zwp_text_input_v3@22.leave(wl_surface@45)
[2626994.696] wl_pointer@28.leave(3070, wl_surface@45)
00:00:16 - SDL Info (0): SDL EVENT: SDL_WINDOWEVENT (timestamp=16717 windowid=2 event=SDL_WINDOWEVENT_LEAVE data1=0 data2=0)

@wengxt
Copy link
Member

wengxt commented Dec 6, 2024

这么看感觉是sdl的bug,keyboad leave 之后不应该假定任何按键的状态 sway也没有产生新的 wl keyboad key

wl_keyboard@30.modifiers(1378, 0, 0, 0, 0) 也清空了modifier key的状态

@wengxt wengxt closed this as completed Dec 6, 2024
@wengxt
Copy link
Member

wengxt commented Dec 12, 2024

Duplicate of #1202

@wengxt wengxt marked this as a duplicate of #1202 Dec 12, 2024
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

No branches or pull requests

2 participants