diff --git a/include/SDL_hints.h b/include/SDL_hints.h index 61bf6bc9a83a4..31c76788d0daa 100644 --- a/include/SDL_hints.h +++ b/include/SDL_hints.h @@ -2709,6 +2709,23 @@ extern "C" { * \brief A variable that decides whether to let the app handle exit key (long-pressing back for magic remotes). */ #define SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_EXIT "SDL_WEBOS_ACCESS_POLICY_KEYS_EXIT" +/** + * \brief A variable that decides whether to let the app handle home key. (L_Super on keyboard) + */ +#define SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_HOME "SDL_WEBOS_ACCESS_POLICY_KEYS_HOME" +/** + * \brief A variable that decides whether to let the app handle TV guide key. + */ +#define SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_GUIDE "SDL_WEBOS_ACCESS_POLICY_KEYS_GUIDE" +/** + * \brief A variable that decides whether to let the app handle meta key. + * This hint is only available on webOS 8 or later. + */ +#define SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_META "SDL_WEBOS_ACCESS_POLICY_KEYS_META" +/** + * \brief A variable that decides whether to let the app allow ribbon (home launcher). + */ +#define SDL_HINT_WEBOS_ACCESS_POLICY_RIBBON "SDL_WEBOS_ACCESS_POLICY_RIBBON" /** * \brief A variable that decides how long till the cursor is hidden in milliseconds. */ diff --git a/include/SDL_scancode.h b/include/SDL_scancode.h index a97b473ce592d..93d8a6aaffe1b 100644 --- a/include/SDL_scancode.h +++ b/include/SDL_scancode.h @@ -429,6 +429,26 @@ typedef enum /* Add any other keys here. */ + /** + * \name webOS keys + * + * These are values that are used on webOS. + * The mapping can be found in decompiled keyboard_handle_key function as a series of int arrays. + */ + /* @{ */ + SDL_SCANCODE_WEBOS_1 = 340, + SDL_SCANCODE_WEBOS_2 = 341, + SDL_SCANCODE_WEBOS_3 = 342, + SDL_SCANCODE_WEBOS_4 = 343, + SDL_SCANCODE_WEBOS_5 = 344, + SDL_SCANCODE_WEBOS_6 = 345, + SDL_SCANCODE_WEBOS_7 = 346, + SDL_SCANCODE_WEBOS_8 = 347, + SDL_SCANCODE_WEBOS_9 = 348, + SDL_SCANCODE_WEBOS_10 = 349, + SDL_SCANCODE_WEBOS_11 = 350, + SDL_SCANCODE_WEBOS_12 = 351, + SDL_SCANCODE_WEBOS_HOME = 384 /**< webOS remote home button (keyboard super button) */, SDL_SCANCODE_WEBOS_CH_UP = 480 /**< webOS remote previous channel button */, SDL_SCANCODE_WEBOS_CH_DOWN = 481 /**< webOS remote next channel button */, SDL_SCANCODE_WEBOS_BACK = 482 /**< webOS back button */, @@ -438,8 +458,9 @@ typedef enum SDL_SCANCODE_WEBOS_GREEN = 487 /**< webOS remote green button */, SDL_SCANCODE_WEBOS_YELLOW = 488 /**< webOS remote yellow button */, SDL_SCANCODE_WEBOS_BLUE = 489 /**< webOS remote blue button */, + SDL_SCANCODE_WEBOS_GUIDE = 495 /**< webOS remote guide button */, SDL_SCANCODE_WEBOS_EXIT = 505 /**< webOS remote exit button */, - + /* @} *//* webOS keys */ SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes for array bounds */ diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 846f244fde777..0bb0a60aec498 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -231,7 +231,7 @@ void SDL_MousePostInit(void) SDL_FreeSurface(surface); } } -#if __WEBOS__ +#ifdef __WEBOS__ { SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_RGBA32); SDL_memset(surface->pixels, 0, (size_t)surface->h * surface->pitch); diff --git a/src/events/SDL_scancode_webos.c b/src/events/SDL_scancode_webos.c index 11a08e573b595..35b8594c41846 100644 --- a/src/events/SDL_scancode_webos.c +++ b/src/events/SDL_scancode_webos.c @@ -30,6 +30,10 @@ SDL_Scancode SDL_GetWebOSScancode(int keycode) return SDL_SCANCODE_WEBOS_BACK; case 182: return SDL_SCANCODE_WEBOS_EXIT; + case 370: + return SDL_SCANCODE_WEBOS_GUIDE; + case 781: + return SDL_SCANCODE_WEBOS_HOME; case 406: return SDL_SCANCODE_WEBOS_RED; case 407: @@ -54,8 +58,9 @@ SDL_Scancode SDL_GetWebOSScancode(int keycode) return SDL_SCANCODE_AUDIOREWIND; case 216: return SDL_SCANCODE_AUDIOFASTFORWARD; + default: + return SDL_SCANCODE_UNKNOWN; } - return SDL_SCANCODE_UNKNOWN; } #endif /* __WEBOS__ */ diff --git a/src/events/SDL_scancode_webos_c.h b/src/events/SDL_scancode_webos_c.h index dcbf4443e8d52..c3b650b5217b3 100644 --- a/src/events/SDL_scancode_webos_c.h +++ b/src/events/SDL_scancode_webos_c.h @@ -24,6 +24,10 @@ #ifdef __WEBOS__ +/** + * Get SDL_Scancode from wayland keycode. + * The mapping can be found in /usr/share/X11/xkb/keycodes/lg + */ extern SDL_Scancode SDL_GetWebOSScancode(int keycode); #endif /* __WEBOS__ */ diff --git a/src/video/wayland/SDL_waylandwebos.c b/src/video/wayland/SDL_waylandwebos.c index 146a90fc51cbd..2d06e5557aad2 100644 --- a/src/video/wayland/SDL_waylandwebos.c +++ b/src/video/wayland/SDL_waylandwebos.c @@ -33,9 +33,13 @@ #include "SDL_waylandwebos_foreign.h" #include "webos-shell-client-protocol.h" -static const char* webos_window_hints[] = { +static const char *webos_window_hints[] = { SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_BACK, SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_EXIT, + SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_HOME, + SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_GUIDE, + SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_META, + SDL_HINT_WEBOS_ACCESS_POLICY_RIBBON, SDL_HINT_WEBOS_CURSOR_CALIBRATION_DISABLE, SDL_HINT_WEBOS_CURSOR_FREQUENCY, SDL_HINT_WEBOS_CURSOR_SLEEP_TIME, @@ -73,7 +77,7 @@ void WaylandWebOS_VideoInit(_THIS) _this->webos_cursor_sleep_time = 300000; } - for(int i = 0; webos_window_hints[i] != NULL; i++) { + for (int i = 0; webos_window_hints[i] != NULL; i++) { SDL_AddHintCallback(webos_window_hints[i], WindowHintsCallback, _this); } } @@ -107,7 +111,7 @@ void WaylandWebOS_VideoCleanUp(_THIS) int WaylandWebOS_SetupSurface(_THIS, SDL_WindowData *data) { const char *appId; - const char* hintValue; + const char *hintValue; appId = SDL_getenv("APPID"); if (appId == NULL) { return SDL_SetError("APPID environment variable is not set"); @@ -120,10 +124,22 @@ int WaylandWebOS_SetupSurface(_THIS, SDL_WindowData *data) if (SDL_GetHintBoolean(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_EXIT, SDL_FALSE)) { wl_webos_shell_surface_set_property(data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_EXIT", "true"); } - if(SDL_GetHintBoolean(SDL_HINT_WEBOS_CURSOR_CALIBRATION_DISABLE, SDL_FALSE)) { + if (SDL_GetHintBoolean(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_HOME, SDL_FALSE)) { + wl_webos_shell_surface_set_property(data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_HOME", "true"); + } + if (SDL_GetHintBoolean(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_GUIDE, SDL_FALSE)) { + wl_webos_shell_surface_set_property(data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_GUIDE", "true"); + } + if (SDL_GetHintBoolean(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_META, SDL_FALSE)) { + wl_webos_shell_surface_set_property(data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_META", "true"); + } + if (!SDL_GetHintBoolean(SDL_HINT_WEBOS_ACCESS_POLICY_RIBBON, SDL_TRUE)) { + wl_webos_shell_surface_set_property(data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_RIBBON", "false"); + } + if (SDL_GetHintBoolean(SDL_HINT_WEBOS_CURSOR_CALIBRATION_DISABLE, SDL_FALSE)) { wl_webos_shell_surface_set_property(data->shell_surface.webos.webos, "restore_cursor_position", "true"); } - if(SDL_GetHintBoolean(SDL_HINT_WEBOS_CLOUDGAME_ACTIVE, SDL_TRUE)) { + if (SDL_GetHintBoolean(SDL_HINT_WEBOS_CLOUDGAME_ACTIVE, SDL_TRUE)) { wl_webos_shell_surface_set_property(data->shell_surface.webos.webos, "cloudgame_active", "true"); } if ((hintValue = SDL_GetHint(SDL_HINT_WEBOS_CURSOR_FREQUENCY)) != NULL) { @@ -188,7 +204,7 @@ static void webos_shell_handle_state_about_to_change(void *data, struct wl_webos static void WindowHintsCallback(void *userdata, const char *name, const char *oldValue, const char *newValue) { SDL_VideoDevice *_this = userdata; - SDL_Window * windows = _this->windows; + SDL_Window *windows = _this->windows; SDL_WindowData *win_data; if (windows == NULL) { return; @@ -197,12 +213,24 @@ static void WindowHintsCallback(void *userdata, const char *name, const char *ol if (win_data == NULL) { return; } - if (SDL_strcmp(name, SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_BACK) == 0 ) { + if (SDL_strcmp(name, SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_BACK) == 0) { wl_webos_shell_surface_set_property(win_data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_BACK", SDL_GetStringBoolean(newValue, SDL_FALSE) ? "true" : "false"); } else if (SDL_strcmp(name, SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_EXIT) == 0) { wl_webos_shell_surface_set_property(win_data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_EXIT", SDL_GetStringBoolean(newValue, SDL_FALSE) ? "true" : "false"); + } else if (SDL_strcmp(name, SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_HOME) == 0) { + wl_webos_shell_surface_set_property(win_data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_HOME", + SDL_GetStringBoolean(newValue, SDL_FALSE) ? "true" : "false"); + } else if (SDL_strcmp(name, SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_GUIDE) == 0) { + wl_webos_shell_surface_set_property(win_data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_GUIDE", + SDL_GetStringBoolean(newValue, SDL_FALSE) ? "true" : "false"); + } else if (SDL_strcmp(name, SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_META) == 0) { + wl_webos_shell_surface_set_property(win_data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_KEYS_META", + SDL_GetStringBoolean(newValue, SDL_FALSE) ? "true" : "false"); + } else if (SDL_strcmp(name, SDL_HINT_WEBOS_ACCESS_POLICY_RIBBON) == 0) { + wl_webos_shell_surface_set_property(win_data->shell_surface.webos.webos, "_WEBOS_ACCESS_POLICY_RIBBON", + SDL_GetStringBoolean(newValue, SDL_TRUE) ? "true" : "false"); } else if (SDL_strcmp(name, SDL_HINT_WEBOS_CURSOR_CALIBRATION_DISABLE) == 0) { wl_webos_shell_surface_set_property(win_data->shell_surface.webos.webos, "restore_cursor_position", SDL_GetStringBoolean(newValue, SDL_FALSE) ? "true" : "false");