mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-04-05 11:16:28 +09:00
Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71d28f8ba3 | ||
|
|
bb1e9c6616 | ||
|
|
e14bb0cbcf | ||
|
|
5a13bd2491 | ||
|
|
b875f96885 | ||
|
|
0d3d4229bf | ||
|
|
ed23f56a29 | ||
|
|
a9a1f9d01c | ||
|
|
2506750243 | ||
|
|
f017f04bdc | ||
|
|
d1f8db3760 | ||
|
|
0995e86e89 | ||
|
|
4992185323 | ||
|
|
70df557c2b | ||
|
|
be07070789 | ||
|
|
2bc2252d30 | ||
|
|
9af3c85161 | ||
|
|
d7f6d2cc0c | ||
|
|
0f5b225107 | ||
|
|
85e8b04ee2 | ||
|
|
a6b1111230 | ||
|
|
d70b36000f | ||
|
|
12c090c7d3 | ||
|
|
d9496e0a0a | ||
|
|
c4ff7fd6b8 | ||
|
|
5bd600fad6 | ||
|
|
5144994575 | ||
|
|
1c24616388 | ||
|
|
ecd9a1f13f | ||
|
|
4181d80405 | ||
|
|
085f4d8bad | ||
|
|
bb320e97ed | ||
|
|
ccf96030da | ||
|
|
ca4061f171 | ||
|
|
0b4af1e6bb | ||
|
|
9e03cd0354 | ||
|
|
3d4badf5cd | ||
|
|
071ecf46de |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@ compile_commands.json
|
||||
|
||||
**/xdg-output-unstable-v1-client-protocol.h
|
||||
**/xdg-output-unstable-v1-protocol.c
|
||||
|
||||
depends/.wraplock
|
||||
|
||||
@@ -37,8 +37,8 @@ There are also additional dependencies needed at runtime:
|
||||
* [GPU Screen Recorder Notification](https://git.dec05eba.com/gpu-screen-recorder-notification/)
|
||||
|
||||
## Program behavior notes
|
||||
This program has to grab all keyboards and create a virtual keyboard (`gsr-ui virtual keyboard`) to make global hotkeys work on all Wayland compositors.\
|
||||
This might cause issues for you if you use keyboard remapping software. To workaround this you can go into settings and select "Only grab virtual devices".\
|
||||
By default this program has to grab all keyboards and creates a virtual keyboard (`gsr-ui virtual keyboard`) to make global hotkeys work on all Wayland compositors.\
|
||||
This might cause issues for you if you use keyboard remapping software. To workaround this you can go into settings and select "Yes, but only grab virtual devices" or "Yes, but don't grab devices".\
|
||||
If you use keyboard remapping software such as keyd then make sure to make it ignore "gsr-ui virtual keyboard" (dec0:5eba device id), otherwise your keyboard can get locked
|
||||
as gpu screen recorder tries to grab keys and keyd grabs gpu screen recorder, leading to a lock.\
|
||||
If you are stuck in such a lock where you cant press and keyboard keys you can press (left) ctrl+shift+alt+esc to close gpu screen recorder and remove it from system startup.
|
||||
@@ -71,3 +71,8 @@ I'm looking for somebody that can create sound effects for the notifications.
|
||||
If you have previously used the flatpak version of GPU Screen Recorder with the new UI then the non-flatpak version of the systemd service will conflict with that. Run `gsr-ui` to fix that.
|
||||
## I use a non-qwerty keyboard layout and I have an issue with incorrect keys registered in the software
|
||||
This is a KDE Plasma Wayland issue. Use `setxkbmap <language>` command, for example `setxkbmap se` to make sure X11 applications (such as this one) gets updated to use your languages keyboard layout.
|
||||
## "Save to clipboard" option doesn't work for screenshots
|
||||
Some Wayland compositors don't support copying images on the clipboard between X11 and Wayland applications. GPU Screen Recorder UI is an X11 application. It can't be done properly on Wayland
|
||||
since Wayland doesn't support a non-focused application from setting the clipboard, so it can't work with GPU Screen Recorder hotkey usage. Use X11 if you want a functioning desktop.
|
||||
## The controller hotkey and steam overlap (home button brings up steam overlay)
|
||||
You can either disable the steam overlay or in steam click Steam->Settings->Controller and then click "Begin Test" under "Test Device Inputs". Click on "Setup Device Inputs" and configure controller buttons there and when you get to the home button press X to unbind it from steam.
|
||||
|
||||
44
TODO
44
TODO
@@ -84,9 +84,6 @@ Dont put widget position to int position when scrolling. This makes the UI jitte
|
||||
|
||||
Show warning if another instance of gpu screen recorder is already running when starting recording?
|
||||
|
||||
Keyboard leds get turned off when stopping gsr-global-hotkeys (for example numlock). The numlock key has to be pressed twice again to make it look correct to match its state.
|
||||
Fix this by writing 0 or 1 to /sys/class/leds/input2::numlock/brightness.
|
||||
|
||||
Make gsr-ui flatpak systemd work nicely with non-flatpak gsr-ui. Maybe change ExecStart to do flatpak run ... || gsr-ui, but make it run as a shell command first with /bin/sh -c "".
|
||||
|
||||
When enabling X11 global hotkey again only grab lalt, not ralt.
|
||||
@@ -210,4 +207,43 @@ Window selection doesn't work when a window is fullscreen on x11.
|
||||
Make it possible to change replay duration of the "save 1 min" and "save 10 min" by adding them to the replay settings as options.
|
||||
|
||||
If replay duration is set below the "save 1 min" or "save 10 min" then gray them out and when hovering over those buttons
|
||||
show a tooltip that says that those buttons cant be used because the replay duration in replay settings is set to a lower value than that (and display the replay duration there).
|
||||
show a tooltip that says that those buttons cant be used because the replay duration in replay settings is set to a lower value than that (and display the replay duration there).
|
||||
|
||||
The UI is unusable on a vertical monitor.
|
||||
|
||||
Steam overlay interfers with controller input in gsr ui. Maybe move controller handling the gsr-global-hotkeys to do a grab on the controller, to only give the key input to gsr ui.
|
||||
|
||||
For joysticks (gamepads) create a virtual device for each one (/dev/uinput) that has the same vendor, product and name. This is to make sure that it behaves the same way in applications since applications
|
||||
access joysticks directly through /dev/input/eventN or /dev/input/jsN. It needs the same number of buttons and pretend to be a controller of the same time, for example a ps4 controller
|
||||
so that games automatically display ps4 buttons if supported.
|
||||
This also allows us to copy event bits and other data from the device instead of saying we support everything.
|
||||
This should fix the issue of not being able to write to /dev/uinput with ABS_X event bit set.
|
||||
Maybe do this for regular keyboard inputs as well?
|
||||
|
||||
Use generic icons for controller input in settings and allow configuring them.
|
||||
|
||||
Add option to include game name in file name (video and screenshot). Replace / with space.
|
||||
|
||||
Check if the focused window is on top on x11 when choosing to take screenshot or show the window as the background of the overlay.
|
||||
|
||||
Convert clipboard image to requested type (from jpg to png for example).
|
||||
|
||||
Save clipboard image with wayland on wayland. Some wayland compositors (such as hyprland, budgie and maybe more (wlroots based ones?)) don't support copying clipboard image data from x11 applications to wayland applications.
|
||||
This can be done because retarded wayland only supports setting clipboard when the application has focus. This doesn't work with hotkey screenshot use.
|
||||
This is specifically an issue when using wl_data_device_manager, which is a standard protocol. It can be done when using wlr specific protocol.
|
||||
|
||||
When gsr supports pausing recording done in replay/streaming session then add support for that in gsr-ui as well.
|
||||
|
||||
Add recording timer when recording to show for how long we have been recording for. Maybe the same for live streaming and replay.
|
||||
|
||||
Add option to trim video in the ui. Show a list of all videos recorded so you dont have to navigate to them (maybe add option to manually navigate to a video as well). Maybe use mpv to view it (embedded) in the ui and trim regions (multiple) and ffmpeg command to trim it.
|
||||
|
||||
Show the currently recorded capture in the ui, to preview if everything looks ok. This is also good for webcam overlay. Do this when gsr supports rpc, which would also include an option to get a fd to the capture texture.
|
||||
|
||||
Show a question mark beside options. When hovering the question mark show a tooltip that explains the options.
|
||||
|
||||
Remove all mgl::Clock usage in Overlay. We only need to get the time once per update in Overlay::handle_events. Also get time in other places outside handle_events.
|
||||
|
||||
Handle stopping replay/stream when recording is running (show notification that the video is saved and move the video to folder with game name).
|
||||
|
||||
Support translations.
|
||||
Submodule depends/mglpp updated: 6e720fe411...b569045831
@@ -60,11 +60,15 @@ namespace gsr {
|
||||
bool overclock = false;
|
||||
bool record_cursor = true;
|
||||
bool restore_portal_session = true;
|
||||
|
||||
bool show_notifications = true;
|
||||
bool use_led_indicator = false;
|
||||
};
|
||||
|
||||
struct MainConfig {
|
||||
int32_t config_file_version = GSR_CONFIG_FILE_VERSION;
|
||||
bool software_encoding_warning_shown = false;
|
||||
bool wayland_warning_shown = false;
|
||||
std::string hotkeys_enable_option = "enable_hotkeys";
|
||||
std::string joystick_hotkeys_enable_option = "disable_hotkeys";
|
||||
std::string tint_color;
|
||||
@@ -92,8 +96,6 @@ namespace gsr {
|
||||
|
||||
struct StreamingConfig {
|
||||
RecordOptions record_options;
|
||||
bool show_streaming_started_notifications = true;
|
||||
bool show_streaming_stopped_notifications = true;
|
||||
std::string streaming_service = "twitch";
|
||||
YoutubeStreamConfig youtube;
|
||||
TwitchStreamConfig twitch;
|
||||
@@ -105,9 +107,6 @@ namespace gsr {
|
||||
struct RecordConfig {
|
||||
RecordOptions record_options;
|
||||
bool save_video_in_game_folder = false;
|
||||
bool show_recording_started_notifications = true;
|
||||
bool show_video_saved_notifications = true;
|
||||
bool show_video_paused_notifications = true;
|
||||
std::string save_directory;
|
||||
std::string container = "mp4";
|
||||
ConfigHotkey start_stop_hotkey;
|
||||
@@ -119,9 +118,6 @@ namespace gsr {
|
||||
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;
|
||||
@@ -144,7 +140,8 @@ namespace gsr {
|
||||
|
||||
bool save_screenshot_in_game_folder = false;
|
||||
bool save_screenshot_to_clipboard = false;
|
||||
bool show_screenshot_saved_notifications = true;
|
||||
bool show_notifications = true;
|
||||
bool use_led_indicator = false;
|
||||
std::string save_directory;
|
||||
ConfigHotkey take_screenshot_hotkey;
|
||||
ConfigHotkey take_screenshot_region_hotkey;
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace gsr {
|
||||
std::vector<WaylandOutput> monitors;
|
||||
struct zxdg_output_manager_v1 *xdg_output_manager = nullptr;
|
||||
private:
|
||||
void clear_monitors();
|
||||
void set_monitor_outputs_from_xdg_output(struct wl_display *dpy);
|
||||
private:
|
||||
int drm_fd = -1;
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
#include "../Hotplug.hpp"
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <poll.h>
|
||||
#include <linux/joystick.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
namespace gsr {
|
||||
static constexpr int max_js_poll_fd = 16;
|
||||
@@ -30,8 +32,10 @@ namespace gsr {
|
||||
bool bind_action(const std::string &id, GlobalHotkeyCallback callback) override;
|
||||
void poll_events() override;
|
||||
private:
|
||||
void close_fds();
|
||||
void read_events();
|
||||
void process_js_event(int fd, js_event &event);
|
||||
void process_input_event(int fd, input_event &event);
|
||||
void add_all_joystick_devices();
|
||||
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);
|
||||
@@ -45,6 +49,11 @@ namespace gsr {
|
||||
std::unordered_map<std::string, GlobalHotkeyCallback> bound_actions_by_id;
|
||||
std::thread read_thread;
|
||||
|
||||
std::thread close_fd_thread;
|
||||
std::vector<int> fds_to_close;
|
||||
std::mutex close_fd_mutex;
|
||||
std::condition_variable close_fd_cv;
|
||||
|
||||
pollfd poll_fd[max_js_poll_fd];
|
||||
ExtraData extra_data[max_js_poll_fd];
|
||||
int num_poll_fd = 0;
|
||||
@@ -56,8 +65,6 @@ namespace gsr {
|
||||
bool down_pressed = false;
|
||||
bool left_pressed = false;
|
||||
bool right_pressed = false;
|
||||
bool l3_button_pressed = false;
|
||||
bool r3_button_pressed = false;
|
||||
|
||||
bool save_replay = false;
|
||||
bool save_1_min_replay = false;
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace gsr {
|
||||
public:
|
||||
enum class GrabType {
|
||||
ALL,
|
||||
VIRTUAL
|
||||
VIRTUAL,
|
||||
NO_GRAB
|
||||
};
|
||||
|
||||
GlobalHotkeysLinux(GrabType grab_type);
|
||||
@@ -21,6 +22,8 @@ namespace gsr {
|
||||
bool bind_key_press(Hotkey hotkey, const std::string &id, GlobalHotkeyCallback callback) override;
|
||||
void unbind_all_keys() override;
|
||||
void poll_events() override;
|
||||
|
||||
std::function<void()> on_gsr_ui_virtual_keyboard_grabbed;
|
||||
private:
|
||||
void close_fds();
|
||||
private:
|
||||
|
||||
33
include/LedIndicator.hpp
Normal file
33
include/LedIndicator.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
#include <mglpp/system/Clock.hpp>
|
||||
|
||||
namespace gsr {
|
||||
class LedIndicator {
|
||||
public:
|
||||
LedIndicator();
|
||||
LedIndicator(const LedIndicator&) = delete;
|
||||
LedIndicator& operator=(const LedIndicator&) = delete;
|
||||
~LedIndicator();
|
||||
|
||||
void set_led(bool enabled);
|
||||
void blink();
|
||||
void update();
|
||||
private:
|
||||
bool run_gsr_global_hotkeys_set_leds(bool enabled);
|
||||
void update_led(bool new_state);
|
||||
void update_led_with_active_status();
|
||||
void check_led_status_outdated();
|
||||
private:
|
||||
pid_t gsr_global_hotkeys_pid = -1;
|
||||
bool led_indicator_on = false;
|
||||
bool led_enabled = false;
|
||||
bool perform_blink = false;
|
||||
mgl::Clock blink_timer;
|
||||
|
||||
std::vector<int> led_brightness_files;
|
||||
mgl::Clock read_led_brightness_timer;
|
||||
};
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "RegionSelector.hpp"
|
||||
#include "WindowSelector.hpp"
|
||||
#include "ClipboardFile.hpp"
|
||||
#include "LedIndicator.hpp"
|
||||
#include "CursorTracker/CursorTracker.hpp"
|
||||
|
||||
#include <mglpp/window/Window.hpp>
|
||||
@@ -42,6 +43,11 @@ namespace gsr {
|
||||
SCREENSHOT
|
||||
};
|
||||
|
||||
enum class NotificationLevel {
|
||||
INFO,
|
||||
ERROR,
|
||||
};
|
||||
|
||||
enum class ScreenshotForceType {
|
||||
NONE,
|
||||
REGION,
|
||||
@@ -65,7 +71,7 @@ namespace gsr {
|
||||
bool draw();
|
||||
|
||||
void show();
|
||||
void hide();
|
||||
void hide_next_frame();
|
||||
void toggle_show();
|
||||
void toggle_record();
|
||||
void toggle_pause();
|
||||
@@ -77,7 +83,7 @@ namespace gsr {
|
||||
void take_screenshot();
|
||||
void take_screenshot_region();
|
||||
void take_screenshot_window();
|
||||
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);
|
||||
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, NotificationLevel notification_level = NotificationLevel::INFO);
|
||||
bool is_open() const;
|
||||
bool should_exit(std::string &reason) const;
|
||||
void exit();
|
||||
@@ -89,10 +95,17 @@ namespace gsr {
|
||||
void rebind_all_keyboard_hotkeys();
|
||||
|
||||
void set_notification_speed(NotificationSpeed notification_speed);
|
||||
|
||||
bool global_hotkeys_ungrab_keyboard = false;
|
||||
private:
|
||||
void update_upause_status();
|
||||
|
||||
void hide();
|
||||
|
||||
void handle_keyboard_mapping_event();
|
||||
void on_event(mgl::Event &event);
|
||||
|
||||
void recreate_global_hotkeys(const char *hotkey_option);
|
||||
void create_frontpage_ui_components();
|
||||
void xi_setup();
|
||||
void handle_xi_events();
|
||||
@@ -156,6 +169,7 @@ namespace gsr {
|
||||
GsrInfo gsr_info;
|
||||
egl_functions egl_funcs;
|
||||
Config config;
|
||||
Config current_recording_config;
|
||||
|
||||
bool visible = false;
|
||||
|
||||
@@ -192,6 +206,8 @@ namespace gsr {
|
||||
|
||||
RecordingStatus recording_status = RecordingStatus::NONE;
|
||||
bool paused = false;
|
||||
mgl::Clock paused_clock;
|
||||
double paused_total_time_seconds = 0.0;
|
||||
|
||||
mgl::Clock replay_status_update_clock;
|
||||
std::string power_supply_online_filepath;
|
||||
@@ -220,7 +236,7 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<GlobalHotkeys> global_hotkeys = nullptr;
|
||||
std::unique_ptr<GlobalHotkeysJoystick> global_hotkeys_js = nullptr;
|
||||
Display *x11_mapping_display = nullptr;
|
||||
Display *x11_dpy = nullptr;
|
||||
XEvent x11_mapping_xev;
|
||||
|
||||
mgl::Clock replay_save_clock;
|
||||
@@ -229,7 +245,6 @@ namespace gsr {
|
||||
bool try_replay_startup = true;
|
||||
bool replay_recording = false;
|
||||
int replay_save_duration_min = 0;
|
||||
double replay_buffer_save_duration_sec = 0.0;
|
||||
mgl::Clock replay_duration_clock;
|
||||
double replay_saved_duration_sec = 0.0;
|
||||
bool replay_restart_on_save = false;
|
||||
@@ -255,5 +270,7 @@ namespace gsr {
|
||||
bool hide_ui = false;
|
||||
double notification_duration_multiplier = 1.0;
|
||||
ClipboardFile clipboard_file;
|
||||
|
||||
std::unique_ptr<LedIndicator> led_indicator = nullptr;
|
||||
};
|
||||
}
|
||||
@@ -4,31 +4,47 @@
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <poll.h>
|
||||
|
||||
typedef struct _IO_FILE FILE;
|
||||
#define GSR_RPC_MAX_CONNECTIONS 8
|
||||
#define GSR_RPC_MAX_POLLS (1 + GSR_RPC_MAX_CONNECTIONS) /* +1 to include the socket_fd itself for accept */
|
||||
#define GSR_RPC_MAX_MESSAGE_SIZE 128
|
||||
|
||||
namespace gsr {
|
||||
using RpcCallback = std::function<void(const std::string &name)>;
|
||||
|
||||
enum class RpcOpenResult {
|
||||
OK,
|
||||
CONNECTION_REFUSED,
|
||||
ERROR
|
||||
};
|
||||
|
||||
class Rpc {
|
||||
public:
|
||||
Rpc() = default;
|
||||
struct PollData {
|
||||
char buffer[GSR_RPC_MAX_MESSAGE_SIZE];
|
||||
int buffer_size = 0;
|
||||
};
|
||||
|
||||
Rpc();
|
||||
Rpc(const Rpc&) = delete;
|
||||
Rpc& operator=(const Rpc&) = delete;
|
||||
~Rpc();
|
||||
|
||||
bool create(const char *name);
|
||||
bool open(const char *name);
|
||||
RpcOpenResult 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);
|
||||
void handle_client_data(int client_fd, PollData &poll_data);
|
||||
private:
|
||||
int fd = 0;
|
||||
FILE *file = nullptr;
|
||||
std::string fifo_filepath;
|
||||
int socket_fd = 0;
|
||||
std::string socket_filepath;
|
||||
struct pollfd polls[GSR_RPC_MAX_POLLS];
|
||||
PollData polls_data[GSR_RPC_MAX_POLLS];
|
||||
int num_polls = 0;
|
||||
std::unordered_map<std::string, RpcCallback> handlers_by_name;
|
||||
};
|
||||
}
|
||||
@@ -73,6 +73,7 @@ namespace gsr {
|
||||
std::unique_ptr<List> create_notification_speed();
|
||||
std::unique_ptr<Subsection> create_application_options_subsection(ScrollablePage *parent_page);
|
||||
std::unique_ptr<Subsection> create_application_info_subsection(ScrollablePage *parent_page);
|
||||
std::unique_ptr<Subsection> create_donate_subsection(ScrollablePage *parent_page);
|
||||
void add_widgets();
|
||||
|
||||
Button* configure_hotkey_get_button_by_active_type();
|
||||
|
||||
@@ -43,8 +43,10 @@ namespace gsr {
|
||||
std::unique_ptr<Widget> create_file_info_section();
|
||||
std::unique_ptr<CheckBox> create_save_screenshot_in_game_folder();
|
||||
std::unique_ptr<CheckBox> create_save_screenshot_to_clipboard();
|
||||
std::unique_ptr<Widget> create_notifications();
|
||||
std::unique_ptr<Widget> create_led_indicator();
|
||||
std::unique_ptr<Widget> create_general_section();
|
||||
std::unique_ptr<Widget> create_notifications_section();
|
||||
std::unique_ptr<Widget> create_screenshot_indicator_section();
|
||||
std::unique_ptr<Widget> create_settings();
|
||||
void add_widgets();
|
||||
|
||||
@@ -71,7 +73,8 @@ namespace gsr {
|
||||
Button *save_directory_button_ptr = nullptr;
|
||||
CheckBox *save_screenshot_in_game_folder_checkbox_ptr = nullptr;
|
||||
CheckBox *save_screenshot_to_clipboard_checkbox_ptr = nullptr;
|
||||
CheckBox *show_screenshot_saved_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *show_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *led_indicator_checkbox_ptr = nullptr;
|
||||
|
||||
PageStack *page_stack = nullptr;
|
||||
};
|
||||
|
||||
@@ -112,6 +112,9 @@ namespace gsr {
|
||||
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();
|
||||
std::unique_ptr<CheckBox> create_led_indicator(const char *type);
|
||||
std::unique_ptr<CheckBox> create_notifications(const char *type);
|
||||
std::unique_ptr<List> create_indicator(const char *type);
|
||||
void add_replay_widgets();
|
||||
void add_record_widgets();
|
||||
|
||||
@@ -136,7 +139,7 @@ namespace gsr {
|
||||
void save_record();
|
||||
void save_stream();
|
||||
|
||||
void view_changed(bool advanced_view, Subsection *notifications_subsection_ptr);
|
||||
void view_changed(bool advanced_view);
|
||||
private:
|
||||
Type type;
|
||||
Config &config;
|
||||
@@ -179,15 +182,7 @@ namespace gsr {
|
||||
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;
|
||||
CheckBox *show_replay_saved_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *save_recording_in_game_folder_ptr = nullptr;
|
||||
CheckBox *show_recording_started_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *show_video_saved_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *show_video_paused_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *show_streaming_started_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *show_streaming_stopped_notification_checkbox_ptr = nullptr;
|
||||
Button *save_directory_button_ptr = nullptr;
|
||||
Entry *twitch_stream_key_entry_ptr = nullptr;
|
||||
Entry *youtube_stream_key_entry_ptr = nullptr;
|
||||
@@ -200,6 +195,8 @@ namespace gsr {
|
||||
RadioButton *turn_on_replay_automatically_mode_ptr = nullptr;
|
||||
Subsection *audio_section_ptr = nullptr;
|
||||
List *audio_track_section_list_ptr = nullptr;
|
||||
CheckBox *led_indicator_checkbox_ptr = nullptr;
|
||||
CheckBox *show_notification_checkbox_ptr = nullptr;
|
||||
|
||||
PageStack *page_stack = nullptr;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.7.7', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.8.2', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
|
||||
add_project_arguments('-D_FILE_OFFSET_BITS=64', language : ['c', 'cpp'])
|
||||
|
||||
@@ -50,6 +50,7 @@ src = [
|
||||
'src/AudioPlayer.cpp',
|
||||
'src/Hotplug.cpp',
|
||||
'src/ClipboardFile.cpp',
|
||||
'src/LedIndicator.cpp',
|
||||
'src/Rpc.cpp',
|
||||
'src/main.cpp',
|
||||
]
|
||||
@@ -65,7 +66,7 @@ datadir = get_option('datadir')
|
||||
gsr_ui_resources_path = join_paths(prefix, datadir, 'gsr-ui')
|
||||
|
||||
add_project_arguments('-DGSR_UI_VERSION="' + meson.project_version() + '"', language: ['c', 'cpp'])
|
||||
add_project_arguments('-DGSR_FLATPAK_VERSION="5.8.2"', language: ['c', 'cpp'])
|
||||
add_project_arguments('-DGSR_FLATPAK_VERSION="5.9.0"', language: ['c', 'cpp'])
|
||||
|
||||
executable(
|
||||
meson.project_name(),
|
||||
@@ -93,6 +94,7 @@ executable(
|
||||
'tools/gsr-global-hotkeys/hotplug.c',
|
||||
'tools/gsr-global-hotkeys/keyboard_event.c',
|
||||
'tools/gsr-global-hotkeys/keys.c',
|
||||
'tools/gsr-global-hotkeys/leds.c',
|
||||
'tools/gsr-global-hotkeys/main.c'
|
||||
],
|
||||
c_args : '-fstack-protector-all',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "gsr-ui"
|
||||
type = "executable"
|
||||
version = "1.7.7"
|
||||
version = "1.8.2"
|
||||
platforms = ["posix"]
|
||||
|
||||
[lang.cpp]
|
||||
|
||||
@@ -149,26 +149,31 @@ namespace gsr {
|
||||
|
||||
if(xselectionrequest->target == targets_atom) {
|
||||
int num_targets = 1;
|
||||
Atom targets[3];
|
||||
Atom targets[4];
|
||||
targets[0] = targets_atom;
|
||||
|
||||
switch(file_type) {
|
||||
case FileType::JPG:
|
||||
num_targets = 3;
|
||||
num_targets = 4;
|
||||
targets[1] = image_jpg_atom;
|
||||
targets[2] = image_jpeg_atom;
|
||||
targets[3] = image_png_atom;
|
||||
break;
|
||||
case FileType::PNG:
|
||||
num_targets = 2;
|
||||
targets[1] = image_png_atom;
|
||||
targets[2] = image_jpg_atom;
|
||||
targets[3] = image_jpeg_atom;
|
||||
break;
|
||||
}
|
||||
|
||||
XChangeProperty(dpy, selection_event.requestor, selection_event.property, XA_ATOM, 32, PropModeReplace, (unsigned char*)targets, num_targets);
|
||||
} else if(xselectionrequest->target == image_jpg_atom || xselectionrequest->target == image_jpeg_atom || xselectionrequest->target == image_png_atom) {
|
||||
// TODO: Convert image to requested image type. Right now sending a jpg file when a png file is requested works ok in browsers (discord and element)
|
||||
if(!file_type_matches_request_atom(file_type, xselectionrequest->target)) {
|
||||
fprintf(stderr, "gsr ui: warning: ClipboardFile::send_clipboard: requestor window " FORMAT_I64 " tried to request clipboard of type %s, but %s was expected\n", (int64_t)xselectionrequest->requestor, file_type_clipboard_get_name(xselectionrequest->target), file_type_get_name(file_type));
|
||||
return;
|
||||
const char *expected_file_type = file_type_get_name(file_type);
|
||||
fprintf(stderr, "gsr ui: warning: ClipboardFile::send_clipboard: requestor window " FORMAT_I64 " tried to request clipboard of type %s, but %s was expected. Ignoring requestor and sending as %s\n", (int64_t)xselectionrequest->requestor, file_type_clipboard_get_name(xselectionrequest->target), expected_file_type, expected_file_type);
|
||||
//return;
|
||||
}
|
||||
|
||||
ClipboardCopy *clipboard_copy = get_clipboard_copy_by_requestor(xselectionrequest->requestor);
|
||||
|
||||
@@ -171,6 +171,7 @@ namespace gsr {
|
||||
return {
|
||||
{"main.config_file_version", &config.main_config.config_file_version},
|
||||
{"main.software_encoding_warning_shown", &config.main_config.software_encoding_warning_shown},
|
||||
{"main.wayland_warning_shown", &config.main_config.wayland_warning_shown},
|
||||
{"main.hotkeys_enable_option", &config.main_config.hotkeys_enable_option},
|
||||
{"main.joystick_hotkeys_enable_option", &config.main_config.joystick_hotkeys_enable_option},
|
||||
{"main.tint_color", &config.main_config.tint_color},
|
||||
@@ -198,8 +199,8 @@ namespace gsr {
|
||||
{"streaming.record_options.overclock", &config.streaming_config.record_options.overclock},
|
||||
{"streaming.record_options.record_cursor", &config.streaming_config.record_options.record_cursor},
|
||||
{"streaming.record_options.restore_portal_session", &config.streaming_config.record_options.restore_portal_session},
|
||||
{"streaming.show_streaming_started_notifications", &config.streaming_config.show_streaming_started_notifications},
|
||||
{"streaming.show_streaming_stopped_notifications", &config.streaming_config.show_streaming_stopped_notifications},
|
||||
{"streaming.record_options.show_notifications", &config.streaming_config.record_options.show_notifications},
|
||||
{"streaming.record_options.use_led_indicator", &config.streaming_config.record_options.use_led_indicator},
|
||||
{"streaming.service", &config.streaming_config.streaming_service},
|
||||
{"streaming.youtube.key", &config.streaming_config.youtube.stream_key},
|
||||
{"streaming.twitch.key", &config.streaming_config.twitch.stream_key},
|
||||
@@ -230,10 +231,9 @@ namespace gsr {
|
||||
{"record.record_options.overclock", &config.record_config.record_options.overclock},
|
||||
{"record.record_options.record_cursor", &config.record_config.record_options.record_cursor},
|
||||
{"record.record_options.restore_portal_session", &config.record_config.record_options.restore_portal_session},
|
||||
{"record.record_options.show_notifications", &config.record_config.record_options.show_notifications},
|
||||
{"record.record_options.use_led_indicator", &config.record_config.record_options.use_led_indicator},
|
||||
{"record.save_video_in_game_folder", &config.record_config.save_video_in_game_folder},
|
||||
{"record.show_recording_started_notifications", &config.record_config.show_recording_started_notifications},
|
||||
{"record.show_video_saved_notifications", &config.record_config.show_video_saved_notifications},
|
||||
{"record.show_video_paused_notifications", &config.record_config.show_video_paused_notifications},
|
||||
{"record.save_directory", &config.record_config.save_directory},
|
||||
{"record.container", &config.record_config.container},
|
||||
{"record.start_stop_hotkey", &config.record_config.start_stop_hotkey},
|
||||
@@ -260,12 +260,11 @@ namespace gsr {
|
||||
{"replay.record_options.overclock", &config.replay_config.record_options.overclock},
|
||||
{"replay.record_options.record_cursor", &config.replay_config.record_options.record_cursor},
|
||||
{"replay.record_options.restore_portal_session", &config.replay_config.record_options.restore_portal_session},
|
||||
{"replay.record_options.show_notifications", &config.replay_config.record_options.show_notifications},
|
||||
{"replay.record_options.use_led_indicator", &config.replay_config.record_options.use_led_indicator},
|
||||
{"replay.turn_on_replay_automatically_mode", &config.replay_config.turn_on_replay_automatically_mode},
|
||||
{"replay.save_video_in_game_folder", &config.replay_config.save_video_in_game_folder},
|
||||
{"replay.restart_replay_on_save", &config.replay_config.restart_replay_on_save},
|
||||
{"replay.show_replay_started_notifications", &config.replay_config.show_replay_started_notifications},
|
||||
{"replay.show_replay_stopped_notifications", &config.replay_config.show_replay_stopped_notifications},
|
||||
{"replay.show_replay_saved_notifications", &config.replay_config.show_replay_saved_notifications},
|
||||
{"replay.save_directory", &config.replay_config.save_directory},
|
||||
{"replay.container", &config.replay_config.container},
|
||||
{"replay.time", &config.replay_config.replay_time},
|
||||
@@ -285,7 +284,8 @@ namespace gsr {
|
||||
{"screenshot.restore_portal_session", &config.screenshot_config.restore_portal_session},
|
||||
{"screenshot.save_screenshot_in_game_folder", &config.screenshot_config.save_screenshot_in_game_folder},
|
||||
{"screenshot.save_screenshot_to_clipboard", &config.screenshot_config.save_screenshot_to_clipboard},
|
||||
{"screenshot.show_screenshot_saved_notifications", &config.screenshot_config.show_screenshot_saved_notifications},
|
||||
{"screenshot.show_notifications", &config.screenshot_config.show_notifications},
|
||||
{"screenshot.use_led_indicator", &config.screenshot_config.use_led_indicator},
|
||||
{"screenshot.save_directory", &config.screenshot_config.save_directory},
|
||||
{"screenshot.take_screenshot_hotkey", &config.screenshot_config.take_screenshot_hotkey},
|
||||
{"screenshot.take_screenshot_region_hotkey", &config.screenshot_config.take_screenshot_region_hotkey},
|
||||
|
||||
@@ -403,6 +403,7 @@ namespace gsr {
|
||||
}
|
||||
|
||||
CursorTrackerWayland::~CursorTrackerWayland() {
|
||||
clear_monitors();
|
||||
if(drm_fd > 0)
|
||||
close(drm_fd);
|
||||
}
|
||||
@@ -480,6 +481,21 @@ namespace gsr {
|
||||
wl_display_roundtrip(dpy);
|
||||
}
|
||||
|
||||
void CursorTrackerWayland::clear_monitors() {
|
||||
for(WaylandOutput &monitor : monitors) {
|
||||
if(monitor.output) {
|
||||
wl_output_destroy(monitor.output);
|
||||
monitor.output = nullptr;
|
||||
}
|
||||
|
||||
if(monitor.xdg_output) {
|
||||
zxdg_output_v1_destroy(monitor.xdg_output);
|
||||
monitor.xdg_output = nullptr;
|
||||
}
|
||||
}
|
||||
monitors.clear();
|
||||
}
|
||||
|
||||
std::optional<CursorInfo> CursorTrackerWayland::get_latest_cursor_info() {
|
||||
if(drm_fd <= 0 || latest_crtc_id == -1)
|
||||
return std::nullopt;
|
||||
@@ -494,7 +510,7 @@ namespace gsr {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
monitors.clear();
|
||||
clear_monitors();
|
||||
struct wl_registry *registry = wl_display_get_registry(dpy);
|
||||
wl_registry_add_listener(registry, ®istry_listener, this);
|
||||
|
||||
@@ -508,22 +524,13 @@ namespace gsr {
|
||||
|
||||
mgl::vec2i cursor_position = latest_cursor_position;
|
||||
const WaylandOutput *wayland_monitor = get_wayland_monitor_by_name(monitors, monitor_name);
|
||||
if(!wayland_monitor)
|
||||
if(!wayland_monitor) {
|
||||
clear_monitors();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
cursor_position = wayland_monitor->pos + latest_cursor_position;
|
||||
for(WaylandOutput &monitor : monitors) {
|
||||
if(monitor.output) {
|
||||
wl_output_destroy(monitor.output);
|
||||
monitor.output = nullptr;
|
||||
}
|
||||
|
||||
if(monitor.xdg_output) {
|
||||
zxdg_output_v1_destroy(monitor.xdg_output);
|
||||
monitor.xdg_output = nullptr;
|
||||
}
|
||||
}
|
||||
monitors.clear();
|
||||
clear_monitors();
|
||||
|
||||
if(xdg_output_manager) {
|
||||
zxdg_output_manager_v1_destroy(xdg_output_manager);
|
||||
|
||||
@@ -3,92 +3,48 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
namespace gsr {
|
||||
static constexpr int button_pressed = 1;
|
||||
static constexpr int cross_button = 0;
|
||||
static constexpr int triangle_button = 2;
|
||||
static constexpr int options_button = 9;
|
||||
static constexpr int playstation_button = 10;
|
||||
static constexpr int l3_button = 11;
|
||||
static constexpr int r3_button = 12;
|
||||
static constexpr int axis_up_down = 7;
|
||||
static constexpr int axis_left_right = 6;
|
||||
|
||||
struct DeviceId {
|
||||
uint16_t vendor;
|
||||
uint16_t product;
|
||||
};
|
||||
|
||||
static bool read_file_hex_number(const char *path, unsigned int *value) {
|
||||
*value = 0;
|
||||
FILE *f = fopen(path, "rb");
|
||||
if(!f)
|
||||
return false;
|
||||
|
||||
fscanf(f, "%x", value);
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
static DeviceId joystick_get_device_id(const char *path) {
|
||||
DeviceId device_id;
|
||||
device_id.vendor = 0;
|
||||
device_id.product = 0;
|
||||
|
||||
const char *js_path_id = nullptr;
|
||||
const int len = strlen(path);
|
||||
for(int i = len - 1; i >= 0; --i) {
|
||||
if(path[i] == '/') {
|
||||
js_path_id = path + i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!js_path_id)
|
||||
return device_id;
|
||||
|
||||
unsigned int vendor = 0;
|
||||
unsigned int product = 0;
|
||||
char path_buf[1024];
|
||||
|
||||
snprintf(path_buf, sizeof(path_buf), "/sys/class/input/%s/device/id/vendor", js_path_id);
|
||||
if(!read_file_hex_number(path_buf, &vendor))
|
||||
return device_id;
|
||||
|
||||
snprintf(path_buf, sizeof(path_buf), "/sys/class/input/%s/device/id/product", js_path_id);
|
||||
if(!read_file_hex_number(path_buf, &product))
|
||||
return device_id;
|
||||
|
||||
device_id.vendor = vendor;
|
||||
device_id.product = product;
|
||||
return device_id;
|
||||
}
|
||||
|
||||
static bool is_ps4_controller(DeviceId device_id) {
|
||||
return device_id.vendor == 0x054C && (device_id.product == 0x09CC || device_id.product == 0x0BA0 || device_id.product == 0x05C4);
|
||||
}
|
||||
|
||||
static bool is_ps5_controller(DeviceId device_id) {
|
||||
return device_id.vendor == 0x054C && (device_id.product == 0x0DF2 || device_id.product == 0x0CE6);
|
||||
}
|
||||
|
||||
static bool is_stadia_controller(DeviceId device_id) {
|
||||
return device_id.vendor == 0x18D1 && (device_id.product == 0x9400);
|
||||
}
|
||||
|
||||
// Returns -1 on error
|
||||
static int get_js_dev_input_id_from_filepath(const char *dev_input_filepath) {
|
||||
if(strncmp(dev_input_filepath, "/dev/input/js", 13) != 0)
|
||||
static int get_dev_input_event_id_from_filepath(const char *dev_input_filepath) {
|
||||
if(strncmp(dev_input_filepath, "/dev/input/event", 16) != 0)
|
||||
return -1;
|
||||
|
||||
int dev_input_id = -1;
|
||||
if(sscanf(dev_input_filepath + 13, "%d", &dev_input_id) == 1)
|
||||
if(sscanf(dev_input_filepath + 16, "%d", &dev_input_id) == 1)
|
||||
return dev_input_id;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline bool supports_key(unsigned char *key_bits, unsigned int key) {
|
||||
return key_bits[key/8] & (1 << (key % 8));
|
||||
}
|
||||
|
||||
static bool supports_joystick_keys(unsigned char *key_bits) {
|
||||
const int keys[7] = { BTN_A, BTN_B, BTN_X, BTN_Y, BTN_SELECT, BTN_START, BTN_SELECT };
|
||||
for(int i = 0; i < 7; ++i) {
|
||||
if(supports_key(key_bits, keys[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool is_input_device_joystick(int input_fd) {
|
||||
unsigned long evbit = 0;
|
||||
ioctl(input_fd, EVIOCGBIT(0, sizeof(evbit)), &evbit);
|
||||
if((evbit & (1 << EV_SYN)) && (evbit & (1 << EV_KEY))) {
|
||||
unsigned char key_bits[KEY_MAX/8 + 1];
|
||||
memset(key_bits, 0, sizeof(key_bits));
|
||||
ioctl(input_fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), &key_bits);
|
||||
return supports_joystick_keys(key_bits);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
GlobalHotkeysJoystick::~GlobalHotkeysJoystick() {
|
||||
if(event_fd > 0) {
|
||||
const uint64_t exit = 1;
|
||||
@@ -98,8 +54,18 @@ namespace gsr {
|
||||
if(read_thread.joinable())
|
||||
read_thread.join();
|
||||
|
||||
if(event_fd > 0)
|
||||
if(event_fd > 0) {
|
||||
close(event_fd);
|
||||
event_fd = 0;
|
||||
}
|
||||
|
||||
close_fd_cv.notify_one();
|
||||
if(close_fd_thread.joinable())
|
||||
close_fd_thread.join();
|
||||
|
||||
for(int fd : fds_to_close) {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
for(int i = 0; i < num_poll_fd; ++i) {
|
||||
if(poll_fd[i].fd > 0)
|
||||
@@ -141,16 +107,10 @@ namespace gsr {
|
||||
++num_poll_fd;
|
||||
}
|
||||
|
||||
char dev_input_path[128];
|
||||
for(int i = 0; i < 8; ++i) {
|
||||
snprintf(dev_input_path, sizeof(dev_input_path), "/dev/input/js%d", i);
|
||||
add_device(dev_input_path, false);
|
||||
}
|
||||
|
||||
if(num_poll_fd == 0)
|
||||
fprintf(stderr, "Info: no joysticks found, assuming they might be connected later\n");
|
||||
add_all_joystick_devices();
|
||||
|
||||
read_thread = std::thread(&GlobalHotkeysJoystick::read_events, this);
|
||||
close_fd_thread = std::thread(&GlobalHotkeysJoystick::close_fds, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -214,8 +174,30 @@ namespace gsr {
|
||||
}
|
||||
}
|
||||
|
||||
// Retarded linux takes very long time to close /dev/input/eventN files, even though they are virtual and opened read-only
|
||||
void GlobalHotkeysJoystick::close_fds() {
|
||||
std::vector<int> current_fds_to_close;
|
||||
while(event_fd > 0) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(close_fd_mutex);
|
||||
close_fd_cv.wait(lock, [this]{ return !fds_to_close.empty() || event_fd <= 0; });
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(close_fd_mutex);
|
||||
current_fds_to_close = std::move(fds_to_close);
|
||||
fds_to_close.clear();
|
||||
}
|
||||
|
||||
for(int fd : current_fds_to_close) {
|
||||
close(fd);
|
||||
}
|
||||
current_fds_to_close.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void GlobalHotkeysJoystick::read_events() {
|
||||
js_event event;
|
||||
input_event event;
|
||||
while(poll(poll_fd, num_poll_fd, -1) > 0) {
|
||||
for(int i = 0; i < num_poll_fd; ++i) {
|
||||
if(poll_fd[i].revents & (POLLHUP|POLLERR|POLLNVAL)) {
|
||||
@@ -223,7 +205,7 @@ namespace gsr {
|
||||
goto done;
|
||||
|
||||
char dev_input_filepath[256];
|
||||
snprintf(dev_input_filepath, sizeof(dev_input_filepath), "/dev/input/js%d", extra_data[i].dev_input_id);
|
||||
snprintf(dev_input_filepath, sizeof(dev_input_filepath), "/dev/input/event%d", extra_data[i].dev_input_id);
|
||||
fprintf(stderr, "Info: removed joystick: %s\n", dev_input_filepath);
|
||||
if(remove_poll_fd(i))
|
||||
--i; // This item was removed so we want to repeat the same index to continue to the next item
|
||||
@@ -240,7 +222,7 @@ namespace gsr {
|
||||
hotplug.process_event_data(poll_fd[i].fd, [&](HotplugAction hotplug_action, const char *devname) {
|
||||
switch(hotplug_action) {
|
||||
case HotplugAction::ADD: {
|
||||
add_device(devname);
|
||||
add_device(devname, false);
|
||||
break;
|
||||
}
|
||||
case HotplugAction::REMOVE: {
|
||||
@@ -251,7 +233,7 @@ namespace gsr {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
process_js_event(poll_fd[i].fd, event);
|
||||
process_input_event(poll_fd[i].fd, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,54 +242,44 @@ namespace gsr {
|
||||
;
|
||||
}
|
||||
|
||||
void GlobalHotkeysJoystick::process_js_event(int fd, js_event &event) {
|
||||
void GlobalHotkeysJoystick::process_input_event(int fd, input_event &event) {
|
||||
if(read(fd, &event, sizeof(event)) != sizeof(event))
|
||||
return;
|
||||
|
||||
if((event.type & JS_EVENT_BUTTON) == JS_EVENT_BUTTON) {
|
||||
switch(event.number) {
|
||||
case playstation_button: {
|
||||
// Workaround weird steam input (in-game) behavior where steam triggers playstation button + options when pressing both l3 and r3 at the same time
|
||||
playstation_button_pressed = (event.value == button_pressed) && !l3_button_pressed && !r3_button_pressed;
|
||||
if(event.type == EV_KEY) {
|
||||
switch(event.code) {
|
||||
case BTN_MODE: {
|
||||
playstation_button_pressed = (event.value == button_pressed);
|
||||
break;
|
||||
}
|
||||
case options_button: {
|
||||
case BTN_START: {
|
||||
if(playstation_button_pressed && event.value == button_pressed)
|
||||
toggle_show = true;
|
||||
break;
|
||||
}
|
||||
case cross_button: {
|
||||
case BTN_SOUTH: {
|
||||
if(playstation_button_pressed && event.value == button_pressed)
|
||||
save_1_min_replay = true;
|
||||
break;
|
||||
}
|
||||
case triangle_button: {
|
||||
case BTN_NORTH: {
|
||||
if(playstation_button_pressed && event.value == button_pressed)
|
||||
save_10_min_replay = true;
|
||||
break;
|
||||
}
|
||||
case l3_button: {
|
||||
l3_button_pressed = event.value == button_pressed;
|
||||
break;
|
||||
}
|
||||
case r3_button: {
|
||||
r3_button_pressed = event.value == button_pressed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if((event.type & JS_EVENT_AXIS) == JS_EVENT_AXIS && playstation_button_pressed) {
|
||||
const int trigger_threshold = 16383;
|
||||
} else if(event.type == EV_ABS && playstation_button_pressed) {
|
||||
const bool prev_up_pressed = up_pressed;
|
||||
const bool prev_down_pressed = down_pressed;
|
||||
const bool prev_left_pressed = left_pressed;
|
||||
const bool prev_right_pressed = right_pressed;
|
||||
|
||||
if(event.number == axis_up_down) {
|
||||
up_pressed = event.value <= -trigger_threshold;
|
||||
down_pressed = event.value >= trigger_threshold;
|
||||
} else if(event.number == axis_left_right) {
|
||||
left_pressed = event.value <= -trigger_threshold;
|
||||
right_pressed = event.value >= trigger_threshold;
|
||||
if(event.code == ABS_HAT0Y) {
|
||||
up_pressed = event.value == -1;
|
||||
down_pressed = event.value == 1;
|
||||
} else if(event.code == ABS_HAT0X) {
|
||||
left_pressed = event.value == -1;
|
||||
right_pressed = event.value == 1;
|
||||
}
|
||||
|
||||
if(up_pressed && !prev_up_pressed)
|
||||
@@ -321,13 +293,36 @@ namespace gsr {
|
||||
}
|
||||
}
|
||||
|
||||
void GlobalHotkeysJoystick::add_all_joystick_devices() {
|
||||
DIR *dir = opendir("/dev/input");
|
||||
if(!dir) {
|
||||
fprintf(stderr, "Error: failed to open /dev/input, error: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
char dev_input_filepath[1024];
|
||||
for(;;) {
|
||||
struct dirent *entry = readdir(dir);
|
||||
if(!entry)
|
||||
break;
|
||||
|
||||
if(strncmp(entry->d_name, "event", 5) != 0)
|
||||
continue;
|
||||
|
||||
snprintf(dev_input_filepath, sizeof(dev_input_filepath), "/dev/input/%s", entry->d_name);
|
||||
add_device(dev_input_filepath, false);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
bool GlobalHotkeysJoystick::add_device(const char *dev_input_filepath, bool print_error) {
|
||||
if(num_poll_fd >= max_js_poll_fd) {
|
||||
fprintf(stderr, "Warning: failed to add joystick device %s, too many joysticks have been added\n", dev_input_filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
const int dev_input_id = get_js_dev_input_id_from_filepath(dev_input_filepath);
|
||||
const int dev_input_id = get_dev_input_event_id_from_filepath(dev_input_filepath);
|
||||
if(dev_input_id == -1)
|
||||
return false;
|
||||
|
||||
@@ -338,6 +333,15 @@ namespace gsr {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_input_device_joystick(fd)) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(close_fd_mutex);
|
||||
fds_to_close.push_back(fd);
|
||||
}
|
||||
close_fd_cv.notify_one();
|
||||
return false;
|
||||
}
|
||||
|
||||
poll_fd[num_poll_fd] = {
|
||||
fd,
|
||||
POLLIN,
|
||||
@@ -356,7 +360,7 @@ namespace gsr {
|
||||
}
|
||||
|
||||
bool GlobalHotkeysJoystick::remove_device(const char *dev_input_filepath) {
|
||||
const int dev_input_id = get_js_dev_input_id_from_filepath(dev_input_filepath);
|
||||
const int dev_input_id = get_dev_input_event_id_from_filepath(dev_input_filepath);
|
||||
if(dev_input_id == -1)
|
||||
return false;
|
||||
|
||||
@@ -372,8 +376,13 @@ namespace gsr {
|
||||
if(index < 0 || index >= num_poll_fd)
|
||||
return false;
|
||||
|
||||
if(poll_fd[index].fd > 0)
|
||||
close(poll_fd[index].fd);
|
||||
if(poll_fd[index].fd > 0) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(close_fd_mutex);
|
||||
fds_to_close.push_back(poll_fd[index].fd);
|
||||
}
|
||||
close_fd_cv.notify_one();
|
||||
}
|
||||
|
||||
for(int i = index + 1; i < num_poll_fd; ++i) {
|
||||
poll_fd[i - 1] = poll_fd[i];
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace gsr {
|
||||
switch(grab_type) {
|
||||
case GlobalHotkeysLinux::GrabType::ALL: return "--all";
|
||||
case GlobalHotkeysLinux::GrabType::VIRTUAL: return "--virtual";
|
||||
case GlobalHotkeysLinux::GrabType::NO_GRAB: return "--no-grab";
|
||||
}
|
||||
return "--all";
|
||||
}
|
||||
@@ -192,7 +193,7 @@ namespace gsr {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(hotkey.key == 0) {
|
||||
if(hotkey.key == 0 || hotkey.key == XK_VoidSymbol) {
|
||||
//fprintf(stderr, "Error: GlobalHotkeysLinux::bind_key_press: hotkey requires a key\n");
|
||||
return false;
|
||||
}
|
||||
@@ -270,6 +271,8 @@ namespace gsr {
|
||||
auto it = bound_actions_by_id.find(action);
|
||||
if(it != bound_actions_by_id.end())
|
||||
it->second(action);
|
||||
else if(on_gsr_ui_virtual_keyboard_grabbed && action == "gsr-ui-virtual-keyboard-grabbed")
|
||||
on_gsr_ui_virtual_keyboard_grabbed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
170
src/LedIndicator.cpp
Normal file
170
src/LedIndicator.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
#include "../include/LedIndicator.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// TODO: Support hotplug for led indicator check (led_brightness_files)
|
||||
|
||||
namespace gsr {
|
||||
static bool string_starts_with(const char *str, const char *sub) {
|
||||
const int str_len = strlen(str);
|
||||
const int sub_len = strlen(sub);
|
||||
return str_len >= sub_len && memcmp(str, sub, sub_len) == 0;
|
||||
}
|
||||
|
||||
static bool string_ends_with(const char *str, const char *sub) {
|
||||
const int str_len = strlen(str);
|
||||
const int sub_len = strlen(sub);
|
||||
return str_len >= sub_len && memcmp(str + str_len - sub_len, sub, sub_len) == 0;
|
||||
}
|
||||
|
||||
static std::vector<int> open_device_leds_brightness_files(const char *led_name_path) {
|
||||
std::vector<int> files;
|
||||
|
||||
DIR *dir = opendir("/sys/class/leds");
|
||||
if(!dir)
|
||||
return files;
|
||||
|
||||
char brightness_filepath[1024];
|
||||
struct dirent *entry;
|
||||
while((entry = readdir(dir)) != NULL) {
|
||||
if(entry->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
if(!string_starts_with(entry->d_name, "input") || !string_ends_with(entry->d_name, led_name_path))
|
||||
continue;
|
||||
|
||||
snprintf(brightness_filepath, sizeof(brightness_filepath), "/sys/class/leds/%s/brightness", entry->d_name);
|
||||
const int led_brightness_file_fd = open(brightness_filepath, O_RDONLY | O_NONBLOCK);
|
||||
if(led_brightness_file_fd > 0)
|
||||
files.push_back(led_brightness_file_fd);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return files;
|
||||
}
|
||||
|
||||
LedIndicator::LedIndicator() {
|
||||
led_brightness_files = open_device_leds_brightness_files("scrolllock");
|
||||
run_gsr_global_hotkeys_set_leds(false);
|
||||
}
|
||||
|
||||
LedIndicator::~LedIndicator() {
|
||||
for(int led_brightness_file_fd : led_brightness_files) {
|
||||
close(led_brightness_file_fd);
|
||||
}
|
||||
|
||||
run_gsr_global_hotkeys_set_leds(false);
|
||||
if(gsr_global_hotkeys_pid > 0) {
|
||||
int status;
|
||||
waitpid(gsr_global_hotkeys_pid, &status, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void LedIndicator::set_led(bool enabled) {
|
||||
led_enabled = enabled;
|
||||
perform_blink = false;
|
||||
}
|
||||
|
||||
void LedIndicator::blink() {
|
||||
perform_blink = true;
|
||||
blink_timer.restart();
|
||||
}
|
||||
|
||||
bool LedIndicator::run_gsr_global_hotkeys_set_leds(bool enabled) {
|
||||
if(gsr_global_hotkeys_pid > 0) {
|
||||
int status;
|
||||
if(waitpid(gsr_global_hotkeys_pid, &status, WNOHANG) == 0) {
|
||||
// Still running
|
||||
return false;
|
||||
}
|
||||
gsr_global_hotkeys_pid = -1;
|
||||
}
|
||||
|
||||
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
|
||||
const char *user_homepath = getenv("HOME");
|
||||
if(!user_homepath)
|
||||
user_homepath = "/tmp";
|
||||
|
||||
gsr_global_hotkeys_pid = vfork();
|
||||
if(gsr_global_hotkeys_pid == -1) {
|
||||
fprintf(stderr, "Error: LedIndicator::run_gsr_global_hotkeys_set_leds: failed to fork\n");
|
||||
return false;
|
||||
} else if(gsr_global_hotkeys_pid == 0) { // Child
|
||||
if(inside_flatpak) {
|
||||
const char *args[] = { "flatpak-spawn", "--host", "/var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/kms-server-proxy", "launch-gsr-global-hotkeys", user_homepath, "--set-led", "Scroll Lock", enabled ? "on" : "off", nullptr };
|
||||
execvp(args[0], (char* const*)args);
|
||||
} else {
|
||||
const char *args[] = { "gsr-global-hotkeys", "--set-led", "Scroll Lock", enabled ? "on" : "off", nullptr };
|
||||
execvp(args[0], (char* const*)args);
|
||||
}
|
||||
|
||||
perror("gsr-global-hotkeys");
|
||||
_exit(127);
|
||||
return false;
|
||||
} else { // Parent
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void LedIndicator::update_led(bool new_state) {
|
||||
if(new_state == led_indicator_on)
|
||||
return;
|
||||
|
||||
if(run_gsr_global_hotkeys_set_leds(new_state))
|
||||
led_indicator_on = new_state;
|
||||
}
|
||||
|
||||
void LedIndicator::update() {
|
||||
update_led_with_active_status();
|
||||
check_led_status_outdated();
|
||||
}
|
||||
|
||||
void LedIndicator::update_led_with_active_status() {
|
||||
if(perform_blink) {
|
||||
const double blink_elapsed_sec = blink_timer.get_elapsed_time_seconds();
|
||||
if(blink_elapsed_sec < 0.2) {
|
||||
update_led(false);
|
||||
} else if(blink_elapsed_sec < 0.4) {
|
||||
update_led(true);
|
||||
} else if(blink_elapsed_sec < 0.6) {
|
||||
update_led(false);
|
||||
} else if(blink_elapsed_sec < 0.8) {
|
||||
update_led(true);
|
||||
} else {
|
||||
perform_blink = false;
|
||||
}
|
||||
} else {
|
||||
update_led(led_enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void LedIndicator::check_led_status_outdated() {
|
||||
// The display server will unset our scroll lock led when pressing capslock/numlock as it updates
|
||||
// all leds at the same time (not just the button pressed) (or at least xorg server does that).
|
||||
// When that is done we want to set the scroll lock led on again if it should be on.
|
||||
// TODO: Improve this. Dont do this with a timer.. but inotify doesn't work sysfs. netlink should work (man 7 netlink).
|
||||
if(read_led_brightness_timer.get_elapsed_time_seconds() > 0.2) {
|
||||
read_led_brightness_timer.restart();
|
||||
|
||||
bool led_status_outdated = false;
|
||||
char buffer[32];
|
||||
for(int led_brightness_file_fd : led_brightness_files) {
|
||||
const ssize_t bytes_read = read(led_brightness_file_fd, buffer, sizeof(buffer));
|
||||
if(bytes_read > 0) {
|
||||
if(buffer[0] == '0')
|
||||
led_status_outdated = true;
|
||||
lseek(led_brightness_file_fd, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
||||
if(led_status_outdated && led_enabled)
|
||||
run_gsr_global_hotkeys_set_leds(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
381
src/Overlay.cpp
381
src/Overlay.cpp
@@ -32,6 +32,7 @@
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
@@ -401,6 +402,9 @@ namespace gsr {
|
||||
fprintf(stderr, "error: failed to start global hotkeys\n");
|
||||
|
||||
bind_linux_hotkeys(global_hotkeys.get(), overlay);
|
||||
global_hotkeys->on_gsr_ui_virtual_keyboard_grabbed = [overlay]() {
|
||||
overlay->global_hotkeys_ungrab_keyboard = true;
|
||||
};
|
||||
return global_hotkeys;
|
||||
}
|
||||
|
||||
@@ -463,6 +467,7 @@ namespace gsr {
|
||||
gsr_info(std::move(gsr_info)),
|
||||
egl_funcs(egl_funcs),
|
||||
config(capture_options),
|
||||
current_recording_config(capture_options),
|
||||
bg_screenshot_overlay({0.0f, 0.0f}),
|
||||
top_bar_background({0.0f, 0.0f}),
|
||||
close_button_widget({0.0f, 0.0f})
|
||||
@@ -492,20 +497,33 @@ namespace gsr {
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::ALL);
|
||||
else if(config.main_config.hotkeys_enable_option == "enable_hotkeys_virtual_devices")
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::VIRTUAL);
|
||||
else if(config.main_config.hotkeys_enable_option == "enable_hotkeys_no_grab")
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::NO_GRAB);
|
||||
|
||||
if(config.main_config.joystick_hotkeys_enable_option == "enable_hotkeys")
|
||||
global_hotkeys_js = register_joystick_hotkeys(this);
|
||||
|
||||
x11_mapping_display = XOpenDisplay(nullptr);
|
||||
if(x11_mapping_display)
|
||||
XKeysymToKeycode(x11_mapping_display, XK_F1); // If we dont call we will never get a MappingNotify
|
||||
x11_dpy = XOpenDisplay(nullptr);
|
||||
if(x11_dpy)
|
||||
XKeysymToKeycode(x11_dpy, XK_F1); // If we dont call we will never get a MappingNotify
|
||||
else
|
||||
fprintf(stderr, "Warning: XOpenDisplay failed to mapping notify\n");
|
||||
|
||||
if(this->gsr_info.system_info.display_server == DisplayServer::X11)
|
||||
cursor_tracker = std::make_unique<CursorTrackerX11>((Display*)mgl_get_context()->connection);
|
||||
else if(this->gsr_info.system_info.display_server == DisplayServer::WAYLAND && !this->gsr_info.gpu_info.card_path.empty())
|
||||
cursor_tracker = std::make_unique<CursorTrackerWayland>(this->gsr_info.gpu_info.card_path.c_str());
|
||||
else if(this->gsr_info.system_info.display_server == DisplayServer::WAYLAND) {
|
||||
if(!this->gsr_info.gpu_info.card_path.empty())
|
||||
cursor_tracker = std::make_unique<CursorTrackerWayland>(this->gsr_info.gpu_info.card_path.c_str());
|
||||
|
||||
if(!config.main_config.wayland_warning_shown) {
|
||||
config.main_config.wayland_warning_shown = true;
|
||||
save_config(config);
|
||||
show_notification("Wayland doesn't support GPU Screen Recorder UI properly,\nthings may not work as expected. Use X11 if you experience issues.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Only do this if led indicator is enabled (at startup or when changing recording/screenshot settings to enabled it)
|
||||
led_indicator = std::make_unique<LedIndicator>();
|
||||
}
|
||||
|
||||
Overlay::~Overlay() {
|
||||
@@ -541,11 +559,13 @@ namespace gsr {
|
||||
gpu_screen_recorder_screenshot_process = -1;
|
||||
}
|
||||
|
||||
led_indicator.reset();
|
||||
|
||||
close_gpu_screen_recorder_output();
|
||||
deinit_color_theme();
|
||||
|
||||
if(x11_mapping_display)
|
||||
XCloseDisplay(x11_mapping_display);
|
||||
if(x11_dpy)
|
||||
XCloseDisplay(x11_dpy);
|
||||
}
|
||||
|
||||
void Overlay::xi_setup() {
|
||||
@@ -689,12 +709,12 @@ namespace gsr {
|
||||
}
|
||||
|
||||
void Overlay::handle_keyboard_mapping_event() {
|
||||
if(!x11_mapping_display)
|
||||
if(!x11_dpy)
|
||||
return;
|
||||
|
||||
bool mapping_updated = false;
|
||||
while(XPending(x11_mapping_display)) {
|
||||
XNextEvent(x11_mapping_display, &x11_mapping_xev);
|
||||
while(XPending(x11_dpy)) {
|
||||
XNextEvent(x11_dpy, &x11_mapping_xev);
|
||||
if(x11_mapping_xev.type == MappingNotify) {
|
||||
XRefreshKeyboardMapping(&x11_mapping_xev.xmapping);
|
||||
mapping_updated = true;
|
||||
@@ -706,6 +726,21 @@ namespace gsr {
|
||||
}
|
||||
|
||||
void Overlay::handle_events() {
|
||||
if(led_indicator)
|
||||
led_indicator->update();
|
||||
|
||||
if(global_hotkeys_ungrab_keyboard) {
|
||||
global_hotkeys_ungrab_keyboard = false;
|
||||
show_notification(
|
||||
"Some keyboard remapping software conflicts with GPU Screen Recorder on your system.\n"
|
||||
"Keyboards have been ungrabbed, applications will now receive the hotkeys you press."
|
||||
, 7.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
|
||||
config.main_config.hotkeys_enable_option = "enable_hotkeys_no_grab";
|
||||
save_config(config);
|
||||
recreate_global_hotkeys("enable_hotkeys_no_grab");
|
||||
}
|
||||
|
||||
if(global_hotkeys)
|
||||
global_hotkeys->poll_events();
|
||||
|
||||
@@ -738,7 +773,7 @@ namespace gsr {
|
||||
if(selected_window && selected_window != DefaultRootWindow(display)) {
|
||||
on_window_selected();
|
||||
} else {
|
||||
show_notification("No window selected", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("No window selected", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
on_window_selected = nullptr;
|
||||
}
|
||||
@@ -789,7 +824,7 @@ namespace gsr {
|
||||
start_region_capture = false;
|
||||
hide();
|
||||
if(!region_selector.start(get_color_theme().tint_color)) {
|
||||
show_notification("Failed to start region capture", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to start region capture", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
on_region_selected = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -798,7 +833,7 @@ namespace gsr {
|
||||
start_window_capture = false;
|
||||
hide();
|
||||
if(!window_selector.start(get_color_theme().tint_color)) {
|
||||
show_notification("Failed to start window capture", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to start window capture", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
on_window_selected = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -1016,6 +1051,7 @@ namespace gsr {
|
||||
// Use Glx on Wayland to workaround this issue. This is fine since Egl is only needed for x11 to reliably get the texture of the fullscreen window on Nvidia
|
||||
// when a compositor isn't running.
|
||||
window_create_params.graphics_api = gsr_info.system_info.display_server == DisplayServer::WAYLAND ? MGL_GRAPHICS_API_GLX : MGL_GRAPHICS_API_EGL;
|
||||
window_create_params.class_name = "gsr-ui";
|
||||
|
||||
if(!window->create("gsr ui", window_create_params)) {
|
||||
fprintf(stderr, "error: failed to create window\n");
|
||||
@@ -1125,6 +1161,18 @@ namespace gsr {
|
||||
draw();
|
||||
}
|
||||
|
||||
void Overlay::recreate_global_hotkeys(const char *hotkey_option) {
|
||||
global_hotkeys.reset();
|
||||
if(strcmp(hotkey_option, "enable_hotkeys") == 0)
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::ALL);
|
||||
else if(strcmp(hotkey_option, "enable_hotkeys_virtual_devices") == 0)
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::VIRTUAL);
|
||||
else if(strcmp(hotkey_option, "enable_hotkeys_no_grab") == 0)
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::NO_GRAB);
|
||||
else if(strcmp(hotkey_option, "disable_hotkeys") == 0)
|
||||
global_hotkeys.reset();
|
||||
}
|
||||
|
||||
void Overlay::create_frontpage_ui_components() {
|
||||
bg_screenshot_overlay = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height));
|
||||
top_bar_background = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height*0.06f).floor());
|
||||
@@ -1269,12 +1317,12 @@ namespace gsr {
|
||||
|
||||
if(exit_status == 127) {
|
||||
if(enable)
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup.\nThis option only works on systems that use systemd.\nYou have to manually add \"gsr-ui\" to system startup on systems that uses another init system.", 7.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup.\nThis option only works on systems that use systemd.\nYou have to manually add \"gsr-ui\" to system startup on systems that uses another init system.", 7.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
} else {
|
||||
if(enable)
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
else
|
||||
show_notification("Failed to remove GPU Screen Recorder from system startup", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to remove GPU Screen Recorder from system startup", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1284,13 +1332,7 @@ namespace gsr {
|
||||
};
|
||||
|
||||
settings_page->on_keyboard_hotkey_changed = [this](const char *hotkey_option) {
|
||||
global_hotkeys.reset();
|
||||
if(strcmp(hotkey_option, "enable_hotkeys") == 0)
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::ALL);
|
||||
else if(strcmp(hotkey_option, "enable_hotkeys_virtual_devices") == 0)
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::VIRTUAL);
|
||||
else if(strcmp(hotkey_option, "disable_hotkeys") == 0)
|
||||
global_hotkeys.reset();
|
||||
recreate_global_hotkeys(hotkey_option);
|
||||
};
|
||||
|
||||
settings_page->on_joystick_hotkey_changed = [this](const char *hotkey_option) {
|
||||
@@ -1443,7 +1485,13 @@ namespace gsr {
|
||||
}
|
||||
|
||||
deinit_theme();
|
||||
#ifdef __GLIBC__
|
||||
malloc_trim(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Overlay::hide_next_frame() {
|
||||
hide_ui = true;
|
||||
}
|
||||
|
||||
void Overlay::toggle_show() {
|
||||
@@ -1467,18 +1515,29 @@ namespace gsr {
|
||||
if(recording_status != RecordingStatus::RECORD || gpu_screen_recorder_process <= 0)
|
||||
return;
|
||||
|
||||
if(paused) {
|
||||
update_ui_recording_unpaused();
|
||||
if(config.record_config.show_video_paused_notifications)
|
||||
show_notification("Recording has been unpaused", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
} else {
|
||||
update_ui_recording_paused();
|
||||
if(config.record_config.show_video_paused_notifications)
|
||||
show_notification("Recording has been paused", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
}
|
||||
|
||||
kill(gpu_screen_recorder_process, SIGUSR2);
|
||||
paused = !paused;
|
||||
|
||||
if(paused) {
|
||||
paused_clock.restart();
|
||||
update_ui_recording_paused();
|
||||
if(config.record_config.record_options.show_notifications)
|
||||
show_notification("Recording has been paused", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
} else {
|
||||
paused_total_time_seconds += paused_clock.get_elapsed_time_seconds();
|
||||
update_ui_recording_unpaused();
|
||||
if(config.record_config.record_options.show_notifications)
|
||||
show_notification("Recording has been unpaused", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
}
|
||||
|
||||
if(led_indicator && config.record_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
}
|
||||
|
||||
void Overlay::update_upause_status() {
|
||||
paused = false;
|
||||
paused_clock.restart();
|
||||
paused_total_time_seconds = 0.0;
|
||||
}
|
||||
|
||||
void Overlay::toggle_stream() {
|
||||
@@ -1657,8 +1716,9 @@ namespace gsr {
|
||||
return focused_monitor_name;
|
||||
}
|
||||
|
||||
void Overlay::show_notification(const char *str, double timeout_seconds, mgl::Color icon_color, mgl::Color bg_color, NotificationType notification_type, const char *capture_target) {
|
||||
timeout_seconds *= notification_duration_multiplier;
|
||||
void Overlay::show_notification(const char *str, double timeout_seconds, mgl::Color icon_color, mgl::Color bg_color, NotificationType notification_type, const char *capture_target, NotificationLevel notification_level) {
|
||||
if(notification_level != NotificationLevel::ERROR)
|
||||
timeout_seconds *= notification_duration_multiplier;
|
||||
|
||||
char timeout_seconds_str[32];
|
||||
snprintf(timeout_seconds_str, sizeof(timeout_seconds_str), "%f", timeout_seconds);
|
||||
@@ -1833,8 +1893,8 @@ namespace gsr {
|
||||
|
||||
double Overlay::get_time_passed_in_replay_buffer_seconds() {
|
||||
double replay_duration_sec = replay_saved_duration_sec;
|
||||
if(replay_duration_sec > replay_buffer_save_duration_sec)
|
||||
replay_duration_sec = replay_buffer_save_duration_sec;
|
||||
if(replay_duration_sec > current_recording_config.replay_config.replay_time)
|
||||
replay_duration_sec = current_recording_config.replay_config.replay_time;
|
||||
if(replay_save_duration_min > 0 && replay_duration_sec > replay_save_duration_min * 60)
|
||||
replay_duration_sec = replay_save_duration_min * 60;
|
||||
return replay_duration_sec;
|
||||
@@ -1861,7 +1921,7 @@ namespace gsr {
|
||||
if(focused_window_name.empty())
|
||||
focused_window_name = "Game";
|
||||
|
||||
string_replace_characters(focused_window_name.data(), "/\\", '_');
|
||||
string_replace_characters(focused_window_name.data(), "/\\", ' ');
|
||||
|
||||
std::string video_directory = filepath_get_directory(video_filepath) + "/" + focused_window_name;
|
||||
create_directory_recursive(video_directory.data());
|
||||
@@ -1875,10 +1935,19 @@ namespace gsr {
|
||||
|
||||
switch(notification_type) {
|
||||
case NotificationType::RECORD: {
|
||||
if(!config.record_config.show_video_saved_notifications)
|
||||
if(led_indicator) {
|
||||
if(recording_status == RecordingStatus::REPLAY && !current_recording_config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
else if(recording_status == RecordingStatus::STREAM && !current_recording_config.streaming_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
else if(config.record_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
}
|
||||
|
||||
if(!config.record_config.record_options.show_notifications)
|
||||
return;
|
||||
|
||||
const std::string duration_str = to_duration_string(recording_duration_clock.get_elapsed_time_seconds());
|
||||
const std::string duration_str = to_duration_string(recording_duration_clock.get_elapsed_time_seconds() - paused_total_time_seconds - (paused ? paused_clock.get_elapsed_time_seconds() : 0.0));
|
||||
snprintf(msg, sizeof(msg), "Saved a %s recording of %s\nto \"%s\"",
|
||||
duration_str.c_str(),
|
||||
capture_target_get_notification_name(recording_capture_target.c_str(), true).c_str(), focused_window_name.c_str());
|
||||
@@ -1886,7 +1955,10 @@ namespace gsr {
|
||||
break;
|
||||
}
|
||||
case NotificationType::REPLAY: {
|
||||
if(!config.replay_config.show_replay_saved_notifications)
|
||||
if(led_indicator && config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
|
||||
if(!config.replay_config.record_options.show_notifications)
|
||||
return;
|
||||
|
||||
const std::string duration_str = to_duration_string(get_time_passed_in_replay_buffer_seconds());
|
||||
@@ -1897,7 +1969,10 @@ namespace gsr {
|
||||
break;
|
||||
}
|
||||
case NotificationType::SCREENSHOT: {
|
||||
if(!config.screenshot_config.show_screenshot_saved_notifications)
|
||||
if(led_indicator && config.screenshot_config.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
|
||||
if(!config.screenshot_config.show_notifications)
|
||||
return;
|
||||
|
||||
snprintf(msg, sizeof(msg), "Saved a screenshot of %s\nto \"%s\"",
|
||||
@@ -1929,21 +2004,28 @@ namespace gsr {
|
||||
replay_save_show_notification = false;
|
||||
if(config.replay_config.save_video_in_game_folder) {
|
||||
save_video_in_current_game_directory(replay_saved_filepath, NotificationType::REPLAY);
|
||||
} else if(config.replay_config.show_replay_saved_notifications) {
|
||||
const std::string duration_str = to_duration_string(get_time_passed_in_replay_buffer_seconds());
|
||||
return;
|
||||
} else {
|
||||
if(config.replay_config.record_options.show_notifications) {
|
||||
const std::string duration_str = to_duration_string(get_time_passed_in_replay_buffer_seconds());
|
||||
|
||||
char msg[512];
|
||||
snprintf(msg, sizeof(msg), "Saved a %s replay of %s",
|
||||
duration_str.c_str(),
|
||||
capture_target_get_notification_name(recording_capture_target.c_str(), true).c_str());
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY, recording_capture_target.c_str());
|
||||
char msg[512];
|
||||
snprintf(msg, sizeof(msg), "Saved a %s replay of %s",
|
||||
duration_str.c_str(),
|
||||
capture_target_get_notification_name(recording_capture_target.c_str(), true).c_str());
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY, recording_capture_target.c_str());
|
||||
}
|
||||
|
||||
if(led_indicator && config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
}
|
||||
}
|
||||
|
||||
void Overlay::process_gsr_output() {
|
||||
if(replay_save_show_notification && replay_save_clock.get_elapsed_time_seconds() >= replay_saving_notification_timeout_seconds) {
|
||||
replay_save_show_notification = false;
|
||||
show_notification("Saving replay, this might take some time", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
if(config.replay_config.record_options.show_notifications)
|
||||
show_notification("Saving replay, this might take some time", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
}
|
||||
|
||||
if(gpu_screen_recorder_process_output_file) {
|
||||
@@ -1957,7 +2039,7 @@ namespace gsr {
|
||||
line[line_len - 1] = '\0';
|
||||
|
||||
if(starts_with({line, (size_t)line_len}, "Error: ")) {
|
||||
show_notification(line + 7, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), recording_status_to_notification_type(recording_status));
|
||||
show_notification(line + 7, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), recording_status_to_notification_type(recording_status), nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1987,17 +2069,17 @@ namespace gsr {
|
||||
void Overlay::on_gsr_process_error(int exit_code, NotificationType notification_type) {
|
||||
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_process, exit_code);
|
||||
if(exit_code == 50) {
|
||||
show_notification("Desktop portal capture failed.\nEither you canceled the desktop portal or your Wayland compositor doesn't support desktop portal capture\nor it's incorrectly setup on your system.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type);
|
||||
show_notification("Desktop portal capture failed.\nEither you canceled the desktop portal or your Wayland compositor doesn't support desktop portal capture\nor it's incorrectly setup on your system.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type, nullptr, NotificationLevel::ERROR);
|
||||
} else if(exit_code == 51) {
|
||||
show_notification("Monitor capture failed.\nThe monitor you are trying to capture is invalid.\nPlease validate your capture settings.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type);
|
||||
show_notification("Monitor capture failed.\nThe monitor you are trying to capture is invalid.\nPlease validate your capture settings.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type, nullptr, NotificationLevel::ERROR);
|
||||
} else if(exit_code == 52) {
|
||||
show_notification("Capture failed. Neither H264, HEVC nor AV1 video codecs are supported\non your system or you are trying to capture at a resolution higher than your\nsystem supports for each video codec.", 10.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type);
|
||||
show_notification("Capture failed. Neither H264, HEVC nor AV1 video codecs are supported\non your system or you are trying to capture at a resolution higher than your\nsystem supports for each video codec.", 10.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type, nullptr, NotificationLevel::ERROR);
|
||||
} else if(exit_code == 53) {
|
||||
show_notification("Capture failed. Your system doesn't support the resolution you are trying to\nrecord at with the video codec you have chosen.\nChange capture resolution or video codec and try again.\nNote: AV1 supports the highest resolution, then HEVC and then H264.", 10.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type);
|
||||
show_notification("Capture failed. Your system doesn't support the resolution you are trying to\nrecord at with the video codec you have chosen.\nChange capture resolution or video codec and try again.\nNote: AV1 supports the highest resolution, then HEVC and then H264.", 10.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type, nullptr, NotificationLevel::ERROR);
|
||||
} else if(exit_code == 54) {
|
||||
show_notification("Capture failed. Your system doesn't support the video codec you have chosen.\nChange video codec and try again.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type);
|
||||
show_notification("Capture failed. Your system doesn't support the video codec you have chosen.\nChange video codec and try again.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type, nullptr, NotificationLevel::ERROR);
|
||||
} else if(exit_code == 60) {
|
||||
show_notification("Stopped capture because the user canceled the desktop portal", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type);
|
||||
show_notification("Stopped capture because the user canceled the desktop portal", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type, nullptr, NotificationLevel::ERROR);
|
||||
} else {
|
||||
const char *prefix = "";
|
||||
switch(notification_type) {
|
||||
@@ -2019,7 +2101,7 @@ namespace gsr {
|
||||
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "%s. Verify if settings are correct", prefix);
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type);
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), notification_type, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2046,26 +2128,36 @@ namespace gsr {
|
||||
replay_save_duration_min = 0;
|
||||
update_ui_replay_stopped();
|
||||
if(exit_code == 0) {
|
||||
if(config.replay_config.show_replay_stopped_notifications)
|
||||
if(config.replay_config.record_options.show_notifications)
|
||||
show_notification("Replay stopped", short_notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
} else {
|
||||
on_gsr_process_error(exit_code, NotificationType::REPLAY);
|
||||
}
|
||||
|
||||
if(led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
|
||||
break;
|
||||
}
|
||||
case RecordingStatus::RECORD: {
|
||||
update_ui_recording_stopped();
|
||||
on_stop_recording(exit_code, record_filepath);
|
||||
|
||||
if(led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
break;
|
||||
}
|
||||
case RecordingStatus::STREAM: {
|
||||
update_ui_streaming_stopped();
|
||||
if(exit_code == 0) {
|
||||
if(config.streaming_config.show_streaming_stopped_notifications)
|
||||
if(config.streaming_config.record_options.show_notifications)
|
||||
show_notification("Streaming has stopped", short_notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
} else {
|
||||
on_gsr_process_error(exit_code, NotificationType::STREAM);
|
||||
}
|
||||
|
||||
if(led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2091,18 +2183,23 @@ namespace gsr {
|
||||
if(exit_code == 0) {
|
||||
if(config.screenshot_config.save_screenshot_in_game_folder) {
|
||||
save_video_in_current_game_directory(screenshot_filepath.c_str(), NotificationType::SCREENSHOT);
|
||||
} else if(config.screenshot_config.show_screenshot_saved_notifications) {
|
||||
char msg[512];
|
||||
snprintf(msg, sizeof(msg), "Saved a screenshot of %s",
|
||||
capture_target_get_notification_name(screenshot_capture_target.c_str(), true).c_str());
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::SCREENSHOT, screenshot_capture_target.c_str());
|
||||
} else {
|
||||
if(config.screenshot_config.show_notifications) {
|
||||
char msg[512];
|
||||
snprintf(msg, sizeof(msg), "Saved a screenshot of %s",
|
||||
capture_target_get_notification_name(screenshot_capture_target.c_str(), true).c_str());
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::SCREENSHOT, screenshot_capture_target.c_str());
|
||||
|
||||
if(config.screenshot_config.save_screenshot_to_clipboard)
|
||||
clipboard_file.set_current_file(screenshot_filepath, filename_to_clipboard_file_type(screenshot_filepath));
|
||||
if(config.screenshot_config.save_screenshot_to_clipboard)
|
||||
clipboard_file.set_current_file(screenshot_filepath, filename_to_clipboard_file_type(screenshot_filepath));
|
||||
}
|
||||
|
||||
if(led_indicator && config.screenshot_config.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_screenshot_process, exit_code);
|
||||
show_notification("Failed to take a screenshot. Verify if settings are correct", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT);
|
||||
show_notification("Failed to take a screenshot. Verify if settings are correct", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
|
||||
gpu_screen_recorder_screenshot_process = -1;
|
||||
@@ -2194,18 +2291,30 @@ namespace gsr {
|
||||
if(exit_code == 0) {
|
||||
if(config.record_config.save_video_in_game_folder) {
|
||||
save_video_in_current_game_directory(video_filepath.c_str(), NotificationType::RECORD);
|
||||
} else if(config.record_config.show_video_saved_notifications) {
|
||||
const std::string duration_str = to_duration_string(recording_duration_clock.get_elapsed_time_seconds());
|
||||
} else {
|
||||
if(config.record_config.record_options.show_notifications) {
|
||||
const std::string duration_str = to_duration_string(recording_duration_clock.get_elapsed_time_seconds() - paused_total_time_seconds - (paused ? paused_clock.get_elapsed_time_seconds() : 0.0));
|
||||
|
||||
char msg[512];
|
||||
snprintf(msg, sizeof(msg), "Saved a %s recording of %s",
|
||||
duration_str.c_str(),
|
||||
capture_target_get_notification_name(recording_capture_target.c_str(), true).c_str());
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD, recording_capture_target.c_str());
|
||||
char msg[512];
|
||||
snprintf(msg, sizeof(msg), "Saved a %s recording of %s",
|
||||
duration_str.c_str(),
|
||||
capture_target_get_notification_name(recording_capture_target.c_str(), true).c_str());
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD, recording_capture_target.c_str());
|
||||
}
|
||||
|
||||
if(led_indicator) {
|
||||
if(recording_status == RecordingStatus::REPLAY && !current_recording_config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
else if(recording_status == RecordingStatus::STREAM && !current_recording_config.streaming_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
else if(config.record_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
on_gsr_process_error(exit_code, NotificationType::RECORD);
|
||||
}
|
||||
|
||||
update_ui_recording_stopped();
|
||||
replay_recording = false;
|
||||
}
|
||||
@@ -2251,7 +2360,7 @@ namespace gsr {
|
||||
record_dropdown_button_ptr->set_item_label("pause", "Pause");
|
||||
record_dropdown_button_ptr->set_item_icon("pause", &get_theme().pause_texture);
|
||||
record_dropdown_button_ptr->set_item_enabled("pause", false);
|
||||
paused = false;
|
||||
update_upause_status();
|
||||
replay_recording = false;
|
||||
}
|
||||
|
||||
@@ -2285,8 +2394,8 @@ namespace gsr {
|
||||
replay_dropdown_button_ptr->set_description("On");
|
||||
replay_dropdown_button_ptr->set_item_icon("start", &get_theme().stop_texture);
|
||||
replay_dropdown_button_ptr->set_item_enabled("save", true);
|
||||
replay_dropdown_button_ptr->set_item_enabled("save_1_min", true);
|
||||
replay_dropdown_button_ptr->set_item_enabled("save_10_min", true);
|
||||
replay_dropdown_button_ptr->set_item_enabled("save_1_min", current_recording_config.replay_config.replay_time >= 60);
|
||||
replay_dropdown_button_ptr->set_item_enabled("save_10_min", current_recording_config.replay_config.replay_time >= 60 * 10);
|
||||
}
|
||||
|
||||
void Overlay::update_ui_replay_stopped() {
|
||||
@@ -2492,6 +2601,7 @@ namespace gsr {
|
||||
replay_saved_duration_sec = replay_duration_clock.get_elapsed_time_seconds();
|
||||
if(replay_restart_on_save)
|
||||
replay_duration_clock.restart();
|
||||
|
||||
kill(gpu_screen_recorder_process, SIGUSR1);
|
||||
}
|
||||
|
||||
@@ -2499,6 +2609,9 @@ namespace gsr {
|
||||
if(recording_status != RecordingStatus::REPLAY || gpu_screen_recorder_process <= 0)
|
||||
return;
|
||||
|
||||
if(current_recording_config.replay_config.replay_time < 60)
|
||||
return;
|
||||
|
||||
replay_save_duration_min = 1;
|
||||
replay_save_show_notification = true;
|
||||
replay_save_clock.restart();
|
||||
@@ -2510,6 +2623,9 @@ namespace gsr {
|
||||
if(recording_status != RecordingStatus::REPLAY || gpu_screen_recorder_process <= 0)
|
||||
return;
|
||||
|
||||
if(current_recording_config.replay_config.replay_time < 60 * 10)
|
||||
return;
|
||||
|
||||
replay_save_duration_min = 10;
|
||||
replay_save_show_notification = true;
|
||||
replay_save_clock.restart();
|
||||
@@ -2575,15 +2691,14 @@ namespace gsr {
|
||||
case RecordingStatus::REPLAY:
|
||||
break;
|
||||
case RecordingStatus::RECORD:
|
||||
show_notification("Unable to start replay when recording.\nStop recording before starting replay.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
|
||||
show_notification("Unable to start replay when recording.\nStop recording before starting replay.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD, nullptr, NotificationLevel::ERROR);
|
||||
return false;
|
||||
case RecordingStatus::STREAM:
|
||||
show_notification("Unable to start replay when streaming.\nStop streaming before starting replay.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM);
|
||||
show_notification("Unable to start replay when streaming.\nStop streaming before starting replay.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM, nullptr, NotificationLevel::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
paused = false;
|
||||
replay_save_show_notification = false;
|
||||
update_upause_status();
|
||||
try_replay_startup = false;
|
||||
|
||||
close_gpu_screen_recorder_output();
|
||||
@@ -2601,8 +2716,11 @@ namespace gsr {
|
||||
replay_save_duration_min = 0;
|
||||
update_ui_replay_stopped();
|
||||
|
||||
if(led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
|
||||
// TODO: Show this with a slight delay to make sure it doesn't show up in the video
|
||||
if(!disable_notification && config.replay_config.show_replay_stopped_notifications)
|
||||
if(!disable_notification && config.replay_config.record_options.show_notifications)
|
||||
show_notification("Replay stopped", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
|
||||
return true;
|
||||
@@ -2613,7 +2731,7 @@ namespace gsr {
|
||||
if(!validate_capture_target(config.replay_config.record_options.record_area_option, capture_options)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to start replay, capture target \"%s\" is invalid.\nPlease change capture target in settings", recording_capture_target.c_str());
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY);
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY, nullptr, NotificationLevel::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2691,13 +2809,18 @@ namespace gsr {
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
current_recording_config = config;
|
||||
|
||||
gpu_screen_recorder_process = exec_program(args.data(), &gpu_screen_recorder_process_output_fd);
|
||||
if(gpu_screen_recorder_process == -1) {
|
||||
show_notification("Failed to launch gpu-screen-recorder to start replay", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY);
|
||||
show_notification("Failed to launch gpu-screen-recorder to start replay", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY, nullptr, NotificationLevel::ERROR);
|
||||
return false;
|
||||
} else {
|
||||
recording_status = RecordingStatus::REPLAY;
|
||||
update_ui_replay_started();
|
||||
|
||||
if(led_indicator && config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(true);
|
||||
}
|
||||
|
||||
prepare_gsr_output_for_reading();
|
||||
@@ -2711,7 +2834,7 @@ namespace gsr {
|
||||
// TODO: Do not run this is a daemon. Instead get the pid and when launching another notification close the current notification
|
||||
// program and start another one. This can also be used to check when the notification has finished by checking with waitpid NOWAIT
|
||||
// to see when the program has exit.
|
||||
if(!disable_notification && config.replay_config.show_replay_started_notifications) {
|
||||
if(!disable_notification && config.replay_config.record_options.show_notifications) {
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "Started replaying %s", capture_target_get_notification_name(recording_capture_target.c_str(), false).c_str());
|
||||
show_notification(msg, short_notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::REPLAY, recording_capture_target.c_str());
|
||||
@@ -2723,7 +2846,6 @@ namespace gsr {
|
||||
// TODO: This will be incorrect if the user uses portal capture, as capture wont start until the user has
|
||||
// selected what to capture and accepted it.
|
||||
replay_duration_clock.restart();
|
||||
replay_buffer_save_duration_sec = config.replay_config.replay_time;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2741,18 +2863,27 @@ namespace gsr {
|
||||
|
||||
if(gsr_info.system_info.gsr_version >= GsrVersion{5, 4, 0}) {
|
||||
if(!replay_recording) {
|
||||
if(config.record_config.show_recording_started_notifications)
|
||||
if(config.record_config.record_options.show_notifications)
|
||||
show_notification("Started recording in the replay session", short_notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::RECORD);
|
||||
update_ui_recording_started();
|
||||
|
||||
// TODO: This will be incorrect if the user uses portal capture, as capture wont start until the user has
|
||||
// selected what to capture and accepted it.
|
||||
recording_duration_clock.restart();
|
||||
update_upause_status();
|
||||
|
||||
if(led_indicator) {
|
||||
if(!current_recording_config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(true);
|
||||
else if(config.record_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
}
|
||||
}
|
||||
|
||||
replay_recording = true;
|
||||
kill(gpu_screen_recorder_process, SIGRTMIN);
|
||||
} else {
|
||||
show_notification("Unable to start recording when replay is turned on.\nTurn off replay before starting recording.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification("Unable to start recording when replay is turned on.\nTurn off replay before starting recording.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), get_color_theme().tint_color, NotificationType::REPLAY, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -2762,25 +2893,32 @@ namespace gsr {
|
||||
|
||||
if(gsr_info.system_info.gsr_version >= GsrVersion{5, 4, 0}) {
|
||||
if(!replay_recording) {
|
||||
if(config.record_config.show_recording_started_notifications)
|
||||
if(config.record_config.record_options.show_notifications)
|
||||
show_notification("Started recording in the streaming session", short_notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::RECORD);
|
||||
update_ui_recording_started();
|
||||
|
||||
// TODO: This will be incorrect if the user uses portal capture, as capture wont start until the user has
|
||||
// selected what to capture and accepted it.
|
||||
recording_duration_clock.restart();
|
||||
update_upause_status();
|
||||
|
||||
if(led_indicator) {
|
||||
if(!current_recording_config.streaming_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(true);
|
||||
else if(config.record_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
}
|
||||
}
|
||||
|
||||
replay_recording = true;
|
||||
kill(gpu_screen_recorder_process, SIGRTMIN);
|
||||
} else {
|
||||
show_notification("Unable to start recording when streaming.\nStop streaming before starting recording.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
show_notification("Unable to start recording when streaming.\nStop streaming before starting recording.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), get_color_theme().tint_color, NotificationType::STREAM, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
paused = false;
|
||||
|
||||
close_gpu_screen_recorder_output();
|
||||
|
||||
if(gpu_screen_recorder_process > 0) {
|
||||
@@ -2799,16 +2937,22 @@ namespace gsr {
|
||||
gpu_screen_recorder_process = -1;
|
||||
recording_status = RecordingStatus::NONE;
|
||||
update_ui_recording_stopped();
|
||||
update_upause_status();
|
||||
record_filepath.clear();
|
||||
|
||||
if(led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
return;
|
||||
}
|
||||
|
||||
update_upause_status();
|
||||
|
||||
const SupportedCaptureOptions capture_options = get_supported_capture_options(gsr_info);
|
||||
recording_capture_target = get_capture_target(config.record_config.record_options.record_area_option, capture_options);
|
||||
if(!validate_capture_target(config.record_config.record_options.record_area_option, capture_options)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to start recording, capture target \"%s\" is invalid.\nPlease change capture target in settings", recording_capture_target.c_str());
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD, nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2868,14 +3012,19 @@ namespace gsr {
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
current_recording_config = config;
|
||||
|
||||
record_filepath = output_file;
|
||||
gpu_screen_recorder_process = exec_program(args.data(), &gpu_screen_recorder_process_output_fd);
|
||||
if(gpu_screen_recorder_process == -1) {
|
||||
show_notification("Failed to launch gpu-screen-recorder to start recording", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
|
||||
show_notification("Failed to launch gpu-screen-recorder to start recording", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD, nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
} else {
|
||||
recording_status = RecordingStatus::RECORD;
|
||||
update_ui_recording_started();
|
||||
|
||||
if(led_indicator && config.record_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(true);
|
||||
}
|
||||
|
||||
prepare_gsr_output_for_reading();
|
||||
@@ -2886,7 +3035,7 @@ namespace gsr {
|
||||
// Starting recording in 3...
|
||||
// 2...
|
||||
// 1...
|
||||
if(config.record_config.show_recording_started_notifications) {
|
||||
if(config.record_config.record_options.show_notifications) {
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "Started recording %s", capture_target_get_notification_name(recording_capture_target.c_str(), false).c_str());
|
||||
show_notification(msg, short_notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::RECORD, recording_capture_target.c_str());
|
||||
@@ -2949,14 +3098,14 @@ namespace gsr {
|
||||
case RecordingStatus::STREAM:
|
||||
break;
|
||||
case RecordingStatus::REPLAY:
|
||||
show_notification("Unable to start streaming when replay is turned on.\nTurn off replay before starting streaming.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY);
|
||||
show_notification("Unable to start streaming when replay is turned on.\nTurn off replay before starting streaming.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY, nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
case RecordingStatus::RECORD:
|
||||
show_notification("Unable to start streaming when recording.\nStop recording before starting streaming.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
|
||||
show_notification("Unable to start streaming when recording.\nStop recording before starting streaming.", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD, nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
paused = false;
|
||||
update_upause_status();
|
||||
|
||||
close_gpu_screen_recorder_output();
|
||||
|
||||
@@ -2972,8 +3121,11 @@ namespace gsr {
|
||||
recording_status = RecordingStatus::NONE;
|
||||
update_ui_streaming_stopped();
|
||||
|
||||
if(led_indicator)
|
||||
led_indicator->set_led(false);
|
||||
|
||||
// TODO: Show this with a slight delay to make sure it doesn't show up in the video
|
||||
if(config.streaming_config.show_streaming_stopped_notifications)
|
||||
if(config.streaming_config.record_options.show_notifications)
|
||||
show_notification("Streaming has stopped", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
return;
|
||||
}
|
||||
@@ -2983,7 +3135,7 @@ namespace gsr {
|
||||
if(!validate_capture_target(config.streaming_config.record_options.record_area_option, capture_options)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to start streaming, capture target \"%s\" is invalid.\nPlease change capture target in settings", recording_capture_target.c_str());
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM);
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM, nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3023,10 +3175,10 @@ namespace gsr {
|
||||
|
||||
char size[64];
|
||||
size[0] = '\0';
|
||||
if(config.record_config.record_options.record_area_option == "focused")
|
||||
if(config.streaming_config.record_options.record_area_option == "focused")
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.streaming_config.record_options.record_area_width, (int)config.streaming_config.record_options.record_area_height);
|
||||
|
||||
if(config.record_config.record_options.record_area_option != "focused" && config.streaming_config.record_options.change_video_resolution)
|
||||
if(config.streaming_config.record_options.record_area_option != "focused" && config.streaming_config.record_options.change_video_resolution)
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.streaming_config.record_options.video_width, (int)config.streaming_config.record_options.video_height);
|
||||
|
||||
std::vector<const char*> args = {
|
||||
@@ -3036,6 +3188,7 @@ namespace gsr {
|
||||
"-cursor", config.streaming_config.record_options.record_cursor ? "yes" : "no",
|
||||
"-cr", config.streaming_config.record_options.color_range.c_str(),
|
||||
"-fm", framerate_mode.c_str(),
|
||||
"-k", video_codec,
|
||||
"-encoder", encoder,
|
||||
"-f", fps.c_str(),
|
||||
"-v", "no",
|
||||
@@ -3052,13 +3205,18 @@ namespace gsr {
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
current_recording_config = config;
|
||||
|
||||
gpu_screen_recorder_process = exec_program(args.data(), &gpu_screen_recorder_process_output_fd);
|
||||
if(gpu_screen_recorder_process == -1) {
|
||||
show_notification("Failed to launch gpu-screen-recorder to start streaming", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM);
|
||||
show_notification("Failed to launch gpu-screen-recorder to start streaming", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM, nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
} else {
|
||||
recording_status = RecordingStatus::STREAM;
|
||||
update_ui_streaming_started();
|
||||
|
||||
if(led_indicator && config.streaming_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(true);
|
||||
}
|
||||
|
||||
prepare_gsr_output_for_reading();
|
||||
@@ -3072,7 +3230,7 @@ namespace gsr {
|
||||
// TODO: Do not run this is a daemon. Instead get the pid and when launching another notification close the current notification
|
||||
// program and start another one. This can also be used to check when the notification has finished by checking with waitpid NOWAIT
|
||||
// to see when the program has exit.
|
||||
if(config.streaming_config.show_streaming_started_notifications) {
|
||||
if(config.streaming_config.record_options.show_notifications) {
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "Started streaming %s", capture_target_get_notification_name(recording_capture_target.c_str(), false).c_str());
|
||||
show_notification(msg, short_notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::STREAM, recording_capture_target.c_str());
|
||||
@@ -3091,7 +3249,6 @@ namespace gsr {
|
||||
return;
|
||||
}
|
||||
|
||||
bool hotkey_window_capture = false;
|
||||
std::string record_area_option;
|
||||
switch(force_type) {
|
||||
case ScreenshotForceType::NONE:
|
||||
@@ -3102,7 +3259,6 @@ namespace gsr {
|
||||
break;
|
||||
case ScreenshotForceType::WINDOW:
|
||||
record_area_option = gsr_info.system_info.display_server == DisplayServer::X11 ? "window" : "portal";
|
||||
hotkey_window_capture = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3111,7 +3267,7 @@ namespace gsr {
|
||||
if(!validate_capture_target(record_area_option, capture_options)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to take a screenshot, capture target \"%s\" is invalid.\nPlease change capture target in settings", screenshot_capture_target.c_str());
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT);
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT, nullptr, NotificationLevel::ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3133,10 +3289,11 @@ namespace gsr {
|
||||
|
||||
// TODO: Validate input, fallback to valid values
|
||||
const std::string output_file = config.screenshot_config.save_directory + "/Screenshot_" + get_date_str() + "." + config.screenshot_config.image_format; // TODO: Validate image format
|
||||
const bool capture_cursor = force_type == ScreenshotForceType::NONE && config.screenshot_config.record_cursor;
|
||||
|
||||
std::vector<const char*> args = {
|
||||
"gpu-screen-recorder", "-w", screenshot_capture_target.c_str(),
|
||||
"-cursor", config.screenshot_config.record_cursor ? "yes" : "no",
|
||||
"-cursor", capture_cursor ? "yes" : "no",
|
||||
"-v", "no",
|
||||
"-q", config.screenshot_config.image_quality.c_str(),
|
||||
"-o", output_file.c_str()
|
||||
@@ -3150,7 +3307,7 @@ namespace gsr {
|
||||
args.push_back(size);
|
||||
}
|
||||
|
||||
if(config.screenshot_config.restore_portal_session && !hotkey_window_capture) {
|
||||
if(config.screenshot_config.restore_portal_session && force_type != ScreenshotForceType::WINDOW) {
|
||||
args.push_back("-restore-portal-session");
|
||||
args.push_back("yes");
|
||||
}
|
||||
@@ -3158,7 +3315,7 @@ namespace gsr {
|
||||
const std::string hotkey_window_capture_portal_session_token_filepath = get_config_dir() + "/gpu-screen-recorder/gsr-ui-window-capture-token";
|
||||
if(record_area_option == "portal") {
|
||||
hide_ui = true;
|
||||
if(hotkey_window_capture) {
|
||||
if(force_type == ScreenshotForceType::WINDOW) {
|
||||
args.push_back("-portal-session-token-filepath");
|
||||
args.push_back(hotkey_window_capture_portal_session_token_filepath.c_str());
|
||||
}
|
||||
@@ -3173,7 +3330,7 @@ namespace gsr {
|
||||
screenshot_filepath = output_file;
|
||||
gpu_screen_recorder_screenshot_process = exec_program(args.data(), nullptr);
|
||||
if(gpu_screen_recorder_screenshot_process == -1) {
|
||||
show_notification("Failed to launch gpu-screen-recorder to take a screenshot", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT);
|
||||
show_notification("Failed to launch gpu-screen-recorder to take a screenshot", notification_error_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
@@ -221,6 +222,9 @@ namespace gsr {
|
||||
}
|
||||
set_window_size_not_resizable(dpy, region_window, XWidthOfScreen(screen), XHeightOfScreen(screen));
|
||||
|
||||
unsigned char data = 2; // Prefer being composed to allow transparency. Do this to prevent the compositor from getting turned on/off when taking a screenshot
|
||||
XChangeProperty(dpy, region_window, XInternAtom(dpy, "_NET_WM_BYPASS_COMPOSITOR", False), XA_CARDINAL, 32, PropModeReplace, &data, 1);
|
||||
|
||||
if(!is_wayland) {
|
||||
cursor_window = create_cursor_window(dpy, cursor_window_size, cursor_window_size, &vinfo, border_color_x11);
|
||||
if(!cursor_window)
|
||||
@@ -309,6 +313,9 @@ namespace gsr {
|
||||
region_window = 0;
|
||||
}
|
||||
|
||||
XFlush(dpy);
|
||||
XSync(dpy, False);
|
||||
|
||||
XCloseDisplay(dpy);
|
||||
dpy = nullptr;
|
||||
selecting_region = false;
|
||||
|
||||
204
src/Rpc.cpp
204
src/Rpc.cpp
@@ -5,11 +5,12 @@
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
namespace gsr {
|
||||
static void get_runtime_filepath(char *buffer, size_t buffer_size, const char *filename) {
|
||||
static void get_socket_filepath(char *buffer, size_t buffer_size, const char *filename) {
|
||||
char dir[PATH_MAX];
|
||||
|
||||
const char *runtime_dir = getenv("XDG_RUNTIME_DIR");
|
||||
@@ -24,79 +25,117 @@ namespace gsr {
|
||||
snprintf(buffer, buffer_size, "%s/%s", dir, filename);
|
||||
}
|
||||
|
||||
static int create_socket(const char *name, struct sockaddr_un *addr, std::string &socket_filepath) {
|
||||
char socket_filepath_tmp[PATH_MAX];
|
||||
get_socket_filepath(socket_filepath_tmp, sizeof(socket_filepath_tmp), name);
|
||||
socket_filepath = socket_filepath_tmp;
|
||||
|
||||
memset(addr, 0, sizeof(*addr));
|
||||
if(strlen(name) > sizeof(addr->sun_path))
|
||||
return false;
|
||||
|
||||
addr->sun_family = AF_UNIX;
|
||||
snprintf(addr->sun_path, sizeof(addr->sun_path), "%s", socket_filepath.c_str());
|
||||
|
||||
return socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
||||
}
|
||||
|
||||
Rpc::Rpc() {
|
||||
num_polls = 0;
|
||||
}
|
||||
|
||||
Rpc::~Rpc() {
|
||||
if(fd > 0)
|
||||
close(fd);
|
||||
if(socket_fd > 0)
|
||||
close(socket_fd);
|
||||
|
||||
if(file)
|
||||
fclose(file);
|
||||
|
||||
if(!fifo_filepath.empty())
|
||||
unlink(fifo_filepath.c_str());
|
||||
if(!socket_filepath.empty())
|
||||
unlink(socket_filepath.c_str());
|
||||
}
|
||||
|
||||
bool Rpc::create(const char *name) {
|
||||
if(file) {
|
||||
if(socket_fd > 0) {
|
||||
fprintf(stderr, "Error: Rpc::create: already created/opened\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
char fifo_filepath_tmp[PATH_MAX];
|
||||
get_runtime_filepath(fifo_filepath_tmp, sizeof(fifo_filepath_tmp), name);
|
||||
fifo_filepath = fifo_filepath_tmp;
|
||||
unlink(fifo_filepath.c_str());
|
||||
|
||||
if(mkfifo(fifo_filepath.c_str(), 0600) != 0) {
|
||||
fprintf(stderr, "Error: mkfifo failed, error: %s, %s\n", strerror(errno), fifo_filepath.c_str());
|
||||
fifo_filepath.clear();
|
||||
struct sockaddr_un addr;
|
||||
socket_fd = create_socket(name, &addr, socket_filepath);
|
||||
if(socket_fd <= 0) {
|
||||
fprintf(stderr, "Error: Rpc::create: failed to create socket, error: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!open_filepath(fifo_filepath.c_str())) {
|
||||
unlink(fifo_filepath.c_str());
|
||||
fifo_filepath.clear();
|
||||
unlink(socket_filepath.c_str());
|
||||
|
||||
if(bind(socket_fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||
const int err = errno;
|
||||
close(socket_fd);
|
||||
socket_fd = 0;
|
||||
|
||||
fprintf(stderr, "Error: Rpc::create: failed to bind, error: %s\n", strerror(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(listen(socket_fd, GSR_RPC_MAX_CONNECTIONS) == -1) {
|
||||
const int err = errno;
|
||||
close(socket_fd);
|
||||
socket_fd = 0;
|
||||
|
||||
fprintf(stderr, "Error: Rpc::create: failed to listen, error: %s\n", strerror(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
polls[0].fd = socket_fd;
|
||||
polls[0].events = POLLIN;
|
||||
polls[0].revents = 0;
|
||||
++num_polls;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Rpc::open(const char *name) {
|
||||
if(file) {
|
||||
RpcOpenResult Rpc::open(const char *name) {
|
||||
if(socket_fd > 0) {
|
||||
fprintf(stderr, "Error: Rpc::open: already created/opened\n");
|
||||
return false;
|
||||
return RpcOpenResult::ERROR;
|
||||
}
|
||||
|
||||
char fifo_filepath_tmp[PATH_MAX];
|
||||
get_runtime_filepath(fifo_filepath_tmp, sizeof(fifo_filepath_tmp), name);
|
||||
return open_filepath(fifo_filepath_tmp);
|
||||
}
|
||||
|
||||
bool Rpc::open_filepath(const char *filepath) {
|
||||
fd = ::open(filepath, O_RDWR | O_NONBLOCK);
|
||||
if(fd <= 0)
|
||||
return false;
|
||||
|
||||
file = fdopen(fd, "r+");
|
||||
if(!file) {
|
||||
close(fd);
|
||||
fd = 0;
|
||||
return false;
|
||||
struct sockaddr_un addr;
|
||||
socket_fd = create_socket(name, &addr, socket_filepath);
|
||||
socket_filepath.clear(); /* We dont want to delete the socket on exit as the client */
|
||||
if(socket_fd <= 0) {
|
||||
fprintf(stderr, "Error: Rpc::open: failed to create socket, error: %s\n", strerror(errno));
|
||||
return RpcOpenResult::ERROR;
|
||||
}
|
||||
fd = 0;
|
||||
return true;
|
||||
|
||||
while(true) {
|
||||
if(connect(socket_fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||
const int err = errno;
|
||||
if(err == EWOULDBLOCK) {
|
||||
usleep(10 * 1000);
|
||||
} else {
|
||||
close(socket_fd);
|
||||
socket_fd = 0;
|
||||
if(err != ENOENT && err != ECONNREFUSED)
|
||||
fprintf(stderr, "Error: Rpc::create: failed to connect, error: %s\n", strerror(err));
|
||||
return RpcOpenResult::ERROR;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RpcOpenResult::OK;
|
||||
}
|
||||
|
||||
bool Rpc::write(const char *str, size_t size) {
|
||||
if(!file) {
|
||||
fprintf(stderr, "Error: Rpc::write: fifo not created/opened yet\n");
|
||||
if(socket_fd <= 0) {
|
||||
fprintf(stderr, "Error: Rpc::write: unix domain socket not created/opened yet\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t offset = 0;
|
||||
while(offset < (ssize_t)size) {
|
||||
const ssize_t bytes_written = fwrite(str + offset, 1, size - offset, file);
|
||||
fflush(file);
|
||||
const ssize_t bytes_written = ::write(socket_fd, str + offset, size - offset);
|
||||
if(bytes_written > 0)
|
||||
offset += bytes_written;
|
||||
}
|
||||
@@ -104,30 +143,73 @@ namespace gsr {
|
||||
}
|
||||
|
||||
void Rpc::poll() {
|
||||
if(!file) {
|
||||
//fprintf(stderr, "Error: Rpc::poll: fifo not created/opened yet\n");
|
||||
if(socket_fd <= 0) {
|
||||
//fprintf(stderr, "Error: Rpc::poll: unix domain socket not created/opened yet\n");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
char line[1024];
|
||||
while(fgets(line, sizeof(line), file)) {
|
||||
int line_len = strlen(line);
|
||||
if(line_len == 0)
|
||||
continue;
|
||||
while(::poll(polls, num_polls, 0) > 0) {
|
||||
for(int i = 0; i < num_polls; ++i) {
|
||||
if(polls[i].fd == socket_fd) {
|
||||
if(polls[i].revents & (POLLERR|POLLHUP)) {
|
||||
close(socket_fd);
|
||||
socket_fd = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(line[line_len - 1] == '\n') {
|
||||
line[line_len - 1] = '\0';
|
||||
--line_len;
|
||||
const int client_fd = accept(socket_fd, NULL, NULL);
|
||||
if(num_polls >= GSR_RPC_MAX_POLLS) {
|
||||
if(errno != EWOULDBLOCK)
|
||||
fprintf(stderr, "Error: Rpc::poll: unable to accept more clients, error: %s\n", strerror(errno));
|
||||
} else {
|
||||
polls[num_polls].fd = client_fd;
|
||||
polls[num_polls].events = POLLIN;
|
||||
polls[num_polls].revents = 0;
|
||||
++num_polls;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(polls[i].revents & POLLIN)
|
||||
handle_client_data(polls[i].fd, polls_data[i]);
|
||||
|
||||
if(polls[i].revents & (POLLERR|POLLHUP)) {
|
||||
close(polls[i].fd);
|
||||
polls[i] = polls[num_polls - 1];
|
||||
|
||||
memcpy(polls_data[i].buffer, polls_data[num_polls - 1].buffer, polls_data[num_polls - 1].buffer_size);
|
||||
polls_data[i].buffer_size = polls_data[num_polls - 1].buffer_size;
|
||||
|
||||
--num_polls;
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
name = line;
|
||||
auto it = handlers_by_name.find(name);
|
||||
if(it != handlers_by_name.end())
|
||||
it->second(name);
|
||||
}
|
||||
}
|
||||
|
||||
void Rpc::handle_client_data(int client_fd, PollData &poll_data) {
|
||||
char *write_buffer = poll_data.buffer + poll_data.buffer_size;
|
||||
const ssize_t num_bytes_read = read(client_fd, write_buffer, sizeof(poll_data.buffer) - poll_data.buffer_size);
|
||||
if(num_bytes_read <= 0)
|
||||
return;
|
||||
|
||||
poll_data.buffer_size += num_bytes_read;
|
||||
const char *newline_p = (const char*)memchr(write_buffer, '\n', num_bytes_read);
|
||||
if(!newline_p)
|
||||
return;
|
||||
|
||||
const size_t command_size = newline_p - poll_data.buffer;
|
||||
std::string name;
|
||||
name.assign(poll_data.buffer, command_size);
|
||||
memmove(poll_data.buffer, newline_p + 1, poll_data.buffer_size - (command_size + 1));
|
||||
poll_data.buffer_size -= (command_size + 1);
|
||||
|
||||
auto it = handlers_by_name.find(name);
|
||||
if(it != handlers_by_name.end())
|
||||
it->second(name);
|
||||
}
|
||||
|
||||
bool Rpc::add_handler(const std::string &name, RpcCallback callback) {
|
||||
return handlers_by_name.insert(std::make_pair(name, std::move(callback))).second;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/keysym.h>
|
||||
@@ -122,6 +123,10 @@ namespace gsr {
|
||||
return false;
|
||||
}
|
||||
set_window_size_not_resizable(dpy, border_window, XWidthOfScreen(screen), XHeightOfScreen(screen));
|
||||
|
||||
unsigned char data = 2; // Prefer being composed to allow transparency. Do this to prevent the compositor from getting turned on/off when taking a screenshot
|
||||
XChangeProperty(dpy, border_window, XInternAtom(dpy, "_NET_WM_BYPASS_COMPOSITOR", False), XA_CARDINAL, 32, PropModeReplace, &data, 1);
|
||||
|
||||
if(cursor_window && cursor_window != DefaultRootWindow(dpy))
|
||||
set_region_rectangle(dpy, border_window, cursor_window_pos.x, cursor_window_pos.y, cursor_window_size.x, cursor_window_size.y, rectangle_border_size);
|
||||
else
|
||||
@@ -163,6 +168,8 @@ namespace gsr {
|
||||
}
|
||||
|
||||
XFlush(dpy);
|
||||
XSync(dpy, False);
|
||||
|
||||
XCloseDisplay(dpy);
|
||||
dpy = nullptr;
|
||||
}
|
||||
|
||||
@@ -190,11 +190,12 @@ namespace gsr {
|
||||
}
|
||||
|
||||
std::unique_ptr<RadioButton> GlobalSettingsPage::create_enable_keyboard_hotkeys_button() {
|
||||
auto enable_hotkeys_radio_button = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::HORIZONTAL);
|
||||
auto enable_hotkeys_radio_button = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::VERTICAL);
|
||||
enable_keyboard_hotkeys_radio_button_ptr = enable_hotkeys_radio_button.get();
|
||||
enable_hotkeys_radio_button->add_item("Yes", "enable_hotkeys");
|
||||
enable_hotkeys_radio_button->add_item("Yes, but only grab virtual devices (supports some input remapping software)", "enable_hotkeys_virtual_devices");
|
||||
enable_hotkeys_radio_button->add_item("Yes, but don't grab devices (supports all input remapping software)", "enable_hotkeys_no_grab");
|
||||
enable_hotkeys_radio_button->add_item("No", "disable_hotkeys");
|
||||
enable_hotkeys_radio_button->add_item("Only grab virtual devices (supports input remapping software)", "enable_hotkeys_virtual_devices");
|
||||
enable_hotkeys_radio_button->on_selection_changed = [&](const std::string&, const std::string &id) {
|
||||
if(on_keyboard_hotkey_changed)
|
||||
on_keyboard_hotkey_changed(id.c_str());
|
||||
@@ -528,6 +529,22 @@ namespace gsr {
|
||||
return std::make_unique<Subsection>("Application info", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<Subsection> GlobalSettingsPage::create_donate_subsection(ScrollablePage *parent_page) {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
list->add_widget(std::make_unique<Label>(&get_theme().body_font, "If you would like to donate you can do so by donating at https://buymeacoffee.com/dec05eba:", get_color_theme().text_color));
|
||||
|
||||
auto donate_button = std::make_unique<Button>(&get_theme().body_font, "Donate", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
|
||||
donate_button->on_click = [this] {
|
||||
const char *args[] = { "xdg-open", "https://buymeacoffee.com/dec05eba", nullptr };
|
||||
exec_program_daemonized(args);
|
||||
overlay->hide_next_frame();
|
||||
};
|
||||
list->add_widget(std::move(donate_button));
|
||||
|
||||
list->add_widget(std::make_unique<Label>(&get_theme().body_font, "All donations go toward developing software (including GPU Screen Recorder)\nand buying hardware to test the software.", get_color_theme().text_color));
|
||||
return std::make_unique<Subsection>("Donate", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
void GlobalSettingsPage::add_widgets() {
|
||||
auto scrollable_page = std::make_unique<ScrollablePage>(content_page_ptr->get_inner_size());
|
||||
|
||||
@@ -539,6 +556,7 @@ namespace gsr {
|
||||
settings_list->add_widget(create_controller_hotkey_subsection(scrollable_page.get()));
|
||||
settings_list->add_widget(create_application_options_subsection(scrollable_page.get()));
|
||||
settings_list->add_widget(create_application_info_subsection(scrollable_page.get()));
|
||||
settings_list->add_widget(create_donate_subsection(scrollable_page.get()));
|
||||
scrollable_page->add_widget(std::move(settings_list));
|
||||
|
||||
content_page_ptr->add_widget(std::move(scrollable_page));
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace gsr {
|
||||
if(capture_options.region)
|
||||
record_area_box->add_item("Region", "region");
|
||||
if(!capture_options.monitors.empty())
|
||||
record_area_box->add_item(gsr_info->system_info.display_server == DisplayServer::WAYLAND ? "Focused monitor (Experimental on Wayland)" : "Focused monitor", "focused_monitor");
|
||||
record_area_box->add_item("Focused monitor", "focused_monitor");
|
||||
for(const auto &monitor : capture_options.monitors) {
|
||||
char name[256];
|
||||
snprintf(name, sizeof(name), "Monitor %s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y);
|
||||
@@ -202,7 +202,7 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_file_info_section() {
|
||||
auto file_info_data_list = std::make_unique<List>(List::Orientation::HORIZONTAL);
|
||||
file_info_data_list->add_widget(create_save_directory("Directory to save the screenshot:"));
|
||||
file_info_data_list->add_widget(create_save_directory("Directory to save screenshots:"));
|
||||
file_info_data_list->add_widget(create_image_format_section());
|
||||
return std::make_unique<Subsection>("File info", std::move(file_info_data_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
}
|
||||
@@ -216,11 +216,25 @@ namespace gsr {
|
||||
}
|
||||
|
||||
std::unique_ptr<CheckBox> ScreenshotSettingsPage::create_save_screenshot_to_clipboard() {
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Save screenshot to clipboard");
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, gsr_info->system_info.display_server == DisplayServer::X11 ? "Save screenshot to clipboard" : "Save screenshot to clipboard (Not supported properly by Wayland)");
|
||||
save_screenshot_to_clipboard_checkbox_ptr = checkbox.get();
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_notifications() {
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show screenshot notifications");
|
||||
checkbox->set_checked(true);
|
||||
show_notification_checkbox_ptr = checkbox.get();
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_led_indicator() {
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Blink scroll lock led when taking a screenshot");
|
||||
checkbox->set_checked(true);
|
||||
led_indicator_checkbox_ptr = checkbox.get();
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_general_section() {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
list->add_widget(create_save_screenshot_in_game_folder());
|
||||
@@ -228,11 +242,11 @@ namespace gsr {
|
||||
return std::make_unique<Subsection>("General", std::move(list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_notifications_section() {
|
||||
auto show_screenshot_saved_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show screenshot saved notification");
|
||||
show_screenshot_saved_notification_checkbox->set_checked(true);
|
||||
show_screenshot_saved_notification_checkbox_ptr = show_screenshot_saved_notification_checkbox.get();
|
||||
return std::make_unique<Subsection>("Notifications", std::move(show_screenshot_saved_notification_checkbox), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_screenshot_indicator_section() {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
list->add_widget(create_notifications());
|
||||
list->add_widget(create_led_indicator());
|
||||
return std::make_unique<Subsection>("Screenshot indicator", std::move(list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_settings() {
|
||||
@@ -248,7 +262,7 @@ namespace gsr {
|
||||
settings_list->add_widget(create_image_section());
|
||||
settings_list->add_widget(create_file_info_section());
|
||||
settings_list->add_widget(create_general_section());
|
||||
settings_list->add_widget(create_notifications_section());
|
||||
settings_list->add_widget(create_screenshot_indicator_section());
|
||||
settings_scrollable_page_ptr->add_widget(std::move(settings_list));
|
||||
return page_list;
|
||||
}
|
||||
@@ -291,7 +305,8 @@ namespace gsr {
|
||||
save_directory_button_ptr->set_text(config.screenshot_config.save_directory);
|
||||
save_screenshot_in_game_folder_checkbox_ptr->set_checked(config.screenshot_config.save_screenshot_in_game_folder);
|
||||
save_screenshot_to_clipboard_checkbox_ptr->set_checked(config.screenshot_config.save_screenshot_to_clipboard);
|
||||
show_screenshot_saved_notification_checkbox_ptr->set_checked(config.screenshot_config.show_screenshot_saved_notifications);
|
||||
show_notification_checkbox_ptr->set_checked(config.screenshot_config.show_notifications);
|
||||
led_indicator_checkbox_ptr->set_checked(config.screenshot_config.use_led_indicator);
|
||||
|
||||
if(config.screenshot_config.image_width == 0)
|
||||
config.screenshot_config.image_width = 1920;
|
||||
@@ -320,7 +335,8 @@ namespace gsr {
|
||||
config.screenshot_config.save_directory = save_directory_button_ptr->get_text();
|
||||
config.screenshot_config.save_screenshot_in_game_folder = save_screenshot_in_game_folder_checkbox_ptr->is_checked();
|
||||
config.screenshot_config.save_screenshot_to_clipboard = save_screenshot_to_clipboard_checkbox_ptr->is_checked();
|
||||
config.screenshot_config.show_screenshot_saved_notifications = show_screenshot_saved_notification_checkbox_ptr->is_checked();
|
||||
config.screenshot_config.show_notifications = show_notification_checkbox_ptr->is_checked();
|
||||
config.screenshot_config.use_led_indicator = led_indicator_checkbox_ptr->is_checked();
|
||||
|
||||
if(config.screenshot_config.image_width == 0)
|
||||
config.screenshot_config.image_width = 1920;
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace gsr {
|
||||
if(capture_options.region)
|
||||
record_area_box->add_item("Region", "region");
|
||||
if(!capture_options.monitors.empty())
|
||||
record_area_box->add_item(gsr_info->system_info.display_server == DisplayServer::WAYLAND ? "Focused monitor (Experimental on Wayland)" : "Focused monitor", "focused_monitor");
|
||||
record_area_box->add_item("Focused monitor", "focused_monitor");
|
||||
for(const auto &monitor : capture_options.monitors) {
|
||||
char name[256];
|
||||
snprintf(name, sizeof(name), "Monitor %s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y);
|
||||
@@ -821,16 +821,41 @@ namespace gsr {
|
||||
replay_time_label_ptr->set_text(buffer);
|
||||
}
|
||||
|
||||
void SettingsPage::view_changed(bool advanced_view, Subsection *notifications_subsection_ptr) {
|
||||
void SettingsPage::view_changed(bool advanced_view) {
|
||||
color_range_list_ptr->set_visible(advanced_view);
|
||||
audio_codec_ptr->set_visible(advanced_view);
|
||||
video_codec_ptr->set_visible(advanced_view);
|
||||
framerate_mode_list_ptr->set_visible(advanced_view);
|
||||
notifications_subsection_ptr->set_visible(advanced_view);
|
||||
set_application_audio_options_visible(audio_track_section_list_ptr, advanced_view, *gsr_info);
|
||||
settings_scrollable_page_ptr->reset_scroll();
|
||||
}
|
||||
|
||||
std::unique_ptr<CheckBox> SettingsPage::create_led_indicator(const char *type) {
|
||||
char label_str[256];
|
||||
snprintf(label_str, sizeof(label_str), "Show %s status with scroll lock led", type);
|
||||
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, label_str);
|
||||
checkbox->set_checked(false);
|
||||
led_indicator_checkbox_ptr = checkbox.get();
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
std::unique_ptr<CheckBox> SettingsPage::create_notifications(const char *type) {
|
||||
char label_str[256];
|
||||
snprintf(label_str, sizeof(label_str), "Show %s notifications", type);
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, label_str);
|
||||
checkbox->set_checked(true);
|
||||
show_notification_checkbox_ptr = checkbox.get();
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
std::unique_ptr<List> SettingsPage::create_indicator(const char *type) {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
list->add_widget(create_notifications(type));
|
||||
list->add_widget(create_led_indicator(type));
|
||||
return list;
|
||||
}
|
||||
|
||||
void SettingsPage::add_replay_widgets() {
|
||||
auto file_info_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
auto file_info_data_list = std::make_unique<List>(List::Orientation::HORIZONTAL);
|
||||
@@ -846,33 +871,13 @@ namespace gsr {
|
||||
general_list->add_widget(create_save_replay_in_game_folder());
|
||||
if(gsr_info->system_info.gsr_version >= GsrVersion{5, 0, 3})
|
||||
general_list->add_widget(create_restart_replay_on_save());
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("General", std::move(general_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("General", std::move(general_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("Replay indicator", create_indicator("replay"), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("Autostart", create_start_replay_automatically(), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
|
||||
auto checkboxes_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
|
||||
auto show_replay_started_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show replay started notification");
|
||||
show_replay_started_notification_checkbox->set_checked(true);
|
||||
show_replay_started_notification_checkbox_ptr = show_replay_started_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_replay_started_notification_checkbox));
|
||||
|
||||
auto show_replay_stopped_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show replay stopped notification");
|
||||
show_replay_stopped_notification_checkbox->set_checked(true);
|
||||
show_replay_stopped_notification_checkbox_ptr = show_replay_stopped_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_replay_stopped_notification_checkbox));
|
||||
|
||||
auto show_replay_saved_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show replay saved notification");
|
||||
show_replay_saved_notification_checkbox->set_checked(true);
|
||||
show_replay_saved_notification_checkbox_ptr = show_replay_saved_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_replay_saved_notification_checkbox));
|
||||
|
||||
auto notifications_subsection = std::make_unique<Subsection>("Notifications", std::move(checkboxes_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
Subsection *notifications_subsection_ptr = notifications_subsection.get();
|
||||
settings_list_ptr->add_widget(std::move(notifications_subsection));
|
||||
|
||||
view_radio_button_ptr->on_selection_changed = [this, notifications_subsection_ptr](const std::string&, const std::string &id) {
|
||||
view_changed(id == "advanced", notifications_subsection_ptr);
|
||||
view_radio_button_ptr->on_selection_changed = [this](const std::string&, const std::string &id) {
|
||||
view_changed(id == "advanced");
|
||||
return true;
|
||||
};
|
||||
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
||||
@@ -913,37 +918,21 @@ namespace gsr {
|
||||
void SettingsPage::add_record_widgets() {
|
||||
auto file_info_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
auto file_info_data_list = std::make_unique<List>(List::Orientation::HORIZONTAL);
|
||||
file_info_data_list->add_widget(create_save_directory("Directory to save the video:"));
|
||||
file_info_data_list->add_widget(create_save_directory("Directory to save videos:"));
|
||||
file_info_data_list->add_widget(create_container_section());
|
||||
file_info_list->add_widget(std::move(file_info_data_list));
|
||||
file_info_list->add_widget(create_estimated_record_file_size());
|
||||
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("File info", std::move(file_info_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("General", create_save_recording_in_game_folder(), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
auto general_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
general_list->add_widget(create_save_recording_in_game_folder());
|
||||
|
||||
auto checkboxes_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("General", std::move(general_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("Recording indicator", create_indicator("recording"), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
|
||||
auto show_recording_started_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show recording started notification");
|
||||
show_recording_started_notification_checkbox->set_checked(true);
|
||||
show_recording_started_notification_checkbox_ptr = show_recording_started_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_recording_started_notification_checkbox));
|
||||
|
||||
auto show_video_saved_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show video saved notification");
|
||||
show_video_saved_notification_checkbox->set_checked(true);
|
||||
show_video_saved_notification_checkbox_ptr = show_video_saved_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_video_saved_notification_checkbox));
|
||||
|
||||
auto show_video_paused_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show video paused/unpaused notification");
|
||||
show_video_paused_notification_checkbox->set_checked(true);
|
||||
show_video_paused_notification_checkbox_ptr = show_video_paused_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_video_paused_notification_checkbox));
|
||||
|
||||
auto notifications_subsection = std::make_unique<Subsection>("Notifications", std::move(checkboxes_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
Subsection *notifications_subsection_ptr = notifications_subsection.get();
|
||||
settings_list_ptr->add_widget(std::move(notifications_subsection));
|
||||
|
||||
view_radio_button_ptr->on_selection_changed = [this, notifications_subsection_ptr](const std::string&, const std::string &id) {
|
||||
view_changed(id == "advanced", notifications_subsection_ptr);
|
||||
view_radio_button_ptr->on_selection_changed = [this](const std::string&, const std::string &id) {
|
||||
view_changed(id == "advanced");
|
||||
return true;
|
||||
};
|
||||
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
||||
@@ -1063,23 +1052,14 @@ namespace gsr {
|
||||
streaming_info_list->add_widget(create_streaming_service_section());
|
||||
streaming_info_list->add_widget(create_stream_key_section());
|
||||
streaming_info_list->add_widget(create_stream_custom_section());
|
||||
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("Streaming info", std::move(streaming_info_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
|
||||
auto checkboxes_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
auto general_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
general_list->add_widget(create_save_recording_in_game_folder());
|
||||
|
||||
auto show_streaming_started_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show streaming started notification");
|
||||
show_streaming_started_notification_checkbox->set_checked(true);
|
||||
show_streaming_started_notification_checkbox_ptr = show_streaming_started_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_streaming_started_notification_checkbox));
|
||||
|
||||
auto show_streaming_stopped_notification_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Show streaming stopped notification");
|
||||
show_streaming_stopped_notification_checkbox->set_checked(true);
|
||||
show_streaming_stopped_notification_checkbox_ptr = show_streaming_stopped_notification_checkbox.get();
|
||||
checkboxes_list->add_widget(std::move(show_streaming_stopped_notification_checkbox));
|
||||
|
||||
auto notifications_subsection = std::make_unique<Subsection>("Notifications", std::move(checkboxes_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
Subsection *notifications_subsection_ptr = notifications_subsection.get();
|
||||
settings_list_ptr->add_widget(std::move(notifications_subsection));
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("General", std::move(general_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
settings_list_ptr->add_widget(std::make_unique<Subsection>("Streaming indicator", create_indicator("streaming"), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
|
||||
|
||||
streaming_service_box_ptr->on_selection_changed = [this](const std::string&, const std::string &id) {
|
||||
const bool twitch_option = id == "twitch";
|
||||
@@ -1095,8 +1075,8 @@ namespace gsr {
|
||||
};
|
||||
streaming_service_box_ptr->on_selection_changed("Twitch", "twitch");
|
||||
|
||||
view_radio_button_ptr->on_selection_changed = [this, notifications_subsection_ptr](const std::string&, const std::string &id) {
|
||||
view_changed(id == "advanced", notifications_subsection_ptr);
|
||||
view_radio_button_ptr->on_selection_changed = [this](const std::string&, const std::string &id) {
|
||||
view_changed(id == "advanced");
|
||||
return true;
|
||||
};
|
||||
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
||||
@@ -1217,6 +1197,8 @@ namespace gsr {
|
||||
//record_options.overclock = false;
|
||||
record_cursor_checkbox_ptr->set_checked(record_options.record_cursor);
|
||||
restore_portal_session_checkbox_ptr->set_checked(record_options.restore_portal_session);
|
||||
show_notification_checkbox_ptr->set_checked(record_options.show_notifications);
|
||||
led_indicator_checkbox_ptr->set_checked(record_options.use_led_indicator);
|
||||
|
||||
if(record_options.record_area_width == 0)
|
||||
record_options.record_area_width = 1920;
|
||||
@@ -1262,9 +1244,7 @@ namespace gsr {
|
||||
save_replay_in_game_folder_ptr->set_checked(config.replay_config.save_video_in_game_folder);
|
||||
if(restart_replay_on_save)
|
||||
restart_replay_on_save->set_checked(config.replay_config.restart_replay_on_save);
|
||||
show_replay_started_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_started_notifications);
|
||||
show_replay_stopped_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_stopped_notifications);
|
||||
show_replay_saved_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_saved_notifications);
|
||||
|
||||
save_directory_button_ptr->set_text(config.replay_config.save_directory);
|
||||
container_box_ptr->set_selected_item(config.replay_config.container);
|
||||
|
||||
@@ -1278,17 +1258,12 @@ namespace gsr {
|
||||
void SettingsPage::load_record() {
|
||||
load_common(config.record_config.record_options);
|
||||
save_recording_in_game_folder_ptr->set_checked(config.record_config.save_video_in_game_folder);
|
||||
show_recording_started_notification_checkbox_ptr->set_checked(config.record_config.show_recording_started_notifications);
|
||||
show_video_saved_notification_checkbox_ptr->set_checked(config.record_config.show_video_saved_notifications);
|
||||
show_video_paused_notification_checkbox_ptr->set_checked(config.record_config.show_video_paused_notifications);
|
||||
save_directory_button_ptr->set_text(config.record_config.save_directory);
|
||||
container_box_ptr->set_selected_item(config.record_config.container);
|
||||
}
|
||||
|
||||
void SettingsPage::load_stream() {
|
||||
load_common(config.streaming_config.record_options);
|
||||
show_streaming_started_notification_checkbox_ptr->set_checked(config.streaming_config.show_streaming_started_notifications);
|
||||
show_streaming_stopped_notification_checkbox_ptr->set_checked(config.streaming_config.show_streaming_stopped_notifications);
|
||||
streaming_service_box_ptr->set_selected_item(config.streaming_config.streaming_service);
|
||||
youtube_stream_key_entry_ptr->set_text(config.streaming_config.youtube.stream_key);
|
||||
twitch_stream_key_entry_ptr->set_text(config.streaming_config.twitch.stream_key);
|
||||
@@ -1354,6 +1329,8 @@ namespace gsr {
|
||||
//record_options.overclock = false;
|
||||
record_options.record_cursor = record_cursor_checkbox_ptr->is_checked();
|
||||
record_options.restore_portal_session = restore_portal_session_checkbox_ptr->is_checked();
|
||||
record_options.show_notifications = show_notification_checkbox_ptr->is_checked();
|
||||
record_options.use_led_indicator = led_indicator_checkbox_ptr->is_checked();
|
||||
|
||||
if(record_options.record_area_width == 0)
|
||||
record_options.record_area_width = 1920;
|
||||
@@ -1404,9 +1381,6 @@ namespace gsr {
|
||||
config.replay_config.save_video_in_game_folder = save_replay_in_game_folder_ptr->is_checked();
|
||||
if(restart_replay_on_save)
|
||||
config.replay_config.restart_replay_on_save = restart_replay_on_save->is_checked();
|
||||
config.replay_config.show_replay_started_notifications = show_replay_started_notification_checkbox_ptr->is_checked();
|
||||
config.replay_config.show_replay_stopped_notifications = show_replay_stopped_notification_checkbox_ptr->is_checked();
|
||||
config.replay_config.show_replay_saved_notifications = show_replay_saved_notification_checkbox_ptr->is_checked();
|
||||
config.replay_config.save_directory = save_directory_button_ptr->get_text();
|
||||
config.replay_config.container = container_box_ptr->get_selected_id();
|
||||
config.replay_config.replay_time = atoi(replay_time_entry_ptr->get_text().c_str());
|
||||
@@ -1421,17 +1395,12 @@ namespace gsr {
|
||||
void SettingsPage::save_record() {
|
||||
save_common(config.record_config.record_options);
|
||||
config.record_config.save_video_in_game_folder = save_recording_in_game_folder_ptr->is_checked();
|
||||
config.record_config.show_recording_started_notifications = show_recording_started_notification_checkbox_ptr->is_checked();
|
||||
config.record_config.show_video_saved_notifications = show_video_saved_notification_checkbox_ptr->is_checked();
|
||||
config.record_config.show_video_paused_notifications = show_video_paused_notification_checkbox_ptr->is_checked();
|
||||
config.record_config.save_directory = save_directory_button_ptr->get_text();
|
||||
config.record_config.container = container_box_ptr->get_selected_id();
|
||||
}
|
||||
|
||||
void SettingsPage::save_stream() {
|
||||
save_common(config.streaming_config.record_options);
|
||||
config.streaming_config.show_streaming_started_notifications = show_streaming_started_notification_checkbox_ptr->is_checked();
|
||||
config.streaming_config.show_streaming_stopped_notifications = show_streaming_stopped_notification_checkbox_ptr->is_checked();
|
||||
config.streaming_config.streaming_service = streaming_service_box_ptr->get_selected_id();
|
||||
config.streaming_config.youtube.stream_key = youtube_stream_key_entry_ptr->get_text();
|
||||
config.streaming_config.twitch.stream_key = twitch_stream_key_entry_ptr->get_text();
|
||||
|
||||
30
src/main.cpp
30
src/main.cpp
@@ -102,24 +102,6 @@ static void rpc_add_commands(gsr::Rpc *rpc, gsr::Overlay *overlay) {
|
||||
});
|
||||
}
|
||||
|
||||
static bool is_gsr_ui_virtual_keyboard_running() {
|
||||
FILE *f = fopen("/proc/bus/input/devices", "rb");
|
||||
if(!f)
|
||||
return false;
|
||||
|
||||
bool virtual_keyboard_running = false;
|
||||
char line[1024];
|
||||
while(fgets(line, sizeof(line), f)) {
|
||||
if(strstr(line, "gsr-ui virtual keyboard")) {
|
||||
virtual_keyboard_running = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return virtual_keyboard_running;
|
||||
}
|
||||
|
||||
static void install_flatpak_systemd_service() {
|
||||
const bool systemd_service_exists = system(
|
||||
"data_home=$(flatpak-spawn --host -- /bin/sh -c 'echo \"${XDG_DATA_HOME:-$HOME/.local/share}\"') && "
|
||||
@@ -226,16 +208,13 @@ int main(int argc, char **argv) {
|
||||
set_display_server_environment_variables();
|
||||
|
||||
auto rpc = std::make_unique<gsr::Rpc>();
|
||||
const bool rpc_created = rpc->create("gsr-ui");
|
||||
if(!rpc_created)
|
||||
fprintf(stderr, "Error: Failed to create rpc\n");
|
||||
const gsr::RpcOpenResult rpc_open_result = rpc->open("gsr-ui");
|
||||
|
||||
if(is_gsr_ui_virtual_keyboard_running() || !rpc_created) {
|
||||
if(rpc_open_result == gsr::RpcOpenResult::OK) {
|
||||
if(launch_action == LaunchAction::LAUNCH_DAEMON)
|
||||
return 1;
|
||||
|
||||
rpc = std::make_unique<gsr::Rpc>();
|
||||
if(rpc->open("gsr-ui") && rpc->write("show_ui\n", 8)) {
|
||||
if(rpc->write("show_ui\n", 8)) {
|
||||
fprintf(stderr, "Error: another instance of gsr-ui is already running, opening that one instead\n");
|
||||
} else {
|
||||
fprintf(stderr, "Error: failed to send command to running gsr-ui instance, user will have to open the UI manually with Alt+Z\n");
|
||||
@@ -245,6 +224,9 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!rpc->create("gsr-ui"))
|
||||
fprintf(stderr, "Error: Failed to create rpc\n");
|
||||
|
||||
if(gsr::pidof("gpu-screen-recorder", -1) != -1) {
|
||||
const char *args[] = { "gsr-notify", "--text", "GPU Screen Recorder is already running in another process.\nPlease close it before using GPU Screen Recorder UI.", "--timeout", "5.0", "--icon-color", "ff0000", "--bg-color", "ff0000", nullptr };
|
||||
gsr::exec_program_daemonized(args);
|
||||
|
||||
@@ -24,4 +24,9 @@ To close gsr-global-hotkeys send `exit<newline>` to the programs stdin, for exam
|
||||
```
|
||||
exit
|
||||
|
||||
```
|
||||
```
|
||||
# Conflict with other keyboard software
|
||||
Some keyboard remapping software such as keyd may conflict with gsr-global-hotkeys if configured incorrect (if it's configured to grab all devices, including gsr-ui virtual keyboard).
|
||||
If that happens it may grab gsr-ui-virtual keyboard while gsr-global-hotkeys will grab the keyboard remapping software virtual device, leading to a circular lock, making it not possible
|
||||
to use your keyboard. gsr-global-hotkeys detects this and outputs `gsr-ui-virtual-keyboard-grabbed` to stdout. You can listen to this and stop gsr-global-hotkeys or restart it with `--no-grab`
|
||||
option to only listen to devices, not grabbing them.
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "keyboard_event.h"
|
||||
#include "keys.h"
|
||||
#include "leds.h"
|
||||
|
||||
/* C stdlib */
|
||||
#include <stdio.h>
|
||||
@@ -7,6 +8,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
/* POSIX */
|
||||
#include <fcntl.h>
|
||||
@@ -17,6 +19,7 @@
|
||||
/* LINUX */
|
||||
#include <linux/input.h>
|
||||
#include <linux/uinput.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#define GSR_UI_VIRTUAL_KEYBOARD_NAME "gsr-ui virtual keyboard"
|
||||
|
||||
@@ -26,6 +29,14 @@
|
||||
|
||||
#define KEY_STATES_SIZE (KEY_MAX/8 + 1)
|
||||
|
||||
static double clock_get_monotonic_seconds(void) {
|
||||
struct timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 0;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (double)ts.tv_sec + (double)ts.tv_nsec * 0.000000001;
|
||||
}
|
||||
|
||||
static inline int count_num_bits_set(unsigned char c) {
|
||||
int n = 0;
|
||||
n += (c & 1);
|
||||
@@ -183,6 +194,12 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
|
||||
return;
|
||||
}
|
||||
|
||||
if(extra_data->gsr_ui_virtual_keyboard) {
|
||||
if(event.type == EV_KEY || event.type == EV_MSC)
|
||||
self->check_grab_lock = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.type == EV_SYN && event.code == SYN_DROPPED) {
|
||||
/* TODO: Don't do this on every SYN_DROPPED to prevent spamming this, instead wait until the next event or wait for timeout */
|
||||
keyboard_event_fetch_update_key_states(self, extra_data, fd);
|
||||
@@ -211,11 +228,27 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
|
||||
}
|
||||
|
||||
if(extra_data->grabbed) {
|
||||
if(!self->check_grab_lock && (event.type == EV_KEY || event.type == EV_MSC)) {
|
||||
self->uinput_written_time_seconds = clock_get_monotonic_seconds();
|
||||
self->check_grab_lock = true;
|
||||
}
|
||||
|
||||
/* TODO: What to do on error? */
|
||||
if(write(self->uinput_fd, &event, sizeof(event)) != sizeof(event))
|
||||
fprintf(stderr, "Error: failed to write event data to virtual keyboard for exclusively grabbed device\n");
|
||||
}
|
||||
|
||||
if(event.type == EV_LED) {
|
||||
write(fd, &event, sizeof(event));
|
||||
|
||||
const struct input_event syn_event = {
|
||||
.type = EV_SYN,
|
||||
.code = 0,
|
||||
.value = 0
|
||||
};
|
||||
write(fd, &syn_event, sizeof(syn_event));
|
||||
}
|
||||
|
||||
if(!extra_data->is_possibly_non_keyboard_device)
|
||||
return;
|
||||
|
||||
@@ -234,14 +267,23 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
|
||||
/* Retarded linux takes very long time to close /dev/input/eventN files, even though they are virtual and opened read-only */
|
||||
static void* keyboard_event_close_fds_callback(void *userdata) {
|
||||
keyboard_event *self = userdata;
|
||||
int fds_to_close_now[MAX_CLOSE_FDS];
|
||||
int num_fds_to_close_now = 0;
|
||||
|
||||
while(self->running) {
|
||||
pthread_mutex_lock(&self->close_dev_input_mutex);
|
||||
for(int i = 0; i < self->num_close_fds; ++i) {
|
||||
close(self->close_fds[i]);
|
||||
fds_to_close_now[i] = self->close_fds[i];
|
||||
}
|
||||
num_fds_to_close_now = self->num_close_fds;
|
||||
self->num_close_fds = 0;
|
||||
pthread_mutex_unlock(&self->close_dev_input_mutex);
|
||||
|
||||
for(int i = 0; i < num_fds_to_close_now; ++i) {
|
||||
close(fds_to_close_now[i]);
|
||||
}
|
||||
num_fds_to_close_now = 0;
|
||||
|
||||
usleep(100 * 1000); /* 100 milliseconds */
|
||||
}
|
||||
return NULL;
|
||||
@@ -359,7 +401,7 @@ static bool keyboard_event_try_add_device_if_keyboard(keyboard_event *self, cons
|
||||
if(keyboard_event_has_event_with_dev_input_fd(self, dev_input_id))
|
||||
return false;
|
||||
|
||||
const int fd = open(dev_input_filepath, O_RDONLY);
|
||||
const int fd = open(dev_input_filepath, O_RDWR);
|
||||
if(fd == -1)
|
||||
return false;
|
||||
|
||||
@@ -371,7 +413,29 @@ static bool keyboard_event_try_add_device_if_keyboard(keyboard_event *self, cons
|
||||
ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), &evbit);
|
||||
const bool is_keyboard = (evbit & (1 << EV_SYN)) && (evbit & (1 << EV_KEY));
|
||||
|
||||
if(is_keyboard && strcmp(device_name, GSR_UI_VIRTUAL_KEYBOARD_NAME) != 0) {
|
||||
if(strcmp(device_name, GSR_UI_VIRTUAL_KEYBOARD_NAME) == 0) {
|
||||
if(self->num_event_polls < MAX_EVENT_POLLS) {
|
||||
self->event_polls[self->num_event_polls] = (struct pollfd) {
|
||||
.fd = fd,
|
||||
.events = POLLIN,
|
||||
.revents = 0
|
||||
};
|
||||
|
||||
self->event_extra_data[self->num_event_polls] = (event_extra_data) {
|
||||
.dev_input_id = dev_input_id,
|
||||
.grabbed = false,
|
||||
.key_states = NULL,
|
||||
.key_presses_grabbed = NULL,
|
||||
.num_keys_pressed = 0,
|
||||
.gsr_ui_virtual_keyboard = true
|
||||
};
|
||||
|
||||
++self->num_event_polls;
|
||||
return true;
|
||||
} else {
|
||||
fprintf(stderr, "Error: failed to listen to gsr-ui virtual keyboard\n");
|
||||
}
|
||||
} else if(is_keyboard) {
|
||||
unsigned char key_bits[KEY_MAX/8 + 1] = {0};
|
||||
ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), &key_bits);
|
||||
|
||||
@@ -456,9 +520,13 @@ static void keyboard_event_remove_event(keyboard_event *self, int index) {
|
||||
if(index < 0 || index >= self->num_event_polls)
|
||||
return;
|
||||
|
||||
if(self->event_polls[index].fd > 0) {
|
||||
ioctl(self->event_polls[index].fd, EVIOCGRAB, 0);
|
||||
close(self->event_polls[index].fd);
|
||||
const int poll_fd = self->event_polls[index].fd;
|
||||
if(poll_fd > 0) {
|
||||
ioctl(poll_fd, EVIOCGRAB, 0);
|
||||
if(!keyboard_event_try_add_close_fd(self, poll_fd)) {
|
||||
fprintf(stderr, "Error: failed to add immediately, closing now\n");
|
||||
close(poll_fd);
|
||||
}
|
||||
}
|
||||
free(self->event_extra_data[index].key_states);
|
||||
free(self->event_extra_data[index].key_presses_grabbed);
|
||||
@@ -497,10 +565,12 @@ static int setup_virtual_keyboard_input(const char *name) {
|
||||
if(is_keyboard_key(i) || is_mouse_button(i))
|
||||
success &= (ioctl(fd, UI_SET_KEYBIT, i) != -1);
|
||||
}
|
||||
|
||||
for(int i = 0; i < REL_MAX; ++i) {
|
||||
success &= (ioctl(fd, UI_SET_RELBIT, i) != -1);
|
||||
}
|
||||
// for(int i = 0; i < LED_MAX; ++i) {
|
||||
|
||||
// for(int i = 0; i <= LED_CHARGING; ++i) {
|
||||
// success &= (ioctl(fd, UI_SET_LEDBIT, i) != -1);
|
||||
// }
|
||||
|
||||
@@ -539,7 +609,6 @@ static int setup_virtual_keyboard_input(const char *name) {
|
||||
|
||||
bool keyboard_event_init(keyboard_event *self, bool exclusive_grab, keyboard_grab_type grab_type) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
self->stdin_event_index = -1;
|
||||
self->hotplug_event_index = -1;
|
||||
self->grab_type = grab_type;
|
||||
self->running = true;
|
||||
@@ -571,9 +640,51 @@ bool keyboard_event_init(keyboard_event *self, bool exclusive_grab, keyboard_gra
|
||||
.num_keys_pressed = 0
|
||||
};
|
||||
|
||||
self->stdin_event_index = self->num_event_polls;
|
||||
++self->num_event_polls;
|
||||
|
||||
self->timer_fd = timerfd_create(CLOCK_MONOTONIC, 0);
|
||||
if(self->timer_fd <= 0) {
|
||||
fprintf(stderr, "Error: timerfd_create failed\n");
|
||||
keyboard_event_deinit(self);
|
||||
return false;
|
||||
}
|
||||
|
||||
self->event_polls[self->num_event_polls] = (struct pollfd) {
|
||||
.fd = self->timer_fd,
|
||||
.events = POLLIN,
|
||||
.revents = 0
|
||||
};
|
||||
|
||||
self->event_extra_data[self->num_event_polls] = (event_extra_data) {
|
||||
.dev_input_id = -1,
|
||||
.grabbed = false,
|
||||
.key_states = NULL,
|
||||
.key_presses_grabbed = NULL,
|
||||
.num_keys_pressed = 0
|
||||
};
|
||||
|
||||
++self->num_event_polls;
|
||||
|
||||
/* 0.5 seconds */
|
||||
const struct itimerspec timer_value = {
|
||||
.it_value = (struct timespec) {
|
||||
.tv_sec = 0,
|
||||
.tv_nsec = 500000000ULL,
|
||||
},
|
||||
.it_interval = (struct timespec) {
|
||||
.tv_sec = 0,
|
||||
.tv_nsec = 500000000ULL
|
||||
}
|
||||
};
|
||||
|
||||
if(timerfd_settime(self->timer_fd, 0, &timer_value, NULL) < 0) {
|
||||
fprintf(stderr, "Error: timerfd_settime failed\n");
|
||||
keyboard_event_deinit(self);
|
||||
return false;
|
||||
}
|
||||
|
||||
self->uinput_written_time_seconds = clock_get_monotonic_seconds();
|
||||
|
||||
if(hotplug_event_init(&self->hotplug_ev)) {
|
||||
self->event_polls[self->num_event_polls] = (struct pollfd) {
|
||||
.fd = hotplug_event_steal_fd(&self->hotplug_ev),
|
||||
@@ -606,6 +717,41 @@ bool keyboard_event_init(keyboard_event *self, bool exclusive_grab, keyboard_gra
|
||||
return true;
|
||||
}
|
||||
|
||||
static void write_led_data_to_device(int fd, uint16_t led, int value) {
|
||||
struct input_event led_data = {
|
||||
.type = EV_LED,
|
||||
.code = led,
|
||||
.value = value
|
||||
};
|
||||
write(fd, &led_data, sizeof(led_data));
|
||||
|
||||
struct input_event syn_data = {
|
||||
.type = EV_SYN,
|
||||
.code = 0,
|
||||
.value = 0
|
||||
};
|
||||
write(fd, &syn_data, sizeof(syn_data));
|
||||
}
|
||||
|
||||
/* When the device is ungrabbed the leds are unset for some reason. Set them back to their previous brightness */
|
||||
static void keyboard_event_device_deinit(int fd, event_extra_data *extra_data) {
|
||||
ggh_leds leds;
|
||||
const bool got_leds = get_leds(extra_data->dev_input_id, &leds);
|
||||
|
||||
ioctl(fd, EVIOCGRAB, 0);
|
||||
if(got_leds) {
|
||||
if(leds.scroll_lock_brightness >= 0)
|
||||
write_led_data_to_device(fd, LED_SCROLLL, leds.scroll_lock_brightness);
|
||||
|
||||
if(leds.num_lock_brightness >= 0)
|
||||
write_led_data_to_device(fd, LED_NUML, leds.num_lock_brightness);
|
||||
|
||||
if(leds.caps_lock_brightness >= 0)
|
||||
write_led_data_to_device(fd, LED_CAPSL, leds.caps_lock_brightness);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void keyboard_event_deinit(keyboard_event *self) {
|
||||
self->running = false;
|
||||
|
||||
@@ -622,8 +768,10 @@ void keyboard_event_deinit(keyboard_event *self) {
|
||||
|
||||
for(int i = 0; i < self->num_event_polls; ++i) {
|
||||
if(self->event_polls[i].fd > 0) {
|
||||
ioctl(self->event_polls[i].fd, EVIOCGRAB, 0);
|
||||
close(self->event_polls[i].fd);
|
||||
if(self->event_extra_data[i].dev_input_id > 0 && !self->event_extra_data[i].gsr_ui_virtual_keyboard)
|
||||
keyboard_event_device_deinit(self->event_polls[i].fd, &self->event_extra_data[i]);
|
||||
else
|
||||
close(self->event_polls[i].fd);
|
||||
}
|
||||
free(self->event_extra_data[i].key_states);
|
||||
free(self->event_extra_data[i].key_presses_grabbed);
|
||||
@@ -817,7 +965,7 @@ void keyboard_event_poll_events(keyboard_event *self, int timeout_milliseconds)
|
||||
return;
|
||||
|
||||
for(int i = 0; i < self->num_event_polls; ++i) {
|
||||
if(i == self->stdin_event_index && (self->event_polls[i].revents & (POLLHUP|POLLERR)))
|
||||
if(self->event_polls[i].fd == STDIN_FILENO && (self->event_polls[i].revents & (POLLHUP|POLLERR)))
|
||||
self->stdin_failed = true;
|
||||
|
||||
if(self->event_polls[i].revents & POLLHUP) { /* TODO: What if this is the hotplug fd? */
|
||||
@@ -832,8 +980,17 @@ void keyboard_event_poll_events(keyboard_event *self, int timeout_milliseconds)
|
||||
if(i == self->hotplug_event_index) {
|
||||
/* Device is added to end of |event_polls| so it's ok to add while iterating it via index */
|
||||
hotplug_event_process_event_data(&self->hotplug_ev, self->event_polls[i].fd, on_device_added_callback, self);
|
||||
} else if(i == self->stdin_event_index) {
|
||||
} else if(self->event_polls[i].fd == STDIN_FILENO) {
|
||||
keyboard_event_process_stdin_command_data(self, self->event_polls[i].fd);
|
||||
} else if(self->event_polls[i].fd == self->timer_fd) {
|
||||
uint64_t timers_elapsed = 0;
|
||||
read(self->timer_fd, &timers_elapsed, sizeof(timers_elapsed));
|
||||
|
||||
if(self->grab_type != KEYBOARD_GRAB_TYPE_NO_GRAB && self->check_grab_lock && clock_get_monotonic_seconds() - self->uinput_written_time_seconds >= 1.5) {
|
||||
self->check_grab_lock = false;
|
||||
puts("gsr-ui-virtual-keyboard-grabbed");
|
||||
fflush(stdout);
|
||||
}
|
||||
} else {
|
||||
keyboard_event_process_input_event_data(self, &self->event_extra_data[i], self->event_polls[i].fd);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#define MAX_EVENT_POLLS 32
|
||||
#define MAX_CLOSE_FDS 256
|
||||
#define MAX_GLOBAL_HOTKEYS 32
|
||||
#define MAX_GLOBAL_HOTKEYS 40
|
||||
|
||||
typedef enum {
|
||||
KEYBOARD_MODKEY_LALT = 1 << 0,
|
||||
@@ -41,6 +41,7 @@ typedef struct {
|
||||
bool grabbed;
|
||||
bool is_non_keyboard_device;
|
||||
bool is_possibly_non_keyboard_device;
|
||||
bool gsr_ui_virtual_keyboard;
|
||||
unsigned char *key_states;
|
||||
unsigned char *key_presses_grabbed;
|
||||
int num_keys_pressed;
|
||||
@@ -48,7 +49,8 @@ typedef struct {
|
||||
|
||||
typedef enum {
|
||||
KEYBOARD_GRAB_TYPE_ALL,
|
||||
KEYBOARD_GRAB_TYPE_VIRTUAL
|
||||
KEYBOARD_GRAB_TYPE_VIRTUAL,
|
||||
KEYBOARD_GRAB_TYPE_NO_GRAB
|
||||
} keyboard_grab_type;
|
||||
|
||||
typedef struct {
|
||||
@@ -62,10 +64,12 @@ typedef struct {
|
||||
event_extra_data event_extra_data[MAX_EVENT_POLLS]; /* Current size is |num_event_polls| */
|
||||
int num_event_polls;
|
||||
|
||||
int stdin_event_index;
|
||||
int hotplug_event_index;
|
||||
int uinput_fd;
|
||||
int timer_fd;
|
||||
bool stdin_failed;
|
||||
bool check_grab_lock;
|
||||
double uinput_written_time_seconds;
|
||||
keyboard_grab_type grab_type;
|
||||
|
||||
pthread_t close_dev_input_fds_thread;
|
||||
|
||||
181
tools/gsr-global-hotkeys/leds.c
Normal file
181
tools/gsr-global-hotkeys/leds.c
Normal file
@@ -0,0 +1,181 @@
|
||||
#include "leds.h"
|
||||
|
||||
/* C stdlib */
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* POSIX */
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* LINUX */
|
||||
#include <linux/input.h>
|
||||
|
||||
/* Returns -1 on error */
|
||||
static int read_int_from_file(const char *filepath) {
|
||||
const int fd = open(filepath, O_RDONLY);
|
||||
if(fd == -1) {
|
||||
fprintf(stderr, "Warning: get_max_brightness open error: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
int value = 0;
|
||||
char buffer[32];
|
||||
const ssize_t num_bytes_read = read(fd, buffer, sizeof(buffer));
|
||||
if(num_bytes_read > 0) {
|
||||
buffer[num_bytes_read] = '\0';
|
||||
success = sscanf(buffer, "%d", &value) == 1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return success ? value : -1;
|
||||
}
|
||||
|
||||
static int get_max_brightness(const char *sys_class_path, const char *filename) {
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof(path), "%s/%s/max_brightness", sys_class_path, filename);
|
||||
return read_int_from_file(path);
|
||||
}
|
||||
|
||||
static int get_brightness(const char *sys_class_path, const char *filename) {
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof(path), "%s/%s/brightness", sys_class_path, filename);
|
||||
return read_int_from_file(path);
|
||||
}
|
||||
|
||||
static bool string_starts_with(const char *str, const char *sub) {
|
||||
const int str_len = strlen(str);
|
||||
const int sub_len = strlen(sub);
|
||||
return str_len >= sub_len && memcmp(str, sub, sub_len) == 0;
|
||||
}
|
||||
|
||||
static bool string_ends_with(const char *str, const char *sub) {
|
||||
const int str_len = strlen(str);
|
||||
const int sub_len = strlen(sub);
|
||||
return str_len >= sub_len && memcmp(str + str_len - sub_len, sub, sub_len) == 0;
|
||||
}
|
||||
|
||||
static int sys_class_led_path_get_event_number(const char *sys_class_path, const char *filename) {
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof(path), "%s/%s/device", sys_class_path, filename);
|
||||
|
||||
DIR *dir = opendir(path);
|
||||
if(!dir)
|
||||
return -1;
|
||||
|
||||
int event_number = -1;
|
||||
struct dirent *entry;
|
||||
while((entry = readdir(dir)) != NULL) {
|
||||
int v = -1;
|
||||
if(sscanf(entry->d_name, "event%d", &v) == 1 && v >= 0) {
|
||||
event_number = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return event_number;
|
||||
}
|
||||
|
||||
/*
|
||||
We have to do this retardation instead of setting /sys/class/leds brightness since it doesn't work with /dev/uinput
|
||||
and we cant loop all /dev/input devices and open and write to them either since closing a /dev/input is very slow on linux.
|
||||
So we instead check which devices have the led before opening it.
|
||||
*/
|
||||
static bool set_device_leds(const char *led_name_path, bool enabled) {
|
||||
DIR *dir = opendir("/sys/class/leds");
|
||||
if(!dir)
|
||||
return false;
|
||||
|
||||
char dev_input_filepath[1024];
|
||||
struct dirent *entry;
|
||||
while((entry = readdir(dir)) != NULL) {
|
||||
if(entry->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
if(!string_starts_with(entry->d_name, "input") || !string_ends_with(entry->d_name, led_name_path))
|
||||
continue;
|
||||
|
||||
const int event_number = sys_class_led_path_get_event_number("/sys/class/leds", entry->d_name);
|
||||
if(event_number == -1)
|
||||
continue;
|
||||
|
||||
snprintf(dev_input_filepath, sizeof(dev_input_filepath), "/dev/input/event%d", event_number);
|
||||
|
||||
const int device_fd = open(dev_input_filepath, O_WRONLY);
|
||||
if(device_fd == -1)
|
||||
continue;
|
||||
|
||||
int brightness = 0;
|
||||
if(enabled) {
|
||||
brightness = get_max_brightness("/sys/class/leds", entry->d_name);
|
||||
if(brightness < 0)
|
||||
brightness = 1;
|
||||
}
|
||||
|
||||
struct input_event led_data = {
|
||||
.type = EV_LED,
|
||||
.code = LED_SCROLLL,
|
||||
.value = brightness
|
||||
};
|
||||
write(device_fd, &led_data, sizeof(led_data));
|
||||
|
||||
struct input_event syn_data = {
|
||||
.type = EV_SYN,
|
||||
.code = 0,
|
||||
.value = 0
|
||||
};
|
||||
write(device_fd, &syn_data, sizeof(syn_data));
|
||||
|
||||
close(device_fd);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_leds(const char *led_name, bool enabled) {
|
||||
if(strcmp(led_name, "Scroll Lock") == 0) {
|
||||
return set_device_leds("::scrolllock", enabled);
|
||||
} else {
|
||||
fprintf(stderr, "Error: invalid led: \"%s\", expected \"Scroll Lock\"\n", led_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool get_leds(int event_number, ggh_leds *leds) {
|
||||
leds->scroll_lock_brightness = -1;
|
||||
leds->num_lock_brightness = -1;
|
||||
leds->caps_lock_brightness = -1;
|
||||
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof(path), "/sys/class/input/event%d/device", event_number);
|
||||
|
||||
DIR *dir = opendir(path);
|
||||
if(!dir)
|
||||
return false;
|
||||
|
||||
struct dirent *entry;
|
||||
while((entry = readdir(dir)) != NULL) {
|
||||
if(entry->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
if(!string_starts_with(entry->d_name, "input"))
|
||||
continue;
|
||||
|
||||
if(string_ends_with(entry->d_name, "::scrolllock"))
|
||||
leds->scroll_lock_brightness = get_brightness(path, entry->d_name);
|
||||
else if(string_ends_with(entry->d_name, "::numlock"))
|
||||
leds->num_lock_brightness = get_brightness(path, entry->d_name);
|
||||
else if(string_ends_with(entry->d_name, "::capslock"))
|
||||
leds->caps_lock_brightness = get_brightness(path, entry->d_name);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return true;
|
||||
}
|
||||
17
tools/gsr-global-hotkeys/leds.h
Normal file
17
tools/gsr-global-hotkeys/leds.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef LEDS_H
|
||||
#define LEDS_H
|
||||
|
||||
/* C stdlib */
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
/* These are set to -1 if not supported */
|
||||
int scroll_lock_brightness;
|
||||
int num_lock_brightness;
|
||||
int caps_lock_brightness;
|
||||
} ggh_leds;
|
||||
|
||||
bool set_leds(const char *led_name, bool enabled);
|
||||
bool get_leds(int event_number, ggh_leds *leds);
|
||||
|
||||
#endif /* LEDS_H */
|
||||
@@ -1,18 +1,26 @@
|
||||
#include "keyboard_event.h"
|
||||
#include "leds.h"
|
||||
|
||||
/* C stdlib */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* POSIX */
|
||||
#include <unistd.h>
|
||||
|
||||
static void usage(void) {
|
||||
fprintf(stderr, "usage: gsr-global-hotkeys [--all|--virtual]\n");
|
||||
fprintf(stderr, "usage: gsr-global-hotkeys [--all|--virtual|--no-grab|--set-led] [Scroll Lock] [on|off]\n");
|
||||
fprintf(stderr, "OPTIONS:\n");
|
||||
fprintf(stderr, " --all Grab all devices.\n");
|
||||
fprintf(stderr, " --virtual Grab all virtual devices only.\n");
|
||||
fprintf(stderr, " --no-grab Don't grab devices, only listen to them.\n");
|
||||
fprintf(stderr, " --set-led Turn device led on/off.\n");
|
||||
fprintf(stderr, "EXAMPLES:\n");
|
||||
fprintf(stderr, " gsr-global-hotkeys --all\n");
|
||||
fprintf(stderr, " gsr-global-hotkeys --set-led \"Scroll Lock\" on\n");
|
||||
fprintf(stderr, " gsr-global-hotkeys --set-led \"Scroll Lock\" off\n");
|
||||
}
|
||||
|
||||
static bool is_gsr_global_hotkeys_already_running(void) {
|
||||
@@ -37,17 +45,52 @@ int main(int argc, char **argv) {
|
||||
setlocale(LC_ALL, "C"); /* Sigh... stupid C */
|
||||
|
||||
keyboard_grab_type grab_type = KEYBOARD_GRAB_TYPE_ALL;
|
||||
const uid_t user_id = getuid();
|
||||
|
||||
if(argc == 2) {
|
||||
const char *grab_type_arg = argv[1];
|
||||
if(strcmp(grab_type_arg, "--all") == 0) {
|
||||
grab_type = KEYBOARD_GRAB_TYPE_ALL;
|
||||
} else if(strcmp(grab_type_arg, "--virtual") == 0) {
|
||||
grab_type = KEYBOARD_GRAB_TYPE_VIRTUAL;
|
||||
} else if(strcmp(grab_type_arg, "--no-grab") == 0) {
|
||||
grab_type = KEYBOARD_GRAB_TYPE_NO_GRAB;
|
||||
} else if(strcmp(grab_type_arg, "--set-led") == 0) {
|
||||
fprintf(stderr, "Error: missing led name and on/off argument to --set-led\n");
|
||||
usage();
|
||||
return 1;
|
||||
} else {
|
||||
fprintf(stderr, "gsr-global-hotkeys error: expected --all or --virtual, got %s\n", grab_type_arg);
|
||||
fprintf(stderr, "gsr-global-hotkeys error: expected --all, --virtual, --no-grab or --set-led, got %s\n", grab_type_arg);
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
} else if(argc == 4) {
|
||||
/* It's not ideal to use gsr-global-hotkeys for leds, but we do that for now because it's a mess to create another binary for flatpak and distros */
|
||||
const char *led_name = argv[2];
|
||||
const char *led_enabled_str = argv[3];
|
||||
bool led_enabled = false;
|
||||
|
||||
if(strcmp(led_enabled_str, "on") == 0) {
|
||||
led_enabled = true;
|
||||
} else if(strcmp(led_enabled_str, "off") == 0) {
|
||||
led_enabled = false;
|
||||
} else {
|
||||
fprintf(stderr, "Error: expected \"on\" or \"off\" for --set-led option, got: \"%s\"", led_enabled_str);
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(geteuid() != 0) {
|
||||
if(setuid(0) == -1) {
|
||||
fprintf(stderr, "gsr-global-hotkeys error: failed to change user to root, global hotkeys will not work. Make sure to set the correct capability on gsr-global-hotkeys\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const bool success = set_leds(led_name, led_enabled);
|
||||
setuid(user_id);
|
||||
|
||||
return success ? 0 : 1;
|
||||
} else if(argc != 1) {
|
||||
fprintf(stderr, "gsr-global-hotkeys error: expected 0 or 1 arguments, got %d argument(s)\n", argc);
|
||||
usage();
|
||||
@@ -59,7 +102,6 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const uid_t user_id = getuid();
|
||||
if(geteuid() != 0) {
|
||||
if(setuid(0) == -1) {
|
||||
fprintf(stderr, "gsr-global-hotkeys error: failed to change user to root, global hotkeys will not work. Make sure to set the correct capability on gsr-global-hotkeys\n");
|
||||
@@ -68,7 +110,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
keyboard_event keyboard_ev;
|
||||
if(!keyboard_event_init(&keyboard_ev, true, grab_type)) {
|
||||
if(!keyboard_event_init(&keyboard_ev, grab_type != KEYBOARD_GRAB_TYPE_NO_GRAB, grab_type)) {
|
||||
fprintf(stderr, "gsr-global-hotkeys error: failed to setup hotplugging and no keyboard input devices were found\n");
|
||||
setuid(user_id);
|
||||
return 1;
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
static void get_runtime_filepath(char *buffer, size_t buffer_size, const char *filename) {
|
||||
static void get_socket_filepath(char *buffer, size_t buffer_size, const char *filename) {
|
||||
char dir[PATH_MAX];
|
||||
|
||||
const char *runtime_dir = getenv("XDG_RUNTIME_DIR");
|
||||
@@ -23,7 +25,7 @@ static void get_runtime_filepath(char *buffer, size_t buffer_size, const char *f
|
||||
}
|
||||
|
||||
/* Assumes |str| size is less than 256 */
|
||||
static void fifo_write_all(int file_fd, const char *str) {
|
||||
static void file_write_all(int file_fd, const char *str) {
|
||||
char command[256];
|
||||
const ssize_t command_size = snprintf(command, sizeof(command), "%s\n", str);
|
||||
if(command_size >= (ssize_t)sizeof(command)) {
|
||||
@@ -33,7 +35,7 @@ static void fifo_write_all(int file_fd, const char *str) {
|
||||
|
||||
ssize_t offset = 0;
|
||||
while(offset < (ssize_t)command_size) {
|
||||
const ssize_t bytes_written = write(file_fd, str + offset, command_size - offset);
|
||||
const ssize_t bytes_written = write(file_fd, command + offset, command_size - offset);
|
||||
if(bytes_written > 0)
|
||||
offset += bytes_written;
|
||||
}
|
||||
@@ -112,15 +114,34 @@ int main(int argc, char **argv) {
|
||||
usage();
|
||||
}
|
||||
|
||||
char fifo_filepath[PATH_MAX];
|
||||
get_runtime_filepath(fifo_filepath, sizeof(fifo_filepath), "gsr-ui");
|
||||
const int fifo_fd = open(fifo_filepath, O_RDWR | O_NONBLOCK);
|
||||
if(fifo_fd <= 0) {
|
||||
fprintf(stderr, "Error: failed to open fifo file %s. Maybe gsr-ui is not running?\n", fifo_filepath);
|
||||
char socket_filepath[PATH_MAX];
|
||||
get_socket_filepath(socket_filepath, sizeof(socket_filepath), "gsr-ui");
|
||||
|
||||
const int socket_fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
||||
if(socket_fd <= 0) {
|
||||
fprintf(stderr, "Error: failed to create socket\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
fifo_write_all(fifo_fd, command);
|
||||
close(fifo_fd);
|
||||
struct sockaddr_un addr = {0};
|
||||
addr.sun_family = AF_UNIX;
|
||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_filepath);
|
||||
|
||||
for(;;) {
|
||||
if(connect(socket_fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||
const int err = errno;
|
||||
if(err == EWOULDBLOCK) {
|
||||
usleep(10 * 1000);
|
||||
} else {
|
||||
fprintf(stderr, "Error: failed to connect, error: %s. Maybe gsr-ui is not running?\n", strerror(err));
|
||||
exit(2);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
file_write_all(socket_fd, command);
|
||||
close(socket_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user