added support for special media buttons on Amazon Fire TV remote control
authorHolger Schemel <info@artsoft.org>
Tue, 11 Jul 2017 21:21:25 +0000 (23:21 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 11 Jul 2017 22:06:28 +0000 (00:06 +0200)
src/events.c
src/events.h
src/libgame/sdl.h
src/tools.c

index 69d7a2120a6fe78f2c7536f16954c2fb4908cc2d..2472fdf5f8978b048af638730299206544445255 100644 (file)
@@ -1525,6 +1525,14 @@ void HandleKey(Key key, int key_status)
   int joy = 0;
   int i;
 
+#if defined(TARGET_SDL2)
+  /* map special "play/pause" media key to default key for play/pause actions */
+  if (key == KSYM_PlayPause)
+    key = KSYM_space;
+#endif
+
+  HandleSpecialGameControllerKeys(key, key_status);
+
   if (game_status == GAME_MODE_PLAYING)
   {
     /* only needed for single-step tape recording mode */
@@ -2099,3 +2107,33 @@ void HandleSpecialGameControllerButtons(Event *event)
   }
 #endif
 }
+
+void HandleSpecialGameControllerKeys(Key key, int key_status)
+{
+#if defined(TARGET_SDL2)
+#if defined(KSYM_Rewind) && defined(KSYM_FastForward)
+  int button = SDL_CONTROLLER_BUTTON_INVALID;
+
+  /* map keys to joystick buttons (special hack for Amazon Fire TV remote) */
+  if (key == KSYM_Rewind)
+    button = SDL_CONTROLLER_BUTTON_A;
+  else if (key == KSYM_FastForward || key == KSYM_Menu)
+    button = SDL_CONTROLLER_BUTTON_B;
+
+  if (button != SDL_CONTROLLER_BUTTON_INVALID)
+  {
+    Event event;
+
+    event.type = (key_status == KEY_PRESSED ? SDL_CONTROLLERBUTTONDOWN :
+                 SDL_CONTROLLERBUTTONUP);
+
+    event.cbutton.which = 0;   /* first joystick (Amazon Fire TV remote) */
+    event.cbutton.button = button;
+    event.cbutton.state = (key_status == KEY_PRESSED ? SDL_PRESSED :
+                          SDL_RELEASED);
+
+    HandleJoystickEvent(&event);
+  }
+#endif
+#endif
+}
index b4c9c3214880fd6b0ddca0f1c04a7d4946a7472a..71ff762730b1539ee27f976b3819d200fc749308 100644 (file)
@@ -45,5 +45,6 @@ void HandleButton(int, int, int, int);
 void HandleKey(Key, int);
 void HandleJoystick();
 void HandleSpecialGameControllerButtons(Event *);
+void HandleSpecialGameControllerKeys(Key, int);
 
 #endif
index f9fc1a87b2d6132d4e6b5bfb92ffc2d900c9c681..838be3ad467ca6e96cbd5293fbb8e3428b740fe8 100644 (file)
@@ -201,6 +201,11 @@ struct MouseCursorInfo
 #if defined(TARGET_SDL2)
 #define KSYM_Menu              SDLK_MENU
 #define KSYM_Back              SDLK_AC_BACK
+#define KSYM_PlayPause         SDLK_AUDIOPLAY
+#if defined(PLATFORM_ANDROID)
+#define KSYM_Rewind            SDLK_AUDIORWND
+#define KSYM_FastForward       SDLK_AUDIOFFWD
+#endif
 #endif
 
 #define KSYM_space             SDLK_SPACE
index 626cb8973a892c62612bf68454ebc6f488251ac7..a766c2d668f459149e2d87726a007fbe4b7708e0 100644 (file)
@@ -3913,6 +3913,9 @@ static int RequestHandleEvents(unsigned int req_state)
              case KSYM_Return:
 #if defined(TARGET_SDL2)
              case KSYM_Menu:
+#if defined(KSYM_Rewind)
+             case KSYM_Rewind:         /* for Amazon Fire TV remote */
+#endif
 #endif
                result = 1;
                break;
@@ -3920,6 +3923,9 @@ static int RequestHandleEvents(unsigned int req_state)
              case KSYM_Escape:
 #if defined(TARGET_SDL2)
              case KSYM_Back:
+#if defined(KSYM_FastForward)
+             case KSYM_FastForward:    /* for Amazon Fire TV remote */
+#endif
 #endif
                result = 0;
                break;