From 8c9f70de8298c5fa14eec9a2268f068fa1d511f2 Mon Sep 17 00:00:00 2001 From: Christian Soffke Date: Tue, 16 Dec 2025 13:39:03 +0100 Subject: [PATCH] plugins: text viewer: use SBS title Take advantage of skinned status bar title, instead of displaying a custom header that reduces space for content. A custom header will still be displayed if the SBS doesn't come with its own title, such as on the default theme, or if the status bar has been turned off in Text Viewer's settings. Change-Id: I14c8d9a61acf338d09d7f54947399e8692987a7b --- apps/plugin.c | 2 ++ apps/plugin.h | 2 ++ apps/plugins/text_viewer/tv_action.c | 4 ++++ apps/plugins/text_viewer/tv_display.c | 29 ++++++++++++++++++++++++--- apps/plugins/text_viewer/tv_display.h | 8 ++++++++ apps/plugins/text_viewer/tv_window.c | 6 ++++++ apps/plugins/text_viewer/tv_window.h | 3 +++ 7 files changed, 51 insertions(+), 3 deletions(-) diff --git a/apps/plugin.c b/apps/plugin.c index 5cd37389d0..5058bdf7bf 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -870,6 +870,7 @@ static const struct plugin_api rockbox_api = { gesture_vel_get, #endif strstr, + sb_set_title_text, }; static int plugin_buffer_handle; @@ -889,6 +890,7 @@ int plugin_load(const char* plugin, const void* parameter) bool theme_enabled = sepch && (!strcmp("properties.rock", sepch + 1) || !strcmp("playing_time.rock", sepch + 1) || !strcmp("main_menu_config.rock", sepch + 1) || + !strcmp("text_viewer.rock", sepch + 1) || !strcmp("disktidy.rock", sepch + 1)); if (current_plugin_handle) diff --git a/apps/plugin.h b/apps/plugin.h index e71afe3b52..29dfebe583 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -112,6 +112,7 @@ int plugin_open(const char *plugin, const char *parameter); #include "menu.h" #include "rbunicode.h" #include "list.h" +#include "statusbar-skinned.h" #include "tree.h" #include "color_picker.h" #include "buflib.h" @@ -1020,6 +1021,7 @@ struct plugin_api { bool (*gesture_vel_get)(struct gesture_vel *gv, int *xvel, int *yvel); #endif char* (*strstr)(const char *s1, const char *s2); + bool (*sb_set_title_text)(const char* title, enum themable_icons icon, enum screen_type screen); }; /* plugin header */ diff --git a/apps/plugins/text_viewer/tv_action.c b/apps/plugins/text_viewer/tv_action.c index 6d12889123..b10a650013 100644 --- a/apps/plugins/text_viewer/tv_action.c +++ b/apps/plugins/text_viewer/tv_action.c @@ -76,6 +76,8 @@ bool tv_load_file(const unsigned char *file) /* select to read the page */ tv_select_bookmark(); + tv_update_sbs_title(); + return true; } @@ -189,6 +191,8 @@ unsigned tv_menu(void) res = tv_display_menu(); + tv_update_sbs_title(); + if (res == TV_MENU_RESULT_EXIT_MENU) { #ifdef HAVE_ADJUSTABLE_CPU_FREQ diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c index 3d3763583c..790f7d1225 100644 --- a/apps/plugins/text_viewer/tv_display.c +++ b/apps/plugins/text_viewer/tv_display.c @@ -69,7 +69,11 @@ struct tv_rect { static struct viewport vp_info; static struct viewport vp_text; -static bool is_initialized_vp = false; +static bool is_initialized_vp; +static bool sbs_has_title; +#if LCD_DEPTH > 1 +static fb_data* backdrop; +#endif static struct screen* display; @@ -90,9 +94,15 @@ static int row_height = 1; static int totalsize; +static bool tv_has_sbs_title(void) +{ + return preferences->statusbar && sbs_has_title; +} + static void tv_show_header(void) { - if (preferences->header_mode) + /* Ignore header mode if we have an SBS title */ + if (preferences->header_mode && !tv_has_sbs_title()) display->putsxy(header.x, header.y, preferences->file_name); } @@ -189,6 +199,12 @@ void tv_draw_text(int row, const unsigned char *text, int offset) display->set_viewport(&vp_info); } +bool tv_set_sbs_title(void) +{ + sbs_has_title = rb->sb_set_title_text(preferences->file_name, Icon_NOICON, SCREEN_MAIN); + return preferences->statusbar && sbs_has_title; +} + void tv_start_display(void) { display->set_viewport(&vp_info); @@ -197,7 +213,10 @@ void tv_start_display(void) #if LCD_DEPTH > 1 if (preferences->night_mode) + { + backdrop = rb->lcd_get_backdrop(); rb->lcd_set_backdrop(NULL); + } #endif display->clear_viewport(); @@ -207,6 +226,10 @@ void tv_end_display(void) { display->update_viewport(); display->set_viewport(NULL); +#if LCD_DEPTH > 1 + if (preferences->night_mode) + rb->lcd_set_backdrop(backdrop); +#endif } void tv_set_layout(bool show_scrollbar) @@ -221,7 +244,7 @@ void tv_set_layout(bool show_scrollbar) header.x = 0; header.y = 0; header.w = vp_info.width; - header.h = (preferences->header_mode)? row_height + 1 : 0; + header.h = (preferences->header_mode && !tv_set_sbs_title()) ? row_height + 1 : 0; footer.x = 0; footer.w = vp_info.width; diff --git a/apps/plugins/text_viewer/tv_display.h b/apps/plugins/text_viewer/tv_display.h index 9dfe17d900..448957837c 100644 --- a/apps/plugins/text_viewer/tv_display.h +++ b/apps/plugins/text_viewer/tv_display.h @@ -97,6 +97,14 @@ void tv_update_extra(int window, int col, const struct tv_screen_pos *pos, int s */ void tv_init_scrollbar(off_t total, bool show_scrollbar); +/* set the SBS title + * + * return + * true, if title is displayed in SBS + * false, if SBS is hidden or has no title + */ +bool tv_set_sbs_title(void); + /* start the display processing */ void tv_start_display(void); diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c index 15db75260e..cbef2e0ef7 100644 --- a/apps/plugins/text_viewer/tv_window.c +++ b/apps/plugins/text_viewer/tv_window.c @@ -54,6 +54,12 @@ static void tv_draw_bookmarks(const struct tv_screen_pos *top_pos) tv_show_bookmarks(disp_bookmarks, disp_count); } +void tv_update_sbs_title(void) +{ + if (tv_set_sbs_title()) + rb->send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); +} + void tv_draw_window(void) { struct tv_screen_pos pos; diff --git a/apps/plugins/text_viewer/tv_window.h b/apps/plugins/text_viewer/tv_window.h index 14eeb0820d..80f1d6f1ed 100644 --- a/apps/plugins/text_viewer/tv_window.h +++ b/apps/plugins/text_viewer/tv_window.h @@ -41,6 +41,9 @@ bool tv_init_window(unsigned char **buf, size_t *bufsize); /* finalize the window module */ void tv_finalize_window(void); +/* update the skinned status bar title, if one is present */ +void tv_update_sbs_title(void); + /* draw the display */ void tv_draw_window(void);