feat: adds an option to run a script after a screenshot

This commit is contained in:
Giovane Perlin
2025-11-30 22:04:30 -04:00
committed by dec05eba
parent d7be9b38b1
commit 11aa237821
5 changed files with 44 additions and 7 deletions

View File

@@ -289,7 +289,8 @@ namespace gsr {
{"screenshot.save_directory", &config.screenshot_config.save_directory},
{"screenshot.take_screenshot_hotkey", &config.screenshot_config.take_screenshot_hotkey},
{"screenshot.take_screenshot_region_hotkey", &config.screenshot_config.take_screenshot_region_hotkey},
{"screenshot.take_screenshot_window_hotkey", &config.screenshot_config.take_screenshot_window_hotkey}
{"screenshot.take_screenshot_window_hotkey", &config.screenshot_config.take_screenshot_window_hotkey},
{"screenshot.custom_script", &config.screenshot_config.custom_script},
};
}
@@ -487,4 +488,4 @@ namespace gsr {
fclose(file);
}
}
}

View File

@@ -2176,6 +2176,11 @@ namespace gsr {
if(led_indicator && config.screenshot_config.use_led_indicator)
led_indicator->blink();
if(!strip(config.screenshot_config.custom_script).empty()) {
const char *args[] = { config.screenshot_config.custom_script.c_str(), screenshot_filepath.c_str(), nullptr };
exec_program_on_host_daemonized(args);
}
} else {
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_screenshot_process, exit_code);
show_notification("Failed to take a screenshot. Verify if settings are correct", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT, nullptr, NotificationLevel::ERROR);

View File

@@ -139,7 +139,7 @@ namespace gsr {
return list;
}
std::unique_ptr<Widget> ScreenshotSettingsPage::create_record_cursor_section() {
auto record_cursor_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Record cursor");
record_cursor_checkbox->set_checked(true);
@@ -163,7 +163,7 @@ namespace gsr {
auto select_directory_page = std::make_unique<GsrPage>("File", "Settings");
select_directory_page->add_button("Save", "save", get_color_theme().tint_color);
select_directory_page->add_button("Cancel", "cancel", get_color_theme().page_bg_color);
auto file_chooser = std::make_unique<FileChooser>(save_directory_button_ptr->get_text().c_str(), select_directory_page->get_inner_size());
FileChooser *file_chooser_ptr = file_chooser.get();
select_directory_page->add_widget(std::move(file_chooser));
@@ -249,6 +249,27 @@ namespace gsr {
return std::make_unique<Subsection>("Screenshot indicator", std::move(list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
}
std::unique_ptr<List> ScreenshotSettingsPage::create_custom_script_screenshot_entry() {
auto list = std::make_unique<List>(List::Orientation::VERTICAL, List::Alignment::CENTER);
auto create_custom_script_screenshot_entry = std::make_unique<Entry>(&get_theme().body_font, "kolourpaint", get_theme().body_font.get_character_size() * 20);
create_custom_script_screenshot_entry_ptr = create_custom_script_screenshot_entry.get();
list->add_widget(std::move(create_custom_script_screenshot_entry));
return list;
}
std::unique_ptr<List> ScreenshotSettingsPage::create_custom_script_screenshot() {
auto custom_script_screenshot_list = std::make_unique<List>(List::Orientation::VERTICAL);
custom_script_screenshot_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Program to open the screenshot with:", get_color_theme().text_color));
custom_script_screenshot_list->add_widget(create_custom_script_screenshot_entry());
return custom_script_screenshot_list;
}
std::unique_ptr<Widget> ScreenshotSettingsPage::create_custom_script_screenshot_section() {
return std::make_unique<Subsection>("Script", create_custom_script_screenshot(), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
}
std::unique_ptr<Widget> ScreenshotSettingsPage::create_settings() {
auto page_list = std::make_unique<List>(List::Orientation::VERTICAL);
page_list->set_spacing(0.018f);
@@ -263,6 +284,7 @@ namespace gsr {
settings_list->add_widget(create_file_info_section());
settings_list->add_widget(create_general_section());
settings_list->add_widget(create_screenshot_indicator_section());
settings_list->add_widget(create_custom_script_screenshot_section());
settings_scrollable_page_ptr->add_widget(std::move(settings_list));
return page_list;
}
@@ -321,6 +343,8 @@ namespace gsr {
if(config.screenshot_config.image_height < 32)
config.screenshot_config.image_height = 32;
image_height_entry_ptr->set_text(std::to_string(config.screenshot_config.image_height));
create_custom_script_screenshot_entry_ptr->set_text(config.screenshot_config.custom_script);
}
void ScreenshotSettingsPage::save() {
@@ -337,6 +361,7 @@ namespace gsr {
config.screenshot_config.save_screenshot_to_clipboard = save_screenshot_to_clipboard_checkbox_ptr->is_checked();
config.screenshot_config.show_notifications = show_notification_checkbox_ptr->is_checked();
config.screenshot_config.use_led_indicator = led_indicator_checkbox_ptr->is_checked();
config.screenshot_config.custom_script = create_custom_script_screenshot_entry_ptr->get_text();
if(config.screenshot_config.image_width == 0)
config.screenshot_config.image_width = 1920;
@@ -356,4 +381,4 @@ namespace gsr {
save_config(config);
}
}
}