aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/AudioPlayer.hpp22
-rw-r--r--include/Config.hpp36
-rw-r--r--include/GlobalHotkeys.hpp21
-rw-r--r--include/GlobalHotkeysJoystick.hpp54
-rw-r--r--include/GlobalHotkeysLinux.hpp14
-rw-r--r--include/GlobalHotkeysX11.hpp5
-rw-r--r--include/GsrInfo.hpp21
-rw-r--r--include/Hotplug.hpp33
-rw-r--r--include/Overlay.hpp77
-rw-r--r--include/Process.hpp14
-rw-r--r--include/Rpc.hpp34
-rw-r--r--include/Theme.hpp4
-rw-r--r--include/WindowUtils.hpp30
-rw-r--r--include/gui/Button.hpp7
-rw-r--r--include/gui/GlobalSettingsPage.hpp97
-rw-r--r--include/gui/RadioButton.hpp3
-rw-r--r--include/gui/SettingsPage.hpp66
-rw-r--r--include/gui/Utils.hpp1
18 files changed, 480 insertions, 59 deletions
diff --git a/include/AudioPlayer.hpp b/include/AudioPlayer.hpp
new file mode 100644
index 0000000..22c3be8
--- /dev/null
+++ b/include/AudioPlayer.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <thread>
+
+namespace gsr {
+ // Only plays raw stereo PCM audio in 48000hz in s16le format.
+ // Use this command to convert an audio file (input.wav) to a format playable by this class (output.pcm):
+ // ffmpeg -i input.wav -f s16le -acodec pcm_s16le -ar 48000 output.pcm
+ class AudioPlayer {
+ public:
+ AudioPlayer() = default;
+ ~AudioPlayer();
+ AudioPlayer(const AudioPlayer&) = delete;
+ AudioPlayer& operator=(const AudioPlayer&) = delete;
+
+ bool play(const char *filepath);
+ private:
+ std::thread thread;
+ bool stop_playing_audio = false;
+ int audio_file_fd = -1;
+ };
+} \ No newline at end of file
diff --git a/include/Config.hpp b/include/Config.hpp
index 6044ab8..34c2010 100644
--- a/include/Config.hpp
+++ b/include/Config.hpp
@@ -6,12 +6,17 @@
#include <vector>
#include <optional>
+#define GSR_CONFIG_FILE_VERSION 1
+
namespace gsr {
- struct GsrInfo;
+ struct SupportedCaptureOptions;
struct ConfigHotkey {
- int64_t keysym = 0;
- uint32_t modifiers = 0;
+ int64_t key = 0; // Mgl key
+ uint32_t modifiers = 0; // HotkeyModifier
+
+ bool operator==(const ConfigHotkey &other) const;
+ bool operator!=(const ConfigHotkey &other) const;
};
struct RecordOptions {
@@ -22,7 +27,7 @@ namespace gsr {
int32_t video_height = 0;
int32_t fps = 60;
int32_t video_bitrate = 15000;
- bool merge_audio_tracks = true;
+ 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 change_video_resolution = false;
std::vector<std::string> audio_tracks;
@@ -38,8 +43,12 @@ namespace gsr {
};
struct MainConfig {
- int32_t config_file_version = 0;
+ int32_t config_file_version = GSR_CONFIG_FILE_VERSION;
bool software_encoding_warning_shown = false;
+ std::string hotkeys_enable_option = "enable_hotkeys";
+ std::string joystick_hotkeys_enable_option = "disable_hotkeys";
+ std::string tint_color;
+ ConfigHotkey show_hide_hotkey;
};
struct YoutubeStreamConfig {
@@ -63,7 +72,7 @@ namespace gsr {
YoutubeStreamConfig youtube;
TwitchStreamConfig twitch;
CustomStreamConfig custom;
- ConfigHotkey start_stop_recording_hotkey;
+ ConfigHotkey start_stop_hotkey;
};
struct RecordConfig {
@@ -73,26 +82,29 @@ namespace gsr {
bool show_video_saved_notifications = true;
std::string save_directory;
std::string container = "mp4";
- ConfigHotkey start_stop_recording_hotkey;
- ConfigHotkey pause_unpause_recording_hotkey;
+ ConfigHotkey start_stop_hotkey;
+ ConfigHotkey pause_unpause_hotkey;
};
struct ReplayConfig {
RecordOptions record_options;
std::string turn_on_replay_automatically_mode = "dont_turn_on_automatically";
bool save_video_in_game_folder = false;
+ bool restart_replay_on_save = false;
bool show_replay_started_notifications = true;
bool show_replay_stopped_notifications = true;
bool show_replay_saved_notifications = true;
std::string save_directory;
std::string container = "mp4";
int32_t replay_time = 60;
- ConfigHotkey start_stop_recording_hotkey;
- ConfigHotkey save_recording_hotkey;
+ ConfigHotkey start_stop_hotkey;
+ ConfigHotkey save_hotkey;
};
struct Config {
- Config(const GsrInfo &gsr_info);
+ Config(const SupportedCaptureOptions &capture_options);
+ bool operator==(const Config &other);
+ bool operator!=(const Config &other);
MainConfig main_config;
StreamingConfig streaming_config;
@@ -100,6 +112,6 @@ namespace gsr {
ReplayConfig replay_config;
};
- std::optional<Config> read_config(const GsrInfo &gsr_info);
+ std::optional<Config> read_config(const SupportedCaptureOptions &capture_options);
void save_config(Config &config);
} \ No newline at end of file
diff --git a/include/GlobalHotkeys.hpp b/include/GlobalHotkeys.hpp
index 662113e..2927fa7 100644
--- a/include/GlobalHotkeys.hpp
+++ b/include/GlobalHotkeys.hpp
@@ -4,10 +4,25 @@
#include <functional>
#include <string>
+namespace mgl {
+ class Event;
+}
+
namespace gsr {
+ enum HotkeyModifier : uint32_t {
+ HOTKEY_MOD_LSHIFT = 1 << 0,
+ HOTKEY_MOD_RSHIFT = 1 << 1,
+ HOTKEY_MOD_LCTRL = 1 << 2,
+ HOTKEY_MOD_RCTRL = 1 << 3,
+ HOTKEY_MOD_LALT = 1 << 4,
+ HOTKEY_MOD_RALT = 1 << 5,
+ HOTKEY_MOD_LSUPER = 1 << 6,
+ HOTKEY_MOD_RSUPER = 1 << 7
+ };
+
struct Hotkey {
- uint64_t key = 0;
- uint32_t modifiers = 0;
+ uint32_t key = 0; // X11 keysym
+ uint32_t modifiers = 0; // HotkeyModifier
};
using GlobalHotkeyCallback = std::function<void(const std::string &id)>;
@@ -24,5 +39,7 @@ namespace gsr {
virtual void unbind_all_keys() {}
virtual bool bind_action(const std::string &id, GlobalHotkeyCallback callback) { (void)id; (void)callback; return false; };
virtual void poll_events() = 0;
+ // Returns true if the event wasn't consumed (if the event didn't match a key that has been bound)
+ virtual bool on_event(mgl::Event &event) { (void)event; return true; }
};
} \ No newline at end of file
diff --git a/include/GlobalHotkeysJoystick.hpp b/include/GlobalHotkeysJoystick.hpp
new file mode 100644
index 0000000..69f66df
--- /dev/null
+++ b/include/GlobalHotkeysJoystick.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+#include "GlobalHotkeys.hpp"
+#include "Hotplug.hpp"
+#include <unordered_map>
+#include <optional>
+#include <thread>
+#include <poll.h>
+#include <mglpp/system/Clock.hpp>
+#include <linux/joystick.h>
+
+namespace gsr {
+ static constexpr int max_js_poll_fd = 16;
+
+ class GlobalHotkeysJoystick : public GlobalHotkeys {
+ class GlobalHotkeysJoystickHotplugDelegate;
+ public:
+ GlobalHotkeysJoystick() = default;
+ GlobalHotkeysJoystick(const GlobalHotkeysJoystick&) = delete;
+ GlobalHotkeysJoystick& operator=(const GlobalHotkeysJoystick&) = delete;
+ ~GlobalHotkeysJoystick() override;
+
+ bool start();
+ bool bind_action(const std::string &id, GlobalHotkeyCallback callback) override;
+ void poll_events() override;
+ private:
+ void read_events();
+ void process_js_event(int fd, js_event &event);
+ bool add_device(const char *dev_input_filepath, bool print_error = true);
+ bool remove_device(const char *dev_input_filepath);
+ bool remove_poll_fd(int index);
+ // Returns -1 if not found
+ int get_poll_fd_index_by_dev_input_id(int dev_input_id) const;
+ private:
+ struct ExtraData {
+ int dev_input_id = 0;
+ };
+
+ std::unordered_map<std::string, GlobalHotkeyCallback> bound_actions_by_id;
+ std::thread read_thread;
+
+ pollfd poll_fd[max_js_poll_fd];
+ ExtraData extra_data[max_js_poll_fd];
+ int num_poll_fd = 0;
+ int event_fd = -1;
+ int event_index = -1;
+
+ mgl::Clock double_click_clock;
+ std::optional<double> prev_time_clicked;
+ bool save_replay = false;
+ int hotplug_poll_index = -1;
+ Hotplug hotplug;
+ };
+} \ No newline at end of file
diff --git a/include/GlobalHotkeysLinux.hpp b/include/GlobalHotkeysLinux.hpp
index 62da74e..c9428de 100644
--- a/include/GlobalHotkeysLinux.hpp
+++ b/include/GlobalHotkeysLinux.hpp
@@ -7,18 +7,26 @@
namespace gsr {
class GlobalHotkeysLinux : public GlobalHotkeys {
public:
- GlobalHotkeysLinux();
+ enum class GrabType {
+ ALL,
+ VIRTUAL
+ };
+
+ GlobalHotkeysLinux(GrabType grab_type);
GlobalHotkeysLinux(const GlobalHotkeysLinux&) = delete;
GlobalHotkeysLinux& operator=(const GlobalHotkeysLinux&) = delete;
~GlobalHotkeysLinux() override;
bool start();
- bool bind_action(const std::string &id, GlobalHotkeyCallback callback) override;
+ bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) override;
+ void unbind_all_keys() override;
void poll_events() override;
private:
pid_t process_id = 0;
- int pipes[2];
+ int read_pipes[2];
+ int write_pipes[2];
FILE *read_file = nullptr;
std::unordered_map<std::string, GlobalHotkeyCallback> bound_actions_by_id;
+ GrabType grab_type;
};
} \ No newline at end of file
diff --git a/include/GlobalHotkeysX11.hpp b/include/GlobalHotkeysX11.hpp
index 427e9f0..610399a 100644
--- a/include/GlobalHotkeysX11.hpp
+++ b/include/GlobalHotkeysX11.hpp
@@ -12,12 +12,15 @@ namespace gsr {
GlobalHotkeysX11& operator=(const GlobalHotkeysX11&) = delete;
~GlobalHotkeysX11() override;
+ // Hotkey key is a KeySym (XK_z for example) and modifiers is a bitmask of X11 modifier masks (for example ShiftMask | Mod1Mask)
bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) override;
void unbind_key_press(const std::string &id) override;
void unbind_all_keys() override;
void poll_events() override;
+ bool on_event(mgl::Event &event) override;
private:
- void call_hotkey_callback(Hotkey hotkey) const;
+ // Returns true if a key bind has been registered for the hotkey
+ bool call_hotkey_callback(Hotkey hotkey) const;
private:
struct HotkeyData {
Hotkey hotkey;
diff --git a/include/GsrInfo.hpp b/include/GsrInfo.hpp
index cd6292c..a8c0742 100644
--- a/include/GsrInfo.hpp
+++ b/include/GsrInfo.hpp
@@ -2,6 +2,7 @@
#include <string>
#include <vector>
+#include <stdint.h>
#include <mglpp/system/vec.hpp>
@@ -24,10 +25,24 @@ namespace gsr {
mgl::vec2i size;
};
+ struct GsrVersion {
+ uint8_t major = 0;
+ uint8_t minor = 0;
+ uint8_t patch = 0;
+
+ bool operator>(const GsrVersion &other) const;
+ bool operator>=(const GsrVersion &other) const;
+ bool operator<(const GsrVersion &other) const;
+ bool operator<=(const GsrVersion &other) const;
+ bool operator==(const GsrVersion &other) const;
+ bool operator!=(const GsrVersion &other) const;
+
+ std::string to_string() const;
+ };
+
struct SupportedCaptureOptions {
bool window = false;
bool focused = false;
- bool screen = false;
bool portal = false;
std::vector<GsrMonitor> monitors;
};
@@ -41,6 +56,7 @@ namespace gsr {
struct SystemInfo {
DisplayServer display_server = DisplayServer::UNKNOWN;
bool supports_app_audio = false;
+ GsrVersion gsr_version;
};
enum class GpuVendor {
@@ -52,13 +68,13 @@ namespace gsr {
struct GpuInfo {
GpuVendor vendor = GpuVendor::UNKNOWN;
+ std::string card_path;
};
struct GsrInfo {
SystemInfo system_info;
GpuInfo gpu_info;
SupportedVideoCodecs supported_video_codecs;
- SupportedCaptureOptions supported_capture_options;
};
enum class GsrInfoExitStatus {
@@ -78,4 +94,5 @@ namespace gsr {
std::vector<AudioDevice> get_audio_devices();
std::vector<std::string> get_application_audio();
+ SupportedCaptureOptions get_supported_capture_options(const GsrInfo &gsr_info);
} \ No newline at end of file
diff --git a/include/Hotplug.hpp b/include/Hotplug.hpp
new file mode 100644
index 0000000..38fe25d
--- /dev/null
+++ b/include/Hotplug.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <functional>
+
+namespace gsr {
+ enum class HotplugAction {
+ ADD,
+ REMOVE
+ };
+
+ using HotplugEventCallback = std::function<void(HotplugAction hotplug_action, const char *devname)>;
+
+ class Hotplug {
+ public:
+ Hotplug() = default;
+ Hotplug(const Hotplug&) = delete;
+ Hotplug& operator=(const Hotplug&) = delete;
+ ~Hotplug();
+
+ bool start();
+ int steal_fd();
+ void process_event_data(int fd, const HotplugEventCallback &callback);
+ private:
+ void parse_netlink_data(const char *line, const HotplugEventCallback &callback);
+ private:
+ int fd = -1;
+ bool started = false;
+ bool event_is_add = false;
+ bool event_is_remove = false;
+ bool subsystem_is_input = false;
+ char event_data[1024];
+ };
+} \ No newline at end of file
diff --git a/include/Overlay.hpp b/include/Overlay.hpp
index 580759c..f3025b2 100644
--- a/include/Overlay.hpp
+++ b/include/Overlay.hpp
@@ -5,6 +5,10 @@
#include "GsrInfo.hpp"
#include "Config.hpp"
#include "window_texture.h"
+#include "WindowUtils.hpp"
+#include "GlobalHotkeysLinux.hpp"
+#include "GlobalHotkeysJoystick.hpp"
+#include "AudioPlayer.hpp"
#include <mglpp/window/Window.hpp>
#include <mglpp/window/Event.hpp>
@@ -14,8 +18,11 @@
#include <mglpp/graphics/Text.hpp>
#include <mglpp/system/Clock.hpp>
+#include <array>
+
namespace gsr {
class DropdownButton;
+ class GlobalHotkeys;
enum class RecordingStatus {
NONE,
@@ -33,13 +40,12 @@ namespace gsr {
class Overlay {
public:
- Overlay(std::string resources_path, GsrInfo gsr_info, egl_functions egl_funcs);
+ Overlay(std::string resources_path, GsrInfo gsr_info, SupportedCaptureOptions capture_options, egl_functions egl_funcs);
Overlay(const Overlay&) = delete;
Overlay& operator=(const Overlay&) = delete;
~Overlay();
void handle_events();
- void on_event(mgl::Event &event);
// Returns false if not visible
bool draw();
@@ -53,16 +59,38 @@ namespace gsr {
void save_replay();
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;
+ void exit();
+
+ const Config& get_config() const;
+
+ void unbind_all_keyboard_hotkeys();
+ void rebind_all_keyboard_hotkeys();
private:
+ void handle_keyboard_mapping_event();
+ void on_event(mgl::Event &event);
+
+ void xi_setup();
+ void handle_xi_events();
void process_key_bindings(mgl::Event &event);
+ void grab_mouse_and_keyboard();
+ void xi_setup_fake_cursor();
+ void xi_grab_all_mouse_devices();
+
+ void close_gpu_screen_recorder_output();
void update_notification_process_status();
+ void save_video_in_current_game_directory(const char *video_filepath, NotificationType notification_type);
+ void on_replay_saved(const char *replay_saved_filepath);
+ void update_gsr_replay_save();
void update_gsr_process_status();
void replay_status_update_status();
void update_focused_fullscreen_status();
void update_power_supply_status();
+ void on_stop_recording(int exit_code);
+
void update_ui_recording_paused();
void update_ui_recording_unpaused();
@@ -79,7 +107,7 @@ namespace gsr {
void on_press_start_replay(bool disable_notification);
void on_press_start_record();
void on_press_start_stream();
- bool update_compositor_texture(const mgl_monitor *monitor);
+ bool update_compositor_texture(const Monitor &monitor);
void force_window_on_top();
private:
@@ -94,11 +122,20 @@ namespace gsr {
std::string resources_path;
GsrInfo gsr_info;
egl_functions egl_funcs;
+ Config config;
+
+ bool visible = false;
+
mgl::Texture window_texture_texture;
mgl::Sprite window_texture_sprite;
mgl::Texture screenshot_texture;
mgl::Sprite screenshot_sprite;
mgl::Rectangle bg_screenshot_overlay;
+
+ mgl::Texture cursor_texture;
+ mgl::Sprite cursor_sprite;
+ mgl::vec2i cursor_hotspot;
+
WindowTexture window_texture;
PageStack page_stack;
mgl::Rectangle top_bar_background;
@@ -106,14 +143,17 @@ namespace gsr {
mgl::Sprite logo_sprite;
CustomRendererWidget close_button_widget;
bool close_button_pressed_inside = false;
- bool visible = false;
uint64_t default_cursor = 0;
+
pid_t gpu_screen_recorder_process = -1;
pid_t notification_process = -1;
- Config config;
+ int gpu_screen_recorder_process_output_fd = -1;
+ FILE *gpu_screen_recorder_process_output_file = nullptr;
+
DropdownButton *replay_dropdown_button_ptr = nullptr;
DropdownButton *record_dropdown_button_ptr = nullptr;
DropdownButton *stream_dropdown_button_ptr = nullptr;
+
mgl::Clock force_window_on_top_clock;
RecordingStatus recording_status = RecordingStatus::NONE;
@@ -124,6 +164,33 @@ namespace gsr {
bool power_supply_connected = false;
bool focused_window_is_fullscreen = false;
+ std::string record_filepath;
+
+ Display *xi_display = nullptr;
+ int xi_opcode = 0;
+ XEvent *xi_input_xev = nullptr;
+ XEvent *xi_output_xev = nullptr;
+
std::array<KeyBinding, 1> key_bindings;
+ bool drawn_first_frame = false;
+
+ bool do_exit = false;
+ std::string exit_reason;
+
+ mgl::vec2i window_size = { 1280, 720 };
+ mgl::vec2i window_pos = { 0, 0 };
+
+ mgl::Clock show_overlay_clock;
+ double show_overlay_timeout_seconds = 0.0;
+
+ std::unique_ptr<GlobalHotkeys> global_hotkeys = nullptr;
+ std::unique_ptr<GlobalHotkeysJoystick> global_hotkeys_js = nullptr;
+ Display *x11_mapping_display = nullptr;
+ XEvent x11_mapping_xev;
+
+ mgl::Clock replay_save_clock;
+ bool replay_save_show_notification = false;
+
+ AudioPlayer audio_player;
};
} \ No newline at end of file
diff --git a/include/Process.hpp b/include/Process.hpp
index 125a880..072ef58 100644
--- a/include/Process.hpp
+++ b/include/Process.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <sys/types.h>
+#include <string>
namespace gsr {
enum class GsrMode {
@@ -12,8 +13,13 @@ namespace gsr {
// Arguments ending with NULL
bool exec_program_daemonized(const char **args);
- // Arguments ending with NULL
- pid_t exec_program(const char **args);
- // |output_buffer| should be at least PATH_MAX in size
- bool read_cmdline_arg0(const char *filepath, char *output_buffer);
+ // Arguments ending with NULL. |read_fd| can be NULL
+ pid_t exec_program(const char **args, int *read_fd);
+ // Arguments ending with NULL. Returns the exit status of the program or -1 on error
+ int exec_program_get_stdout(const char **args, std::string &result);
+ // Arguments ending with NULL. Returns the exit status of the program or -1 on error.
+ // This works the same as |exec_program_get_stdout|, except on flatpak where this runs the program on the
+ // host machine with flatpak-spawn --host
+ int exec_program_on_host_get_stdout(const char **args, std::string &result);
+ pid_t pidof(const char *process_name, pid_t ignore_pid);
} \ No newline at end of file
diff --git a/include/Rpc.hpp b/include/Rpc.hpp
new file mode 100644
index 0000000..d6db218
--- /dev/null
+++ b/include/Rpc.hpp
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <stddef.h>
+#include <functional>
+#include <unordered_map>
+#include <string>
+
+typedef struct _IO_FILE FILE;
+
+namespace gsr {
+ using RpcCallback = std::function<void(const std::string &name)>;
+
+ class Rpc {
+ public:
+ Rpc() = default;
+ Rpc(const Rpc&) = delete;
+ Rpc& operator=(const Rpc&) = delete;
+ ~Rpc();
+
+ bool create(const char *name);
+ bool open(const char *name);
+ bool write(const char *str, size_t size);
+ void poll();
+
+ bool add_handler(const std::string &name, RpcCallback callback);
+ private:
+ bool open_filepath(const char *filepath);
+ private:
+ int fd = 0;
+ FILE *file = nullptr;
+ std::string fifo_filepath;
+ std::unordered_map<std::string, RpcCallback> handlers_by_name;
+ };
+} \ No newline at end of file
diff --git a/include/Theme.hpp b/include/Theme.hpp
index 23bcbb7..185bcdc 100644
--- a/include/Theme.hpp
+++ b/include/Theme.hpp
@@ -8,6 +8,7 @@
#include <string>
namespace gsr {
+ struct Config;
struct GsrInfo;
struct Theme {
@@ -26,6 +27,7 @@ namespace gsr {
mgl::Texture combobox_arrow_texture;
mgl::Texture settings_texture;
+ mgl::Texture settings_small_texture;
mgl::Texture folder_texture;
mgl::Texture up_arrow_texture;
mgl::Texture replay_button_texture;
@@ -56,7 +58,7 @@ namespace gsr {
mgl::Color text_color = mgl::Color(255, 255, 255);
};
- bool init_color_theme(const GsrInfo &gsr_info);
+ bool init_color_theme(const Config &config, const GsrInfo &gsr_info);
void deinit_color_theme();
ColorTheme& get_color_theme();
} \ No newline at end of file
diff --git a/include/WindowUtils.hpp b/include/WindowUtils.hpp
new file mode 100644
index 0000000..99b45e9
--- /dev/null
+++ b/include/WindowUtils.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <mglpp/system/vec.hpp>
+#include <string>
+#include <vector>
+#include <optional>
+#include <X11/Xlib.h>
+
+namespace gsr {
+ enum class WindowCaptureType {
+ FOCUSED,
+ CURSOR
+ };
+
+ struct Monitor {
+ mgl::vec2i position;
+ mgl::vec2i size;
+ };
+
+ std::optional<std::string> get_window_title(Display *dpy, Window window);
+ Window get_focused_window(Display *dpy, WindowCaptureType cap_type);
+ std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type);
+ 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);
+ 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);
+ bool is_compositor_running(Display *dpy, int screen);
+ std::vector<Monitor> get_monitors(Display *dpy);
+} \ No newline at end of file
diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp
index bc1dd94..eb68e99 100644
--- a/include/gui/Button.hpp
+++ b/include/gui/Button.hpp
@@ -5,6 +5,7 @@
#include <mglpp/graphics/Color.hpp>
#include <mglpp/graphics/Text.hpp>
+#include <mglpp/graphics/Sprite.hpp>
namespace gsr {
class Button : public Widget {
@@ -20,15 +21,21 @@ namespace gsr {
mgl::vec2f get_size() override;
void set_border_scale(float scale);
+ void set_bg_hover_color(mgl::Color color);
+ void set_icon(mgl::Texture *texture);
const std::string& get_text() const;
void set_text(std::string str);
std::function<void()> on_click;
private:
+ void scale_sprite_to_button_size();
+ private:
mgl::vec2f size;
mgl::Color bg_color;
+ mgl::Color bg_hover_color;
mgl::Text text;
+ mgl::Sprite sprite;
float border_scale = 0.0015f;
};
} \ No newline at end of file
diff --git a/include/gui/GlobalSettingsPage.hpp b/include/gui/GlobalSettingsPage.hpp
new file mode 100644
index 0000000..580e943
--- /dev/null
+++ b/include/gui/GlobalSettingsPage.hpp
@@ -0,0 +1,97 @@
+#pragma once
+
+#include "StaticPage.hpp"
+#include "../GsrInfo.hpp"
+#include "../Config.hpp"
+
+#include <functional>
+#include <mglpp/window/Event.hpp>
+
+namespace gsr {
+ class Overlay;
+ class GsrPage;
+ class PageStack;
+ class ScrollablePage;
+ class Subsection;
+ class RadioButton;
+ class Button;
+ class List;
+ class CustomRendererWidget;
+
+ enum ConfigureHotkeyType {
+ NONE,
+ REPLAY_START_STOP,
+ REPLAY_SAVE,
+ RECORD_START_STOP,
+ RECORD_PAUSE_UNPAUSE,
+ STREAM_START_STOP,
+ SHOW_HIDE
+ };
+
+ class GlobalSettingsPage : public StaticPage {
+ public:
+ GlobalSettingsPage(Overlay *overlay, const GsrInfo *gsr_info, Config &config, PageStack *page_stack);
+ GlobalSettingsPage(const GlobalSettingsPage&) = delete;
+ GlobalSettingsPage& operator=(const GlobalSettingsPage&) = delete;
+
+ void load();
+ void save();
+ void on_navigate_away_from_page() override;
+
+ bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
+
+ std::function<void(bool enable, int exit_status)> on_startup_changed;
+ 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;
+ private:
+ void load_hotkeys();
+
+ std::unique_ptr<Subsection> create_appearance_subsection(ScrollablePage *parent_page);
+ std::unique_ptr<Subsection> create_startup_subsection(ScrollablePage *parent_page);
+ std::unique_ptr<RadioButton> create_enable_keyboard_hotkeys_button();
+ std::unique_ptr<RadioButton> create_enable_joystick_hotkeys_button();
+ std::unique_ptr<List> create_show_hide_hotkey_options();
+ 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_hotkey_control_buttons();
+ std::unique_ptr<Subsection> create_hotkey_subsection(ScrollablePage *parent_page);
+ std::unique_ptr<Button> create_exit_program_button();
+ std::unique_ptr<Button> create_go_back_to_old_ui_button();
+ std::unique_ptr<Subsection> create_application_options_subsection(ScrollablePage *parent_page);
+ std::unique_ptr<Subsection> create_application_info_subsection(ScrollablePage *parent_page);
+ void add_widgets();
+
+ Button* configure_hotkey_get_button_by_active_type();
+ ConfigHotkey* configure_hotkey_get_config_by_active_type();
+ void for_each_config_hotkey(std::function<void(ConfigHotkey *config_hotkey)> callback);
+ void configure_hotkey_start(ConfigureHotkeyType hotkey_type);
+ void configure_hotkey_cancel();
+ void configure_hotkey_stop_and_save();
+ private:
+ Overlay *overlay = nullptr;
+ Config &config;
+ const GsrInfo *gsr_info = nullptr;
+
+ GsrPage *content_page_ptr = nullptr;
+ PageStack *page_stack = nullptr;
+ RadioButton *tint_color_radio_button_ptr = nullptr;
+ RadioButton *startup_radio_button_ptr = nullptr;
+ RadioButton *enable_keyboard_hotkeys_radio_button_ptr = nullptr;
+ RadioButton *enable_joystick_hotkeys_radio_button_ptr = nullptr;
+
+ Button *turn_replay_on_off_button_ptr = nullptr;
+ Button *save_replay_button_ptr = nullptr;
+ Button *start_stop_recording_button_ptr = nullptr;
+ Button *pause_unpause_recording_button_ptr = nullptr;
+ Button *start_stop_streaming_button_ptr = nullptr;
+ Button *show_hide_button_ptr = nullptr;
+
+ ConfigHotkey configure_config_hotkey;
+ ConfigureHotkeyType configure_hotkey_type = ConfigureHotkeyType::NONE;
+
+ CustomRendererWidget *hotkey_overlay_ptr = nullptr;
+ std::string hotkey_configure_action_name;
+ };
+} \ No newline at end of file
diff --git a/include/gui/RadioButton.hpp b/include/gui/RadioButton.hpp
index a009eab..16d638e 100644
--- a/include/gui/RadioButton.hpp
+++ b/include/gui/RadioButton.hpp
@@ -27,7 +27,8 @@ namespace gsr {
mgl::vec2f get_size() override;
- std::function<void(const std::string &text, const std::string &id)> on_selection_changed;
+ // Return false to revert the change
+ std::function<bool(const std::string &text, const std::string &id)> on_selection_changed;
private:
void update_if_dirty();
private:
diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp
index f18ff65..ad5f05a 100644
--- a/include/gui/SettingsPage.hpp
+++ b/include/gui/SettingsPage.hpp
@@ -10,6 +10,8 @@
#include "../GsrInfo.hpp"
#include "../Config.hpp"
+#include <functional>
+
namespace gsr {
class GsrPage;
class PageStack;
@@ -25,17 +27,19 @@ namespace gsr {
STREAM
};
- SettingsPage(Type type, const GsrInfo &gsr_info, Config &config, PageStack *page_stack);
+ SettingsPage(Type type, const GsrInfo *gsr_info, Config &config, PageStack *page_stack);
SettingsPage(const SettingsPage&) = delete;
SettingsPage& operator=(const SettingsPage&) = delete;
- void load(const GsrInfo &gsr_info);
+ void load();
void save();
void on_navigate_away_from_page() override;
+
+ std::function<void()> on_config_changed;
private:
std::unique_ptr<RadioButton> create_view_radio_button();
- std::unique_ptr<ComboBox> create_record_area_box(const GsrInfo &gsr_info);
- std::unique_ptr<Widget> create_record_area(const GsrInfo &gsr_info);
+ 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();
@@ -48,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(const GsrInfo &gsr_info);
+ std::unique_ptr<Widget> create_capture_target();
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();
@@ -65,13 +69,13 @@ namespace gsr {
std::unique_ptr<Widget> create_audio_track_section();
std::unique_ptr<Widget> create_audio_section();
std::unique_ptr<List> create_video_quality_box();
- std::unique_ptr<Entry> create_video_bitrate_entry();
+ std::unique_ptr<List> create_video_bitrate_entry();
std::unique_ptr<List> create_video_bitrate();
std::unique_ptr<ComboBox> create_color_range_box();
std::unique_ptr<List> create_color_range();
std::unique_ptr<List> create_video_quality_section();
- std::unique_ptr<ComboBox> create_video_codec_box(const GsrInfo &gsr_info);
- std::unique_ptr<List> create_video_codec(const GsrInfo &gsr_info);
+ std::unique_ptr<ComboBox> create_video_codec_box();
+ std::unique_ptr<List> create_video_codec();
std::unique_ptr<ComboBox> create_audio_codec_box();
std::unique_ptr<List> create_audio_codec();
std::unique_ptr<Entry> create_framerate_entry();
@@ -80,24 +84,28 @@ namespace gsr {
std::unique_ptr<List> create_framerate_mode();
std::unique_ptr<List> create_framerate_section();
std::unique_ptr<Widget> create_record_cursor_section();
- std::unique_ptr<Widget> create_video_section(const GsrInfo &gsr_info);
- std::unique_ptr<Widget> create_settings(const GsrInfo &gsr_info);
- void add_widgets(const GsrInfo &gsr_info);
+ std::unique_ptr<Widget> create_video_section();
+ std::unique_ptr<Widget> create_settings();
+ void add_widgets();
- void add_page_specific_widgets(const GsrInfo &gsr_info);
+ void add_page_specific_widgets();
std::unique_ptr<List> create_save_directory(const char *label);
std::unique_ptr<ComboBox> create_container_box();
std::unique_ptr<List> create_container_section();
- std::unique_ptr<Entry> create_replay_time_entry();
+ std::unique_ptr<List> create_replay_time_entry();
std::unique_ptr<List> create_replay_time();
- std::unique_ptr<RadioButton> create_start_replay_automatically(const GsrInfo &gsr_info);
- std::unique_ptr<CheckBox> create_save_replay_in_game_folder(const GsrInfo &gsr_info);
- std::unique_ptr<Label> create_estimated_file_size();
- void update_estimated_file_size();
- std::unique_ptr<CheckBox> create_save_recording_in_game_folder(const GsrInfo &gsr_info);
- void add_replay_widgets(const GsrInfo &gsr_info);
- void add_record_widgets(const GsrInfo &gsr_info);
+ std::unique_ptr<RadioButton> create_start_replay_automatically();
+ std::unique_ptr<CheckBox> create_save_replay_in_game_folder();
+ std::unique_ptr<CheckBox> create_restart_replay_on_save();
+ std::unique_ptr<Label> create_estimated_replay_file_size();
+ void update_estimated_replay_file_size();
+ void update_replay_time_text();
+ std::unique_ptr<CheckBox> create_save_recording_in_game_folder();
+ std::unique_ptr<Label> create_estimated_record_file_size();
+ void update_estimated_record_file_size();
+ void add_replay_widgets();
+ void add_record_widgets();
std::unique_ptr<ComboBox> create_streaming_service_box();
std::unique_ptr<List> create_streaming_service_section();
@@ -105,13 +113,13 @@ namespace gsr {
std::unique_ptr<List> create_stream_url_section();
std::unique_ptr<ComboBox> create_stream_container_box();
std::unique_ptr<List> create_stream_container_section();
- void add_stream_widgets(const GsrInfo &gsr_info);
+ void add_stream_widgets();
- void load_audio_tracks(const RecordOptions &record_options, const GsrInfo &gsr_info);
- void load_common(RecordOptions &record_options, const GsrInfo &gsr_info);
- void load_replay(const GsrInfo &gsr_info);
- void load_record(const GsrInfo &gsr_info);
- void load_stream(const GsrInfo &gsr_info);
+ void load_audio_tracks(const RecordOptions &record_options);
+ void load_common(RecordOptions &record_options);
+ void load_replay();
+ void load_record();
+ void load_stream();
void save_common(RecordOptions &record_options);
void save_replay();
@@ -120,8 +128,10 @@ namespace gsr {
private:
Type type;
Config &config;
+ const GsrInfo *gsr_info = nullptr;
std::vector<AudioDevice> audio_devices;
std::vector<std::string> application_audio;
+ SupportedCaptureOptions capture_options;
GsrPage *content_page_ptr = nullptr;
ScrollablePage *settings_scrollable_page_ptr = nullptr;
@@ -162,6 +172,7 @@ namespace gsr {
List *stream_url_list_ptr = nullptr;
List *container_list_ptr = nullptr;
CheckBox *save_replay_in_game_folder_ptr = nullptr;
+ CheckBox *restart_replay_on_save = nullptr;
Label *estimated_file_size_ptr = nullptr;
CheckBox *show_replay_started_notification_checkbox_ptr = nullptr;
CheckBox *show_replay_stopped_notification_checkbox_ptr = nullptr;
@@ -176,10 +187,9 @@ namespace gsr {
Entry *youtube_stream_key_entry_ptr = nullptr;
Entry *stream_url_entry_ptr = nullptr;
Entry *replay_time_entry_ptr = nullptr;
+ Label *replay_time_label_ptr = nullptr;
RadioButton *turn_on_replay_automatically_mode_ptr = nullptr;
PageStack *page_stack = nullptr;
-
- mgl::Text settings_title_text;
};
} \ No newline at end of file
diff --git a/include/gui/Utils.hpp b/include/gui/Utils.hpp
index 6963bc5..35b2bb7 100644
--- a/include/gui/Utils.hpp
+++ b/include/gui/Utils.hpp
@@ -15,4 +15,5 @@ namespace gsr {
void draw_rectangle_outline(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, mgl::Color color, float border_size);
double get_frame_delta_seconds();
void set_frame_delta_seconds(double frame_delta);
+ mgl::vec2f scale_keep_aspect_ratio(mgl::vec2f from, mgl::vec2f to);
} \ No newline at end of file