From 13562d2aa1ffcec50c0d0393cf3468d233e4c68d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 25 Dec 2025 08:19:07 +0100 Subject: [PATCH] Add webcam support --- TODO | 2 + depends/mglpp | 2 +- include/Config.hpp | 8 + include/GsrInfo.hpp | 13 ++ include/Theme.hpp | 1 + include/gui/ComboBox.hpp | 2 + include/gui/SettingsPage.hpp | 35 +++ include/gui/Utils.hpp | 4 + src/Config.cpp | 21 ++ src/GsrInfo.cpp | 84 +++++++- src/Overlay.cpp | 92 +++++++- src/Theme.cpp | 3 + src/gui/ComboBox.cpp | 7 + src/gui/CustomRendererWidget.cpp | 10 +- src/gui/ScreenshotSettingsPage.cpp | 2 +- src/gui/ScrollablePage.cpp | 4 +- src/gui/SettingsPage.cpp | 250 +++++++++++++++++++++- src/gui/Utils.cpp | 8 +- tools/gsr-global-hotkeys/keyboard_event.c | 9 +- 19 files changed, 531 insertions(+), 26 deletions(-) diff --git a/TODO b/TODO index 410aaa1..4998345 100644 --- a/TODO +++ b/TODO @@ -253,3 +253,5 @@ Sometimes when opening gpu screen recorder ui gsr-global-hotkeys incorrectly det When running replay for a long time and then stopping it it takes a while. Improve this. When adding webcamera make replay auto start wait for camera to be available (when /dev/video device exists and can be initialized), just like audio device. + +Make it possible to resize webcam box from top left, top right and bottom left as well. \ No newline at end of file diff --git a/depends/mglpp b/depends/mglpp index f69ab7f..cdd4014 160000 --- a/depends/mglpp +++ b/depends/mglpp @@ -1 +1 @@ -Subproject commit f69ab7f0056fdfc722185551365aaf2aeb69cbf7 +Subproject commit cdd401478d8e70a895e06415e95c077f3fdd0ba5 diff --git a/include/Config.hpp b/include/Config.hpp index fbb3d40..a913497 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -61,6 +61,14 @@ namespace gsr { bool record_cursor = true; bool restore_portal_session = true; + std::string webcam_source = ""; + bool webcam_flip_horizontally = false; + std::string webcam_video_format = "auto"; + int32_t webcam_x = 0; // A value between 0 and 100 (percentage) + int32_t webcam_y = 0; // A value between 0 and 100 (percentage) + int32_t webcam_width = 30; // A value between 0 and 100 (percentage), 0 = Don't scale it + int32_t webcam_height = 30; // A value between 0 and 100 (percentage), 0 = Don't scale it + bool show_notifications = true; bool use_led_indicator = false; }; diff --git a/include/GsrInfo.hpp b/include/GsrInfo.hpp index 156125b..d8fcef4 100644 --- a/include/GsrInfo.hpp +++ b/include/GsrInfo.hpp @@ -25,11 +25,22 @@ namespace gsr { bool png = false; }; + struct SupportedCameraPixelFormats { + bool yuyv = false; + bool mjpeg = false; + }; + struct GsrMonitor { std::string name; mgl::vec2i size; }; + struct GsrCamera { + std::string path; + mgl::vec2i size; + SupportedCameraPixelFormats supported_pixel_formats; + }; + struct GsrVersion { uint8_t major = 0; uint8_t minor = 0; @@ -51,6 +62,7 @@ namespace gsr { bool focused = false; bool portal = false; std::vector monitors; + std::vector cameras; }; enum class DisplayServer { @@ -103,4 +115,5 @@ namespace gsr { std::vector get_audio_devices(); std::vector get_application_audio(); SupportedCaptureOptions get_supported_capture_options(const GsrInfo &gsr_info); + std::vector get_v4l2_devices(); } \ No newline at end of file diff --git a/include/Theme.hpp b/include/Theme.hpp index e854e75..855c5d0 100644 --- a/include/Theme.hpp +++ b/include/Theme.hpp @@ -24,6 +24,7 @@ namespace gsr { mgl::Font body_font; mgl::Font title_font; mgl::Font top_bar_font; + mgl::Font camera_setup_font; mgl::Texture combobox_arrow_texture; mgl::Texture settings_texture; diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp index e2eb082..dd35a32 100644 --- a/include/gui/ComboBox.hpp +++ b/include/gui/ComboBox.hpp @@ -19,6 +19,8 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; void add_item(const std::string &text, const std::string &id); + void clear_items(); + // The item can only be selected if it's enabled void set_selected_item(const std::string &id, bool trigger_event = true, bool trigger_event_even_if_selection_not_changed = true); void set_item_enabled(const std::string &id, bool enabled); diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp index 928242d..db3f7fb 100644 --- a/include/gui/SettingsPage.hpp +++ b/include/gui/SettingsPage.hpp @@ -25,6 +25,14 @@ namespace gsr { INPUT }; + enum class WebcamBoxResizeCorner { + NONE, + //TOP_LEFT, + //TOP_RIGHT, + //BOTTOM_LEFT, + BOTTOM_RIGHT + }; + class SettingsPage : public StaticPage { public: enum class Type { @@ -58,6 +66,9 @@ namespace gsr { std::unique_ptr create_restore_portal_session_section(); std::unique_ptr create_change_video_resolution_section(); std::unique_ptr create_capture_target_section(); + std::unique_ptr create_webcam_sources(); + std::unique_ptr create_webcam_video_format(); + std::unique_ptr create_webcam_section(); std::unique_ptr create_audio_device_selection_combobox(AudioDeviceType device_type); std::unique_ptr