diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-05-24 18:24:18 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-05-24 18:24:18 +0200 |
commit | b80e3f8bebe48e102033fe7ab0e402aa869135d3 (patch) | |
tree | 45c5132f36ba3a2c018c161662563c7b093e053d /src | |
parent | b807712d79121157b6a6d0df902f0f66da82a23f (diff) |
Fix crash when opening settings page because of recent change
Diffstat (limited to 'src')
-rw-r--r-- | src/Overlay.cpp | 20 | ||||
-rw-r--r-- | src/gui/SettingsPage.cpp | 2 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/Overlay.cpp b/src/Overlay.cpp index 685d95e..8a60b91 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -37,6 +37,7 @@ #include <X11/Xcursor/Xcursor.h> #include <mglpp/system/Rect.hpp> #include <mglpp/window/Event.hpp> +#include <mglpp/system/Utf8.hpp> extern "C" { #include <mgl/mgl.h> @@ -903,6 +904,7 @@ namespace gsr { // Wayland doesn't allow XGrabPointer/XGrabKeyboard when a wayland application is focused. // If the focused window is a wayland application then don't use override redirect and instead create // a fullscreen window for the ui. + // TODO: (x11_cursor_window && is_window_fullscreen_on_monitor(display, x11_cursor_window, *focused_monitor)) const bool prevent_game_minimizing = gsr_info.system_info.display_server != DisplayServer::WAYLAND || x11_cursor_window || is_wlroots; if(prevent_game_minimizing) { @@ -1640,10 +1642,22 @@ namespace gsr { return result; } - // TODO: Utf8 truncate static void truncate_string(std::string &str, int max_length) { - if((int)str.size() > max_length) - str.replace(str.begin() + max_length, str.end(), "..."); + int index = 0; + size_t byte_index = 0; + + while(index < max_length && byte_index < str.size()) { + uint32_t codepoint = 0; + size_t codepoint_length = 0; + mgl::utf8_decode((const unsigned char*)str.c_str() + byte_index, str.size() - byte_index, &codepoint, &codepoint_length); + if(codepoint_length == 0) + codepoint_length = 1; + + index += 1; + byte_index += codepoint_length; + } + + str.erase(byte_index); } void Overlay::save_video_in_current_game_directory(const char *video_filepath, NotificationType notification_type) { diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index ce556b9..1230290 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -768,7 +768,6 @@ namespace gsr { list->add_widget(std::move(replay_storage_button)); list->set_visible(gsr_info->system_info.gsr_version >= GsrVersion{5, 5, 0}); - replay_storage_list_ptr = list.get(); return list; } @@ -837,7 +836,6 @@ namespace gsr { notifications_subsection_ptr->set_visible(advanced_view); set_application_audio_options_visible(audio_track_section_list_ptr, advanced_view, *gsr_info); settings_scrollable_page_ptr->reset_scroll(); - replay_storage_list_ptr->set_visible(advanced_view && gsr_info->system_info.gsr_version >= GsrVersion{5, 5, 0}); } void SettingsPage::add_replay_widgets() { |