From 7e8e3814deeec231ca87b2d8866d235b408532c2 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 18 Sep 2024 21:27:00 +0300
Subject: [PATCH 37/37] sdl3: Update to SDL_KeyboardEvent rearrangements

See RM #875

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-sdl3/gui_main.c    | 24 ++++++++++++------------
 client/gui-sdl3/gui_main.h    |  4 ++--
 client/gui-sdl3/mapctrl.c     |  8 ++++----
 client/gui-sdl3/mapctrl.h     |  2 +-
 client/gui-sdl3/widget.c      | 12 ++++++------
 client/gui-sdl3/widget.h      |  2 +-
 client/gui-sdl3/widget_edit.c | 14 +++++++-------
 7 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/client/gui-sdl3/gui_main.c b/client/gui-sdl3/gui_main.c
index ccca758b7f..4f13c9cd21 100644
--- a/client/gui-sdl3/gui_main.c
+++ b/client/gui-sdl3/gui_main.c
@@ -223,20 +223,20 @@ static bool parse_options(int argc, char **argv)
 /**********************************************************************//**
   Main handler for key presses
 **************************************************************************/
-static Uint16 main_key_down_handler(SDL_Keycode key, void *data)
+static Uint16 main_key_down_handler(SDL_KeyboardEvent *key, void *data)
 {
   static struct widget *pwidget;
 
   if ((pwidget = find_next_widget_for_key(NULL, key)) != NULL) {
     return widget_pressed_action(pwidget);
   } else {
-    if (key.sym == SDLK_TAB) {
-      /* input */
+    if (key->key == SDLK_TAB) {
+      /* Input */
       popup_input_line();
     } else {
       if (map_event_handler(key)
           && C_S_RUNNING == client_state()) {
-        switch (key.sym) {
+        switch (key->key) {
         case SDLK_RETURN:
         case SDLK_KP_ENTER:
           if (LSHIFT || RSHIFT) {
@@ -304,7 +304,7 @@ static Uint16 main_key_down_handler(SDL_Keycode key, void *data)
 /**********************************************************************//**
   Main key release handler.
 **************************************************************************/
-static Uint16 main_key_up_handler(SDL_Keycode key, void *data)
+static Uint16 main_key_up_handler(SDL_KeyboardEvent *key, void *data)
 {
   if (selected_widget) {
     unselect_widget_action();
@@ -596,8 +596,8 @@ bool FilterMouseMotionEvents(void *data, SDL_Event *event)
 **************************************************************************/
 Uint16 gui_event_loop(void *data,
                       void (*loop_action)(void *data),
-                      Uint16 (*key_down_handler)(SDL_Keycode key, void *data),
-                      Uint16 (*key_up_handler)(SDL_Keycode key, void *data),
+                      Uint16 (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
+                      Uint16 (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
                       Uint16 (*textinput_handler)(char *text, void *data),
                       Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
                       Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
@@ -733,8 +733,8 @@ Uint16 gui_event_loop(void *data,
           break;
 
         case SDL_EVENT_KEY_UP:
-          switch (main_data.event.key.keysym.sym) {
-            /* find if Shifts are released */
+          switch (main_data.event.key.key) {
+            /* Find if Shifts are released */
             case SDLK_RSHIFT:
               RSHIFT = FALSE;
             break;
@@ -752,14 +752,14 @@ Uint16 gui_event_loop(void *data,
             break;
             default:
               if (key_up_handler) {
-                ID = key_up_handler(main_data.event.key.keysym, data);
+                ID = key_up_handler(&(main_data.event.key), data);
               }
             break;
           }
           break;
 
         case SDL_EVENT_KEY_DOWN:
-          switch (main_data.event.key.keysym.sym) {
+          switch (main_data.event.key.key) {
 #if 0
           case SDLK_PRINT:
             fc_snprintf(schot, sizeof(schot), "fc_%05d.bmp", schot_nr++);
@@ -795,7 +795,7 @@ Uint16 gui_event_loop(void *data,
 
           default:
             if (key_down_handler) {
-              ID = key_down_handler(main_data.event.key.keysym, data);
+              ID = key_down_handler(&(main_data.event.key), data);
             }
             break;
           }
diff --git a/client/gui-sdl3/gui_main.h b/client/gui-sdl3/gui_main.h
index 57617991a4..fe98f2e897 100644
--- a/client/gui-sdl3/gui_main.h
+++ b/client/gui-sdl3/gui_main.h
@@ -110,8 +110,8 @@ extern int MOVE_STEP_X, MOVE_STEP_Y;
 bool FilterMouseMotionEvents(void *data, SDL_Event *event);
 
 Uint16 gui_event_loop(void *data, void (*loop_action)(void *data),
-                      Uint16 (*key_down_handler)(SDL_Keycode key, void *data),
-                      Uint16 (*key_up_handler)(SDL_Keycode key, void *data),
+                      Uint16 (*key_down_handler)(SDL_KeyboardEvent *key, void *data),
+                      Uint16 (*key_up_handler)(SDL_KeyboardEvent *key, void *data),
                       Uint16 (*textinput_handler)(char *text, void *data),
                       Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
                       Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
diff --git a/client/gui-sdl3/mapctrl.c b/client/gui-sdl3/mapctrl.c
index e912d7a5b5..856803a94c 100644
--- a/client/gui-sdl3/mapctrl.c
+++ b/client/gui-sdl3/mapctrl.c
@@ -2437,12 +2437,12 @@ void button_up_on_map(struct mouse_button_behavior *button_behavior)
 /**********************************************************************//**
   Toggle map drawing stuff.
 **************************************************************************/
-bool map_event_handler(SDL_Keycode key)
+bool map_event_handler(SDL_KeyboardEvent *key)
 {
   if (C_S_RUNNING == client_state()) {
     enum direction8 movedir = DIR8_MAGIC_MAX;
 
-    switch (key.scancode) {
+    switch (key->scancode) {
 
     case SDL_SCANCODE_KP_8:
       movedir = DIR8_NORTH;
@@ -2481,9 +2481,9 @@ bool map_event_handler(SDL_Keycode key)
       return FALSE;
 
     default:
-      switch (key.sym) {
+      switch (key->key) {
 
-        /* cancel action */
+      /* Cancel action */
       case SDLK_ESCAPE:
         key_cancel_action();
         draw_goto_patrol_lines = FALSE;
diff --git a/client/gui-sdl3/mapctrl.h b/client/gui-sdl3/mapctrl.h
index 183738cdcc..e640ce95f3 100644
--- a/client/gui-sdl3/mapctrl.h
+++ b/client/gui-sdl3/mapctrl.h
@@ -87,7 +87,7 @@ void enable_and_redraw_find_city_button(void);
 void enable_and_redraw_revolution_button(void);
 void enable_main_widgets(void);
 void disable_main_widgets(void);
-bool map_event_handler(SDL_Keycode key);
+bool map_event_handler(SDL_KeyboardEvent *key);
 
 void finger_down_on_map(struct finger_behavior *finger_behavior);
 void finger_up_on_map(struct finger_behavior *finger_behavior);
diff --git a/client/gui-sdl3/widget.c b/client/gui-sdl3/widget.c
index 85ce003f11..582c0fde6e 100644
--- a/client/gui-sdl3/widget.c
+++ b/client/gui-sdl3/widget.c
@@ -246,18 +246,18 @@ struct widget *find_next_widget_at_pos(struct widget *start_widget,
   NOTE: This function ignores CapsLock and NumLock Keys.
 **************************************************************************/
 struct widget *find_next_widget_for_key(struct widget *start_widget,
-                                        SDL_Keycode key)
+                                        SDL_KeyboardEvent *key)
 {
   struct widget *pwidget;
 
   pwidget = start_widget ? start_widget : begin_main_widget_list;
 
-  key.mod &= ~(SDL_KMOD_NUM | SDL_KMOD_CAPS);
+  key->mod &= ~(SDL_KMOD_NUM | SDL_KMOD_CAPS);
   while (pwidget) {
-    if ((pwidget->key == key.sym
-         || (pwidget->key == SDLK_RETURN && key.sym == SDLK_KP_ENTER)
-         || (pwidget->key == SDLK_KP_ENTER && key.sym == SDLK_RETURN))
-        && ((pwidget->mod & key.mod) || (pwidget->mod == key.mod))) {
+    if ((pwidget->key == key->key
+         || (pwidget->key == SDLK_RETURN && key->key == SDLK_KP_ENTER)
+         || (pwidget->key == SDLK_KP_ENTER && key->key == SDLK_RETURN))
+        && ((pwidget->mod & key.mod) || (pwidget->mod == key->mod))) {
       if (!((get_wstate(pwidget) == FC_WS_DISABLED)
             || ((get_wflags(pwidget) & WF_HIDDEN) == WF_HIDDEN))) {
         return (struct widget *) pwidget;
diff --git a/client/gui-sdl3/widget.h b/client/gui-sdl3/widget.h
index 63cdf113a5..ed935abae1 100644
--- a/client/gui-sdl3/widget.h
+++ b/client/gui-sdl3/widget.h
@@ -203,7 +203,7 @@ void del_gui_list(struct widget *gui_list);
 void del_main_list(void);
 
 struct widget *find_next_widget_at_pos(struct widget *start_widget, int x, int y);
-struct widget *find_next_widget_for_key(struct widget *start_widget, SDL_Keycode key);
+struct widget *find_next_widget_for_key(struct widget *start_widget, SDL_KeyboardEvent *key);
 
 struct widget *get_widget_pointer_from_id(const struct widget *gui_list,
                                           Uint16 id,
diff --git a/client/gui-sdl3/widget_edit.c b/client/gui-sdl3/widget_edit.c
index cb16ce9383..8af6f943cc 100644
--- a/client/gui-sdl3/widget_edit.c
+++ b/client/gui-sdl3/widget_edit.c
@@ -416,30 +416,30 @@ int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y)
   NOTE: This functions can return NULL in 'edit_widget->string_utf8->text' but
         never free 'edit_widget->string_utf8' struct.
 **************************************************************************/
-static Uint16 edit_key_down(SDL_Keycode key, void *data)
+static Uint16 edit_key_down(SDL_KeyboardEvent *key, void *data)
 {
   struct text_edit *edt = (struct text_edit *)data;
   struct utf8_char *input_chain_tmp;
   bool redraw = FALSE;
 
-  /* find which key is pressed */
-  switch (key.sym) {
+  /* Find which key is pressed */
+  switch (key->key) {
     case SDLK_ESCAPE:
-      /* exit from loop without changes */
+      /* Exit from loop without changes */
       return ED_ESC;
     case SDLK_RETURN:
     case SDLK_KP_ENTER:
-      /* exit from loop */
+      /* Exit from loop */
       return ED_RETURN;
       /*
     case SDLK_KP6:
-      if (key.mod & KMOD_NUM) {
+      if (key->mod & KMOD_NUM) {
         goto INPUT;
       }
       */
     case SDLK_RIGHT:
     {
-      /* move cursor right */
+      /* Move cursor right */
       if (edt->input_chain->next) {
         if (edt->input_chain_x >= (edt->pwidget->size.x + edt->bg->w - adj_size(10))) {
           edt->start_x -= edt->input_chain->tsurf->w -
-- 
2.45.2

