Skip to content

Commit

Permalink
allows capture of webOS home key
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Apr 29, 2024
1 parent 15625ec commit eebeaf7
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ int app_init(app_t *app, app_settings_loader *settings_loader, int argc, char *a
SDL_SetHint(SDL_HINT_WEBOS_CURSOR_FREQUENCY, "60");
SDL_SetHint(SDL_HINT_WEBOS_CURSOR_CALIBRATION_DISABLE, "true");
SDL_SetHint(SDL_HINT_WEBOS_HIDAPI_IGNORE_BLUETOOTH_DEVICES, "0x057e/0x0000");
if (app->settings.syskey_capture) {
SDL_SetHint(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_HOME, "true");
SDL_SetHint(SDL_HINT_WEBOS_ACCESS_POLICY_RIBBON, "false");
}
#endif
// DO not init video subsystem before NDL/LGNC initialization
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/app/app_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ bool settings_save(app_settings_t *config) {
#endif
ini_write_bool(fp, "swap_abxy", config->swap_abxy);
ini_write_int(fp, "stick_deadzone", config->stick_deadzone);
ini_write_bool(fp, "syskey_capture", config->syskey_capture);

ini_write_section(fp, "video");
ini_write_string(fp, "decoder", config->decoder);
Expand Down Expand Up @@ -265,6 +266,8 @@ static int settings_parse(app_settings_t *config, const char *section, const cha
}
} else if (INI_NAME_MATCH("swap_abxy")) {
config->swap_abxy = INI_IS_TRUE(value);
} else if (INI_NAME_MATCH("syskey_capture")) {
config->syskey_capture = INI_IS_TRUE(value);
} else if (INI_FULL_MATCH("video", "decoder")) {
set_string(&config->decoder, value);
} else if (INI_FULL_MATCH("audio", "backend")) {
Expand Down
16 changes: 12 additions & 4 deletions src/app/lvgl/input/lv_drv_sdl_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
#include "lv_drv_sdl_key.h"
#include "stream/session_events.h"

static bool read_event(const SDL_Event *event, lv_drv_sdl_key_t *state);

static bool read_keyboard(app_ui_input_t *input, const SDL_KeyboardEvent *event, lv_drv_sdl_key_t *state);

#if TARGET_WEBOS

#include "platform/webos/app_webos.h"

static bool read_webos_key(app_ui_input_t *input, const SDL_KeyboardEvent *event, lv_drv_sdl_key_t *state);

static void webos_key_input_mode(app_ui_input_t *input, const SDL_KeyboardEvent *event);

#endif

static bool read_event(const SDL_Event *event, lv_drv_sdl_key_t *state);

static bool read_keyboard(app_ui_input_t *input, const SDL_KeyboardEvent *event, lv_drv_sdl_key_t *state);

static void sdl_input_read(lv_indev_drv_t *drv, lv_indev_data_t *data);

int lv_sdl_init_key_input(lv_drv_sdl_key_t *drv, app_ui_input_t *input) {
Expand Down Expand Up @@ -218,8 +220,14 @@ static bool read_webos_key(app_ui_input_t *input, const SDL_KeyboardEvent *event
if (app->session == NULL) {
app_request_exit();
}
return false;
}
case SDL_SCANCODE_WEBOS_HOME: {
if (app->session == NULL) {
app_webos_open_ribbon();
}
return false;
}
case SDL_SCANCODE_WEBOS_RED:
case SDL_SCANCODE_WEBOS_GREEN:
case SDL_SCANCODE_WEBOS_YELLOW:
Expand Down
6 changes: 6 additions & 0 deletions src/app/platform/webos/app_webos.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "app.h"
#include "app_webos.h"
#include "app_launch.h"

#include <pbnjson.h>
Expand Down Expand Up @@ -79,4 +80,9 @@ app_launch_params_t *app_handle_launch(app_t *app, int argc, char *argv[]) {
}
jdomparser_release(&parser);
return params;
}

void app_webos_open_ribbon() {
static const char *payload = "{\"id\":\"com.webos.app.home\",\"params\":{\"launchType\":\"homeKey\"}}";
HLunaServiceCallSync("luna://com.webos.applicationManager/launch", payload, true, NULL);
}
21 changes: 21 additions & 0 deletions src/app/platform/webos/app_webos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Mariotaku <https://github.com/mariotaku>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#pragma once

void app_webos_open_ribbon();
9 changes: 8 additions & 1 deletion src/app/platform/webos/keyboard_webos.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
#include "util/bus.h"
#include "util/user_event.h"
#include "logging.h"
#include "app_webos.h"

#define TV_REMOTE_TOGGLE_SOFT_INPUT 0

bool webos_intercept_remote_keys(stream_input_t *input, const SDL_KeyboardEvent *event, short *keyCode) {
bool stream_input_webos_intercept_remote_keys(stream_input_t *input, const SDL_KeyboardEvent *event, short *keyCode) {
session_t *session = input->session;
app_t *app = session->app;
switch ((unsigned int) event->keysym.scancode) {
Expand All @@ -26,6 +27,12 @@ bool webos_intercept_remote_keys(stream_input_t *input, const SDL_KeyboardEvent
}
return true;
}
case SDL_SCANCODE_WEBOS_HOME: {
if (event->state == SDL_RELEASED) {
app_webos_open_ribbon();
}
return true;
}
case SDL_SCANCODE_WEBOS_BACK:
*keyCode = VK_ESCAPE /* SDL_SCANCODE_ESCAPE */;
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/app/stream/input/session_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int keydown_count = 0;

#if TARGET_WEBOS

bool webos_intercept_remote_keys(stream_input_t *input, const SDL_KeyboardEvent *event, short *keyCode);
bool stream_input_webos_intercept_remote_keys(stream_input_t *input, const SDL_KeyboardEvent *event, short *keyCode);

#endif

Expand Down Expand Up @@ -128,7 +128,7 @@ void performPendingSpecialKeyCombo(stream_input_t *input) {
void stream_input_handle_key(stream_input_t *input, const SDL_KeyboardEvent *event) {
short keyCode = 0;
#if TARGET_WEBOS
if (webos_intercept_remote_keys(input, event, &keyCode)) {
if (stream_input_webos_intercept_remote_keys(input, event, &keyCode)) {
return;
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/app/ui/settings/panes/input.pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) {
pref_checkbox(view, locstr("View-only mode"), &app_configuration->viewonly, false);
pref_desc_label(view, locstr("Don't send mouse, keyboard or gamepad input to host computer."), false);

pref_checkbox(view, locstr("Capture system keys"), &app_configuration->syskey_capture, false);
pref_desc_label(view, locstr("Capture and send system keys (e.g. Meta/Win key) to host computer."), false);

pref_header(view, locstr("Mouse"));

#if FEATURE_INPUT_EVMOUSE
Expand Down

0 comments on commit eebeaf7

Please sign in to comment.