From 11aa23782118b9c35d9e7bfa1488e14ede46b6f5 Mon Sep 17 00:00:00 2001 From: Giovane Perlin Date: Sun, 30 Nov 2025 22:04:30 -0400 Subject: [PATCH] feat: adds an option to run a script after a screenshot --- include/Config.hpp | 4 +++- include/gui/ScreenshotSettingsPage.hpp | 6 ++++- src/Config.cpp | 5 +++-- src/Overlay.cpp | 5 +++++ src/gui/ScreenshotSettingsPage.cpp | 31 +++++++++++++++++++++++--- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/include/Config.hpp b/include/Config.hpp index 1445fbc..fbb3d40 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -146,6 +146,8 @@ namespace gsr { ConfigHotkey take_screenshot_hotkey; ConfigHotkey take_screenshot_region_hotkey; ConfigHotkey take_screenshot_window_hotkey; // Or desktop portal, on wayland + + std::string custom_script; }; struct Config { @@ -164,4 +166,4 @@ namespace gsr { std::optional read_config(const SupportedCaptureOptions &capture_options); void save_config(Config &config); -} \ No newline at end of file +} diff --git a/include/gui/ScreenshotSettingsPage.hpp b/include/gui/ScreenshotSettingsPage.hpp index 1c021b9..cdcd597 100644 --- a/include/gui/ScreenshotSettingsPage.hpp +++ b/include/gui/ScreenshotSettingsPage.hpp @@ -47,6 +47,9 @@ namespace gsr { std::unique_ptr create_led_indicator(); std::unique_ptr create_general_section(); std::unique_ptr create_screenshot_indicator_section(); + std::unique_ptr create_custom_script_screenshot_section(); + std::unique_ptr create_custom_script_screenshot_entry(); + std::unique_ptr create_custom_script_screenshot(); std::unique_ptr create_settings(); void add_widgets(); @@ -75,7 +78,8 @@ namespace gsr { CheckBox *save_screenshot_to_clipboard_checkbox_ptr = nullptr; CheckBox *show_notification_checkbox_ptr = nullptr; CheckBox *led_indicator_checkbox_ptr = nullptr; + Entry *create_custom_script_screenshot_entry_ptr = nullptr; PageStack *page_stack = nullptr; }; -} \ No newline at end of file +} diff --git a/src/Config.cpp b/src/Config.cpp index b4b051e..4c6798b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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); } -} \ No newline at end of file +} diff --git a/src/Overlay.cpp b/src/Overlay.cpp index cc3fb4a..48f3967 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -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); diff --git a/src/gui/ScreenshotSettingsPage.cpp b/src/gui/ScreenshotSettingsPage.cpp index fd4227d..6f9ce75 100644 --- a/src/gui/ScreenshotSettingsPage.cpp +++ b/src/gui/ScreenshotSettingsPage.cpp @@ -139,7 +139,7 @@ namespace gsr { return list; } - + std::unique_ptr ScreenshotSettingsPage::create_record_cursor_section() { auto record_cursor_checkbox = std::make_unique(&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("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(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("Screenshot indicator", std::move(list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)); } + std::unique_ptr ScreenshotSettingsPage::create_custom_script_screenshot_entry() { + auto list = std::make_unique(List::Orientation::VERTICAL, List::Alignment::CENTER); + + auto create_custom_script_screenshot_entry = std::make_unique(&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 ScreenshotSettingsPage::create_custom_script_screenshot() { + auto custom_script_screenshot_list = std::make_unique(List::Orientation::VERTICAL); + custom_script_screenshot_list->add_widget(std::make_unique