diff options
-rw-r--r-- | include/Config.hpp | 1 | ||||
-rw-r--r-- | include/GsrInfo.hpp | 17 | ||||
-rw-r--r-- | include/gui/SettingsPage.hpp | 2 | ||||
-rw-r--r-- | src/Config.cpp | 1 | ||||
-rw-r--r-- | src/GlobalHotkeysJoystick.cpp | 2 | ||||
-rw-r--r-- | src/GlobalHotkeysLinux.cpp | 6 | ||||
-rw-r--r-- | src/GsrInfo.cpp | 89 | ||||
-rw-r--r-- | src/Overlay.cpp | 5 | ||||
-rw-r--r-- | src/gui/GlobalSettingsPage.cpp | 10 | ||||
-rw-r--r-- | src/gui/SettingsPage.cpp | 12 | ||||
-rw-r--r-- | tools/gsr-global-hotkeys/keyboard_event.c | 4 |
11 files changed, 144 insertions, 5 deletions
diff --git a/include/Config.hpp b/include/Config.hpp index 0d311b2..34c2010 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -90,6 +90,7 @@ namespace gsr { RecordOptions record_options; std::string turn_on_replay_automatically_mode = "dont_turn_on_automatically"; bool save_video_in_game_folder = false; + bool restart_replay_on_save = false; bool show_replay_started_notifications = true; bool show_replay_stopped_notifications = true; bool show_replay_saved_notifications = true; diff --git a/include/GsrInfo.hpp b/include/GsrInfo.hpp index 86df0b7..a8c0742 100644 --- a/include/GsrInfo.hpp +++ b/include/GsrInfo.hpp @@ -2,6 +2,7 @@ #include <string> #include <vector> +#include <stdint.h> #include <mglpp/system/vec.hpp> @@ -24,6 +25,21 @@ namespace gsr { mgl::vec2i size; }; + struct GsrVersion { + uint8_t major = 0; + uint8_t minor = 0; + uint8_t patch = 0; + + bool operator>(const GsrVersion &other) const; + bool operator>=(const GsrVersion &other) const; + bool operator<(const GsrVersion &other) const; + bool operator<=(const GsrVersion &other) const; + bool operator==(const GsrVersion &other) const; + bool operator!=(const GsrVersion &other) const; + + std::string to_string() const; + }; + struct SupportedCaptureOptions { bool window = false; bool focused = false; @@ -40,6 +56,7 @@ namespace gsr { struct SystemInfo { DisplayServer display_server = DisplayServer::UNKNOWN; bool supports_app_audio = false; + GsrVersion gsr_version; }; enum class GpuVendor { diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp index efa958e..8db3915 100644 --- a/include/gui/SettingsPage.hpp +++ b/include/gui/SettingsPage.hpp @@ -97,6 +97,7 @@ namespace gsr { std::unique_ptr<List> create_replay_time(); std::unique_ptr<RadioButton> create_start_replay_automatically(); std::unique_ptr<CheckBox> create_save_replay_in_game_folder(); + std::unique_ptr<CheckBox> create_restart_replay_on_save(); std::unique_ptr<Label> create_estimated_replay_file_size(); void update_estimated_replay_file_size(); std::unique_ptr<CheckBox> create_save_recording_in_game_folder(); @@ -170,6 +171,7 @@ namespace gsr { List *stream_url_list_ptr = nullptr; List *container_list_ptr = nullptr; CheckBox *save_replay_in_game_folder_ptr = nullptr; + CheckBox *restart_replay_on_save = nullptr; Label *estimated_file_size_ptr = nullptr; CheckBox *show_replay_started_notification_checkbox_ptr = nullptr; CheckBox *show_replay_stopped_notification_checkbox_ptr = nullptr; diff --git a/src/Config.cpp b/src/Config.cpp index 16b371f..dfe33ff 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -149,6 +149,7 @@ namespace gsr { {"replay.record_options.restore_portal_session", &config.replay_config.record_options.restore_portal_session}, {"replay.turn_on_replay_automatically_mode", &config.replay_config.turn_on_replay_automatically_mode}, {"replay.save_video_in_game_folder", &config.replay_config.save_video_in_game_folder}, + {"replay.restart_replay_on_save", &config.replay_config.restart_replay_on_save}, {"replay.show_replay_started_notifications", &config.replay_config.show_replay_started_notifications}, {"replay.show_replay_stopped_notifications", &config.replay_config.show_replay_stopped_notifications}, {"replay.show_replay_saved_notifications", &config.replay_config.show_replay_saved_notifications}, diff --git a/src/GlobalHotkeysJoystick.cpp b/src/GlobalHotkeysJoystick.cpp index b79e799..dfe1e6f 100644 --- a/src/GlobalHotkeysJoystick.cpp +++ b/src/GlobalHotkeysJoystick.cpp @@ -84,6 +84,8 @@ namespace gsr { } bool GlobalHotkeysJoystick::bind_action(const std::string &id, GlobalHotkeyCallback callback) { + if(num_poll_fd == 0) + return false; return bound_actions_by_id.insert(std::make_pair(id, std::move(callback))).second; } diff --git a/src/GlobalHotkeysLinux.cpp b/src/GlobalHotkeysLinux.cpp index c779777..357fb16 100644 --- a/src/GlobalHotkeysLinux.cpp +++ b/src/GlobalHotkeysLinux.cpp @@ -166,6 +166,9 @@ namespace gsr { } bool GlobalHotkeysLinux::bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) { + if(process_id <= 0) + return false; + if(bound_actions_by_id.find(id) != bound_actions_by_id.end()) return false; @@ -202,6 +205,9 @@ namespace gsr { } void GlobalHotkeysLinux::unbind_all_keys() { + if(process_id <= 0) + return; + if(bound_actions_by_id.empty()) return; diff --git a/src/GsrInfo.cpp b/src/GsrInfo.cpp index 6665dc9..033757c 100644 --- a/src/GsrInfo.cpp +++ b/src/GsrInfo.cpp @@ -6,6 +6,93 @@ #include <string.h> namespace gsr { + bool GsrVersion::operator>(const GsrVersion &other) const { + return major > other.major || (major == other.major && minor > other.minor) || (major == other.major && minor == other.minor && patch > other.patch); + } + + bool GsrVersion::operator>=(const GsrVersion &other) const { + return major >= other.major || (major == other.major && minor >= other.minor) || (major == other.major && minor == other.minor && patch >= other.patch); + } + + bool GsrVersion::operator<(const GsrVersion &other) const { + return !operator>=(other); + } + + bool GsrVersion::operator<=(const GsrVersion &other) const { + return !operator>(other); + } + + bool GsrVersion::operator==(const GsrVersion &other) const { + return major == other.major && minor == other.minor && patch == other.patch; + } + + bool GsrVersion::operator!=(const GsrVersion &other) const { + return !operator==(other); + } + + std::string GsrVersion::to_string() const { + std::string result; + if(major == 0 && minor == 0 && patch == 0) + result = "Unknown"; + else + result = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch); + return result; + } + + /* Returns -1 on error */ + static int parse_u8(const char *str, int size) { + if(size <= 0) + return -1; + + int result = 0; + for(int i = 0; i < size; ++i) { + char c = str[i]; + if(c >= '0' && c <= '9') { + result = result * 10 + (c - '0'); + if(result > 255) + return -1; + } else { + return -1; + } + } + return result; + } + + static GsrVersion parse_gsr_version(const std::string_view str) { + GsrVersion result; + uint8_t numbers[3]; + int number_index = 0; + + size_t index = 0; + while(true) { + size_t next_index = str.find('.', index); + if(next_index == std::string::npos) + next_index = str.size(); + + const int number = parse_u8(str.data() + index, next_index - index); + if(number == -1) { + fprintf(stderr, "Error: gpu-screen-recorder --info contains invalid gsr version: %.*s\n", (int)str.size(), str.data()); + return {0, 0, 0}; + } + + if(number_index >= 3) { + fprintf(stderr, "Error: gpu-screen-recorder --info contains invalid gsr version: %.*s\n", (int)str.size(), str.data()); + return {0, 0, 0}; + } + + numbers[number_index] = number; + ++number_index; + index = next_index + 1; + if(next_index == str.size()) + break; + } + + result.major = numbers[0]; + result.minor = numbers[1]; + result.patch = numbers[2]; + return result; + } + static std::optional<KeyValue> parse_key_value(std::string_view line) { const size_t space_index = line.find('|'); if(space_index == std::string_view::npos) @@ -25,6 +112,8 @@ namespace gsr { gsr_info->system_info.display_server = DisplayServer::WAYLAND; } else if(key_value->key == "supports_app_audio") { gsr_info->system_info.supports_app_audio = key_value->value == "yes"; + } else if(key_value->key == "gsr_version") { + gsr_info->system_info.gsr_version = parse_gsr_version(key_value->value); } } diff --git a/src/Overlay.cpp b/src/Overlay.cpp index a8490ab..6ecd32e 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -1866,6 +1866,11 @@ namespace gsr { "-o", output_directory.c_str() }; + if(config.replay_config.restart_replay_on_save && gsr_info.system_info.gsr_version >= GsrVersion{5, 0, 2}) { + args.push_back("-overlap-replay"); + args.push_back("no"); + } + add_common_gpu_screen_recorder_args(args, config.replay_config.record_options, audio_tracks, video_bitrate, region, audio_tracks_merged); args.push_back(nullptr); diff --git a/src/gui/GlobalSettingsPage.cpp b/src/gui/GlobalSettingsPage.cpp index d4a87c2..e3c09ff 100644 --- a/src/gui/GlobalSettingsPage.cpp +++ b/src/gui/GlobalSettingsPage.cpp @@ -24,11 +24,11 @@ extern "C" { #include <mglpp/graphics/Text.hpp> #ifndef GSR_UI_VERSION -#define GSR_UI_VERSION "unknown" +#define GSR_UI_VERSION "Unknown" #endif #ifndef GSR_FLATPAK_VERSION -#define GSR_FLATPAK_VERSION "unknown" +#define GSR_FLATPAK_VERSION "Unknown" #endif namespace gsr { @@ -403,7 +403,11 @@ namespace gsr { auto list = std::make_unique<List>(List::Orientation::VERTICAL); char str[128]; - snprintf(str, sizeof(str), "UI version: %s", GSR_UI_VERSION); + const std::string gsr_version = gsr_info->system_info.gsr_version.to_string(); + snprintf(str, sizeof(str), "GSR version: %s", gsr_version.c_str()); + list->add_widget(std::make_unique<Label>(&get_theme().body_font, str, get_color_theme().text_color)); + + snprintf(str, sizeof(str), "GSR-UI version: %s", GSR_UI_VERSION); list->add_widget(std::make_unique<Label>(&get_theme().body_font, str, get_color_theme().text_color)); if(inside_flatpak) { diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index 5fdcc91..0e5c57b 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -664,6 +664,12 @@ namespace gsr { return checkbox; } + std::unique_ptr<CheckBox> SettingsPage::create_restart_replay_on_save() { + auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Restart replay on save"); + restart_replay_on_save = checkbox.get(); + return checkbox; + } + std::unique_ptr<Label> SettingsPage::create_estimated_replay_file_size() { auto label = std::make_unique<Label>(&get_theme().body_font, "Estimated video max file size in RAM: 57.60MB", get_color_theme().text_color); estimated_file_size_ptr = label.get(); @@ -693,6 +699,8 @@ namespace gsr { auto general_list = std::make_unique<List>(List::Orientation::VERTICAL); general_list->add_widget(create_start_replay_automatically()); general_list->add_widget(create_save_replay_in_game_folder()); + if(gsr_info->system_info.gsr_version >= GsrVersion{5, 0, 2}) + general_list->add_widget(create_restart_replay_on_save()); settings_list_ptr->add_widget(std::make_unique<Subsection>("General", std::move(general_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f))); auto checkboxes_list = std::make_unique<List>(List::Orientation::VERTICAL); @@ -1065,6 +1073,8 @@ namespace gsr { load_common(config.replay_config.record_options); turn_on_replay_automatically_mode_ptr->set_selected_item(config.replay_config.turn_on_replay_automatically_mode); save_replay_in_game_folder_ptr->set_checked(config.replay_config.save_video_in_game_folder); + if(restart_replay_on_save) + restart_replay_on_save->set_checked(config.replay_config.restart_replay_on_save); show_replay_started_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_started_notifications); show_replay_stopped_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_stopped_notifications); show_replay_saved_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_saved_notifications); @@ -1193,6 +1203,8 @@ namespace gsr { save_common(config.replay_config.record_options); config.replay_config.turn_on_replay_automatically_mode = turn_on_replay_automatically_mode_ptr->get_selected_id(); config.replay_config.save_video_in_game_folder = save_replay_in_game_folder_ptr->is_checked(); + if(restart_replay_on_save) + config.replay_config.restart_replay_on_save = restart_replay_on_save->is_checked(); config.replay_config.show_replay_started_notifications = show_replay_started_notification_checkbox_ptr->is_checked(); config.replay_config.show_replay_stopped_notifications = show_replay_stopped_notification_checkbox_ptr->is_checked(); config.replay_config.show_replay_saved_notifications = show_replay_saved_notification_checkbox_ptr->is_checked(); diff --git a/tools/gsr-global-hotkeys/keyboard_event.c b/tools/gsr-global-hotkeys/keyboard_event.c index 261dc57..b8d94fd 100644 --- a/tools/gsr-global-hotkeys/keyboard_event.c +++ b/tools/gsr-global-hotkeys/keyboard_event.c @@ -638,13 +638,13 @@ static void keyboard_event_parse_stdin_command(keyboard_event *self, const char .modifiers = modifiers }; ++self->num_global_hotkeys; - fprintf(stderr, "Info: bound hotkey: %s\n", action); + fprintf(stderr, "Info: binded hotkey: %s\n", action); } else if(strncmp(command, "unbind_all", 10) == 0) { for(int i = 0; i < self->num_global_hotkeys; ++i) { free(self->global_hotkeys[i].action); } self->num_global_hotkeys = 0; - fprintf(stderr, "Info: unbound all hotkeys\n"); + fprintf(stderr, "Info: unbinded all hotkeys\n"); } else { fprintf(stderr, "Warning: got invalid command: \"%s\", expected command to start with either \"bind\" or \"unbind_all\"\n", command); } |