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 special key does not work in linux #62838

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,7 +3202,7 @@ static void CheckMessages()
last_input = input_event( lc, input_event_t::keyboard_char );
} else {
// no key pressed in this event
last_input = input_event();
// last_input = input_event(); //i don't know why it works
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in #24568 to avoid triggering an UNKNOWN_UNICODE input event when SDL sends an SDL_TEXTEDITING event with an empty string.

If commenting out this line fixes the issues, my guess is that the system sends an SDL_KEYDOWN event that is skipped due to being an auto-repeat event, immediately followed by an SDL_TEXTEDITING event which is handled in the same CheckMessage call, therefore overwriting the first event.

I wonder if you could print a log of key events when the issues happen so we can better understand what is happening and make a more specific fix?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-----------------------------------------
16:27:04.328 : Starting log.
16:27:04.328 INFO : Cataclysm DDA version 211b11d37f-dirty
16:27:04.329 INFO : [main] C locale set to zh_CN.UTF-8
16:27:04.329 INFO : [main] C++ locale set to zh_CN.UTF-8
16:27:04.329 INFO : SDL version used during compile is 2.26.1
16:27:04.329 INFO : SDL version used during linking and in runtime is 2.26.1
16:27:04.353 INFO : Number of render drivers on your system: 3
16:27:04.353 INFO : Render driver: 0/opengl
16:27:04.353 INFO : Render driver: 1/opengles2
16:27:04.353 INFO : Render driver: 2/software
16:27:04.355 INFO : [options] C locale set to zh_CN.UTF-8
16:27:04.355 INFO : [options] C++ locale set to zh_CN.UTF-8
16:27:04.355 INFO : Setting language to: 'zh_CN'
16:27:04.355 INFO : [i18n] Scanning core translations from lang/mo/
16:27:04.355 INFO : [i18n] Scanning mod translations from ./mods/
16:27:04.355 WARNING : opendir [./mods/] failed with "没有那个文件或目录".
16:27:04.530 INFO : Active renderer: 0/opengl
16:27:04.697 INFO : USE_COLOR_MODULATED_TEXTURES is set to 0
16:27:04.707 INFO : Setting language to: 'zh_CN'
16:27:04.715 WARNING : opendir [./mods] failed with "没有那个文件或目录".
16:27:05.341 INFO : SDL_KEYDOWN{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:05.341 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:05.432 INFO : SDL_KEYUP{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:05.578 INFO : SDL_KEYDOWN{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:05.578 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:05.647 INFO : SDL_KEYUP{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:05.739 INFO : SDL_KEYDOWN{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:05.739 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:05.823 INFO : SDL_KEYUP{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:05.909 INFO : SDL_KEYDOWN{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:05.909 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:05.979 INFO : SDL_KEYUP{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:06.275 INFO : SDL_KEYDOWN{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:06.275 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:06.359 INFO : SDL_KEYUP{mod:0,scancode:79,sym:1073741903,unused:0}
16:27:06.667 INFO : SDL_KEYDOWN{mod:0,scancode:80,sym:1073741904,unused:0}
16:27:06.667 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:06.780 INFO : SDL_KEYUP{mod:0,scancode:80,sym:1073741904,unused:0}
16:27:06.876 INFO : SDL_KEYDOWN{mod:0,scancode:80,sym:1073741904,unused:0}
16:27:06.876 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:06.952 INFO : SDL_KEYUP{mod:0,scancode:80,sym:1073741904,unused:0}
16:27:08.873 INFO : SDL_KEYDOWN{mod:1,scancode:225,sym:1073742049,unused:0}
16:27:09.099 INFO : SDL_KEYDOWN{mod:1,scancode:4,sym:97,unused:0}
16:27:09.099 INFO : SDL_TEXTINPUT{text:A}
16:27:09.103 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:09.303 INFO : SDL_KEYUP{mod:1,scancode:4,sym:97,unused:0}
16:27:09.374 INFO : SDL_KEYUP{mod:0,scancode:225,sym:1073742049,unused:0}
16:27:10.829 INFO : SDL_KEYDOWN{mod:1,scancode:225,sym:1073742049,unused:0}
16:27:11.160 INFO : SDL_KEYDOWN{mod:1,scancode:23,sym:116,unused:0}
16:27:11.160 INFO : SDL_TEXTINPUT{text:T}
16:27:11.168 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:11.290 INFO : SDL_KEYUP{mod:1,scancode:23,sym:116,unused:0}
16:27:11.374 INFO : SDL_KEYUP{mod:0,scancode:225,sym:1073742049,unused:0}
16:27:11.943 INFO : SDL_KEYDOWN{mod:0,scancode:40,sym:13,unused:0}
16:27:11.943 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:12.012 INFO : SDL_KEYUP{mod:0,scancode:40,sym:13,unused:0}
16:27:12.941 INFO : SDL_KEYDOWN{mod:0,scancode:40,sym:13,unused:0}
16:27:12.941 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:13.016 INFO : SDL_KEYUP{mod:0,scancode:40,sym:13,unused:0}
16:27:13.848 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:13.848 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:13.923 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:14.024 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:14.024 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:14.094 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:14.185 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:14.185 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:14.249 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:14.335 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:14.335 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:14.405 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:14.486 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:14.486 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:14.561 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:14.637 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:14.637 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:14.701 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:14.891 INFO : SDL_KEYDOWN{mod:1,scancode:225,sym:1073742049,unused:0}
16:27:15.093 INFO : SDL_KEYDOWN{mod:1,scancode:23,sym:116,unused:0}
16:27:15.093 INFO : SDL_TEXTINPUT{text:T}
16:27:15.094 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:15.188 INFO : SDL_KEYDOWN{mod:1,scancode:11,sym:104,unused:0}
16:27:15.188 INFO : SDL_TEXTINPUT{text:H}
16:27:15.190 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:15.206 INFO : SDL_KEYUP{mod:0,scancode:225,sym:1073742049,unused:0}
16:27:15.222 INFO : SDL_KEYUP{mod:0,scancode:23,sym:116,unused:0}
16:27:15.273 INFO : SDL_KEYUP{mod:0,scancode:11,sym:104,unused:0}
16:27:15.339 INFO : SDL_KEYDOWN{mod:0,scancode:8,sym:101,unused:0}
16:27:15.339 INFO : SDL_TEXTINPUT{text:e}
16:27:15.340 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:15.448 INFO : SDL_KEYUP{mod:0,scancode:8,sym:101,unused:0}
16:27:15.504 INFO : SDL_KEYDOWN{mod:1,scancode:225,sym:1073742049,unused:0}
16:27:15.719 INFO : SDL_KEYUP{mod:0,scancode:225,sym:1073742049,unused:0}
16:27:15.779 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:15.779 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:15.850 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:15.920 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:15.920 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:16.020 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:16.185 INFO : SDL_KEYDOWN{mod:0,scancode:42,sym:8,unused:0}
16:27:16.185 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:16.280 INFO : SDL_KEYUP{mod:0,scancode:42,sym:8,unused:0}
16:27:16.592 INFO : SDL_KEYDOWN{mod:1,scancode:225,sym:1073742049,unused:0}
16:27:16.842 INFO : SDL_KEYDOWN{mod:1,scancode:23,sym:116,unused:0}
16:27:16.842 INFO : SDL_TEXTINPUT{text:T}
16:27:16.842 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:16.947 INFO : SDL_KEYUP{mod:0,scancode:225,sym:1073742049,unused:0}
16:27:16.958 INFO : SDL_KEYDOWN{mod:0,scancode:11,sym:104,unused:0}
16:27:16.958 INFO : SDL_TEXTINPUT{text:h}
16:27:16.959 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:16.972 INFO : SDL_KEYUP{mod:0,scancode:23,sym:116,unused:0}
16:27:17.043 INFO : SDL_KEYUP{mod:0,scancode:11,sym:104,unused:0}
16:27:17.098 INFO : SDL_KEYDOWN{mod:0,scancode:8,sym:101,unused:0}
16:27:17.098 INFO : SDL_TEXTINPUT{text:e}
16:27:17.099 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:17.179 INFO : SDL_KEYUP{mod:0,scancode:8,sym:101,unused:0}
16:27:17.238 INFO : SDL_KEYDOWN{mod:1,scancode:225,sym:1073742049,unused:0}
16:27:17.384 INFO : SDL_KEYDOWN{mod:1,scancode:19,sym:112,unused:0}
16:27:17.384 INFO : SDL_TEXTINPUT{text:P}
16:27:17.385 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:17.439 INFO : SDL_KEYUP{mod:0,scancode:225,sym:1073742049,unused:0}
16:27:17.464 INFO : SDL_KEYUP{mod:0,scancode:19,sym:112,unused:0}
16:27:17.515 INFO : SDL_KEYDOWN{mod:0,scancode:8,sym:101,unused:0}
16:27:17.515 INFO : SDL_TEXTINPUT{text:e}
16:27:17.516 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:17.611 INFO : SDL_KEYDOWN{mod:0,scancode:12,sym:105,unused:0}
16:27:17.611 INFO : SDL_TEXTINPUT{text:i}
16:27:17.612 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:17.650 INFO : SDL_KEYUP{mod:0,scancode:8,sym:101,unused:0}
16:27:17.690 INFO : SDL_KEYUP{mod:0,scancode:12,sym:105,unused:0}
16:27:17.941 INFO : SDL_KEYDOWN{mod:0,scancode:40,sym:13,unused:0}
16:27:17.941 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:18.036 INFO : SDL_KEYUP{mod:0,scancode:40,sym:13,unused:0}
16:27:18.253 INFO : SDL_KEYDOWN{mod:0,scancode:41,sym:27,unused:0}
16:27:18.253 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:18.337 INFO : SDL_KEYUP{mod:0,scancode:41,sym:27,unused:0}
16:27:18.909 INFO : SDL_KEYDOWN{mod:1,scancode:225,sym:1073742049,unused:0}
16:27:19.110 INFO : SDL_KEYDOWN{mod:1,scancode:20,sym:113,unused:0}
16:27:19.110 INFO : SDL_TEXTINPUT{text:Q}
16:27:19.118 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:19.330 INFO : SDL_KEYUP{mod:1,scancode:20,sym:113,unused:0}
16:27:19.345 INFO : SDL_KEYUP{mod:0,scancode:225,sym:1073742049,unused:0}
16:27:19.947 INFO : SDL_KEYDOWN{mod:0,scancode:80,sym:1073741904,unused:0}
16:27:19.947 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:20.083 INFO : SDL_KEYUP{mod:0,scancode:80,sym:1073741904,unused:0}
16:27:20.253 INFO : SDL_KEYDOWN{mod:0,scancode:40,sym:13,unused:0}
16:27:20.253 INFO : SDL_TEXTEDITING{text:,length:0,start:0}
16:27:20.253 : Log shutdown.
-----------------------------------------

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe what's wrong in your test? According to the log, you opened the options menu, entered a default character name, confirmed, and exited the game, but the issues you linked in the original post were about game not responding to auto-repeated keys.

Copy link
Author

@ThePeiLin ThePeiLin Dec 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是我在注释了那一行代码后的输出的日志,如果没有注释掉那一行代码,令函数sdl_keysym_to_curses的返回值不为零的键盘事件的keysym都会使得在KEYDOWN事件后跟随一个TEXTEDITING事件,而这个跟随的TEXTEDTING事件的ev.edit.text长度为0,进而会执行被注释的那一行代码,使得原本的last_input的结果被覆盖掉

也就是说,这个bug会导致tab键、方向键回车键等都无效

Copy link
Contributor

@Qrox Qrox Dec 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEXTEDTING事件的ev.edit.text为空相当于系统告诉程序把输入法的预览文本设为空,如果只是注释掉这行代码的话,程序根据KEYDOWN和TEXTEDITING两个事件只返回一个input_event,可能导致输入法预览异常。感觉要正确修复比较复杂,可能需要改变SDL_TEXTEDITING的处理方式,不对last_input进行赋值(按理说输入法的预览文本不应该触发输入,不知道原来为啥这里有赋值),并且在根据edit_refresh处理预览文本的时候考虑包括已处理事件的所有事件。

last_input.type = input_event_t::keyboard_char;
}
last_input.edit = ev.edit.text;
Expand Down