Add option to take a screenshot (default hotkey: alt+f1)

This commit is contained in:
dec05eba
2025-02-22 13:31:51 +01:00
parent 8003c209fe
commit 189736c1a9
31 changed files with 1102 additions and 328 deletions

View File

@@ -17,6 +17,8 @@ namespace gsr {
bool operator==(const ConfigHotkey &other) const;
bool operator!=(const ConfigHotkey &other) const;
std::string to_string(bool spaces = true, bool modifier_side = true) const;
};
struct RecordOptions {
@@ -101,15 +103,34 @@ namespace gsr {
ConfigHotkey save_hotkey;
};
struct ScreenshotConfig {
std::string record_area_option = "screen";
int32_t image_width = 0;
int32_t image_height = 0;
bool change_image_resolution = false;
std::string image_quality = "very_high";
std::string image_format = "jpg";
bool record_cursor = true;
bool restore_portal_session = true;
bool save_screenshot_in_game_folder = false;
bool show_screenshot_saved_notifications = true;
std::string save_directory;
ConfigHotkey take_screenshot_hotkey;
};
struct Config {
Config(const SupportedCaptureOptions &capture_options);
bool operator==(const Config &other);
bool operator!=(const Config &other);
void set_hotkeys_to_default();
MainConfig main_config;
StreamingConfig streaming_config;
RecordConfig record_config;
ReplayConfig replay_config;
ScreenshotConfig screenshot_config;
};
std::optional<Config> read_config(const SupportedCaptureOptions &capture_options);

View File

@@ -20,6 +20,11 @@ namespace gsr {
bool vp9 = false;
};
struct SupportedImageFormats {
bool jpeg = false;
bool png = false;
};
struct GsrMonitor {
std::string name;
mgl::vec2i size;
@@ -75,6 +80,7 @@ namespace gsr {
SystemInfo system_info;
GpuInfo gpu_info;
SupportedVideoCodecs supported_video_codecs;
SupportedImageFormats supported_image_formats;
};
enum class GsrInfoExitStatus {

View File

@@ -35,7 +35,8 @@ namespace gsr {
NONE,
RECORD,
REPLAY,
STREAM
STREAM,
SCREENSHOT
};
class Overlay {
@@ -57,6 +58,7 @@ namespace gsr {
void toggle_stream();
void toggle_replay();
void save_replay();
void take_screenshot();
void show_notification(const char *str, double timeout_seconds, mgl::Color icon_color, mgl::Color bg_color, NotificationType notification_type);
bool is_open() const;
bool should_exit(std::string &reason) const;
@@ -70,6 +72,7 @@ namespace gsr {
void handle_keyboard_mapping_event();
void on_event(mgl::Event &event);
void create_frontpage_ui_components();
void xi_setup();
void handle_xi_events();
void process_key_bindings(mgl::Event &event);
@@ -84,6 +87,7 @@ namespace gsr {
void on_replay_saved(const char *replay_saved_filepath);
void update_gsr_replay_save();
void update_gsr_process_status();
void update_gsr_screenshot_process_status();
void replay_status_update_status();
void update_focused_fullscreen_status();
@@ -107,6 +111,7 @@ namespace gsr {
void on_press_start_replay(bool disable_notification);
void on_press_start_record();
void on_press_start_stream();
void on_press_take_screenshot();
bool update_compositor_texture(const Monitor &monitor);
void force_window_on_top();
@@ -149,6 +154,7 @@ namespace gsr {
pid_t notification_process = -1;
int gpu_screen_recorder_process_output_fd = -1;
FILE *gpu_screen_recorder_process_output_file = nullptr;
pid_t gpu_screen_recorder_screenshot_process = -1;
DropdownButton *replay_dropdown_button_ptr = nullptr;
DropdownButton *record_dropdown_button_ptr = nullptr;
@@ -165,6 +171,7 @@ namespace gsr {
bool focused_window_is_fullscreen = false;
std::string record_filepath;
std::string screenshot_filepath;
Display *xi_display = nullptr;
int xi_opcode = 0;

View File

@@ -41,6 +41,7 @@ namespace gsr {
mgl::Texture stop_texture;
mgl::Texture pause_texture;
mgl::Texture save_texture;
mgl::Texture screenshot_texture;
double double_click_timeout_seconds = 0.4;

View File

@@ -24,6 +24,8 @@ namespace gsr {
std::map<std::string, std::string> get_xdg_variables();
std::string get_videos_dir();
std::string get_pictures_dir();
// Returns 0 on success
int create_directory_recursive(char *path);
bool file_get_content(const char *filepath, std::string &file_content);

View File

@@ -30,6 +30,7 @@ namespace gsr {
std::function<void()> on_click;
private:
void scale_sprite_to_button_size();
float get_button_height();
private:
mgl::vec2f size;
mgl::Color bg_color;

View File

@@ -20,6 +20,7 @@ namespace gsr {
void add_item(const std::string &text, const std::string &id, const std::string &description = "");
void set_item_label(const std::string &id, const std::string &new_label);
void set_item_icon(const std::string &id, mgl::Texture *texture);
void set_item_description(const std::string &id, const std::string &new_description);
void set_description(std::string description_text);
void set_activated(bool activated);

View File

@@ -25,6 +25,7 @@ namespace gsr {
RECORD_START_STOP,
RECORD_PAUSE_UNPAUSE,
STREAM_START_STOP,
TAKE_SCREENSHOT,
SHOW_HIDE
};
@@ -44,6 +45,7 @@ namespace gsr {
std::function<void(const char *reason)> on_click_exit_program_button;
std::function<void(const char *hotkey_option)> on_keyboard_hotkey_changed;
std::function<void(const char *hotkey_option)> on_joystick_hotkey_changed;
std::function<void()> on_page_closed;
private:
void load_hotkeys();
@@ -55,6 +57,7 @@ namespace gsr {
std::unique_ptr<List> create_replay_hotkey_options();
std::unique_ptr<List> create_record_hotkey_options();
std::unique_ptr<List> create_stream_hotkey_options();
std::unique_ptr<List> create_screenshot_hotkey_options();
std::unique_ptr<List> create_hotkey_control_buttons();
std::unique_ptr<Subsection> create_hotkey_subsection(ScrollablePage *parent_page);
std::unique_ptr<Button> create_exit_program_button();
@@ -86,6 +89,7 @@ namespace gsr {
Button *start_stop_recording_button_ptr = nullptr;
Button *pause_unpause_recording_button_ptr = nullptr;
Button *start_stop_streaming_button_ptr = nullptr;
Button *take_screenshot_button_ptr = nullptr;
Button *show_hide_button_ptr = nullptr;
ConfigHotkey configure_config_hotkey;

View File

@@ -9,7 +9,7 @@
namespace gsr {
class GsrPage : public Page {
public:
GsrPage();
GsrPage(const char *top_text, const char *bottom_text);
GsrPage(const GsrPage&) = delete;
GsrPage& operator=(const GsrPage&) = delete;
@@ -42,7 +42,8 @@ namespace gsr {
float margin_bottom_scale = 0.0f;
float margin_left_scale = 0.0f;
float margin_right_scale = 0.0f;
mgl::Text label_text;
mgl::Text top_text;
mgl::Text bottom_text;
std::vector<ButtonItem> buttons;
};
}

View File

@@ -0,0 +1,78 @@
#pragma once
#include "StaticPage.hpp"
#include "List.hpp"
#include "ComboBox.hpp"
#include "Entry.hpp"
#include "CheckBox.hpp"
#include "../GsrInfo.hpp"
#include "../Config.hpp"
namespace gsr {
class PageStack;
class GsrPage;
class ScrollablePage;
class Button;
class ScreenshotSettingsPage : public StaticPage {
public:
ScreenshotSettingsPage(const GsrInfo *gsr_info, Config &config, PageStack *page_stack);
ScreenshotSettingsPage(const ScreenshotSettingsPage&) = delete;
ScreenshotSettingsPage& operator=(const ScreenshotSettingsPage&) = delete;
void load();
void save();
void on_navigate_away_from_page() override;
private:
std::unique_ptr<ComboBox> create_record_area_box();
std::unique_ptr<Widget> create_record_area();
std::unique_ptr<List> create_select_window();
std::unique_ptr<Entry> create_image_width_entry();
std::unique_ptr<Entry> create_image_height_entry();
std::unique_ptr<List> create_image_resolution();
std::unique_ptr<List> create_image_resolution_section();
std::unique_ptr<CheckBox> create_restore_portal_session_checkbox();
std::unique_ptr<List> create_restore_portal_session_section();
std::unique_ptr<Widget> create_change_image_resolution_section();
std::unique_ptr<Widget> create_capture_target_section();
std::unique_ptr<List> create_image_quality_section();
std::unique_ptr<Widget> create_record_cursor_section();
std::unique_ptr<Widget> create_image_section();
std::unique_ptr<List> create_save_directory(const char *label);
std::unique_ptr<ComboBox> create_image_format_box();
std::unique_ptr<List> create_image_format_section();
std::unique_ptr<Widget> create_file_info_section();
std::unique_ptr<CheckBox> create_save_screenshot_in_game_folder();
std::unique_ptr<Widget> create_general_section();
std::unique_ptr<Widget> create_notifications_section();
std::unique_ptr<Widget> create_settings();
void add_widgets();
void save(RecordOptions &record_options);
private:
Config &config;
const GsrInfo *gsr_info = nullptr;
SupportedCaptureOptions capture_options;
GsrPage *content_page_ptr = nullptr;
ScrollablePage *settings_scrollable_page_ptr = nullptr;
List *select_window_list_ptr = nullptr;
List *image_resolution_list_ptr = nullptr;
List *restore_portal_session_list_ptr = nullptr;
List *color_range_list_ptr = nullptr;
Widget *image_format_ptr = nullptr;
ComboBox *record_area_box_ptr = nullptr;
Entry *image_width_entry_ptr = nullptr;
Entry *image_height_entry_ptr = nullptr;
CheckBox *record_cursor_checkbox_ptr = nullptr;
CheckBox *restore_portal_session_checkbox_ptr = nullptr;
CheckBox *change_image_resolution_checkbox_ptr = nullptr;
ComboBox *image_quality_box_ptr = nullptr;
ComboBox *image_format_box_ptr = nullptr;
Button *save_directory_button_ptr = nullptr;
CheckBox *save_screenshot_in_game_folder_checkbox_ptr = nullptr;
CheckBox *show_screenshot_saved_notification_checkbox_ptr = nullptr;
PageStack *page_stack = nullptr;
};
}

View File

@@ -52,7 +52,7 @@ namespace gsr {
std::unique_ptr<CheckBox> create_restore_portal_session_checkbox();
std::unique_ptr<List> create_restore_portal_session_section();
std::unique_ptr<Widget> create_change_video_resolution_section();
std::unique_ptr<Widget> create_capture_target();
std::unique_ptr<Widget> create_capture_target_section();
std::unique_ptr<ComboBox> create_audio_device_selection_combobox();
std::unique_ptr<Button> create_remove_audio_device_button(List *audio_device_list_ptr);
std::unique_ptr<List> create_audio_device();