Add hotkey for region/window recording

This commit is contained in:
dec05eba
2026-01-19 22:26:03 +01:00
parent 0269387b9a
commit 5f484bd82c
10 changed files with 153 additions and 38 deletions

View File

@@ -304,6 +304,36 @@ namespace gsr {
return list;
}
std::unique_ptr<List> GlobalSettingsPage::create_record_hotkey_window_region_options() {
auto list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER);
list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Start/stop recording a region:", get_color_theme().text_color));
auto start_stop_recording_region_button = std::make_unique<Button>(&get_theme().body_font, "", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
start_stop_recording_region_button_ptr = start_stop_recording_region_button.get();
list->add_widget(std::move(start_stop_recording_region_button));
char str[128];
if(gsr_info->system_info.display_server == DisplayServer::X11)
snprintf(str, sizeof(str), "Start/stop recording a window:");
else
snprintf(str, sizeof(str), "Start/stop recording with desktop portal:");
list->add_widget(std::make_unique<Label>(&get_theme().body_font, str, get_color_theme().text_color));
auto start_stop_recording_window_button = std::make_unique<Button>(&get_theme().body_font, "", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
start_stop_recording_window_button_ptr = start_stop_recording_window_button.get();
list->add_widget(std::move(start_stop_recording_window_button));
start_stop_recording_region_button_ptr->on_click = [this] {
configure_hotkey_start(ConfigureHotkeyType::RECORD_START_STOP_REGION);
};
start_stop_recording_window_button_ptr->on_click = [this] {
configure_hotkey_start(ConfigureHotkeyType::RECORD_START_STOP_WINDOW);
};
return list;
}
std::unique_ptr<List> GlobalSettingsPage::create_stream_hotkey_options() {
auto list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER);
@@ -375,17 +405,9 @@ namespace gsr {
auto clear_hotkeys_button = std::make_unique<Button>(&get_theme().body_font, "Clear hotkeys", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
clear_hotkeys_button->on_click = [this] {
config.streaming_config.start_stop_hotkey = {mgl::Keyboard::Unknown, 0};
config.record_config.start_stop_hotkey = {mgl::Keyboard::Unknown, 0};
config.record_config.pause_unpause_hotkey = {mgl::Keyboard::Unknown, 0};
config.replay_config.start_stop_hotkey = {mgl::Keyboard::Unknown, 0};
config.replay_config.save_hotkey = {mgl::Keyboard::Unknown, 0};
config.replay_config.save_1_min_hotkey = {mgl::Keyboard::Unknown, 0};
config.replay_config.save_10_min_hotkey = {mgl::Keyboard::Unknown, 0};
config.screenshot_config.take_screenshot_hotkey = {mgl::Keyboard::Unknown, 0};
config.screenshot_config.take_screenshot_region_hotkey = {mgl::Keyboard::Unknown, 0};
config.screenshot_config.take_screenshot_window_hotkey = {mgl::Keyboard::Unknown, 0};
config.main_config.show_hide_hotkey = {mgl::Keyboard::Unknown, 0};
for_each_config_hotkey([&](ConfigHotkey *config_hotkey_item) {
*config_hotkey_item = {mgl::Keyboard::Unknown, 0};
});
load_hotkeys();
overlay->rebind_all_keyboard_hotkeys();
};
@@ -424,6 +446,7 @@ namespace gsr {
list_ptr->add_widget(create_replay_hotkey_options());
list_ptr->add_widget(create_replay_partial_save_hotkey_options());
list_ptr->add_widget(create_record_hotkey_options());
list_ptr->add_widget(create_record_hotkey_window_region_options());
list_ptr->add_widget(create_stream_hotkey_options());
list_ptr->add_widget(create_screenshot_hotkey_options());
list_ptr->add_widget(create_screenshot_region_hotkey_options());
@@ -595,6 +618,8 @@ namespace gsr {
start_stop_recording_button_ptr->set_text(config.record_config.start_stop_hotkey.to_string());
pause_unpause_recording_button_ptr->set_text(config.record_config.pause_unpause_hotkey.to_string());
start_stop_recording_region_button_ptr->set_text(config.record_config.start_stop_region_hotkey.to_string());
start_stop_recording_window_button_ptr->set_text(config.record_config.start_stop_window_hotkey.to_string());
start_stop_streaming_button_ptr->set_text(config.streaming_config.start_stop_hotkey.to_string());
@@ -679,6 +704,10 @@ namespace gsr {
return start_stop_recording_button_ptr;
case ConfigureHotkeyType::RECORD_PAUSE_UNPAUSE:
return pause_unpause_recording_button_ptr;
case ConfigureHotkeyType::RECORD_START_STOP_REGION:
return start_stop_recording_region_button_ptr;
case ConfigureHotkeyType::RECORD_START_STOP_WINDOW:
return start_stop_recording_window_button_ptr;
case ConfigureHotkeyType::STREAM_START_STOP:
return start_stop_streaming_button_ptr;
case ConfigureHotkeyType::TAKE_SCREENSHOT:
@@ -709,6 +738,10 @@ namespace gsr {
return &config.record_config.start_stop_hotkey;
case ConfigureHotkeyType::RECORD_PAUSE_UNPAUSE:
return &config.record_config.pause_unpause_hotkey;
case ConfigureHotkeyType::RECORD_START_STOP_REGION:
return &config.record_config.start_stop_region_hotkey;
case ConfigureHotkeyType::RECORD_START_STOP_WINDOW:
return &config.record_config.start_stop_window_hotkey;
case ConfigureHotkeyType::STREAM_START_STOP:
return &config.streaming_config.start_stop_hotkey;
case ConfigureHotkeyType::TAKE_SCREENSHOT:
@@ -727,8 +760,12 @@ namespace gsr {
ConfigHotkey *config_hotkeys[] = {
&config.replay_config.start_stop_hotkey,
&config.replay_config.save_hotkey,
&config.replay_config.save_1_min_hotkey,
&config.replay_config.save_10_min_hotkey,
&config.record_config.start_stop_hotkey,
&config.record_config.pause_unpause_hotkey,
&config.record_config.start_stop_region_hotkey,
&config.record_config.start_stop_window_hotkey,
&config.streaming_config.start_stop_hotkey,
&config.screenshot_config.take_screenshot_hotkey,
&config.screenshot_config.take_screenshot_region_hotkey,
@@ -772,6 +809,15 @@ namespace gsr {
case ConfigureHotkeyType::RECORD_PAUSE_UNPAUSE:
hotkey_configure_action_name = "Pause/unpause recording";
break;
case ConfigureHotkeyType::RECORD_START_STOP_REGION:
hotkey_configure_action_name = "Start/stop recording a region";
break;
case ConfigureHotkeyType::RECORD_START_STOP_WINDOW:
if(gsr_info->system_info.display_server == DisplayServer::X11)
hotkey_configure_action_name = "Start/stop recording a window";
else
hotkey_configure_action_name = "Start/stop recording with desktop portal";
break;
case ConfigureHotkeyType::STREAM_START_STOP:
hotkey_configure_action_name = "Start/stop streaming";
break;