From 214d02eb0c4dc5d6db22f8c767f7ed1f22f9756c Mon Sep 17 00:00:00 2001 From: Ningyuan Li Date: Tue, 5 Sep 2023 23:46:52 +0900 Subject: [PATCH] updated for latest SDL --- CMakeLists.txt | 3 +- src/app/app.c | 9 +- src/app/platform/common/app_common.c | 2 +- src/app/platform/webos/CMakeLists.txt | 5 +- src/app/platform/webos/app_wakelock_webos.c | 110 -------------------- src/app/platform/webos/app_webos.c | 45 +++----- src/app/ui/settings/panes/about.pane.c | 9 +- src/app/ui/settings/panes/basic.pane.c | 13 ++- src/app/ui/settings/settings.controller.c | 22 ++-- src/app/ui/settings/settings.controller.h | 10 +- src/app/ui/ui_input.c | 7 +- src/app/ui/ui_input.h | 2 - third_party/commons | 2 +- third_party/ss4s | 2 +- 14 files changed, 44 insertions(+), 197 deletions(-) delete mode 100644 src/app/platform/webos/app_wakelock_webos.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 533cf3618..9538bc739 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ if (TARGET_WEBOS) set(WEBOS_APPINFO_ID "com.limelight.webos") set(CMAKE_INSTALL_RPATH "$ORIGIN/lib/backports:$ORIGIN/../lib/backports:$ORIGIN") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -O0") elseif (TARGET_STEAMLINK) set(OS_LINUX TRUE) set(CMAKE_INSTALL_PREFIX moonlight-tv) @@ -253,7 +254,7 @@ if (TARGET_WEBOS) target_include_directories(moonlight-lib SYSTEM PUBLIC ${PBNJSON_C_INCLUDE_DIRS} ${PMLOG_INCLUDE_DIRS} ${WEBOSI18N_INCLUDE_DIRS}) target_link_libraries(moonlight-lib PUBLIC ${PBNJSON_C_LIBRARIES} ${PMLOG_LIBRARIES} ${WEBOSI18N_LIBRARIES}) - target_link_libraries(moonlight-lib PUBLIC commons-luna-sync commons-webos-is-uhd commons-webos-panel-info) + target_link_libraries(moonlight-lib PUBLIC commons-luna-sync) else () if (TARGET_STEAMLINK) set(FEATURE_FORCE_FULLSCREEN ON) diff --git a/src/app/app.c b/src/app/app.c index 6ab472316..6a447799e 100644 --- a/src/app/app.c +++ b/src/app/app.c @@ -40,6 +40,7 @@ int app_init(app_t *app, app_settings_loader *settings_loader, int argc, char *a commons_logging_init("moonlight"); SDL_LogSetOutputFunction(commons_sdl_log, NULL); SDL_SetAssertionHandler(app_assertion_handler_abort, NULL); + SDL_Init(0); commons_log_info("APP", "Start Moonlight. Version %s", APP_VERSION); settings_loader(&app->settings); app->main_thread_id = SDL_ThreadID(); @@ -60,9 +61,11 @@ int app_init(app_t *app, app_settings_loader *settings_loader, int argc, char *a SDL_SetHint(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_BACK, "true"); SDL_SetHint(SDL_HINT_WEBOS_ACCESS_POLICY_KEYS_EXIT, "true"); SDL_SetHint(SDL_HINT_WEBOS_CURSOR_SLEEP_TIME, "5000"); + SDL_SetHint(SDL_HINT_WEBOS_CURSOR_FREQUENCY, "60"); + SDL_SetHint(SDL_HINT_WEBOS_CURSOR_CALIBRATION_DISABLE, "true"); #endif // DO not init video subsystem before NDL/LGNC initialization - SDL_Init(SDL_INIT_VIDEO); + SDL_InitSubSystem(SDL_INIT_VIDEO); // This will occupy SDL_USEREVENT SDL_RegisterEvents(1); commons_log_info("APP", "UI locale: %s (%s)", i18n_locale(), locstr("[Localized Language]")); @@ -85,14 +88,14 @@ void app_deinit(app_t *app) { app_set_keep_awake(app, false); app_input_deinit(&app->input); - backend_destroy(&app->backend); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + backend_destroy(&app->backend); settings_save(&app->settings); settings_clear(&app->settings); free(app->settings.conf_dir); - #if FEATURE_INPUT_LIBCEC cec_sdl_deinit(&app->cec); #endif diff --git a/src/app/platform/common/app_common.c b/src/app/platform/common/app_common.c index b39a1ec8c..a27e158f6 100644 --- a/src/app/platform/common/app_common.c +++ b/src/app/platform/common/app_common.c @@ -6,7 +6,7 @@ #include "util/i18n.h" #include "app_launch.h" -#define USE_OPENURL ((OS_DARWIN || OS_WINDOWS) && SDL_VERSION_ATLEAST(2, 0, 14)) +#define USE_OPENURL SDL_VERSION_ATLEAST(2, 0, 14) #if !USE_OPENURL diff --git a/src/app/platform/webos/CMakeLists.txt b/src/app/platform/webos/CMakeLists.txt index 3b4443605..21a909504 100644 --- a/src/app/platform/webos/CMakeLists.txt +++ b/src/app/platform/webos/CMakeLists.txt @@ -1,7 +1,4 @@ target_sources(moonlight-lib PRIVATE keyboard_webos.c navkey_sdl_webos.c - pbnjson_compat.c - app_wakelock_webos.c) - -set(APP_WAKELOCK_IMPLEMENTED TRUE PARENT_SCOPE) \ No newline at end of file + pbnjson_compat.c) \ No newline at end of file diff --git a/src/app/platform/webos/app_wakelock_webos.c b/src/app/platform/webos/app_wakelock_webos.c deleted file mode 100644 index 2432b33e6..000000000 --- a/src/app/platform/webos/app_wakelock_webos.c +++ /dev/null @@ -1,110 +0,0 @@ -#include "app.h" -#include "logging.h" -#include -#include - -struct app_wakelock_t { - HContext context; - __attribute__((unused)) char padding[128]; -}; - -static app_wakelock_t *app_wakelock_create(); - -static void app_wakelock_destroy(app_wakelock_t *wakelock); - -static bool wakelock_respond(LSHandle *sh, LSMessage *reply, void *ctx); - -void app_set_keep_awake(app_t *app, bool awake) { - if (awake) { - if (app->wakelock != NULL) { - return; - } - app->wakelock = app_wakelock_create(); - } else { - if (app->wakelock == NULL) { - return; - } - app_wakelock_destroy(app->wakelock); - app->wakelock = NULL; - } -} - - -static app_wakelock_t *app_wakelock_create() { - char client_name[64]; - snprintf(client_name, 64, "%s.wakelock", getenv("APPID")); - jvalue_ref payload = jobject_create_var( - jkeyval(J_CSTR_TO_JVAL("subscribe"), jboolean_create(true)), - jkeyval(J_CSTR_TO_JVAL("clientName"), j_cstr_to_jval(client_name)), - NULL - ); - app_wakelock_t *wakelock = calloc(1, sizeof(app_wakelock_t)); - wakelock->context.multiple = 1; - wakelock->context.pub = 1; - wakelock->context.callback = wakelock_respond; - - HLunaServiceCall("luna://com.webos.service.tvpower/power/registerScreenSaverRequest", jvalue_stringify(payload), - &wakelock->context); - - j_release(&payload); - return wakelock; -} - -static void app_wakelock_destroy(app_wakelock_t *wakelock) { - HUnregisterServiceCallback(&wakelock->context); - free(wakelock); -} - -static bool wakelock_respond(LSHandle *sh, LSMessage *reply, void *ctx) { - (void) sh; - (void) ctx; - const char *message = HLunaServiceMessage(reply); - JSchemaInfo schema_info; - jschema_info_init(&schema_info, jschema_all(), NULL, NULL); - jdomparser_ref parser = jdomparser_create(&schema_info, 0); - - commons_log_info("Wakelock", "Got ScreenSaverRequest %s", message); - if (!jdomparser_feed(parser, message, (int) strlen(message))) { - commons_log_warn("Wakelock", "Failed to feed json: %s", jdomparser_get_error(parser)); - jdomparser_release(&parser); - return false; - } - if (!jdomparser_end(parser)) { - commons_log_warn("Wakelock", "Failed to finish parsing: %s", jdomparser_get_error(parser)); - jdomparser_release(&parser); - return false; - } - jvalue_ref request = jdomparser_get_result(parser); - if (!jis_valid(request)) { - commons_log_warn("Wakelock", "Failed to parse json: %s", jdomparser_get_error(parser)); - jdomparser_release(&parser); - return false; - } - jvalue_ref timestamp = jobject_get(request, J_CSTR_TO_BUF("timestamp")); - - if (jis_null(timestamp)) { - commons_log_info("Wakelock", "Skip invalid request (no timestamp)"); - jdomparser_release(&parser); - return true; - } - char client_name[64]; - snprintf(client_name, 64, "%s.wakelock", getenv("APPID")); - jvalue_ref response = jobject_create_var( - jkeyval(J_CSTR_TO_JVAL("clientName"), j_cstr_to_jval(client_name)), - jkeyval(J_CSTR_TO_JVAL("ack"), jboolean_create(false)), - jkeyval(J_CSTR_TO_JVAL("timestamp"), timestamp), - NULL - ); - - HContext resp_context = { - .pub = 1, - .multiple = 0, - }; - - HLunaServiceCall("luna://com.webos.service.tvpower/power/responseScreenSaverRequest", jvalue_stringify(response), - &resp_context); - commons_log_info("Wakelock", "Response ScreenSaverRequest with %s", jvalue_stringify(response)); - j_release(&response); - jdomparser_release(&parser); - return true; -} diff --git a/src/app/platform/webos/app_webos.c b/src/app/platform/webos/app_webos.c index 0b1ee2566..35d1bed50 100644 --- a/src/app/platform/webos/app_webos.c +++ b/src/app/platform/webos/app_webos.c @@ -12,17 +12,7 @@ static char locale_system[16]; void app_open_url(const char *url) { - jvalue_ref payload_obj = jobject_create_var( - jkeyval(J_CSTR_TO_JVAL("id"), J_CSTR_TO_JVAL("com.webos.app.browser")), - jkeyval(J_CSTR_TO_JVAL("params"), jobject_create_var( - jkeyval(J_CSTR_TO_JVAL("target"), j_cstr_to_jval(url)), - J_END_OBJ_DECL - )), - J_END_OBJ_DECL - ); - const char *payload = jvalue_stringify(payload_obj); - HLunaServiceCallSync("luna://com.webos.applicationManager/launch", payload, true, NULL); - j_release(&payload_obj); + SDL_OpenURL(url); } void app_init_locale() { @@ -31,29 +21,18 @@ void app_init_locale() { i18n_setlocale(app_configuration->language); return; } - char *payload = NULL; - commons_log_debug("APP", "Get system locale settings"); - if (!HLunaServiceCallSync("luna://com.webos.settingsservice/getSystemSettings", "{\"key\": \"localeInfo\"}", - true, &payload) || !payload) { - commons_log_warn("APP", "Failed to get system locale settings. Falling back to English."); - return; - } - JSchemaInfo schemaInfo; - jschema_info_init(&schemaInfo, jschema_all(), NULL, NULL); - jdomparser_ref parser = jdomparser_create(&schemaInfo, 0); - jdomparser_feed(parser, payload, (int) strlen(payload)); - jdomparser_end(parser); - jvalue_ref payload_obj = jdomparser_get_result(parser); - jvalue_ref locale = jobject_get_nested(payload_obj, "settings", "localeInfo", "locales", "UI", NULL); - if (jis_string(locale)) { - raw_buffer buf = jstring_get(locale); - size_t len = buf.m_len <= 15 ? buf.m_len : 15; - strncpy(locale_system, buf.m_str, len); - locale_system[len] = '\0'; - jstring_free_buffer(buf); - i18n_setlocale(locale_system); + SDL_Locale *locales = SDL_GetPreferredLocales(); + if (locales) { + for (int i = 0; locales[i].language; i++) { + if (locales[i].country) { + snprintf(locale_system, sizeof(locale_system), "%s-%s", locales[i].language, locales[i].country); + } else { + strncpy(locale_system, locales[i].language, sizeof(locale_system)); + } + i18n_setlocale(locale_system); + } + SDL_free(locales); } - jdomparser_release(&parser); } app_launch_params_t *app_handle_launch(app_t *app, int argc, char *argv[]) { diff --git a/src/app/ui/settings/panes/about.pane.c b/src/app/ui/settings/panes/about.pane.c index 41aaec92e..e23842ec4 100644 --- a/src/app/ui/settings/panes/about.pane.c +++ b/src/app/ui/settings/panes/about.pane.c @@ -65,15 +65,14 @@ static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { } free(os_str); #if TARGET_WEBOS - const webos_panel_info_t *panel_info = &parent->webos_panel_info; - if (panel_info->height && panel_info->width) { + if (parent->panel_width > 0 && parent->panel_height > 0) { char resolution_text[16]; - SDL_snprintf(resolution_text, sizeof(resolution_text), "%5d * %5d", panel_info->width, panel_info->height); + SDL_snprintf(resolution_text, sizeof(resolution_text), "%5d * %5d", parent->panel_width, parent->panel_height); about_line(view, locstr("Screen resolution"), resolution_text, rowcount++, 1); } - if (panel_info->rate) { + if (parent->panel_fps > 0) { char fps_text[16]; - SDL_snprintf(fps_text, sizeof(fps_text), "%4dFPS", panel_info->rate); + SDL_snprintf(fps_text, sizeof(fps_text), "%4dFPS", parent->panel_fps); about_line(view, locstr("Refresh rate"), fps_text, rowcount++, 1); } #endif diff --git a/src/app/ui/settings/panes/basic.pane.c b/src/app/ui/settings/panes/basic.pane.c index 4c2ca3167..891df4c0d 100644 --- a/src/app/ui/settings/panes/basic.pane.c +++ b/src/app/ui/settings/panes/basic.pane.c @@ -93,11 +93,10 @@ static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { unsigned int max_width = app->ss4s.video_cap.maxWidth, max_height = app->ss4s.video_cap.maxHeight; #if TARGET_WEBOS - const webos_panel_info_t *panel_info = &parent->webos_panel_info; - if (panel_info->width > 0 && panel_info->height > 0 && - (max_width == 0 || max_height == 0 || panel_info->width < max_width || panel_info->height < max_height)) { - max_width = panel_info->width; - max_height = panel_info->height; + if (parent->panel_width > 0 && parent->panel_height > 0 && + (max_width == 0 || max_height == 0 || parent->panel_width < max_width || parent->panel_height < max_height)) { + max_width = parent->panel_width; + max_height = parent->panel_height; } #endif @@ -118,8 +117,8 @@ static lv_obj_t *create_obj(lv_fragment_t *self, lv_obj_t *container) { unsigned int max_fps = app->ss4s.video_cap.maxFps; #if TARGET_WEBOS - if (panel_info->rate > 0 && (max_fps == 0 || panel_info->rate < max_fps)) { - max_fps = panel_info->rate; + if (parent->panel_fps > 0 && (max_fps == 0 || parent->panel_fps < max_fps)) { + max_fps = parent->panel_fps; } #endif int fps_len; diff --git a/src/app/ui/settings/settings.controller.c b/src/app/ui/settings/settings.controller.c index 61335aa6a..0c6d1953a 100644 --- a/src/app/ui/settings/settings.controller.c +++ b/src/app/ui/settings/settings.controller.c @@ -11,12 +11,6 @@ #include "util/i18n.h" #include "lvgl/theme/lv_theme_moonlight.h" -#if TARGET_WEBOS - -#include "is_uhd.h" - -#endif - typedef struct { const char *icon; const char *name; @@ -85,16 +79,12 @@ static void settings_controller_ctor(lv_fragment_t *self, void *args) { fragment->mini = fragment->pending_mini = UI_IS_MINI(fragment->app->ui.width); os_info_get(&fragment->os_info); #if TARGET_WEBOS - memset(&fragment->webos_panel_info, 0, sizeof(webos_panel_info_t)); - bool is_uhd = false; - if (commons_webos_get_panel_info(&fragment->webos_panel_info) == 0) { - is_uhd = fragment->webos_panel_info.width >= 3840; - } else if (commons_webos_is_uhd(&is_uhd) == 0 && is_uhd) { - fragment->webos_panel_info.width = 3840; - fragment->webos_panel_info.height = 2160; - fragment->webos_panel_info.rate = 60; - } else { - fragment->webos_panel_info.rate = 60; + if (!SDL_webOSGetPanelResolution(&fragment->panel_width, &fragment->panel_height)) { + fragment->panel_width = 1920; + fragment->panel_height = 1080; + } + if (!SDL_webOSGetRefreshRate(&fragment->panel_fps)) { + fragment->panel_fps = 60; } #endif } diff --git a/src/app/ui/settings/settings.controller.h b/src/app/ui/settings/settings.controller.h index a9ba9628a..28fd82a9e 100644 --- a/src/app/ui/settings/settings.controller.h +++ b/src/app/ui/settings/settings.controller.h @@ -13,12 +13,6 @@ #include "app_settings.h" -#if TARGET_WEBOS - -#include "panel_info.h" - -#endif - typedef struct app_t app_t; typedef struct { @@ -43,7 +37,9 @@ typedef struct { os_info_t os_info; bool needs_restart; #if TARGET_WEBOS - webos_panel_info_t webos_panel_info; + int panel_width; + int panel_height; + int panel_fps; #endif } settings_controller_t; diff --git a/src/app/ui/ui_input.c b/src/app/ui/ui_input.c index 7c6e2e3a8..b577ca895 100644 --- a/src/app/ui/ui_input.c +++ b/src/app/ui/ui_input.c @@ -87,7 +87,7 @@ void app_start_text_input(app_ui_input_t *input, int x, int y, int w, int h) { SDL_SetTextInputRect(NULL); } lv_sdl_key_input_release_key(input->key.indev); - if (app_text_input_active(input)) { + if (SDL_IsTextInputActive()) { return; } SDL_StartTextInput(); @@ -98,11 +98,6 @@ void app_stop_text_input(app_ui_input_t *input) { SDL_StopTextInput(); } -bool app_text_input_active(app_ui_input_t *input) { - (void) input; - return SDL_IsTextInputActive(); -} - bool app_screen_keyboard_active(app_ui_input_t *input) { return SDL_IsScreenKeyboardShown(input->ui->window); } diff --git a/src/app/ui/ui_input.h b/src/app/ui/ui_input.h index a009d1f90..7a9a493bb 100644 --- a/src/app/ui/ui_input.h +++ b/src/app/ui/ui_input.h @@ -58,6 +58,4 @@ void app_start_text_input(app_ui_input_t *input, int x, int y, int w, int h); void app_stop_text_input(app_ui_input_t *input); -bool app_text_input_active(app_ui_input_t *input); - bool app_screen_keyboard_active(app_ui_input_t *input); diff --git a/third_party/commons b/third_party/commons index 1a9db25aa..41ba346f0 160000 --- a/third_party/commons +++ b/third_party/commons @@ -1 +1 @@ -Subproject commit 1a9db25aaf09ffe3baa3126c298f3a0c91fe9a45 +Subproject commit 41ba346f098b750c51ca6f32f70917d34b6ff725 diff --git a/third_party/ss4s b/third_party/ss4s index 234547961..24e26d401 160000 --- a/third_party/ss4s +++ b/third_party/ss4s @@ -1 +1 @@ -Subproject commit 2345479613abd7117c2b63e8d622b4410b351611 +Subproject commit 24e26d401887fd2a288f89307865857b8dac8444