Re: [hatari-devel] Joystick buttons config and sdl gui patches

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi Nicolas,

Great, thank you.  I actually noticed a small bug myself, which I've
now fixed with the attached follow up patch.  If the joystick is used
to control the gui then the JOYBUTTON_UP event from the last press is
received before the user can choose "Button 1" on the new dialog.  To
allow for that scenario I've added another boolean to ignore UP events
received before DOWN is handled.  I should have thought of that
before, but had only been using the mouse and keyboard to start my new
dialog!

NB This is a repost to the list of a reply I sent directly to Nicolas
yesterday (forgot to reply to all).

Br,

Robin.

On Sun, 6 Aug 2023 at 20:50, Nicolas Pomarède <npomarede@xxxxxxxxxxxx> wrote:
>
> Le 30/07/2023 à 10:46, Robin Sergeant a écrit :
> > Hi,
> >
> > Please find the attached patches.  The first just adds the config as
> > before, but with checks to allow for undefined buttons (with negative
> > indexes).
> >
> > The second adds a "Remap joystick buttons" button to the sdl joystick
> > dialog.  This behaves like the existing "Define keys" button.  The
> > user is guided to press each of the 3 buttons, but can also press the
> > ESC key for none (which results in a value of -1 being stored and the
> > button being ignored).   The dialog looks like this:
> >
> > --------------------------------
> > Press joystick button 1
> > or ESC for none...
> >
> > (was: id 3)
> > --------------------------------
> >
> > And then after pressing button 0 (but before releasing):
> >
> > --------------------------------
> > Press joystick button 1
> > or ESC for none...
> >
> > (now: id 0)
> > --------------------------------
> >
> > So as I said, basically consistent with how "Define keys" currently works.
> >
> > Does this look ok, and can the patches be included?  Obviously happy
> > to make any further tweaks or change the UI etc.  I should probably
> > have sent the proposal first, but I got carried away with the coding
> > and wanted to figure out how the dialogs worked :-)
> >
> > Any feedback welcome!
>
> Hi
>
> both patches look ok to me , so unless someone require some changes to
> them or have some remarks then I can commit them to main sources.
>
> Nicolas
>
From 283679804c1e6f7f5f6dc7ed9d7334c502246512 Mon Sep 17 00:00:00 2001
From: Robin Sergeant <robin.sergeant@gmail.com>
Date: Sun, 6 Aug 2023 21:17:11 +0100
Subject: [PATCH 3/3] Fix event handling order in button remapping gui

---
 src/gui-sdl/dlgJoystick.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/gui-sdl/dlgJoystick.c b/src/gui-sdl/dlgJoystick.c
index bd31de5a..37d2f6d0 100644
--- a/src/gui-sdl/dlgJoystick.c
+++ b/src/gui-sdl/dlgJoystick.c
@@ -169,6 +169,7 @@ static void DlgJoystick_MapOneButton(int button, int *pButton)
 {
 	SDL_Event sdlEvent;
 	bool bDone = false;
+	bool bSet = false;
 
 	if (bQuitProgram)
 		return;
@@ -192,16 +193,18 @@ static void DlgJoystick_MapOneButton(int button, int *pButton)
 		{
 			case SDL_JOYBUTTONDOWN:
 				*pButton = sdlEvent.jbutton.button;
+				bSet = true;
 				snprintf(sKeyName, sizeof(sKeyName), "(now: id %d)", *pButton);
 				SDLGui_DrawDialog(joybuttondlg);
 				break;
 			case SDL_JOYBUTTONUP:
-				bDone = true;
+				bDone = bSet;
 				break;
 			case SDL_KEYDOWN:
 				if (sdlEvent.key.keysym.sym == SDLK_ESCAPE)
 				{
 					*pButton = -1;
+					bSet = true;
 					strcpy(sKeyName, "(now: none)");
 					SDLGui_DrawDialog(joybuttondlg);
 				}
@@ -209,7 +212,7 @@ static void DlgJoystick_MapOneButton(int button, int *pButton)
 			case SDL_KEYUP:
 				if (sdlEvent.key.keysym.sym == SDLK_ESCAPE)
 				{
-					bDone = true;
+					bDone = bSet;
 				}
 				break;
 			case SDL_QUIT:
-- 
2.37.1 (Apple Git-137.1)



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/