Skip to content

Commit

Permalink
updated for latest SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Sep 5, 2023
1 parent ec83db7 commit 214d02e
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 197 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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]"));
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/platform/common/app_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/app/platform/webos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
pbnjson_compat.c)
110 changes: 0 additions & 110 deletions src/app/platform/webos/app_wakelock_webos.c

This file was deleted.

45 changes: 12 additions & 33 deletions src/app/platform/webos/app_webos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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[]) {
Expand Down
9 changes: 4 additions & 5 deletions src/app/ui/settings/panes/about.pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions src/app/ui/settings/panes/basic.pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
Expand Down
22 changes: 6 additions & 16 deletions src/app/ui/settings/settings.controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 3 additions & 7 deletions src/app/ui/settings/settings.controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@

#include "app_settings.h"

#if TARGET_WEBOS

#include "panel_info.h"

#endif

typedef struct app_t app_t;

typedef struct {
Expand All @@ -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;

Expand Down
7 changes: 1 addition & 6 deletions src/app/ui/ui_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions src/app/ui/ui_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion third_party/commons
2 changes: 1 addition & 1 deletion third_party/ss4s

0 comments on commit 214d02e

Please sign in to comment.