Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hint for Handling Home/Guide/Meta Keys & Disabling Launcher #1

Merged
merged 9 commits into from
Apr 29, 2024
Merged
17 changes: 17 additions & 0 deletions include/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
23 changes: 22 additions & 1 deletion include/SDL_scancode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */,
Expand All @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/events/SDL_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/events/SDL_scancode_webos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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__ */
Expand Down
4 changes: 4 additions & 0 deletions src/events/SDL_scancode_webos_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
Expand Down
42 changes: 35 additions & 7 deletions src/video/wayland/SDL_waylandwebos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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");
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down
Loading