aboutsummaryrefslogtreecommitdiff
path: root/src/Overlay.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Overlay.cpp')
-rw-r--r--src/Overlay.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/Overlay.cpp b/src/Overlay.cpp
index 63f9822..4eb8844 100644
--- a/src/Overlay.cpp
+++ b/src/Overlay.cpp
@@ -272,7 +272,7 @@ namespace gsr {
static void bind_linux_hotkeys(GlobalHotkeysLinux *global_hotkeys, Overlay *overlay) {
global_hotkeys->bind_key_press(
config_hotkey_to_hotkey(overlay->get_config().main_config.show_hide_hotkey),
- "show_hide", [overlay](const std::string &id) {
+ "toggle_show", [overlay](const std::string &id) {
fprintf(stderr, "pressed %s\n", id.c_str());
overlay->toggle_show();
});
@@ -318,6 +318,13 @@ namespace gsr {
fprintf(stderr, "pressed %s\n", id.c_str());
overlay->take_screenshot();
});
+
+ global_hotkeys->bind_key_press(
+ config_hotkey_to_hotkey(overlay->get_config().screenshot_config.take_screenshot_region_hotkey),
+ "take_screenshot_region", [overlay](const std::string &id) {
+ fprintf(stderr, "pressed %s\n", id.c_str());
+ overlay->take_screenshot_region();
+ });
}
static std::unique_ptr<GlobalHotkeysLinux> register_linux_hotkeys(Overlay *overlay, GlobalHotkeysLinux::GrabType grab_type) {
@@ -334,6 +341,11 @@ namespace gsr {
if(!global_hotkeys_js->start())
fprintf(stderr, "Warning: failed to start joystick hotkeys\n");
+ global_hotkeys_js->bind_action("toggle_show", [overlay](const std::string &id) {
+ fprintf(stderr, "pressed %s\n", id.c_str());
+ overlay->toggle_show();
+ });
+
global_hotkeys_js->bind_action("save_replay", [overlay](const std::string &id) {
fprintf(stderr, "pressed %s\n", id.c_str());
overlay->save_replay();
@@ -1144,6 +1156,7 @@ namespace gsr {
button->set_position((main_buttons_list_ptr->get_position() + main_buttons_size - mgl::vec2f(0.0f, settings_button_size*2) + mgl::vec2f(settings_button_size * 0.333f, 0.0f)).floor());
button->set_bg_hover_color(mgl::Color(0, 0, 0, 255));
button->set_icon(&get_theme().screenshot_texture);
+ button->set_icon_padding_scale(1.2f);
button->on_click = [&]() {
auto screenshot_settings_page = std::make_unique<ScreenshotSettingsPage>(&gsr_info, config, &page_stack);
page_stack.push(std::move(screenshot_settings_page));
@@ -1306,7 +1319,11 @@ namespace gsr {
}
void Overlay::take_screenshot() {
- on_press_take_screenshot(false);
+ on_press_take_screenshot(false, false);
+ }
+
+ void Overlay::take_screenshot_region() {
+ on_press_take_screenshot(false, true);
}
static const char* notification_type_to_string(NotificationType notification_type) {
@@ -2295,7 +2312,7 @@ namespace gsr {
show_notification("Streaming has started", notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::STREAM);
}
- void Overlay::on_press_take_screenshot(bool finished_region_selection) {
+ void Overlay::on_press_take_screenshot(bool finished_region_selection, bool force_region_capture) {
if(region_selector.is_started())
return;
@@ -2304,18 +2321,20 @@ namespace gsr {
return;
}
- if(!validate_capture_target(gsr_info, config.screenshot_config.record_area_option)) {
+ const bool region_capture = config.screenshot_config.record_area_option == "region" || force_region_capture;
+ const char *record_area_option = region_capture ? "region" : config.screenshot_config.record_area_option.c_str();
+ if(!validate_capture_target(gsr_info, record_area_option)) {
char err_msg[256];
- snprintf(err_msg, sizeof(err_msg), "Failed to take a screenshot, capture target \"%s\" is invalid. Please change capture target in settings", config.screenshot_config.record_area_option.c_str());
+ snprintf(err_msg, sizeof(err_msg), "Failed to take a screenshot, capture target \"%s\" is invalid. Please change capture target in settings", record_area_option);
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::SCREENSHOT);
return;
}
- if(config.screenshot_config.record_area_option == "region" && !finished_region_selection) {
+ if(region_capture && !finished_region_selection) {
start_region_capture = true;
- on_region_selected = [this]() {
+ on_region_selected = [this, force_region_capture]() {
usleep(200 * 1000); // Hack: wait 0.2 seconds before taking a screenshot to allow user to move cursor away. TODO: Remove this
- on_press_take_screenshot(true);
+ on_press_take_screenshot(true, force_region_capture);
};
return;
}
@@ -2324,7 +2343,7 @@ namespace gsr {
const std::string output_file = config.screenshot_config.save_directory + "/Screenshot_" + get_date_str() + "." + config.screenshot_config.image_format; // TODO: Validate image format
std::vector<const char*> args = {
- "gpu-screen-recorder", "-w", config.screenshot_config.record_area_option.c_str(),
+ "gpu-screen-recorder", "-w", record_area_option,
"-cursor", config.screenshot_config.record_cursor ? "yes" : "no",
"-v", "no",
"-q", config.screenshot_config.image_quality.c_str(),
@@ -2345,7 +2364,7 @@ namespace gsr {
}
char region_str[128];
- if(config.screenshot_config.record_area_option == "region")
+ if(region_capture)
add_region_command(args, region_str, sizeof(region_str), region_selector);
args.push_back(nullptr);