aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2026-08-01 23:08:48 +0200
committerdec05eba <dec05eba@protonmail.com>2026-08-01 23:08:48 +0200
commit9dda64c39d0fdd6409305faff33c217dcf161e60 (patch)
treeb66b522a0af8d0730bef7852cbe9e3b78835fa86 /include
parent40b6a13d14680cfacb3cdb59f04224540b80d9e4 (diff)
Move screenshot capture and CLI commands from main.cpp into separate modules
The list commands return exit codes through args_parser instead of exiting.
Diffstat (limited to 'include')
-rw-r--r--include/args_parser.h24
-rw-r--r--include/cli/commands.h15
-rw-r--r--include/recorder/screenshot.h36
3 files changed, 67 insertions, 8 deletions
diff --git a/include/args_parser.h b/include/args_parser.h
index 9e388ec..813d4c6 100644
--- a/include/args_parser.h
+++ b/include/args_parser.h
@@ -57,23 +57,31 @@ typedef struct {
} typed_value;
} Arg;
+/* These return the exit code that gpu-screen-recorder should exit with */
typedef struct {
- void (*version)(void *userdata);
- void (*info)(void *userdata);
- void (*list_audio_devices)(void *userdata);
- void (*list_application_audio)(void *userdata);
- void (*list_v4l2_devices)(void *userdata);
- void (*list_capture_options)(const char *card_path, void *userdata);
- void (*list_monitors)(void *userdata);
+ int (*version)(void *userdata);
+ int (*info)(void *userdata);
+ int (*list_audio_devices)(void *userdata);
+ int (*list_application_audio)(void *userdata);
+ int (*list_v4l2_devices)(void *userdata);
+ int (*list_capture_options)(const char *card_path, void *userdata);
+ int (*list_monitors)(void *userdata);
} args_handlers;
+typedef enum {
+ ARGS_PARSE_RESULT_ERROR,
+ ARGS_PARSE_RESULT_OK,
+ /* One of the |args_handlers| ran and |command_exit_code| is set */
+ ARGS_PARSE_RESULT_COMMAND_HANDLED
+} args_parse_result;
+
typedef struct {
Arg args[NUM_ARGS];
gsr_recorder_settings settings;
} args_parser;
/* |argv| is stored as a reference */
-bool args_parser_parse(args_parser *self, int argc, char **argv, const args_handlers *args_handlers, void *userdata);
+args_parse_result args_parser_parse(args_parser *self, int argc, char **argv, const args_handlers *args_handlers, void *userdata, int *command_exit_code);
void args_parser_deinit(args_parser *self);
bool args_parser_validate_with_gl_info(args_parser *self, gsr_egl *egl);
diff --git a/include/cli/commands.h b/include/cli/commands.h
new file mode 100644
index 0000000..9ab00f0
--- /dev/null
+++ b/include/cli/commands.h
@@ -0,0 +1,15 @@
+#ifndef GSR_CLI_COMMANDS_H
+#define GSR_CLI_COMMANDS_H
+
+/* These are the |args_handlers| of the argument parser. They return the exit code that gpu-screen-recorder should exit with */
+int version_command(void *userdata);
+int info_command(void *userdata);
+int list_audio_devices_command(void *userdata);
+int list_application_audio_command(void *userdata);
+int list_v4l2_devices(void *userdata);
+int list_capture_options_command(const char *card_path, void *userdata);
+int list_monitors_command(void *userdata);
+
+void run_recording_saved_script_async(const char *script_file, const char *video_file, const char *type);
+
+#endif /* GSR_CLI_COMMANDS_H */
diff --git a/include/recorder/screenshot.h b/include/recorder/screenshot.h
new file mode 100644
index 0000000..057383c
--- /dev/null
+++ b/include/recorder/screenshot.h
@@ -0,0 +1,36 @@
+#ifndef GSR_RECORDER_SCREENSHOT_H
+#define GSR_RECORDER_SCREENSHOT_H
+
+#include <stdbool.h>
+#include <signal.h>
+#include "../egl.h"
+#include "../image_writer.h"
+#include "../plugins.h"
+#include "capture_source.h"
+#include "capture_setup.h"
+#include "settings.h"
+
+typedef struct {
+ const gsr_recorder_settings *settings;
+ gsr_egl *egl;
+ gsr_window *window;
+ gsr_capture_deps *capture_deps;
+ gsr_capture_sources *capture_sources;
+ gsr_image_format image_format;
+ const char **plugin_filepaths;
+ int num_plugin_filepaths;
+ const volatile sig_atomic_t *running;
+ void (*screenshot_saved)(const char *filepath, void *userdata);
+ void *userdata;
+} gsr_screenshot_params;
+
+bool get_image_format_from_filename(const char *filename, gsr_image_format *image_format);
+gsr_color_range image_format_to_color_range(gsr_image_format image_format, int image_quality);
+int video_quality_to_image_quality_value(gsr_video_quality video_quality);
+
+/* Returns a |gsr_error| value. Captures one frame and writes it to |settings->filename| */
+int gsr_screenshot_take(const gsr_screenshot_params *params);
+
+int gsr_load_plugins(gsr_plugins *plugins, const char **plugin_filepaths, int num_plugin_filepaths, const gsr_recorder_settings *settings, gsr_egl *egl, vec2i video_size);
+
+#endif /* GSR_RECORDER_SCREENSHOT_H */