Re: [hatari-devel] Keyup bug in SDL GUI |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Keyup bug in SDL GUI
- From: Andreas Grabher <andreas_g86@xxxxxxxxxx>
- Date: Sun, 4 Dec 2022 11:35:26 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1670150139; bh=ns6HiStqUklRWx1lVrh6mzprl5L5kUL6ORVjHDpbReQ=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id; b=1T30zlp0MdRINicDjEUQSFSAoSpDRB6Ia2mdiMirnJ4tpQtuGQp0MspM8YEGvRu6q HbOYIXQuMY6TpoFkAGlkbhGt5HpLikdy2OisB121fOn212N+avNvMc3XWyItQ6gex+ gcnPKQSjjWc20L7e3BkoULf0KLozkoP/ZofPMef6IJEBNDgZVM5b6oNRtQyIGlqlRG 64pUQnXkX/LMxRCRgv4hvdRXbNx4RVNg24VcstG7sXg+8LcrMgR2CpCW0CVPKqMNgq +PNp6HrhsKlqxrwDNvXGMdVXji9x+8SzzFmOiiUiEvSDySWlOFCUMGe1+k20DgvUTE fjk5853/R+NCw==
> Am 29.11.2022 um 18:06 schrieb Andreas Grabher <andreas_g86@xxxxxxxxxx>:
>
>
>
>> Am 29.11.2022 um 11:21 schrieb Andreas Grabher <andreas_g86@xxxxxxxxxx>:
>>
>>
>>> Am 02.11.2022 um 18:42 schrieb Thomas Huth <th.huth@xxxxxxxxx>:
>>>
>>> Am Wed, 2 Nov 2022 10:06:50 +0100
>>> schrieb Andreas Grabher <andreas_g86@xxxxxxxxxx>:
>>>
>>>>>> Am 31.10.2022 um 19:48 schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:
>>>>>
>>>>> Hi,
>>>>>
>>>>>> On 31.10.2022 20.35, Andreas Grabher wrote:
>>>>>> I might have found a bug in the SDL GUI. This scenario:
>>>>>> In the guest operating system I confirm some action by pressing enter
>>>>>> —> SDL_KEYDOWN with SDLK_RETURN
>>>>>> Due to some bug in the OS I get a double fault, which then activates Dialog_HaltDlg() before I am able to release the key
>>>>>> I then release the key
>>>>>> —> SDL_KEYUP with SDLK_RETURN
>>>>>> At this time we are already in the SDL_WaitEvent()-Loop in SDLGui_DoDialogExt() and the event is recognized as key up in the GUI. This leads to automatically pressing the default button which exits the dialog without me having a chance to select anything.
>>>>>> Can you confirm this? This will be difficult to fix.
>>>>>
>>>>> You can wait until all keys are up, before starting accepting input in SDL GUI.
>>>>>
>>>>> No notify user about this wait, you can show a note about keys being down in statusbar.
>>>>>
>>>>> If SDL does not provide information about pressed keys, keymap.c keeps count of them.
>>>>>
>>>>>
>>>>> - Eero
>>>>>
>>>> Maybe calling SDL_ResetKeyboard() before entering the SDL_WaitEvent()-loop would be the solution?
>>>
>>> I don't think this would be the right fix - in case you still hold the key
>>> when the SDL_ResetKeyboard() is done, you still get the KEYUP event
>>> afterwards once the key is released. I think you have to something like
>>> this (untested):
>>>
>>> const Uint8 *keys = SDL_GetKeyboardState();
>>> while (keys[SDLK_RETURN])
>>> SDL_PumpEvents();
>>>
>>> HTH,
>>> Thomas
>>>
>> I just read through the SDL code a bit and I think it should work with SDL_ResetKeyboard(). That function will send KEYUP event for all pressed keys. Releasing a key afterwards won‘t send another KEYUP event until the key is pressed again.
>>
>> This should fix the issue:
>> SDL_ResetKeyboard();
>> SDL_PumpEvents();
>> SDL_FlushEvent(SDL_KEYUP);
>>
>> I have some more keyboard issues. Calling host routines can cause stuck keys, especially stuck modifiers. Not sure how this can be fixed.
>>
> I can now confirm that the SDL_ResetKeyboard() function works as expected. There is no KEYUP event afterwards except if i hold the key long enough to trigger key repeat. Maybe repeated key events should also be ignored in the GUI code.
>
I found a way to improve things in Previous (getting modifier keys from sdlkey.mod and calling SDL_ResetKeyboard() in Main_UnPauseEmulation()). It seems Hatari works differently. Maybe this function helps:
struct {
SDL_Scancode scancode;
SDL_Keycode keycode;
} mainModifiers[] = {
{ SDL_SCANCODE_LCTRL, SDLK_LCTRL },
{ SDL_SCANCODE_LSHIFT, SDLK_LSHIFT },
{ SDL_SCANCODE_RSHIFT, SDLK_RSHIFT },
{ SDL_SCANCODE_LGUI, SDLK_LGUI },
{ SDL_SCANCODE_RGUI, SDLK_RGUI },
{ SDL_SCANCODE_LALT, SDLK_LALT },
{ SDL_SCANCODE_RALT, SDLK_RALT }
};
void Main_ResetModifierKeys(void) {
SDL_Event event;
/* Release all modifiers */
for (int i = 0; i < ARRAY_SIZE(mainModifiers); i++) {
event.type = SDL_KEYUP;
event.key.keysym.scancode = mainModifiers[i].scancode;
event.key.keysym.sym = mainModifiers[i].keycode;
SDL_PushEvent(&event);
}
/* Release all other keys */
SDL_ResetKeyboard();
}
The modifier list is made for NeXT keyboards. It might need some modification to work for Atari keyboards.