Mention that recording has to be restarted to apply changes. Fix stuck in repeat state if pressed while gsr-global-hotkey starts

This commit is contained in:
dec05eba
2024-12-26 15:22:57 +01:00
parent ec6d4090af
commit e5b745d696
11 changed files with 119 additions and 18 deletions

View File

@@ -5,6 +5,7 @@
#include <limits.h>
#include <inttypes.h>
#include <libgen.h>
#include <iostream>
#define FORMAT_I32 "%" PRIi32
#define FORMAT_I64 "%" PRIi64
@@ -13,6 +14,14 @@
#define CONFIG_FILE_VERSION 1
namespace gsr {
bool ConfigHotkey::operator==(const ConfigHotkey &other) const {
return keysym == other.keysym && modifiers == other.modifiers;
}
bool ConfigHotkey::operator!=(const ConfigHotkey &other) const {
return !operator==(other);
}
Config::Config(const SupportedCaptureOptions &capture_options) {
const std::string default_save_directory = get_videos_dir();
@@ -141,6 +150,38 @@ namespace gsr {
};
}
bool Config::operator==(const Config &other) {
const auto config_options = get_config_options(*this);
const auto config_options_other = get_config_options(const_cast<Config&>(other));
for(auto it : config_options) {
auto it_other = config_options_other.find(it.first);
if(it_other == config_options_other.end() || it_other->second.index() != it.second.index())
return false;
if(std::holds_alternative<bool*>(it.second)) {
if(*std::get<bool*>(it.second) != *std::get<bool*>(it_other->second))
return false;
} else if(std::holds_alternative<std::string*>(it.second)) {
if(*std::get<std::string*>(it.second) != *std::get<std::string*>(it_other->second))
return false;
} else if(std::holds_alternative<int32_t*>(it.second)) {
if(*std::get<int32_t*>(it.second) != *std::get<int32_t*>(it_other->second))
return false;
} else if(std::holds_alternative<ConfigHotkey*>(it.second)) {
if(*std::get<ConfigHotkey*>(it.second) != *std::get<ConfigHotkey*>(it_other->second))
return false;
} else if(std::holds_alternative<std::vector<std::string>*>(it.second)) {
if(*std::get<std::vector<std::string>*>(it.second) != *std::get<std::vector<std::string>*>(it_other->second))
return false;
}
}
return true;
}
bool Config::operator!=(const Config &other) {
return !operator==(other);
}
std::optional<Config> read_config(const SupportedCaptureOptions &capture_options) {
std::optional<Config> config;

View File

@@ -209,8 +209,6 @@ namespace gsr {
capture_options.window = true;
else if(line == "focused")
capture_options.focused = true;
else if(line == "screen")
capture_options.screen = true;
else if(line == "portal")
capture_options.portal = true;
else {

View File

@@ -906,6 +906,10 @@ namespace gsr {
button->on_click = [this](const std::string &id) {
if(id == "settings") {
auto replay_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::REPLAY, &gsr_info, config, &page_stack);
replay_settings_page->on_config_changed = [this]() {
if(recording_status == RecordingStatus::REPLAY)
show_notification("Replay settings have been modified.\nYou may need to restart replay to apply the changes.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
};
page_stack.push(std::move(replay_settings_page));
} else if(id == "save") {
on_press_save_replay();
@@ -927,6 +931,10 @@ namespace gsr {
button->on_click = [this](const std::string &id) {
if(id == "settings") {
auto record_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::RECORD, &gsr_info, config, &page_stack);
record_settings_page->on_config_changed = [this]() {
if(recording_status == RecordingStatus::RECORD)
show_notification("Recording settings have been modified.\nYou may need to restart recording to apply the changes.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
};
page_stack.push(std::move(record_settings_page));
} else if(id == "pause") {
toggle_pause();
@@ -946,6 +954,10 @@ namespace gsr {
button->on_click = [this](const std::string &id) {
if(id == "settings") {
auto stream_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::STREAM, &gsr_info, config, &page_stack);
stream_settings_page->on_config_changed = [this]() {
if(recording_status == RecordingStatus::STREAM)
show_notification("Streaming settings have been modified.\nYou may need to restart streaming to apply the changes.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
};
page_stack.push(std::move(stream_settings_page));
} else if(id == "start") {
on_press_start_stream();
@@ -1318,7 +1330,7 @@ namespace gsr {
show_notification("Replay stopped", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
} else {
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_process, exit_code);
show_notification("Replay stopped because of an error", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY);
show_notification("Replay stopped because of an error. Verify if settings are correct", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY);
}
break;
}
@@ -1334,7 +1346,7 @@ namespace gsr {
show_notification("Streaming has stopped", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
} else {
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_process, exit_code);
show_notification("Streaming stopped because of an error", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM);
show_notification("Streaming stopped because of an error. Verify if settings are correct", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM);
}
break;
}
@@ -1399,7 +1411,7 @@ namespace gsr {
}
} else {
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_process, exit_code);
show_notification("Failed to start/save recording", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
show_notification("Failed to start/save recording. Verify if settings are correct", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
}
}
@@ -1574,8 +1586,6 @@ namespace gsr {
// TODO: Also check x11 window when enabled (check if capture_target is a decminal/hex number)
if(capture_target == "focused") {
return capture_options.focused;
} else if(capture_target == "screen") {
return capture_options.screen;
} else if(capture_target == "portal") {
return capture_options.portal;
} else {

View File

@@ -64,9 +64,6 @@ namespace gsr {
// record_area_box->add_item("Window", "window");
if(capture_options.focused)
record_area_box->add_item("Follow focused window", "focused");
// Do we really need this? it's only available on nvidia x11
//if(capture_options.screen)
// record_area_box->add_item("All monitors", "screen");
for(const auto &monitor : capture_options.monitors) {
char name[256];
snprintf(name, sizeof(name), "Monitor %s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y);
@@ -896,6 +893,7 @@ namespace gsr {
}
void SettingsPage::save() {
Config prev_config = config;
switch(type) {
case Type::REPLAY:
save_replay();
@@ -908,6 +906,9 @@ namespace gsr {
break;
}
save_config(config);
if(on_config_changed && config != prev_config)
on_config_changed();
}
static const std::string* get_application_audio_by_name_case_insensitive(const std::vector<std::string> &application_audio, const std::string &name) {