Add x11 window capture (video and screenshot)

This commit is contained in:
dec05eba
2025-05-31 22:54:14 +02:00
parent fded9b8d57
commit 4d7526d21e
19 changed files with 455 additions and 161 deletions

View File

@@ -45,7 +45,7 @@ namespace gsr {
int32_t video_width = 0;
int32_t video_height = 0;
int32_t fps = 60;
int32_t video_bitrate = 15000;
int32_t video_bitrate = 8000;
bool merge_audio_tracks = true; // TODO: Remove in the future
bool application_audio_invert = false; // TODO: Remove in the future
bool change_video_resolution = false;

View File

@@ -9,6 +9,7 @@
#include "GlobalHotkeys/GlobalHotkeysJoystick.hpp"
#include "AudioPlayer.hpp"
#include "RegionSelector.hpp"
#include "WindowSelector.hpp"
#include "CursorTracker/CursorTracker.hpp"
#include <mglpp/window/Window.hpp>
@@ -116,10 +117,10 @@ namespace gsr {
void on_press_save_replay();
void on_press_save_replay_1_min_replay();
void on_press_save_replay_10_min_replay();
bool on_press_start_replay(bool disable_notification, bool finished_region_selection);
void on_press_start_record(bool finished_region_selection);
void on_press_start_stream(bool finished_region_selection);
void on_press_take_screenshot(bool finished_region_selection, bool force_region_capture);
bool on_press_start_replay(bool disable_notification, bool finished_selection);
void on_press_start_record(bool finished_selection);
void on_press_start_stream(bool finished_selection);
void on_press_take_screenshot(bool finished_selection, bool force_region_capture);
bool update_compositor_texture(const Monitor &monitor);
std::string get_capture_target(const std::string &capture_target, const SupportedCaptureOptions &capture_options);
@@ -213,10 +214,15 @@ namespace gsr {
int replay_save_duration_min = 0;
AudioPlayer audio_player;
RegionSelector region_selector;
bool start_region_capture = false;
std::function<void()> on_region_selected;
WindowSelector window_selector;
bool start_window_capture = false;
std::function<void()> on_window_selected;
std::string recording_capture_target;
std::string screenshot_capture_target;

View File

@@ -26,7 +26,6 @@ namespace gsr {
bool failed() const;
bool poll_events();
bool is_selected() const;
bool take_selection();
bool take_canceled();
Region get_selection() const;

View File

@@ -16,6 +16,7 @@ namespace gsr {
void string_split_char(std::string_view str, char delimiter, StringSplitCallback callback_func);
bool starts_with(std::string_view str, const char *substr);
bool ends_with(std::string_view str, const char *substr);
std::string strip(const std::string &str);
std::string get_home_dir();
std::string get_config_dir();

View File

@@ -0,0 +1,33 @@
#pragma once
#include <X11/Xlib.h>
#include <mglpp/graphics/Color.hpp>
namespace gsr {
class WindowSelector {
public:
WindowSelector();
WindowSelector(const WindowSelector&) = delete;
WindowSelector& operator=(const WindowSelector&) = delete;
~WindowSelector();
bool start(mgl::Color border_color);
void stop();
bool is_started() const;
bool failed() const;
bool poll_events();
bool take_selection();
bool take_canceled();
Window get_selection() const;
private:
Display *dpy = nullptr;
Cursor crosshair_cursor = None;
Colormap border_window_colormap = None;
Window border_window = None;
Window selected_window = None;
bool selected = false;
bool canceled = false;
};
}

View File

@@ -24,6 +24,7 @@ namespace gsr {
std::string get_window_name_at_position(Display *dpy, mgl::vec2i position, Window ignore_window);
std::string get_window_name_at_cursor_position(Display *dpy, Window ignore_window);
void set_window_size_not_resizable(Display *dpy, Window window, int width, int height);
Window window_get_target_window_child(Display *display, Window window);
mgl::vec2i get_cursor_position(Display *dpy, Window *window);
mgl::vec2i create_window_get_center_position(Display *display);
std::string get_window_manager_name(Display *display);

View File

@@ -26,7 +26,6 @@ namespace gsr {
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();
@@ -56,7 +55,6 @@ namespace gsr {
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;

View File

@@ -46,7 +46,6 @@ namespace gsr {
std::unique_ptr<RadioButton> create_view_radio_button();
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_area_width_entry();
std::unique_ptr<Entry> create_area_height_entry();
std::unique_ptr<List> create_area_size();
@@ -147,7 +146,6 @@ namespace gsr {
GsrPage *content_page_ptr = nullptr;
ScrollablePage *settings_scrollable_page_ptr = nullptr;
List *settings_list_ptr = nullptr;
List *select_window_list_ptr = nullptr;
List *area_size_list_ptr = nullptr;
List *video_resolution_list_ptr = nullptr;
List *restore_portal_session_list_ptr = nullptr;