foxygit / doom Log in
commit 6e363ea1bad43a38b85882e89a9386566b512bf4
Author:     RamonUnch <74856804+RamonUnch@users.noreply.github.com>
AuthorDate: Wed Sep 7 14:24:30 2022 +0100
Commit:     GitHub <noreply@github.com>
CommitDate: Wed Sep 7 16:24:30 2022 +0300

    Fix Mouse wheel conflict with Xbuttons 1&2 (#1440)

    * Fix Mouse wheel conflict with Xbuttons 1&2

    * Display WHEEL UP/DOWN in the setup

    * restore txt_main

    * Better input remapping

    * Adjust setup program

    * Shift Xbuttons 2 up for txt_main.h/txt_sdl.h
---
 src/i_input.c              | 6 +++++-
 src/setup/txt_mouseinput.c | 8 +++++++-
 textscreen/txt_main.h      | 2 ++
 textscreen/txt_sdl.c       | 2 +-
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/i_input.c b/src/i_input.c
index aa9f6ff0..091aa6b8 100644
--- a/src/i_input.c
+++ b/src/i_input.c
@@ -318,6 +318,8 @@ static void UpdateMouseButtonState(unsigned int button, boolean on)
     // Note: button "0" is left, button "1" is right,
     // button "2" is middle for Doom.  This is different
     // to how SDL sees things.
+    // In the end: Left=0, Right=1, Middle=2,
+    // WheelUp=3 WheelDown=4, XButton1=5, XButton2=6

     switch (button)
     {
@@ -335,7 +337,9 @@ static void UpdateMouseButtonState(unsigned int button, boolean on)

         default:
             // SDL buttons are indexed from 1.
-            --button;
+            // And the wheel is mapped to button 3/4
+            // So we have to increment 2 and decrement 1 => inc 1.
+            button++;
             break;
     }

diff --git a/src/setup/txt_mouseinput.c b/src/setup/txt_mouseinput.c
index f5a79cd0..99196a58 100644
--- a/src/setup/txt_mouseinput.c
+++ b/src/setup/txt_mouseinput.c
@@ -84,8 +84,14 @@ static void GetMouseButtonDescription(int button, char *buf, size_t buf_len)
         case 2:
             M_StringCopy(buf, "MID", buf_len);
             break;
+        case 3:
+            M_StringCopy(buf, "WHEEL UP", buf_len);
+            break;
+        case 4:
+            M_StringCopy(buf, "WHEEL DOWN", buf_len);
+            break;
         default:
-            M_snprintf(buf, buf_len, "BUTTON #%i", button + 1);
+            M_snprintf(buf, buf_len, "BUTTON #%i", button - 1);
             break;
     }
 }
diff --git a/textscreen/txt_main.h b/textscreen/txt_main.h
index d8cdda1a..183cc9a9 100644
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -43,6 +43,8 @@
 #define TXT_MOUSE_MIDDLE       (TXT_MOUSE_BASE + 2)
 #define TXT_MOUSE_SCROLLUP     (TXT_MOUSE_BASE + 3)
 #define TXT_MOUSE_SCROLLDOWN   (TXT_MOUSE_BASE + 4)
+#define TXT_MOUSE_X1           (TXT_MOUSE_BASE + 5)
+#define TXT_MOUSE_X2           (TXT_MOUSE_BASE + 6)
 #define TXT_MAX_MOUSE_BUTTONS  16

 #define TXT_KEY_TO_MOUSE_BUTTON(x)                                        \
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index 51aaf9bb..42480f48 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -567,7 +567,7 @@ static int SDLButtonToTXTButton(int button)
         case SDL_BUTTON_MIDDLE:
             return TXT_MOUSE_MIDDLE;
         default:
-            return TXT_MOUSE_BASE + button - 1;
+            return TXT_MOUSE_BASE + button + 1;
     }
 }