diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Config.hpp | 17 | ||||
-rw-r--r-- | include/CursorTracker.hpp | 23 | ||||
-rw-r--r-- | include/CursorTrackerWayland.hpp | 43 | ||||
-rw-r--r-- | include/CursorTrackerX11.hpp | 20 | ||||
-rw-r--r-- | include/GlobalHotkeysLinux.hpp | 2 | ||||
-rw-r--r-- | include/Overlay.hpp | 13 | ||||
-rw-r--r-- | include/SafeVector.hpp | 137 | ||||
-rw-r--r-- | include/Theme.hpp | 1 | ||||
-rw-r--r-- | include/Utils.hpp | 1 | ||||
-rw-r--r-- | include/WindowUtils.hpp | 1 | ||||
-rw-r--r-- | include/gui/List.hpp | 5 | ||||
-rw-r--r-- | include/gui/Page.hpp | 4 | ||||
-rw-r--r-- | include/gui/ScrollablePage.hpp | 1 | ||||
-rw-r--r-- | include/gui/SettingsPage.hpp | 35 | ||||
-rw-r--r-- | include/gui/Subsection.hpp | 5 | ||||
-rw-r--r-- | include/gui/Widget.hpp | 6 |
16 files changed, 247 insertions, 67 deletions
diff --git a/include/Config.hpp b/include/Config.hpp index 0e8e4eb..bbb5381 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -6,7 +6,7 @@ #include <vector> #include <optional> -#define GSR_CONFIG_FILE_VERSION 1 +#define GSR_CONFIG_FILE_VERSION 2 namespace gsr { struct SupportedCaptureOptions; @@ -30,6 +30,14 @@ namespace gsr { std::string to_string(bool spaces = true, bool modifier_side = true) const; }; + struct AudioTrack { + std::vector<std::string> audio_inputs; // ids + bool application_audio_invert = false; + + bool operator==(const AudioTrack &other) const; + bool operator!=(const AudioTrack &other) const; + }; + struct RecordOptions { std::string record_area_option = "screen"; int32_t record_area_width = 0; @@ -38,10 +46,11 @@ namespace gsr { int32_t video_height = 0; int32_t fps = 60; int32_t video_bitrate = 15000; - bool merge_audio_tracks = true; // Currently unused for streaming because all known streaming sites only support 1 audio track - bool application_audio_invert = false; + 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; - std::vector<std::string> audio_tracks; + std::vector<std::string> audio_tracks; // ids, TODO: Remove in the future + std::vector<AudioTrack> audio_tracks_list; std::string color_range = "limited"; std::string video_quality = "very_high"; std::string video_codec = "auto"; diff --git a/include/CursorTracker.hpp b/include/CursorTracker.hpp new file mode 100644 index 0000000..ff7374f --- /dev/null +++ b/include/CursorTracker.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include <optional> +#include <string> +#include <mglpp/system/vec.hpp> + +namespace gsr { + struct CursorInfo { + mgl::vec2i position; + std::string monitor_name; + }; + + class CursorTracker { + public: + CursorTracker() = default; + CursorTracker(const CursorTracker&) = delete; + CursorTracker& operator=(const CursorTracker&) = delete; + virtual ~CursorTracker() = default; + + virtual void update() = 0; + virtual std::optional<CursorInfo> get_latest_cursor_info() = 0; + }; +}
\ No newline at end of file diff --git a/include/CursorTrackerWayland.hpp b/include/CursorTrackerWayland.hpp new file mode 100644 index 0000000..1eeee83 --- /dev/null +++ b/include/CursorTrackerWayland.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include "CursorTracker.hpp" +#include <stdint.h> +#include <vector> + +struct wl_display; +struct wl_registry; +struct wl_output; +struct zxdg_output_manager_v1; +struct zxdg_output_v1; + +namespace gsr { + struct WaylandOutput { + uint32_t wl_name; + struct wl_output *output; + struct zxdg_output_v1 *xdg_output; + mgl::vec2i pos; + mgl::vec2i size; + int32_t transform; + std::string name; + }; + + class CursorTrackerWayland : public CursorTracker { + public: + CursorTrackerWayland(const char *card_path); + CursorTrackerWayland(const CursorTrackerWayland&) = delete; + CursorTrackerWayland& operator=(const CursorTrackerWayland&) = delete; + ~CursorTrackerWayland(); + + void update() override; + std::optional<CursorInfo> get_latest_cursor_info() override; + + std::vector<WaylandOutput> monitors; + struct zxdg_output_manager_v1 *xdg_output_manager = nullptr; + private: + void set_monitor_outputs_from_xdg_output(struct wl_display *dpy); + private: + int drm_fd = -1; + mgl::vec2i latest_cursor_position; // Position of the cursor within the monitor + int latest_crtc_id = -1; + }; +}
\ No newline at end of file diff --git a/include/CursorTrackerX11.hpp b/include/CursorTrackerX11.hpp new file mode 100644 index 0000000..66618c4 --- /dev/null +++ b/include/CursorTrackerX11.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "CursorTracker.hpp" + +typedef struct _XDisplay Display; + +namespace gsr { + class CursorTrackerX11 : public CursorTracker { + public: + CursorTrackerX11(Display *dpy); + CursorTrackerX11(const CursorTrackerX11&) = delete; + CursorTrackerX11& operator=(const CursorTrackerX11&) = delete; + ~CursorTrackerX11() = default; + + void update() override {} + std::optional<CursorInfo> get_latest_cursor_info() override; + private: + Display *dpy = nullptr; + }; +}
\ No newline at end of file diff --git a/include/GlobalHotkeysLinux.hpp b/include/GlobalHotkeysLinux.hpp index c9428de..959d095 100644 --- a/include/GlobalHotkeysLinux.hpp +++ b/include/GlobalHotkeysLinux.hpp @@ -22,6 +22,8 @@ namespace gsr { void unbind_all_keys() override; void poll_events() override; private: + void close_fds(); + private: pid_t process_id = 0; int read_pipes[2]; int write_pipes[2]; diff --git a/include/Overlay.hpp b/include/Overlay.hpp index d7b8af1..ac9d2b1 100644 --- a/include/Overlay.hpp +++ b/include/Overlay.hpp @@ -9,6 +9,7 @@ #include "GlobalHotkeysJoystick.hpp" #include "AudioPlayer.hpp" #include "RegionSelector.hpp" +#include "CursorTracker.hpp" #include <mglpp/window/Window.hpp> #include <mglpp/window/Event.hpp> @@ -60,10 +61,11 @@ namespace gsr { void save_replay(); void take_screenshot(); void take_screenshot_region(); - void show_notification(const char *str, double timeout_seconds, mgl::Color icon_color, mgl::Color bg_color, NotificationType notification_type); + void show_notification(const char *str, double timeout_seconds, mgl::Color icon_color, mgl::Color bg_color, NotificationType notification_type, const char *capture_target = nullptr); bool is_open() const; bool should_exit(std::string &reason) const; void exit(); + void go_back_to_old_ui(); const Config& get_config() const; @@ -115,6 +117,8 @@ namespace gsr { void on_press_take_screenshot(bool finished_region_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); + void force_window_on_top(); private: using KeyBindingCallback = std::function<void()>; @@ -205,5 +209,12 @@ namespace gsr { RegionSelector region_selector; bool start_region_capture = false; std::function<void()> on_region_selected; + + std::string recording_capture_target; + std::string replay_capture_target; + std::string screenshot_capture_target; + + std::unique_ptr<CursorTracker> cursor_tracker; + mgl::Clock cursor_tracker_update_clock; }; }
\ No newline at end of file diff --git a/include/SafeVector.hpp b/include/SafeVector.hpp index 6cb4725..63125ad 100644 --- a/include/SafeVector.hpp +++ b/include/SafeVector.hpp @@ -1,8 +1,15 @@ #pragma once #include <vector> -#include <memory> #include <functional> +#include <assert.h> +#include "gui/Widget.hpp" + +template <typename T> +struct SafeVectorItem { + T item; + bool alive = false; +}; // A vector that can be modified while iterating template <typename T> @@ -10,64 +17,84 @@ class SafeVector { public: using PointerType = typename std::pointer_traits<T>::element_type*; + SafeVector() = default; + SafeVector(const SafeVector&) = delete; + SafeVector& operator=(const SafeVector&) = delete; + ~SafeVector() { + clear(); + } + void push_back(T item) { - data.push_back(std::move(item)); + data.push_back({std::move(item), true}); + ++num_items_alive; } // Safe to call when vector is empty // TODO: Make this iterator safe void pop_back() { - if(!data.empty()) + if(!data.empty()) { + gsr::add_widget_to_remove(std::move(data.back().item)); data.pop_back(); + --num_items_alive; + } } // Might not remove the data immediately if inside for_each loop. // In that case the item is removed at the end of the loop. void remove(PointerType item_to_remove) { - if(for_each_depth == 0) + if(for_each_depth == 0) { remove_item(item_to_remove); - else - remove_queue.push_back(item_to_remove); + return; + } + + SafeVectorItem<T> *item = get_item(item_to_remove); + if(item && item->alive) { + item->alive = false; + --num_items_alive; + has_items_to_remove = true; + } } // Safe to call when vector is empty, in which case it returns nullptr T* back() { - if(data.empty()) - return nullptr; - else - return &data.back(); + for(auto it = data.rbegin(), end = data.rend(); it != end; ++it) { + if(it->alive) + return &it->item; + } + return nullptr; } // TODO: Make this iterator safe void clear() { + for(auto &item : data) { + gsr::add_widget_to_remove(std::move(item.item)); + } data.clear(); - remove_queue.clear(); + num_items_alive = 0; } // Return true from |callback| to continue. This function returns false if |callback| returned false - bool for_each(std::function<bool(T &t)> callback) { + bool for_each(std::function<bool(T &t)> callback, bool include_dead = false) { bool result = true; ++for_each_depth; for(size_t i = 0; i < data.size(); ++i) { - result = callback(data[i]); - if(!result) - break; + if(data[i].alive || include_dead) { + result = callback(data[i].item); + if(!result) + break; + } } --for_each_depth; - if(for_each_depth == 0) { - for(PointerType item_to_remove : remove_queue) { - remove_item(item_to_remove); - } - remove_queue.clear(); - } + if(for_each_depth == 0) + remove_dead_items(); return result; } // Return true from |callback| to continue. This function returns false if |callback| returned false - bool for_each_reverse(std::function<bool(T &t)> callback) { + bool for_each_reverse(std::function<bool(T &t)> callback, bool include_dead = false) { bool result = true; ++for_each_depth; @@ -80,50 +107,84 @@ public: if(i < 0) break; - result = callback(data[i]); - if(!result) - break; + if(data[i].alive || include_dead) { + result = callback(data[i].item); + if(!result) + break; + } --i; } --for_each_depth; - if(for_each_depth == 0) { - for(PointerType item_to_remove : remove_queue) { - remove_item(item_to_remove); - } - remove_queue.clear(); - } + if(for_each_depth == 0) + remove_dead_items(); return result; } T& operator[](size_t index) { - return data[index]; + assert(index < data.size()); + return data[index].item; } const T& operator[](size_t index) const { - return data[index]; + assert(index < data.size()); + return data[index].item; } size_t size() const { - return data.size(); + return (size_t)num_items_alive; } bool empty() const { - return data.empty(); + return num_items_alive == 0; + } + + void replace_item(PointerType item_to_replace, T new_item) { + SafeVectorItem<T> *item = get_item(item_to_replace); + if(item->alive) { + gsr::add_widget_to_remove(std::move(item->item)); + item->item = std::move(new_item); + } } private: void remove_item(PointerType item_to_remove) { for(auto it = data.begin(), end = data.end(); it != end; ++it) { - if(&*(*it) == item_to_remove) { + if(&*(it->item) == item_to_remove) { + gsr::add_widget_to_remove(std::move(it->item)); data.erase(it); + --num_items_alive; return; } } } + + SafeVectorItem<T>* get_item(PointerType item_to_remove) { + for(auto &item : data) { + if(&*(item.item) == item_to_remove) + return &item; + } + return nullptr; + } + + void remove_dead_items() { + if(!has_items_to_remove) + return; + + for(auto it = data.begin(); it != data.end();) { + if(it->alive) { + ++it; + } else { + gsr::add_widget_to_remove(std::move(it->item)); + it = data.erase(it); + } + } + has_items_to_remove = false; + } private: - std::vector<T> data; - std::vector<PointerType> remove_queue; + std::vector<SafeVectorItem<T>> data; int for_each_depth = 0; + int num_items_alive = 0; + bool has_items_to_remove = false; };
\ No newline at end of file diff --git a/include/Theme.hpp b/include/Theme.hpp index 4305072..670980f 100644 --- a/include/Theme.hpp +++ b/include/Theme.hpp @@ -42,6 +42,7 @@ namespace gsr { mgl::Texture pause_texture; mgl::Texture save_texture; mgl::Texture screenshot_texture; + mgl::Texture trash_texture; mgl::Texture ps4_home_texture; mgl::Texture ps4_options_texture; diff --git a/include/Utils.hpp b/include/Utils.hpp index 19700df..1415209 100644 --- a/include/Utils.hpp +++ b/include/Utils.hpp @@ -14,6 +14,7 @@ namespace gsr { using StringSplitCallback = std::function<bool(std::string_view line)>; void string_split_char(std::string_view str, char delimiter, StringSplitCallback callback_func); + bool starts_with(std::string_view str, const char *substr); std::string get_home_dir(); std::string get_config_dir(); diff --git a/include/WindowUtils.hpp b/include/WindowUtils.hpp index e31eeb2..72d2179 100644 --- a/include/WindowUtils.hpp +++ b/include/WindowUtils.hpp @@ -15,6 +15,7 @@ namespace gsr { struct Monitor { mgl::vec2i position; mgl::vec2i size; + std::string name; }; std::optional<std::string> get_window_title(Display *dpy, Window window); diff --git a/include/gui/List.hpp b/include/gui/List.hpp index 72c5353..f79d165 100644 --- a/include/gui/List.hpp +++ b/include/gui/List.hpp @@ -21,19 +21,20 @@ namespace gsr { List(Orientation orientation, Alignment content_alignment = Alignment::START); List(const List&) = delete; List& operator=(const List&) = delete; + virtual ~List() override; bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; - //void remove_child_widget(Widget *widget) override; - void add_widget(std::unique_ptr<Widget> widget); void remove_widget(Widget *widget); + void replace_widget(Widget *widget, std::unique_ptr<Widget> new_widget); void clear(); // Return true from |callback| to continue void for_each_child_widget(std::function<bool(std::unique_ptr<Widget> &widget)> callback); // Returns nullptr if index is invalid Widget* get_child_widget_by_index(size_t index) const; + size_t get_num_children() const; void set_spacing(float spacing); diff --git a/include/gui/Page.hpp b/include/gui/Page.hpp index 0d8536a..00a53c6 100644 --- a/include/gui/Page.hpp +++ b/include/gui/Page.hpp @@ -10,13 +10,11 @@ namespace gsr { Page() = default; Page(const Page&) = delete; Page& operator=(const Page&) = delete; - virtual ~Page() = default; + virtual ~Page() override; virtual void on_navigate_to_page() {} virtual void on_navigate_away_from_page() {} - //void remove_child_widget(Widget *widget) override; - virtual void add_widget(std::unique_ptr<Widget> widget); protected: SafeVector<std::unique_ptr<Widget>> widgets; diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp index 452d0e9..54ec2cb 100644 --- a/include/gui/ScrollablePage.hpp +++ b/include/gui/ScrollablePage.hpp @@ -12,6 +12,7 @@ namespace gsr { ScrollablePage(mgl::vec2f size); ScrollablePage(const ScrollablePage&) = delete; ScrollablePage& operator=(const ScrollablePage&) = delete; + virtual ~ScrollablePage() override; bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp index b9f5cde..fb705cc 100644 --- a/include/gui/SettingsPage.hpp +++ b/include/gui/SettingsPage.hpp @@ -18,6 +18,7 @@ namespace gsr { class ScrollablePage; class Label; class LineSeparator; + class Subsection; class SettingsPage : public StaticPage { public: @@ -54,19 +55,20 @@ namespace gsr { std::unique_ptr<Widget> create_change_video_resolution_section(); 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(); - std::unique_ptr<Button> create_add_audio_device_button(); - std::unique_ptr<ComboBox> create_application_audio_selection_combobox(); - std::unique_ptr<List> create_application_audio(); - std::unique_ptr<List> create_custom_application_audio(); - std::unique_ptr<Button> create_add_application_audio_button(); - std::unique_ptr<Button> create_add_custom_application_audio_button(); - std::unique_ptr<List> create_add_audio_buttons(); - std::unique_ptr<List> create_audio_track_track_section(); - std::unique_ptr<CheckBox> create_split_audio_checkbox(); + std::unique_ptr<Button> create_remove_audio_device_button(List *audio_input_list_ptr, List *audio_device_list_ptr); + std::unique_ptr<List> create_audio_device(List *audio_input_list_ptr); + std::unique_ptr<Button> create_add_audio_track_button(); + std::unique_ptr<Button> create_add_audio_device_button(List *audio_input_list_ptr); + std::unique_ptr<ComboBox> create_application_audio_selection_combobox(List *application_audio_row); + std::unique_ptr<List> create_application_audio(List *audio_input_list_ptr); + std::unique_ptr<List> create_custom_application_audio(List *audio_input_list_ptr); + std::unique_ptr<Button> create_add_application_audio_button(List *audio_input_list_ptr); + std::unique_ptr<List> create_add_audio_buttons(List *audio_input_list_ptr); + std::unique_ptr<List> create_audio_input_section(); std::unique_ptr<CheckBox> create_application_audio_invert_checkbox(); - std::unique_ptr<Widget> create_audio_track_section(); + std::unique_ptr<List> create_audio_track_title_and_remove(Subsection *audio_track_subsection, const char *title); + std::unique_ptr<Subsection> create_audio_track_section(Widget *parent_widget); + std::unique_ptr<List> create_audio_track_section_list(); std::unique_ptr<Widget> create_audio_section(); std::unique_ptr<List> create_video_quality_box(); std::unique_ptr<List> create_video_bitrate_entry(); @@ -125,6 +127,8 @@ namespace gsr { void save_replay(); void save_record(); void save_stream(); + + void view_changed(bool advanced_view, Subsection *notifications_subsection_ptr); private: Type type; Config &config; @@ -152,11 +156,6 @@ namespace gsr { Entry *framerate_entry_ptr = nullptr; Entry *video_bitrate_entry_ptr = nullptr; List *video_bitrate_list_ptr = nullptr; - List *audio_track_list_ptr = nullptr; - Button *add_application_audio_button_ptr = nullptr; - Button *add_custom_application_audio_button_ptr = nullptr; - CheckBox *split_audio_checkbox_ptr = nullptr; - CheckBox *application_audio_invert_checkbox_ptr = nullptr; CheckBox *change_video_resolution_checkbox_ptr = nullptr; ComboBox *color_range_box_ptr = nullptr; ComboBox *video_quality_box_ptr = nullptr; @@ -189,6 +188,8 @@ namespace gsr { Entry *replay_time_entry_ptr = nullptr; Label *replay_time_label_ptr = nullptr; RadioButton *turn_on_replay_automatically_mode_ptr = nullptr; + Subsection *audio_section_ptr = nullptr; + List *audio_track_section_list_ptr = nullptr; PageStack *page_stack = nullptr; }; diff --git a/include/gui/Subsection.hpp b/include/gui/Subsection.hpp index 4da6baf..88953d2 100644 --- a/include/gui/Subsection.hpp +++ b/include/gui/Subsection.hpp @@ -11,15 +11,20 @@ namespace gsr { Subsection(const char *title, std::unique_ptr<Widget> inner_widget, mgl::vec2f size); Subsection(const Subsection&) = delete; Subsection& operator=(const Subsection&) = delete; + virtual ~Subsection() override; bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; mgl::vec2f get_size() override; mgl::vec2f get_inner_size() override; + + Widget* get_inner_widget(); + void set_bg_color(mgl::Color color); private: Label label; std::unique_ptr<Widget> inner_widget; mgl::vec2f size; + mgl::Color bg_color{25, 30, 34}; }; }
\ No newline at end of file diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp index 57424cd..131e756 100644 --- a/include/gui/Widget.hpp +++ b/include/gui/Widget.hpp @@ -1,6 +1,7 @@ #pragma once #include <mglpp/system/vec.hpp> +#include <memory> namespace mgl { class Event; @@ -31,8 +32,6 @@ namespace gsr { virtual void draw(mgl::Window &window, mgl::vec2f offset) = 0; virtual void set_position(mgl::vec2f position); - //virtual void remove_child_widget(Widget *widget) { (void)widget; } - virtual mgl::vec2f get_position() const; virtual mgl::vec2f get_size() = 0; // This can be different from get_size, for example with ScrollablePage this excludes the margins @@ -61,4 +60,7 @@ namespace gsr { bool visible = true; }; + + void add_widget_to_remove(std::unique_ptr<Widget> widget); + void remove_widgets_to_be_removed(); }
\ No newline at end of file |