From dccda8c76ff537437ffc11e49e030102a36bf295 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 8 Mar 2025 14:04:42 -0500 Subject: [PATCH] [Bugfix] FS#12436 cache mode strings prior to font disable by checking string len we can cache the USB hid mode strings I guess if the user doesn't have enough glyphs they might still might not get the whole thing but this appears to work with 50 glyphs and the referenced russian language selected remove call to GUI_EVENT_ACTIONUPDATE it is now counterproductive Change-Id: Ica96ed39c7d002fde2d1888e78d2ea18e7c1d61a --- apps/gui/usb_screen.c | 12 +++++++++++- apps/usb_keymaps.c | 6 ++++-- apps/usb_keymaps.h | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c index 8a3510ea15..e16428e1e5 100644 --- a/apps/gui/usb_screen.c +++ b/apps/gui/usb_screen.c @@ -191,6 +191,13 @@ static void usb_screen_fix_viewports(struct screen *screen, logo->y = parent->y; title->y = parent->y + logo->height; } + + int i =0, langid = LANG_USB_KEYPAD_MODE; + while (langid >= 0) /* ensure the USB mode strings get cached */ + { + font_getstringsize(str(langid), NULL, NULL, title->font); + langid = keypad_mode_name_get(i++); + } } #endif } @@ -229,7 +236,7 @@ static void usb_screens_draw(struct usb_screen_vps_t *usb_screen_vps_ar) usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER; snprintf(modestring, sizeof(modestring), "%s: %s", str(LANG_USB_KEYPAD_MODE), - str(keypad_mode_name_get())); + str(keypad_mode_name_get(usb_keypad_mode))); screen->puts_scroll(0, 0, modestring); } #endif /* USB_ENABLE_HID */ @@ -278,9 +285,12 @@ void gui_usb_screen_run(bool early_usb) usb_screen_fix_viewports(screen, &usb_screen_vps_ar[i]); } +#if 0 /* handled in usb_screen_fix_viewports() */ /* update the UI before disabling fonts, this maximizes the propability * that font cache lookups succeed during USB */ send_event(GUI_EVENT_ACTIONUPDATE, NULL); +#endif + if(!early_usb) { /* The font system leaves the .fnt fd's open, so we need for force close them all */ diff --git a/apps/usb_keymaps.c b/apps/usb_keymaps.c index 2781fb5532..f7505aa754 100644 --- a/apps/usb_keymaps.c +++ b/apps/usb_keymaps.c @@ -219,7 +219,9 @@ int get_hid_usb_action(void) return action; } -int keypad_mode_name_get(void) +int keypad_mode_name_get(unsigned int mode) { - return hid_key_mappings[usb_keypad_mode]->lang_name; + if (mode >= ARRAYLEN(hid_key_mappings)) + return -1; + return hid_key_mappings[mode]->lang_name; } diff --git a/apps/usb_keymaps.h b/apps/usb_keymaps.h index 8b08bfda2d..6b727bea6b 100644 --- a/apps/usb_keymaps.h +++ b/apps/usb_keymaps.h @@ -23,6 +23,6 @@ int get_hid_usb_action(void); -int keypad_mode_name_get(void); +int keypad_mode_name_get(unsigned int mode); #endif