mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-04-05 11:16:28 +09:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fed47000ce | ||
|
|
7f43adfbd5 | ||
|
|
1f6251baf3 | ||
|
|
d1220b013e | ||
|
|
93a55b6bdf | ||
|
|
974e760136 | ||
|
|
387141d36f | ||
|
|
3713d3d59e | ||
|
|
2bb6754523 | ||
|
|
df1610431d | ||
|
|
1ea9615584 | ||
|
|
45ae7c95cf | ||
|
|
f1b6df4d56 | ||
|
|
202c0b2415 | ||
|
|
fd5026489c | ||
|
|
8032cb2cf0 | ||
|
|
13562d2aa1 | ||
|
|
1971d4a288 | ||
|
|
c039b79174 | ||
|
|
245dcf5730 | ||
|
|
e68a342b81 | ||
|
|
11aa237821 | ||
|
|
d7be9b38b1 | ||
|
|
4717c64b03 | ||
|
|
2c2633ec58 |
@@ -44,7 +44,7 @@ as gpu screen recorder tries to grab keys and keyd grabs gpu screen recorder, le
|
||||
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.
|
||||
|
||||
# License
|
||||
This software is licensed under GPL3.0-only. Files under `fonts/` directory belong to the Noto Sans Google fonts project and they are licensed under `SIL Open Font License`.\
|
||||
This software is licensed under GPL-3.0-only, see the LICENSE file for more information. Files under `fonts/` directory belong to the Noto Sans Google fonts project and they are licensed under `SIL Open Font License`.\
|
||||
`images/default.cur` it part of the [Adwaita icon theme](https://gitlab.gnome.org/GNOME/adwaita-icon-theme/-/tree/master) which is licensed under `CC BY-SA 3.0`.\
|
||||
The controller buttons under `images/` were created by [Julio Cacko](https://juliocacko.itch.io/free-input-prompts) and they are licensed under `CC0 1.0 Universal`.\
|
||||
The PlayStation logo under `images/` was created by [ArksDigital](https://arks.itch.io/ps4-buttons) and it's licensed under `CC BY 4.0`.
|
||||
|
||||
12
TODO
12
TODO
@@ -127,8 +127,6 @@ Add option to do screen-direct recording. But make it clear that it should not b
|
||||
|
||||
Add systray for recording status.
|
||||
|
||||
Add a desktop icon when gsr-ui has a window mode option (which should be the default launch option).
|
||||
|
||||
Verify if cursor tracker monitor name is always correct. It uses the wayland monitor name for recording, but gpu screen recorder uses a custom name created from the drm connector name.
|
||||
|
||||
Notification with the focused monitor (with CursorTrackerWayland) assumes that the x11 monitor name is the same as the drm monitor name. Same for find_monitor_by_name.
|
||||
@@ -246,4 +244,12 @@ Remove all mgl::Clock usage in Overlay. We only need to get the time once per up
|
||||
|
||||
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.
|
||||
Support translations.
|
||||
|
||||
Sometimes when opening gpu screen recorder ui gsr-global-hotkeys incorrectly detects that keyboard input is locked.
|
||||
|
||||
When running replay for a long time and then stopping it it takes a while. Improve this.
|
||||
|
||||
When adding webcamera make replay auto start wait for camera to be available (when /dev/video device exists and can be initialized), just like audio device.
|
||||
|
||||
Make it possible to resize webcam box from top left, top right and bottom left as well.
|
||||
Submodule depends/mglpp updated: b569045831...f69b0d3ee0
10
gpu-screen-recorder.desktop
Normal file
10
gpu-screen-recorder.desktop
Normal file
@@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=GPU Screen Recorder
|
||||
GenericName=Screen recorder
|
||||
Comment=A ShadowPlay-like screen recorder for Linux
|
||||
Icon=gpu-screen-recorder
|
||||
Exec=gsr-ui launch-hide-announce
|
||||
Terminal=false
|
||||
Keywords=gpu-screen-recorder;gsr-ui;screen recorder;streaming;twitch;replay;shadowplay;
|
||||
Categories=AudioVideo;Recorder;
|
||||
BIN
icons/hicolor/128x128/apps/gpu-screen-recorder.png
Normal file
BIN
icons/hicolor/128x128/apps/gpu-screen-recorder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
BIN
icons/hicolor/32x32/apps/gpu-screen-recorder.png
Normal file
BIN
icons/hicolor/32x32/apps/gpu-screen-recorder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
icons/hicolor/64x64/apps/gpu-screen-recorder.png
Normal file
BIN
icons/hicolor/64x64/apps/gpu-screen-recorder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -61,6 +61,14 @@ namespace gsr {
|
||||
bool record_cursor = true;
|
||||
bool restore_portal_session = true;
|
||||
|
||||
std::string webcam_source = "";
|
||||
bool webcam_flip_horizontally = false;
|
||||
std::string webcam_video_format = "auto";
|
||||
int32_t webcam_x = 0; // A value between 0 and 100 (percentage)
|
||||
int32_t webcam_y = 0; // A value between 0 and 100 (percentage)
|
||||
int32_t webcam_width = 30; // A value between 0 and 100 (percentage), 0 = Don't scale it
|
||||
int32_t webcam_height = 30; // A value between 0 and 100 (percentage), 0 = Don't scale it
|
||||
|
||||
bool show_notifications = true;
|
||||
bool use_led_indicator = false;
|
||||
};
|
||||
@@ -140,12 +148,15 @@ namespace gsr {
|
||||
|
||||
bool save_screenshot_in_game_folder = false;
|
||||
bool save_screenshot_to_clipboard = false;
|
||||
bool save_screenshot_to_disk = true;
|
||||
bool show_notifications = true;
|
||||
bool use_led_indicator = false;
|
||||
std::string save_directory;
|
||||
ConfigHotkey take_screenshot_hotkey;
|
||||
ConfigHotkey take_screenshot_region_hotkey;
|
||||
ConfigHotkey take_screenshot_window_hotkey; // Or desktop portal, on wayland
|
||||
|
||||
std::string custom_script;
|
||||
};
|
||||
|
||||
struct Config {
|
||||
@@ -164,4 +175,4 @@ namespace gsr {
|
||||
|
||||
std::optional<Config> read_config(const SupportedCaptureOptions &capture_options);
|
||||
void save_config(Config &config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,22 @@ namespace gsr {
|
||||
bool png = false;
|
||||
};
|
||||
|
||||
struct SupportedCameraPixelFormats {
|
||||
bool yuyv = false;
|
||||
bool mjpeg = false;
|
||||
};
|
||||
|
||||
struct GsrMonitor {
|
||||
std::string name;
|
||||
mgl::vec2i size;
|
||||
};
|
||||
|
||||
struct GsrCamera {
|
||||
std::string path;
|
||||
mgl::vec2i size;
|
||||
SupportedCameraPixelFormats supported_pixel_formats;
|
||||
};
|
||||
|
||||
struct GsrVersion {
|
||||
uint8_t major = 0;
|
||||
uint8_t minor = 0;
|
||||
@@ -51,6 +62,7 @@ namespace gsr {
|
||||
bool focused = false;
|
||||
bool portal = false;
|
||||
std::vector<GsrMonitor> monitors;
|
||||
std::vector<GsrCamera> cameras;
|
||||
};
|
||||
|
||||
enum class DisplayServer {
|
||||
@@ -103,4 +115,5 @@ namespace gsr {
|
||||
std::vector<AudioDevice> get_audio_devices();
|
||||
std::vector<std::string> get_application_audio();
|
||||
SupportedCaptureOptions get_supported_capture_options(const GsrInfo &gsr_info);
|
||||
std::vector<GsrCamera> get_v4l2_devices();
|
||||
}
|
||||
@@ -40,7 +40,8 @@ namespace gsr {
|
||||
RECORD,
|
||||
REPLAY,
|
||||
STREAM,
|
||||
SCREENSHOT
|
||||
SCREENSHOT,
|
||||
NOTICE
|
||||
};
|
||||
|
||||
enum class NotificationLevel {
|
||||
@@ -98,6 +99,7 @@ namespace gsr {
|
||||
|
||||
bool global_hotkeys_ungrab_keyboard = false;
|
||||
private:
|
||||
const char* notification_type_to_string(NotificationType notification_type);
|
||||
void update_upause_status();
|
||||
|
||||
void hide();
|
||||
@@ -106,6 +108,7 @@ namespace gsr {
|
||||
void on_event(mgl::Event &event);
|
||||
|
||||
void recreate_global_hotkeys(const char *hotkey_option);
|
||||
void update_led_indicator_after_settings_change();
|
||||
void create_frontpage_ui_components();
|
||||
void xi_setup();
|
||||
void handle_xi_events();
|
||||
@@ -117,7 +120,7 @@ namespace gsr {
|
||||
|
||||
double get_time_passed_in_replay_buffer_seconds();
|
||||
void update_notification_process_status();
|
||||
void save_video_in_current_game_directory(const char *video_filepath, NotificationType notification_type);
|
||||
void save_video_in_current_game_directory(std::string &video_filepath, NotificationType notification_type);
|
||||
void on_replay_saved(const char *replay_saved_filepath);
|
||||
void process_gsr_output();
|
||||
void on_gsr_process_error(int exit_code, NotificationType notification_type);
|
||||
@@ -129,7 +132,7 @@ namespace gsr {
|
||||
void update_power_supply_status();
|
||||
void update_system_startup_status();
|
||||
|
||||
void on_stop_recording(int exit_code, const std::string &video_filepath);
|
||||
void on_stop_recording(int exit_code, std::string &video_filepath);
|
||||
|
||||
void update_ui_recording_paused();
|
||||
void update_ui_recording_unpaused();
|
||||
@@ -171,6 +174,8 @@ namespace gsr {
|
||||
Config config;
|
||||
Config current_recording_config;
|
||||
|
||||
std::string gsr_icon_path;
|
||||
|
||||
bool visible = false;
|
||||
|
||||
mgl::Texture window_texture_texture;
|
||||
|
||||
@@ -13,13 +13,17 @@ namespace gsr {
|
||||
|
||||
// Arguments ending with NULL
|
||||
bool exec_program_daemonized(const char **args, bool debug = true);
|
||||
// Arguments ending with NULL.
|
||||
// This works the same as |exec_program_get_stdout|, except on flatpak where this runs the program on the
|
||||
// host machine with flatpak-spawn --host.
|
||||
bool exec_program_on_host_daemonized(const char **args, bool debug = true);
|
||||
// Arguments ending with NULL. |read_fd| can be NULL
|
||||
pid_t exec_program(const char **args, int *read_fd, bool debug = true);
|
||||
// Arguments ending with NULL. Returns the exit status of the program or -1 on error
|
||||
int exec_program_get_stdout(const char **args, std::string &result, bool debug = true);
|
||||
// Arguments ending with NULL. Returns the exit status of the program or -1 on error.
|
||||
// This works the same as |exec_program_get_stdout|, except on flatpak where this runs the program on the
|
||||
// host machine with flatpak-spawn --host
|
||||
// host machine with flatpak-spawn --host.
|
||||
int exec_program_on_host_get_stdout(const char **args, std::string &result, bool debug = true);
|
||||
pid_t pidof(const char *process_name, pid_t ignore_pid);
|
||||
}
|
||||
@@ -24,6 +24,7 @@ namespace gsr {
|
||||
mgl::Font body_font;
|
||||
mgl::Font title_font;
|
||||
mgl::Font top_bar_font;
|
||||
mgl::Font camera_setup_font;
|
||||
|
||||
mgl::Texture combobox_arrow_texture;
|
||||
mgl::Texture settings_texture;
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace gsr {
|
||||
};
|
||||
|
||||
std::optional<std::string> get_window_title(Display *dpy, Window window);
|
||||
Window get_focused_window(Display *dpy, WindowCaptureType cap_type);
|
||||
std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type);
|
||||
Window get_focused_window(Display *dpy, WindowCaptureType cap_type, bool fallback_cursor_focused = true);
|
||||
std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type, bool fallback_cursor_focused = true);
|
||||
std::string get_window_name_at_position(Display *dpy, mgl::vec2i position, Window ignore_window);
|
||||
std::string get_window_name_at_cursor_position(Display *dpy, Window ignore_window);
|
||||
void set_window_size_not_resizable(Display *dpy, Window window, int width, int height);
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace gsr {
|
||||
void draw(mgl::Window &window, mgl::vec2f offset) override;
|
||||
|
||||
void add_item(const std::string &text, const std::string &id);
|
||||
void clear_items();
|
||||
|
||||
// The item can only be selected if it's enabled
|
||||
void set_selected_item(const std::string &id, bool trigger_event = true, bool trigger_event_even_if_selection_not_changed = true);
|
||||
void set_item_enabled(const std::string &id, bool enabled);
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace gsr {
|
||||
void load();
|
||||
void save();
|
||||
void on_navigate_away_from_page() override;
|
||||
|
||||
std::function<void()> on_config_changed;
|
||||
private:
|
||||
std::unique_ptr<ComboBox> create_record_area_box();
|
||||
std::unique_ptr<Widget> create_record_area();
|
||||
@@ -43,10 +45,14 @@ 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<CheckBox> create_save_screenshot_to_disk();
|
||||
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_screenshot_indicator_section();
|
||||
std::unique_ptr<Widget> create_custom_script_screenshot_section();
|
||||
std::unique_ptr<List> create_custom_script_screenshot_entry();
|
||||
std::unique_ptr<List> create_custom_script_screenshot();
|
||||
std::unique_ptr<Widget> create_settings();
|
||||
void add_widgets();
|
||||
|
||||
@@ -73,9 +79,11 @@ 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 *save_screenshot_to_disk_checkbox_ptr = nullptr;
|
||||
CheckBox *show_notification_checkbox_ptr = nullptr;
|
||||
CheckBox *led_indicator_checkbox_ptr = nullptr;
|
||||
Entry *create_custom_script_screenshot_entry_ptr = nullptr;
|
||||
|
||||
PageStack *page_stack = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,14 @@ namespace gsr {
|
||||
INPUT
|
||||
};
|
||||
|
||||
enum class WebcamBoxResizeCorner {
|
||||
NONE,
|
||||
//TOP_LEFT,
|
||||
//TOP_RIGHT,
|
||||
//BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT
|
||||
};
|
||||
|
||||
class SettingsPage : public StaticPage {
|
||||
public:
|
||||
enum class Type {
|
||||
@@ -58,6 +66,12 @@ namespace gsr {
|
||||
std::unique_ptr<List> create_restore_portal_session_section();
|
||||
std::unique_ptr<Widget> create_change_video_resolution_section();
|
||||
std::unique_ptr<Widget> create_capture_target_section();
|
||||
std::unique_ptr<List> create_webcam_sources();
|
||||
std::unique_ptr<List> create_webcam_video_format();
|
||||
std::unique_ptr<Widget> create_webcam_location_widget();
|
||||
std::unique_ptr<CheckBox> create_flip_camera_checkbox();
|
||||
std::unique_ptr<List> create_webcam_body();
|
||||
std::unique_ptr<Widget> create_webcam_section();
|
||||
std::unique_ptr<ComboBox> create_audio_device_selection_combobox(AudioDeviceType device_type);
|
||||
std::unique_ptr<Button> create_remove_audio_device_button(List *audio_input_list_ptr, List *audio_device_list_ptr);
|
||||
std::unique_ptr<List> create_audio_device(AudioDeviceType device_type, List *audio_input_list_ptr);
|
||||
@@ -140,6 +154,8 @@ namespace gsr {
|
||||
void save_stream();
|
||||
|
||||
void view_changed(bool advanced_view);
|
||||
|
||||
RecordOptions& get_current_record_options();
|
||||
private:
|
||||
Type type;
|
||||
Config &config;
|
||||
@@ -197,7 +213,29 @@ namespace gsr {
|
||||
List *audio_track_section_list_ptr = nullptr;
|
||||
CheckBox *led_indicator_checkbox_ptr = nullptr;
|
||||
CheckBox *show_notification_checkbox_ptr = nullptr;
|
||||
ComboBox *webcam_sources_box_ptr = nullptr;
|
||||
ComboBox *webcam_video_format_box_ptr = nullptr;
|
||||
List *webcam_body_list_ptr = nullptr;
|
||||
CheckBox *flip_camera_horizontally_checkbox_ptr = nullptr;
|
||||
|
||||
PageStack *page_stack = nullptr;
|
||||
|
||||
mgl::vec2f webcam_box_pos;
|
||||
mgl::vec2f webcam_box_size;
|
||||
|
||||
mgl::vec2f webcam_box_drawn_pos;
|
||||
mgl::vec2f webcam_box_drawn_size;
|
||||
mgl::vec2f webcam_box_grab_offset;
|
||||
|
||||
mgl::vec2f camera_screen_size;
|
||||
mgl::vec2f screen_inner_size;
|
||||
bool moving_webcam_box = false;
|
||||
|
||||
WebcamBoxResizeCorner webcam_resize_corner = WebcamBoxResizeCorner::NONE;
|
||||
mgl::vec2f webcam_resize_start_pos;
|
||||
mgl::vec2f webcam_box_pos_resize_start;
|
||||
mgl::vec2f webcam_box_size_resize_start;
|
||||
|
||||
std::optional<GsrCamera> selected_camera;
|
||||
};
|
||||
}
|
||||
@@ -9,6 +9,10 @@ namespace mgl {
|
||||
}
|
||||
|
||||
namespace gsr {
|
||||
mgl::vec2i min_vec2i(mgl::vec2i a, mgl::vec2i b);
|
||||
mgl::vec2i max_vec2i(mgl::vec2i a, mgl::vec2i b);
|
||||
mgl::vec2i clamp_vec2i(mgl::vec2i value, mgl::vec2i min, mgl::vec2i max);
|
||||
|
||||
// Inner border
|
||||
void draw_rectangle_outline(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, mgl::Color color, float border_size);
|
||||
double get_frame_delta_seconds();
|
||||
|
||||
13
meson.build
13
meson.build
@@ -1,4 +1,4 @@
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.8.2', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.9.3', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
|
||||
add_project_arguments('-D_FILE_OFFSET_BITS=64', language : ['c', 'cpp'])
|
||||
|
||||
@@ -64,9 +64,10 @@ mglpp_dep = mglpp_proj.get_variable('mglpp_dep')
|
||||
prefix = get_option('prefix')
|
||||
datadir = get_option('datadir')
|
||||
gsr_ui_resources_path = join_paths(prefix, datadir, 'gsr-ui')
|
||||
icons_path = join_paths(prefix, datadir, 'icons')
|
||||
|
||||
add_project_arguments('-DGSR_UI_VERSION="' + meson.project_version() + '"', language: ['c', 'cpp'])
|
||||
add_project_arguments('-DGSR_FLATPAK_VERSION="5.9.0"', language: ['c', 'cpp'])
|
||||
add_project_arguments('-DGSR_FLATPAK_VERSION="5.11.5"', language: ['c', 'cpp'])
|
||||
|
||||
executable(
|
||||
meson.project_name(),
|
||||
@@ -112,6 +113,14 @@ executable(
|
||||
install_subdir('images', install_dir : gsr_ui_resources_path)
|
||||
install_subdir('fonts', install_dir : gsr_ui_resources_path)
|
||||
|
||||
if get_option('desktop-files') == true
|
||||
install_data(files('gpu-screen-recorder.desktop'), install_dir : join_paths(prefix, datadir, 'applications'))
|
||||
install_subdir('icons/hicolor', install_dir : icons_path)
|
||||
|
||||
gnome = import('gnome')
|
||||
gnome.post_install(update_desktop_database : true)
|
||||
endif
|
||||
|
||||
if get_option('systemd') == true
|
||||
install_data(files('extra/gpu-screen-recorder-ui.service'), install_dir : 'lib/systemd/user')
|
||||
endif
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
option('systemd', type : 'boolean', value : true, description : 'Install systemd service file')
|
||||
option('capabilities', type : 'boolean', value : true, description : 'Set binary setuid capability on gsr-global-hotkeys binary to allow global hotkeys')
|
||||
option('capabilities', type : 'boolean', value : true, description : 'Set binary setuid capability on gsr-global-hotkeys binary to allow global hotkeys')
|
||||
option('desktop-files', type : 'boolean', value : true, description : 'Install desktop files')
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "gsr-ui"
|
||||
type = "executable"
|
||||
version = "1.8.2"
|
||||
version = "1.9.3"
|
||||
platforms = ["posix"]
|
||||
|
||||
[lang.cpp]
|
||||
|
||||
@@ -48,11 +48,18 @@ namespace gsr {
|
||||
XNextEvent(dpy, &xev);
|
||||
switch(xev.type) {
|
||||
case SelectionClear: {
|
||||
should_clear_selection = true;
|
||||
if(clipboard_copies.empty()) {
|
||||
should_clear_selection = false;
|
||||
set_current_file("", file_type);
|
||||
bool clear_current_file = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
should_clear_selection = true;
|
||||
if(clipboard_copies.empty()) {
|
||||
should_clear_selection = false;
|
||||
clear_current_file = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(clear_current_file)
|
||||
set_current_file("", file_type);
|
||||
break;
|
||||
}
|
||||
case SelectionRequest:
|
||||
@@ -205,6 +212,9 @@ namespace gsr {
|
||||
uint8_t file_buffer[1<<16];
|
||||
ssize_t file_bytes_read = 0;
|
||||
|
||||
if(file_fd <= 0)
|
||||
return;
|
||||
|
||||
if(lseek(file_fd, clipboard_copy->file_offset, SEEK_SET) == -1) {
|
||||
fprintf(stderr, "gsr ui: error: ClipboardFile::send_clipboard: failed to seek in clipboard file to offset " FORMAT_U64 " for requestor window " FORMAT_I64 ", error: %s\n", (uint64_t)clipboard_copy->file_offset, (int64_t)xselectionrequest->requestor, strerror(errno));
|
||||
clipboard_copy->file_offset = 0;
|
||||
@@ -262,7 +272,13 @@ namespace gsr {
|
||||
}
|
||||
clipboard_copies.clear();
|
||||
|
||||
if(XGetSelectionOwner(dpy, clipboard_atom) == clipboard_window) {
|
||||
XSetSelectionOwner(dpy, clipboard_atom, None, CurrentTime);
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
if(filepath.empty()) {
|
||||
// TODO: Cancel transfer
|
||||
if(file_fd > 0) {
|
||||
close(file_fd);
|
||||
file_fd = -1;
|
||||
|
||||
@@ -199,6 +199,13 @@ 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.record_options.webcam_source", &config.streaming_config.record_options.webcam_source},
|
||||
{"streaming.record_options.webcam_flip_horizontally", &config.streaming_config.record_options.webcam_flip_horizontally},
|
||||
{"streaming.record_options.webcam_video_format", &config.streaming_config.record_options.webcam_video_format},
|
||||
{"streaming.record_options.webcam_x", &config.streaming_config.record_options.webcam_x},
|
||||
{"streaming.record_options.webcam_y", &config.streaming_config.record_options.webcam_y},
|
||||
{"streaming.record_options.webcam_width", &config.streaming_config.record_options.webcam_width},
|
||||
{"streaming.record_options.webcam_height", &config.streaming_config.record_options.webcam_height},
|
||||
{"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},
|
||||
@@ -231,6 +238,13 @@ 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.webcam_source", &config.record_config.record_options.webcam_source},
|
||||
{"record.record_options.webcam_flip_horizontally", &config.record_config.record_options.webcam_flip_horizontally},
|
||||
{"record.record_options.webcam_video_format", &config.record_config.record_options.webcam_video_format},
|
||||
{"record.record_options.webcam_x", &config.record_config.record_options.webcam_x},
|
||||
{"record.record_options.webcam_y", &config.record_config.record_options.webcam_y},
|
||||
{"record.record_options.webcam_width", &config.record_config.record_options.webcam_width},
|
||||
{"record.record_options.webcam_height", &config.record_config.record_options.webcam_height},
|
||||
{"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},
|
||||
@@ -260,6 +274,13 @@ 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.webcam_source", &config.replay_config.record_options.webcam_source},
|
||||
{"replay.record_options.webcam_flip_horizontally", &config.replay_config.record_options.webcam_flip_horizontally},
|
||||
{"replay.record_options.webcam_video_format", &config.replay_config.record_options.webcam_video_format},
|
||||
{"replay.record_options.webcam_x", &config.replay_config.record_options.webcam_x},
|
||||
{"replay.record_options.webcam_y", &config.replay_config.record_options.webcam_y},
|
||||
{"replay.record_options.webcam_width", &config.replay_config.record_options.webcam_width},
|
||||
{"replay.record_options.webcam_height", &config.replay_config.record_options.webcam_height},
|
||||
{"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},
|
||||
@@ -284,12 +305,14 @@ 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.save_screenshot_to_disk", &config.screenshot_config.save_screenshot_to_disk},
|
||||
{"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},
|
||||
{"screenshot.take_screenshot_window_hotkey", &config.screenshot_config.take_screenshot_window_hotkey}
|
||||
{"screenshot.take_screenshot_window_hotkey", &config.screenshot_config.take_screenshot_window_hotkey},
|
||||
{"screenshot.custom_script", &config.screenshot_config.custom_script},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -487,4 +510,4 @@ namespace gsr {
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,6 +288,56 @@ namespace gsr {
|
||||
return application_audio;
|
||||
}
|
||||
|
||||
struct KeyValue3 {
|
||||
std::string_view value1;
|
||||
std::string_view value2;
|
||||
std::string_view value3;
|
||||
};
|
||||
|
||||
static std::optional<KeyValue3> parse_3(std::string_view line) {
|
||||
const size_t space_index1 = line.find('|');
|
||||
if(space_index1 == std::string_view::npos)
|
||||
return std::nullopt;
|
||||
|
||||
const size_t space_index2 = line.find('|', space_index1 + 1);
|
||||
if(space_index2 == std::string_view::npos)
|
||||
return std::nullopt;
|
||||
|
||||
return KeyValue3{
|
||||
line.substr(0, space_index1),
|
||||
line.substr(space_index1 + 1, space_index2 - (space_index1 + 1)),
|
||||
line.substr(space_index2 + 1),
|
||||
};
|
||||
}
|
||||
|
||||
static SupportedCameraPixelFormats parse_supported_camera_pixel_formats(std::string_view line) {
|
||||
SupportedCameraPixelFormats result;
|
||||
string_split_char(line, ',', [&](std::string_view column) {
|
||||
if(column == "yuyv")
|
||||
result.yuyv = true;
|
||||
else if(column == "mjpeg")
|
||||
result.mjpeg = true;
|
||||
return true;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::optional<GsrCamera> capture_option_line_to_camera(std::string_view line) {
|
||||
std::optional<GsrCamera> camera;
|
||||
const std::optional<KeyValue3> key_value3 = parse_3(line);
|
||||
if(!key_value3)
|
||||
return camera;
|
||||
|
||||
mgl::vec2i size;
|
||||
char value_buffer[256];
|
||||
snprintf(value_buffer, sizeof(value_buffer), "%.*s", (int)key_value3->value2.size(), key_value3->value2.data());
|
||||
if(sscanf(value_buffer, "%dx%d", &size.x, &size.y) != 2)
|
||||
return camera;
|
||||
|
||||
camera = GsrCamera{std::string(key_value3->value1), size, parse_supported_camera_pixel_formats(key_value3->value3)};
|
||||
return camera;
|
||||
}
|
||||
|
||||
static std::optional<GsrMonitor> capture_option_line_to_monitor(std::string_view line) {
|
||||
std::optional<GsrMonitor> monitor;
|
||||
const std::optional<KeyValue> key_value = parse_key_value(line);
|
||||
@@ -305,15 +355,19 @@ namespace gsr {
|
||||
}
|
||||
|
||||
static void parse_capture_options_line(SupportedCaptureOptions &capture_options, std::string_view line) {
|
||||
if(line == "window")
|
||||
if(line == "window") {
|
||||
capture_options.window = true;
|
||||
else if(line == "region")
|
||||
} else if(line == "region") {
|
||||
capture_options.region = true;
|
||||
else if(line == "focused")
|
||||
} else if(line == "focused") {
|
||||
capture_options.focused = true;
|
||||
else if(line == "portal")
|
||||
} else if(line == "portal") {
|
||||
capture_options.portal = true;
|
||||
else {
|
||||
} else if(!line.empty() && line[0] == '/') {
|
||||
std::optional<GsrCamera> camera = capture_option_line_to_camera(line);
|
||||
if(camera)
|
||||
capture_options.cameras.push_back(std::move(camera.value()));
|
||||
} else {
|
||||
std::optional<GsrMonitor> monitor = capture_option_line_to_monitor(line);
|
||||
if(monitor)
|
||||
capture_options.monitors.push_back(std::move(monitor.value()));
|
||||
@@ -348,4 +402,24 @@ namespace gsr {
|
||||
|
||||
return capture_options;
|
||||
}
|
||||
|
||||
std::vector<GsrCamera> get_v4l2_devices() {
|
||||
std::vector<GsrCamera> cameras;
|
||||
|
||||
std::string stdout_str;
|
||||
const char *args[] = { "gpu-screen-recorder", "--list-v4l2-devices", nullptr };
|
||||
if(exec_program_get_stdout(args, stdout_str) != 0) {
|
||||
fprintf(stderr, "error: 'gpu-screen-recorder --list-v4l2-devices' failed\n");
|
||||
return cameras;
|
||||
}
|
||||
|
||||
string_split_char(stdout_str, '\n', [&](std::string_view line) {
|
||||
std::optional<GsrCamera> camera = capture_option_line_to_camera(line);
|
||||
if(camera)
|
||||
cameras.push_back(std::move(camera.value()));
|
||||
return true;
|
||||
});
|
||||
|
||||
return cameras;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,19 +152,24 @@ namespace gsr {
|
||||
if(read_led_brightness_timer.get_elapsed_time_seconds() > 0.2) {
|
||||
read_led_brightness_timer.restart();
|
||||
|
||||
bool led_status_outdated = false;
|
||||
bool any_keyboard_with_led_enabled = false;
|
||||
bool any_keyboard_with_led_disabled = 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;
|
||||
any_keyboard_with_led_disabled = true;
|
||||
else
|
||||
any_keyboard_with_led_enabled = true;
|
||||
lseek(led_brightness_file_fd, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
||||
if(led_status_outdated && led_enabled)
|
||||
if(led_enabled && any_keyboard_with_led_disabled)
|
||||
run_gsr_global_hotkeys_set_leds(true);
|
||||
else if(!led_enabled && any_keyboard_with_led_enabled)
|
||||
run_gsr_global_hotkeys_set_leds(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
296
src/Overlay.cpp
296
src/Overlay.cpp
@@ -17,6 +17,7 @@
|
||||
#include "../include/CursorTracker/CursorTrackerX11.hpp"
|
||||
#include "../include/CursorTracker/CursorTrackerWayland.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -472,6 +473,8 @@ namespace gsr {
|
||||
top_bar_background({0.0f, 0.0f}),
|
||||
close_button_widget({0.0f, 0.0f})
|
||||
{
|
||||
gsr_icon_path = this->resources_path + "images/gpu_screen_recorder_logo.png";
|
||||
|
||||
key_bindings[0].key_event.code = mgl::Keyboard::Escape;
|
||||
key_bindings[0].key_event.alt = false;
|
||||
key_bindings[0].key_event.control = false;
|
||||
@@ -518,12 +521,11 @@ namespace gsr {
|
||||
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);
|
||||
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, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, 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>();
|
||||
update_led_indicator_after_settings_change();
|
||||
}
|
||||
|
||||
Overlay::~Overlay() {
|
||||
@@ -734,7 +736,7 @@ namespace gsr {
|
||||
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);
|
||||
, 7.0, mgl::Color(255, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, nullptr, NotificationLevel::ERROR);
|
||||
|
||||
config.main_config.hotkeys_enable_option = "enable_hotkeys_no_grab";
|
||||
save_config(config);
|
||||
@@ -773,7 +775,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, nullptr, NotificationLevel::ERROR);
|
||||
show_notification("No window selected", notification_timeout_seconds, mgl::Color(255, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
on_window_selected = nullptr;
|
||||
}
|
||||
@@ -824,7 +826,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, nullptr, NotificationLevel::ERROR);
|
||||
show_notification("Failed to start region capture", notification_error_timeout_seconds, mgl::Color(255, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, nullptr, NotificationLevel::ERROR);
|
||||
on_region_selected = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -833,7 +835,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, nullptr, NotificationLevel::ERROR);
|
||||
show_notification("Failed to start window capture", notification_error_timeout_seconds, mgl::Color(255, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, nullptr, NotificationLevel::ERROR);
|
||||
on_window_selected = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -1022,7 +1024,10 @@ namespace gsr {
|
||||
// Wayland doesn't allow XGrabPointer/XGrabKeyboard when a wayland application is focused.
|
||||
// If the focused window is a wayland application then don't use override redirect and instead create
|
||||
// a fullscreen window for the ui.
|
||||
const bool prevent_game_minimizing = gsr_info.system_info.display_server != DisplayServer::WAYLAND || (x11_cursor_window && is_window_fullscreen_on_monitor(display, x11_cursor_window, *focused_monitor)) || is_wlroots || is_hyprland;
|
||||
const bool prevent_game_minimizing = gsr_info.system_info.display_server != DisplayServer::WAYLAND
|
||||
|| (x11_cursor_window && is_window_fullscreen_on_monitor(display, x11_cursor_window, *focused_monitor) && get_focused_window(display, WindowCaptureType::FOCUSED, false) == x11_cursor_window)
|
||||
|| is_wlroots
|
||||
|| is_hyprland;
|
||||
|
||||
if(prevent_game_minimizing) {
|
||||
window_pos = focused_monitor->position;
|
||||
@@ -1173,6 +1178,15 @@ namespace gsr {
|
||||
global_hotkeys.reset();
|
||||
}
|
||||
|
||||
void Overlay::update_led_indicator_after_settings_change() {
|
||||
if(config.record_config.record_options.use_led_indicator || config.replay_config.record_options.use_led_indicator || config.streaming_config.record_options.use_led_indicator || config.screenshot_config.use_led_indicator) {
|
||||
if(!led_indicator)
|
||||
led_indicator = std::make_unique<LedIndicator>();
|
||||
} else {
|
||||
led_indicator.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());
|
||||
@@ -1263,6 +1277,8 @@ namespace gsr {
|
||||
record_settings_page->on_config_changed = [this]() {
|
||||
if(recording_status == RecordingStatus::RECORD)
|
||||
show_notification("Recording settings have been modified.\nYou may need to restart recording to apply the changes.", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
|
||||
update_led_indicator_after_settings_change();
|
||||
};
|
||||
page_stack.push(std::move(record_settings_page));
|
||||
} else if(id == "pause") {
|
||||
@@ -1288,6 +1304,8 @@ namespace gsr {
|
||||
stream_settings_page->on_config_changed = [this]() {
|
||||
if(recording_status == RecordingStatus::STREAM)
|
||||
show_notification("Streaming settings have been modified.\nYou may need to restart streaming to apply the changes.", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
|
||||
update_led_indicator_after_settings_change();
|
||||
};
|
||||
page_stack.push(std::move(stream_settings_page));
|
||||
} else if(id == "start") {
|
||||
@@ -1317,12 +1335,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, nullptr, NotificationLevel::ERROR);
|
||||
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, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, 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, nullptr, NotificationLevel::ERROR);
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup", notification_timeout_seconds, mgl::Color(255, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, 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, nullptr, NotificationLevel::ERROR);
|
||||
show_notification("Failed to remove GPU Screen Recorder from system startup", notification_timeout_seconds, mgl::Color(255, 255, 255), mgl::Color(255, 0, 0), NotificationType::NOTICE, nullptr, NotificationLevel::ERROR);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1370,6 +1388,9 @@ namespace gsr {
|
||||
button->set_icon_padding_scale(1.2f);
|
||||
button->on_click = [&]() {
|
||||
auto screenshot_settings_page = std::make_unique<ScreenshotSettingsPage>(&gsr_info, config, &page_stack);
|
||||
screenshot_settings_page->on_config_changed = [this]() {
|
||||
update_led_indicator_after_settings_change();
|
||||
};
|
||||
page_stack.push(std::move(screenshot_settings_page));
|
||||
};
|
||||
front_page_ptr->add_widget(std::move(button));
|
||||
@@ -1572,13 +1593,14 @@ namespace gsr {
|
||||
on_press_take_screenshot(false, ScreenshotForceType::WINDOW);
|
||||
}
|
||||
|
||||
static const char* notification_type_to_string(NotificationType notification_type) {
|
||||
const char* Overlay::notification_type_to_string(NotificationType notification_type) {
|
||||
switch(notification_type) {
|
||||
case NotificationType::NONE: return nullptr;
|
||||
case NotificationType::RECORD: return "record";
|
||||
case NotificationType::REPLAY: return "replay";
|
||||
case NotificationType::STREAM: return "stream";
|
||||
case NotificationType::SCREENSHOT: return "screenshot";
|
||||
case NotificationType::NOTICE: return gsr_icon_path.c_str();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1909,25 +1931,26 @@ namespace gsr {
|
||||
return ClipboardFile::FileType::PNG;
|
||||
}
|
||||
|
||||
void Overlay::save_video_in_current_game_directory(const char *video_filepath, NotificationType notification_type) {
|
||||
void Overlay::save_video_in_current_game_directory(std::string &video_filepath, NotificationType notification_type) {
|
||||
mgl_context *context = mgl_get_context();
|
||||
Display *display = (Display*)context->connection;
|
||||
const std::string video_filename = filepath_get_filename(video_filepath);
|
||||
const std::string video_filename = filepath_get_filename(video_filepath.c_str());
|
||||
|
||||
const Window gsr_ui_window = window ? (Window)window->get_system_handle() : None;
|
||||
std::string focused_window_name = get_window_name_at_cursor_position(display, gsr_ui_window);
|
||||
if(focused_window_name.empty())
|
||||
focused_window_name = get_focused_window_name(display, WindowCaptureType::FOCUSED);
|
||||
focused_window_name = get_focused_window_name(display, WindowCaptureType::FOCUSED, false);
|
||||
if(focused_window_name.empty())
|
||||
focused_window_name = "Game";
|
||||
|
||||
string_replace_characters(focused_window_name.data(), "/\\", ' ');
|
||||
|
||||
std::string video_directory = filepath_get_directory(video_filepath) + "/" + focused_window_name;
|
||||
std::string video_directory = filepath_get_directory(video_filepath.c_str()) + "/" + focused_window_name;
|
||||
create_directory_recursive(video_directory.data());
|
||||
|
||||
const std::string new_video_filepath = video_directory + "/" + video_filename;
|
||||
rename(video_filepath, new_video_filepath.c_str());
|
||||
rename(video_filepath.c_str(), new_video_filepath.c_str());
|
||||
video_filepath = new_video_filepath;
|
||||
|
||||
truncate_string(focused_window_name, 40);
|
||||
const char *capture_target = nullptr;
|
||||
@@ -1935,15 +1958,6 @@ namespace gsr {
|
||||
|
||||
switch(notification_type) {
|
||||
case NotificationType::RECORD: {
|
||||
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;
|
||||
|
||||
@@ -1955,9 +1969,6 @@ namespace gsr {
|
||||
break;
|
||||
}
|
||||
case NotificationType::REPLAY: {
|
||||
if(led_indicator && config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
|
||||
if(!config.replay_config.record_options.show_notifications)
|
||||
return;
|
||||
|
||||
@@ -1969,22 +1980,17 @@ namespace gsr {
|
||||
break;
|
||||
}
|
||||
case NotificationType::SCREENSHOT: {
|
||||
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\"",
|
||||
capture_target_get_notification_name(screenshot_capture_target.c_str(), true).c_str(), focused_window_name.c_str());
|
||||
capture_target = screenshot_capture_target.c_str();
|
||||
|
||||
if(config.screenshot_config.save_screenshot_to_clipboard)
|
||||
clipboard_file.set_current_file(new_video_filepath, filename_to_clipboard_file_type(new_video_filepath));
|
||||
break;
|
||||
}
|
||||
case NotificationType::NONE:
|
||||
case NotificationType::STREAM:
|
||||
case NotificationType::NOTICE:
|
||||
break;
|
||||
}
|
||||
show_notification(msg, notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, notification_type, capture_target);
|
||||
@@ -2003,22 +2009,20 @@ namespace gsr {
|
||||
void Overlay::on_replay_saved(const char *replay_saved_filepath) {
|
||||
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);
|
||||
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());
|
||||
std::string filepath = replay_saved_filepath;
|
||||
save_video_in_current_game_directory(filepath, NotificationType::REPLAY);
|
||||
} 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());
|
||||
}
|
||||
|
||||
if(led_indicator && config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
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() {
|
||||
@@ -2045,7 +2049,8 @@ namespace gsr {
|
||||
|
||||
const std::string video_filepath = filepath_get_filename(line);
|
||||
if(starts_with(video_filepath, "Video_")) {
|
||||
on_stop_recording(0, line);
|
||||
record_filepath = line;
|
||||
on_stop_recording(0, record_filepath);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2084,6 +2089,7 @@ namespace gsr {
|
||||
const char *prefix = "";
|
||||
switch(notification_type) {
|
||||
case NotificationType::NONE:
|
||||
case NotificationType::NOTICE:
|
||||
break;
|
||||
case NotificationType::SCREENSHOT:
|
||||
prefix = "Failed to take a screenshot";
|
||||
@@ -2181,21 +2187,26 @@ namespace gsr {
|
||||
exit_code = WEXITSTATUS(status);
|
||||
|
||||
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_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_in_game_folder && config.screenshot_config.save_screenshot_to_disk) {
|
||||
save_video_in_current_game_directory(screenshot_filepath, NotificationType::SCREENSHOT);
|
||||
} 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();
|
||||
if(led_indicator && config.screenshot_config.use_led_indicator)
|
||||
led_indicator->blink();
|
||||
|
||||
if(!strip(config.screenshot_config.custom_script).empty()) {
|
||||
std::stringstream ss;
|
||||
ss << config.screenshot_config.custom_script << " " << std::quoted(screenshot_filepath);
|
||||
const std::string command = ss.str();
|
||||
const char *args[] = { "/bin/sh", "-c", command.c_str(), nullptr };
|
||||
exec_program_on_host_daemonized(args);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_screenshot_process, exit_code);
|
||||
@@ -2229,6 +2240,18 @@ namespace gsr {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_webcam_available_to_capture(const RecordOptions &record_options) {
|
||||
if(record_options.webcam_source.empty())
|
||||
return true;
|
||||
|
||||
const auto cameras = get_v4l2_devices();
|
||||
for(const GsrCamera &camera : cameras) {
|
||||
if(camera.path == record_options.webcam_source)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Overlay::replay_status_update_status() {
|
||||
if(replay_status_update_clock.get_elapsed_time_seconds() < replay_status_update_check_timeout_seconds)
|
||||
return;
|
||||
@@ -2246,7 +2269,7 @@ namespace gsr {
|
||||
mgl_context *context = mgl_get_context();
|
||||
Display *display = (Display*)context->connection;
|
||||
|
||||
const Window focused_window = get_focused_window(display, WindowCaptureType::FOCUSED);
|
||||
const Window focused_window = get_focused_window(display, WindowCaptureType::FOCUSED, false);
|
||||
if(window && focused_window == (Window)window->get_system_handle())
|
||||
return;
|
||||
|
||||
@@ -2254,7 +2277,7 @@ namespace gsr {
|
||||
focused_window_is_fullscreen = focused_window != 0 && window_is_fullscreen(display, focused_window);
|
||||
if(focused_window_is_fullscreen != prev_focused_window_is_fullscreen) {
|
||||
if(recording_status == RecordingStatus::NONE && focused_window_is_fullscreen) {
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks_list))
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks_list) && is_webcam_available_to_capture(config.replay_config.record_options))
|
||||
on_press_start_replay(false, false);
|
||||
} else if(recording_status == RecordingStatus::REPLAY && !focused_window_is_fullscreen) {
|
||||
on_press_start_replay(true, false);
|
||||
@@ -2271,7 +2294,7 @@ namespace gsr {
|
||||
power_supply_connected = power_supply_online_filepath.empty() || power_supply_is_connected(power_supply_online_filepath.c_str());
|
||||
if(power_supply_connected != prev_power_supply_status) {
|
||||
if(recording_status == RecordingStatus::NONE && power_supply_connected) {
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks_list))
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks_list) && is_webcam_available_to_capture(config.replay_config.record_options))
|
||||
on_press_start_replay(false, false);
|
||||
} else if(recording_status == RecordingStatus::REPLAY && !power_supply_connected) {
|
||||
on_press_start_replay(false, false);
|
||||
@@ -2283,33 +2306,31 @@ namespace gsr {
|
||||
if(replay_startup_mode != ReplayStartupMode::TURN_ON_AT_SYSTEM_STARTUP || recording_status != RecordingStatus::NONE || !try_replay_startup)
|
||||
return;
|
||||
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks_list))
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks_list) && is_webcam_available_to_capture(config.replay_config.record_options))
|
||||
on_press_start_replay(true, false);
|
||||
}
|
||||
|
||||
void Overlay::on_stop_recording(int exit_code, const std::string &video_filepath) {
|
||||
void Overlay::on_stop_recording(int exit_code, std::string &video_filepath) {
|
||||
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.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));
|
||||
save_video_in_current_game_directory(video_filepath, NotificationType::RECORD);
|
||||
} 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();
|
||||
}
|
||||
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);
|
||||
@@ -2682,6 +2703,66 @@ namespace gsr {
|
||||
return framerate_mode;
|
||||
}
|
||||
|
||||
struct CameraAlignment {
|
||||
std::string halign;
|
||||
std::string valign;
|
||||
mgl::vec2i pos;
|
||||
};
|
||||
|
||||
static CameraAlignment position_to_alignment(mgl::vec2i pos, mgl::vec2i size) {
|
||||
const mgl::vec2i pos_overflow = mgl::vec2i(100, 100) - (pos + size);
|
||||
if(pos_overflow.x < 0)
|
||||
pos.x += pos_overflow.x;
|
||||
if(pos_overflow.y < 0)
|
||||
pos.y += pos_overflow.y;
|
||||
|
||||
if(pos.x < 0)
|
||||
pos.x = 0;
|
||||
if(pos.y < 0)
|
||||
pos.y = 0;
|
||||
|
||||
CameraAlignment camera_alignment;
|
||||
const mgl::vec2i center = pos + size/2;
|
||||
|
||||
if(center.x < 50) {
|
||||
camera_alignment.halign = "start";
|
||||
camera_alignment.pos.x = pos.x;
|
||||
} else {
|
||||
camera_alignment.halign = "end";
|
||||
camera_alignment.pos.x = -(100 - (pos.x + size.x));
|
||||
}
|
||||
|
||||
if(center.y < 50) {
|
||||
camera_alignment.valign = "start";
|
||||
camera_alignment.pos.y = pos.y;
|
||||
} else {
|
||||
camera_alignment.valign = "end";
|
||||
camera_alignment.pos.y = -(100 - (pos.y + size.y));
|
||||
}
|
||||
|
||||
return camera_alignment;
|
||||
}
|
||||
|
||||
static std::string compose_capture_source_arg(const std::string &capture_target, const RecordOptions &record_options) {
|
||||
std::string capture_source_arg = capture_target;
|
||||
if(!record_options.webcam_source.empty()) {
|
||||
const mgl::vec2i webcam_size(record_options.webcam_width, record_options.webcam_height);
|
||||
const CameraAlignment camera_alignment = position_to_alignment(mgl::vec2i(record_options.webcam_x, record_options.webcam_y), webcam_size);
|
||||
|
||||
capture_source_arg += "|" + record_options.webcam_source;
|
||||
capture_source_arg += ";halign=" + camera_alignment.halign;
|
||||
capture_source_arg += ";valign=" + camera_alignment.valign;
|
||||
capture_source_arg += ";x=" + std::to_string(camera_alignment.pos.x) + "%";
|
||||
capture_source_arg += ";y=" + std::to_string(camera_alignment.pos.y) + "%";
|
||||
capture_source_arg += ";width=" + std::to_string(webcam_size.x) + "%";
|
||||
capture_source_arg += ";height=" + std::to_string(webcam_size.y) + "%";
|
||||
capture_source_arg += ";pixfmt=" + record_options.webcam_video_format;
|
||||
if(record_options.webcam_flip_horizontally)
|
||||
capture_source_arg += ";hflip=true";
|
||||
}
|
||||
return capture_source_arg;
|
||||
}
|
||||
|
||||
bool Overlay::on_press_start_replay(bool disable_notification, bool finished_selection) {
|
||||
if(region_selector.is_started() || window_selector.is_started())
|
||||
return false;
|
||||
@@ -2771,8 +2852,10 @@ namespace gsr {
|
||||
if(config.replay_config.record_options.record_area_option != "focused" && config.replay_config.record_options.change_video_resolution)
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.replay_config.record_options.video_width, (int)config.replay_config.record_options.video_height);
|
||||
|
||||
const std::string capture_source_arg = compose_capture_source_arg(recording_capture_target, config.replay_config.record_options);
|
||||
|
||||
std::vector<const char*> args = {
|
||||
"gpu-screen-recorder", "-w", recording_capture_target.c_str(),
|
||||
"gpu-screen-recorder", "-w", capture_source_arg.c_str(),
|
||||
"-c", container,
|
||||
"-ac", config.replay_config.record_options.audio_codec.c_str(),
|
||||
"-cursor", config.replay_config.record_options.record_cursor ? "yes" : "no",
|
||||
@@ -2873,10 +2956,12 @@ namespace gsr {
|
||||
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();
|
||||
if(config.record_config.record_options.use_led_indicator) {
|
||||
if(!current_recording_config.replay_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(true);
|
||||
else
|
||||
led_indicator->blink();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2903,10 +2988,12 @@ namespace gsr {
|
||||
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();
|
||||
if(config.record_config.record_options.use_led_indicator) {
|
||||
if(!current_recording_config.streaming_config.record_options.use_led_indicator)
|
||||
led_indicator->set_led(true);
|
||||
else
|
||||
led_indicator->blink();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2993,8 +3080,10 @@ namespace gsr {
|
||||
if(config.record_config.record_options.record_area_option != "focused" && config.record_config.record_options.change_video_resolution)
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.record_config.record_options.video_width, (int)config.record_config.record_options.video_height);
|
||||
|
||||
const std::string capture_source_arg = compose_capture_source_arg(recording_capture_target, config.record_config.record_options);
|
||||
|
||||
std::vector<const char*> args = {
|
||||
"gpu-screen-recorder", "-w", recording_capture_target.c_str(),
|
||||
"gpu-screen-recorder", "-w", capture_source_arg.c_str(),
|
||||
"-c", container,
|
||||
"-ac", config.record_config.record_options.audio_codec.c_str(),
|
||||
"-cursor", config.record_config.record_options.record_cursor ? "yes" : "no",
|
||||
@@ -3181,8 +3270,10 @@ namespace gsr {
|
||||
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);
|
||||
|
||||
const std::string capture_source_arg = compose_capture_source_arg(recording_capture_target, config.streaming_config.record_options);
|
||||
|
||||
std::vector<const char*> args = {
|
||||
"gpu-screen-recorder", "-w", recording_capture_target.c_str(),
|
||||
"gpu-screen-recorder", "-w", capture_source_arg.c_str(),
|
||||
"-c", container,
|
||||
"-ac", config.streaming_config.record_options.audio_codec.c_str(),
|
||||
"-cursor", config.streaming_config.record_options.record_cursor ? "yes" : "no",
|
||||
@@ -3288,7 +3379,12 @@ 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
|
||||
std::string output_file;
|
||||
if(config.screenshot_config.save_screenshot_to_disk)
|
||||
output_file = config.screenshot_config.save_directory + "/Screenshot_" + get_date_str() + "." + config.screenshot_config.image_format; // TODO: Validate image format
|
||||
else
|
||||
output_file = "/tmp/gsr_ui_clipboard_screenshot." + config.screenshot_config.image_format;
|
||||
|
||||
const bool capture_cursor = force_type == ScreenshotForceType::NONE && config.screenshot_config.record_cursor;
|
||||
|
||||
std::vector<const char*> args = {
|
||||
@@ -3312,7 +3408,7 @@ namespace gsr {
|
||||
args.push_back("yes");
|
||||
}
|
||||
|
||||
const std::string hotkey_window_capture_portal_session_token_filepath = get_config_dir() + "/gpu-screen-recorder/gsr-ui-window-capture-token";
|
||||
const std::string hotkey_window_capture_portal_session_token_filepath = get_config_dir() + "/gsr-ui-window-capture-token";
|
||||
if(record_area_option == "portal") {
|
||||
hide_ui = true;
|
||||
if(force_type == ScreenshotForceType::WINDOW) {
|
||||
@@ -3327,6 +3423,8 @@ namespace gsr {
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
clipboard_file.set_current_file("", ClipboardFile::FileType::JPG);
|
||||
|
||||
screenshot_filepath = output_file;
|
||||
gpu_screen_recorder_screenshot_process = exec_program(args.data(), nullptr);
|
||||
if(gpu_screen_recorder_screenshot_process == -1) {
|
||||
|
||||
@@ -73,6 +73,28 @@ namespace gsr {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool exec_program_on_host_daemonized(const char **args, bool debug) {
|
||||
if(count_num_args(args) > 64 - 3) {
|
||||
fprintf(stderr, "Error: too many arguments when trying to launch \"%s\"\n", args[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
|
||||
if(inside_flatpak) {
|
||||
// Assumes programs wont need more than 64 - 3 args
|
||||
const char *modified_args[64] = { "flatpak-spawn", "--host", "--" };
|
||||
for(int i = 3; i < 64; ++i) {
|
||||
const char *arg = args[i - 3];
|
||||
modified_args[i] = arg;
|
||||
if(!arg)
|
||||
break;
|
||||
}
|
||||
return exec_program_daemonized(modified_args, debug);
|
||||
} else {
|
||||
return exec_program_daemonized(args, debug);
|
||||
}
|
||||
}
|
||||
|
||||
pid_t exec_program(const char **args, int *read_fd, bool debug) {
|
||||
if(read_fd)
|
||||
*read_fd = -1;
|
||||
@@ -164,11 +186,9 @@ namespace gsr {
|
||||
const char *modified_args[64] = { "flatpak-spawn", "--host", "--" };
|
||||
for(int i = 3; i < 64; ++i) {
|
||||
const char *arg = args[i - 3];
|
||||
if(!arg) {
|
||||
modified_args[i] = nullptr;
|
||||
break;
|
||||
}
|
||||
modified_args[i] = arg;
|
||||
if(!arg)
|
||||
break;
|
||||
}
|
||||
return exec_program_get_stdout(modified_args, result, debug);
|
||||
} else {
|
||||
|
||||
@@ -48,6 +48,9 @@ namespace gsr {
|
||||
if(!theme->body_font.load_from_file(theme->body_font_file, std::max(13.0f, window_size.y * 0.015f)))
|
||||
return false;
|
||||
|
||||
if(!theme->camera_setup_font.load_from_file(theme->body_font_file, 24))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace gsr {
|
||||
return root_pos;
|
||||
}
|
||||
|
||||
Window get_focused_window(Display *dpy, WindowCaptureType cap_type) {
|
||||
Window get_focused_window(Display *dpy, WindowCaptureType cap_type, bool fallback_cursor_focused) {
|
||||
//const Atom net_active_window_atom = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
|
||||
Window focused_window = None;
|
||||
|
||||
@@ -146,6 +146,9 @@ namespace gsr {
|
||||
XGetInputFocus(dpy, &focused_window, &revert_to);
|
||||
if(focused_window && focused_window != DefaultRootWindow(dpy) && window_is_user_program(dpy, focused_window))
|
||||
return focused_window;
|
||||
|
||||
if(!fallback_cursor_focused)
|
||||
return None;
|
||||
}
|
||||
|
||||
get_cursor_position(dpy, &focused_window);
|
||||
@@ -213,9 +216,9 @@ namespace gsr {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type) {
|
||||
std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type, bool fallback_cursor_focused) {
|
||||
std::string result;
|
||||
const Window focused_window = get_focused_window(dpy, window_capture_type);
|
||||
const Window focused_window = get_focused_window(dpy, window_capture_type, fallback_cursor_focused);
|
||||
if(focused_window == None)
|
||||
return result;
|
||||
|
||||
|
||||
@@ -90,6 +90,13 @@ namespace gsr {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void ComboBox::clear_items() {
|
||||
items.clear();
|
||||
selected_item = 0;
|
||||
show_dropdown = false;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void ComboBox::set_selected_item(const std::string &id, bool trigger_event, bool trigger_event_even_if_selection_not_changed) {
|
||||
for(size_t i = 0; i < items.size(); ++i) {
|
||||
auto &item = items[i];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../../include/gui/CustomRendererWidget.hpp"
|
||||
#include "../../include/gui/Utils.hpp"
|
||||
|
||||
#include <mglpp/window/Window.hpp>
|
||||
|
||||
@@ -17,11 +18,14 @@ namespace gsr {
|
||||
|
||||
const mgl::vec2f draw_pos = position + offset;
|
||||
|
||||
const mgl::Scissor prev_scissor = window.get_scissor();
|
||||
window.set_scissor({draw_pos.to_vec2i(), size.to_vec2i()});
|
||||
const mgl::Scissor parent_scissor = window.get_scissor();
|
||||
const mgl::Scissor scissor = scissor_get_sub_area(parent_scissor, {draw_pos.to_vec2i(), size.to_vec2i()});
|
||||
window.set_scissor(scissor);
|
||||
|
||||
if(draw_handler)
|
||||
draw_handler(window, draw_pos, size);
|
||||
window.set_scissor(prev_scissor);
|
||||
|
||||
window.set_scissor(parent_scissor);
|
||||
}
|
||||
|
||||
mgl::vec2f CustomRendererWidget::get_size() {
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_record_area() {
|
||||
auto record_area_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
record_area_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Capture target:", get_color_theme().text_color));
|
||||
record_area_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Capture source:", get_color_theme().text_color));
|
||||
record_area_list->add_widget(create_record_area_box());
|
||||
return record_area_list;
|
||||
}
|
||||
@@ -139,7 +139,7 @@ namespace gsr {
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_record_cursor_section() {
|
||||
auto record_cursor_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Record cursor");
|
||||
record_cursor_checkbox->set_checked(true);
|
||||
@@ -163,7 +163,7 @@ namespace gsr {
|
||||
auto select_directory_page = std::make_unique<GsrPage>("File", "Settings");
|
||||
select_directory_page->add_button("Save", "save", get_color_theme().tint_color);
|
||||
select_directory_page->add_button("Cancel", "cancel", get_color_theme().page_bg_color);
|
||||
|
||||
|
||||
auto file_chooser = std::make_unique<FileChooser>(save_directory_button_ptr->get_text().c_str(), select_directory_page->get_inner_size());
|
||||
FileChooser *file_chooser_ptr = file_chooser.get();
|
||||
select_directory_page->add_widget(std::move(file_chooser));
|
||||
@@ -221,6 +221,13 @@ namespace gsr {
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
std::unique_ptr<CheckBox> ScreenshotSettingsPage::create_save_screenshot_to_disk() {
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Save screenshot to disk");
|
||||
save_screenshot_to_disk_checkbox_ptr = checkbox.get();
|
||||
checkbox->set_checked(true);
|
||||
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);
|
||||
@@ -239,6 +246,7 @@ namespace gsr {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
list->add_widget(create_save_screenshot_in_game_folder());
|
||||
list->add_widget(create_save_screenshot_to_clipboard());
|
||||
list->add_widget(create_save_screenshot_to_disk());
|
||||
return std::make_unique<Subsection>("General", std::move(list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
@@ -249,10 +257,31 @@ namespace gsr {
|
||||
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<List> ScreenshotSettingsPage::create_custom_script_screenshot_entry() {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL, List::Alignment::CENTER);
|
||||
|
||||
auto create_custom_script_screenshot_entry = std::make_unique<Entry>(&get_theme().body_font, "", get_theme().body_font.get_character_size() * 20);
|
||||
create_custom_script_screenshot_entry_ptr = create_custom_script_screenshot_entry.get();
|
||||
list->add_widget(std::move(create_custom_script_screenshot_entry));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
std::unique_ptr<List> ScreenshotSettingsPage::create_custom_script_screenshot() {
|
||||
auto custom_script_screenshot_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
custom_script_screenshot_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Command to open the screenshot with:", get_color_theme().text_color));
|
||||
custom_script_screenshot_list->add_widget(create_custom_script_screenshot_entry());
|
||||
return custom_script_screenshot_list;
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_custom_script_screenshot_section() {
|
||||
return std::make_unique<Subsection>("Script", create_custom_script_screenshot(), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> ScreenshotSettingsPage::create_settings() {
|
||||
auto page_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
page_list->set_spacing(0.018f);
|
||||
auto scrollable_page = std::make_unique<ScrollablePage>(content_page_ptr->get_inner_size() - mgl::vec2f(0.0f, page_list->get_size().y + 0.018f * get_theme().window_height));
|
||||
auto scrollable_page = std::make_unique<ScrollablePage>(content_page_ptr->get_inner_size() - mgl::vec2f(0.0f, page_list->get_size().y));
|
||||
settings_scrollable_page_ptr = scrollable_page.get();
|
||||
page_list->add_widget(std::move(scrollable_page));
|
||||
|
||||
@@ -263,6 +292,7 @@ namespace gsr {
|
||||
settings_list->add_widget(create_file_info_section());
|
||||
settings_list->add_widget(create_general_section());
|
||||
settings_list->add_widget(create_screenshot_indicator_section());
|
||||
settings_list->add_widget(create_custom_script_screenshot_section());
|
||||
settings_scrollable_page_ptr->add_widget(std::move(settings_list));
|
||||
return page_list;
|
||||
}
|
||||
@@ -305,6 +335,7 @@ 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);
|
||||
save_screenshot_to_disk_checkbox_ptr->set_checked(config.screenshot_config.save_screenshot_to_disk);
|
||||
show_notification_checkbox_ptr->set_checked(config.screenshot_config.show_notifications);
|
||||
led_indicator_checkbox_ptr->set_checked(config.screenshot_config.use_led_indicator);
|
||||
|
||||
@@ -321,9 +352,13 @@ namespace gsr {
|
||||
if(config.screenshot_config.image_height < 32)
|
||||
config.screenshot_config.image_height = 32;
|
||||
image_height_entry_ptr->set_text(std::to_string(config.screenshot_config.image_height));
|
||||
|
||||
create_custom_script_screenshot_entry_ptr->set_text(config.screenshot_config.custom_script);
|
||||
}
|
||||
|
||||
void ScreenshotSettingsPage::save() {
|
||||
Config prev_config = config;
|
||||
|
||||
config.screenshot_config.record_area_option = record_area_box_ptr->get_selected_id();
|
||||
config.screenshot_config.image_width = atoi(image_width_entry_ptr->get_text().c_str());
|
||||
config.screenshot_config.image_height = atoi(image_height_entry_ptr->get_text().c_str());
|
||||
@@ -335,8 +370,10 @@ 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.save_screenshot_to_disk = save_screenshot_to_disk_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();
|
||||
config.screenshot_config.custom_script = create_custom_script_screenshot_entry_ptr->get_text();
|
||||
|
||||
if(config.screenshot_config.image_width == 0)
|
||||
config.screenshot_config.image_width = 1920;
|
||||
@@ -355,5 +392,8 @@ namespace gsr {
|
||||
}
|
||||
|
||||
save_config(config);
|
||||
|
||||
if(on_config_changed && config != prev_config)
|
||||
on_config_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,9 @@ namespace gsr {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(event.type == mgl::Event::MouseButtonPressed || event.type == mgl::Event::MouseButtonReleased) {
|
||||
// Pass release to children even if outside area, because we want to be able to release mouse when moved outside,
|
||||
// for example in Entry when selecting text
|
||||
if(event.type == mgl::Event::MouseButtonPressed/* || event.type == mgl::Event::MouseButtonReleased*/) {
|
||||
if(!mgl::IntRect(scissor_pos, scissor_size).contains({event.mouse_button.x, event.mouse_button.y}))
|
||||
return true;
|
||||
} else if(event.type == mgl::Event::MouseMoved) {
|
||||
|
||||
@@ -4,11 +4,16 @@
|
||||
#include "../../include/gui/PageStack.hpp"
|
||||
#include "../../include/gui/FileChooser.hpp"
|
||||
#include "../../include/gui/Subsection.hpp"
|
||||
#include "../../include/gui/Image.hpp"
|
||||
#include "../../include/gui/CustomRendererWidget.hpp"
|
||||
#include "../../include/gui/Utils.hpp"
|
||||
#include "../../include/Theme.hpp"
|
||||
#include "../../include/GsrInfo.hpp"
|
||||
#include "../../include/Utils.hpp"
|
||||
#include "mglpp/window/Window.hpp"
|
||||
#include "mglpp/window/Event.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <string.h>
|
||||
|
||||
namespace gsr {
|
||||
@@ -87,7 +92,7 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<Widget> SettingsPage::create_record_area() {
|
||||
auto record_area_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
record_area_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Capture target:", get_color_theme().text_color));
|
||||
record_area_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Capture source:", get_color_theme().text_color));
|
||||
record_area_list->add_widget(create_record_area_box());
|
||||
return record_area_list;
|
||||
}
|
||||
@@ -187,6 +192,216 @@ namespace gsr {
|
||||
return std::make_unique<Subsection>("Capture", std::move(ll), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<List> SettingsPage::create_webcam_sources() {
|
||||
auto ll = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
ll->add_widget(std::make_unique<Label>(&get_theme().body_font, "Webcam source:", get_color_theme().text_color));
|
||||
|
||||
auto combobox = std::make_unique<ComboBox>(&get_theme().body_font);
|
||||
combobox->add_item("None", "");
|
||||
for(const GsrCamera &camera : capture_options.cameras) {
|
||||
combobox->add_item(camera.path, camera.path);
|
||||
}
|
||||
webcam_sources_box_ptr = combobox.get();
|
||||
|
||||
webcam_sources_box_ptr->on_selection_changed = [this](const std::string&, const std::string &id) {
|
||||
selected_camera = std::nullopt;
|
||||
webcam_video_format_box_ptr->clear_items();
|
||||
if(id == "") {
|
||||
webcam_body_list_ptr->set_visible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = std::find_if(capture_options.cameras.begin(), capture_options.cameras.end(), [&](const GsrCamera &camera) {
|
||||
return camera.path == id;
|
||||
});
|
||||
if(it == capture_options.cameras.end())
|
||||
return;
|
||||
|
||||
webcam_body_list_ptr->set_visible(true);
|
||||
webcam_video_format_box_ptr->add_item("Auto (recommended)", "auto");
|
||||
|
||||
if(it->supported_pixel_formats.yuyv)
|
||||
webcam_video_format_box_ptr->add_item("YUYV", "yuyv");
|
||||
|
||||
if(it->supported_pixel_formats.mjpeg)
|
||||
webcam_video_format_box_ptr->add_item("Motion-JPEG", "mjpeg");
|
||||
|
||||
webcam_video_format_box_ptr->set_selected_item(get_current_record_options().webcam_video_format);
|
||||
selected_camera = *it;
|
||||
};
|
||||
|
||||
ll->add_widget(std::move(combobox));
|
||||
return ll;
|
||||
}
|
||||
|
||||
std::unique_ptr<List> SettingsPage::create_webcam_video_format() {
|
||||
auto ll = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
ll->add_widget(std::make_unique<Label>(&get_theme().body_font, "Video format:", get_color_theme().text_color));
|
||||
|
||||
auto combobox = std::make_unique<ComboBox>(&get_theme().body_font);
|
||||
webcam_video_format_box_ptr = combobox.get();
|
||||
|
||||
webcam_video_format_box_ptr->on_selection_changed = [this](const std::string&, const std::string &id) {
|
||||
get_current_record_options().webcam_video_format = id;
|
||||
};
|
||||
|
||||
ll->add_widget(std::move(combobox));
|
||||
return ll;
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> SettingsPage::create_webcam_location_widget() {
|
||||
const float camera_screen_width = std::min(400.0f, (float)settings_scrollable_page_ptr->get_inner_size().x * 0.90f);
|
||||
camera_screen_size = mgl::vec2f(camera_screen_width, camera_screen_width * 0.5625);
|
||||
|
||||
const float screen_border = 2.0f;
|
||||
const mgl::vec2f screen_border_size(screen_border, screen_border);
|
||||
screen_inner_size = mgl::vec2f(camera_screen_size - screen_border_size*2.0f);
|
||||
|
||||
const mgl::vec2f bounding_box_size(30.0f, 30.0f);
|
||||
|
||||
auto camera_location_widget = std::make_unique<CustomRendererWidget>(camera_screen_size);
|
||||
camera_location_widget->draw_handler = [this, screen_border_size, screen_border](mgl::Window &window, mgl::vec2f pos, mgl::vec2f size) {
|
||||
if(!selected_camera.has_value())
|
||||
return;
|
||||
|
||||
pos = pos.floor();
|
||||
size = size.floor();
|
||||
const mgl::vec2i mouse_pos = window.get_mouse_position();
|
||||
const mgl::vec2f webcam_box_min_size = clamp_keep_aspect_ratio(selected_camera->size.to_vec2f(), screen_inner_size * 0.2f);
|
||||
|
||||
if(moving_webcam_box) {
|
||||
webcam_box_pos = mouse_pos.to_vec2f() - screen_border_size - webcam_box_grab_offset - pos;
|
||||
} else if(webcam_resize_corner == WebcamBoxResizeCorner::BOTTOM_RIGHT) {
|
||||
const mgl::vec2f mouse_diff = mouse_pos.to_vec2f() - webcam_resize_start_pos;
|
||||
webcam_box_size = webcam_box_size_resize_start + mouse_diff;
|
||||
}
|
||||
|
||||
webcam_box_size = clamp_keep_aspect_ratio(selected_camera->size.to_vec2f(), webcam_box_size);
|
||||
|
||||
if(webcam_box_pos.x < 0.0f)
|
||||
webcam_box_pos.x = 0.0f;
|
||||
else if(webcam_box_pos.x + webcam_box_size.x > screen_inner_size.x)
|
||||
webcam_box_pos.x = screen_inner_size.x - webcam_box_size.x;
|
||||
|
||||
if(webcam_box_pos.y < 0.0f)
|
||||
webcam_box_pos.y = 0.0f;
|
||||
else if(webcam_box_pos.y + webcam_box_size.y > screen_inner_size.y)
|
||||
webcam_box_pos.y = screen_inner_size.y - webcam_box_size.y;
|
||||
|
||||
if(webcam_box_size.x < webcam_box_min_size.x)
|
||||
webcam_box_size.x = webcam_box_min_size.x;
|
||||
else if(webcam_box_pos.x + webcam_box_size.x > screen_inner_size.x)
|
||||
webcam_box_size.x = screen_inner_size.x - webcam_box_pos.x;
|
||||
|
||||
//webcam_box_size = clamp_keep_aspect_ratio(selected_camera->size.to_vec2f(), webcam_box_size);
|
||||
|
||||
if(webcam_box_size.y < webcam_box_min_size.y)
|
||||
webcam_box_size.y = webcam_box_min_size.y;
|
||||
else if(webcam_box_pos.y + webcam_box_size.y > screen_inner_size.y)
|
||||
webcam_box_size.y = screen_inner_size.y - webcam_box_pos.y;
|
||||
|
||||
webcam_box_size = clamp_keep_aspect_ratio(selected_camera->size.to_vec2f(), webcam_box_size);
|
||||
|
||||
{
|
||||
draw_rectangle_outline(window, pos, size, mgl::Color(255, 0, 0, 255), screen_border);
|
||||
mgl::Text screen_text("Screen", get_theme().camera_setup_font);
|
||||
screen_text.set_position((pos + size * 0.5f - screen_text.get_bounds().size * 0.5f).floor());
|
||||
window.draw(screen_text);
|
||||
}
|
||||
|
||||
{
|
||||
webcam_box_drawn_size = clamp_keep_aspect_ratio(selected_camera->size.to_vec2f(), webcam_box_size);
|
||||
webcam_box_drawn_pos = (pos + screen_border_size + webcam_box_pos).floor();
|
||||
|
||||
draw_rectangle_outline(window, webcam_box_drawn_pos, webcam_box_drawn_size, mgl::Color(0, 255, 0, 255), screen_border);
|
||||
|
||||
// mgl::Rectangle resize_area(webcam_box_drawn_pos + webcam_box_drawn_size - bounding_box_size*0.5f - screen_border_size*0.5f, bounding_box_size);
|
||||
// resize_area.set_color(mgl::Color(0, 0, 255, 255));
|
||||
// window.draw(resize_area);
|
||||
|
||||
mgl::Text webcam_text("Webcam", get_theme().camera_setup_font);
|
||||
webcam_text.set_position((webcam_box_drawn_pos + webcam_box_drawn_size * 0.5f - webcam_text.get_bounds().size * 0.5f).floor());
|
||||
window.draw(webcam_text);
|
||||
}
|
||||
};
|
||||
|
||||
camera_location_widget->event_handler = [this, screen_border_size, bounding_box_size](mgl::Event &event, mgl::Window&, mgl::vec2f, mgl::vec2f) {
|
||||
switch(event.type) {
|
||||
case mgl::Event::MouseButtonPressed: {
|
||||
if(event.mouse_button.button == mgl::Mouse::Left && webcam_resize_corner == WebcamBoxResizeCorner::NONE) {
|
||||
const mgl::vec2f mouse_button_pos(event.mouse_button.x, event.mouse_button.y);
|
||||
if(mgl::FloatRect(webcam_box_drawn_pos, webcam_box_drawn_size).contains(mouse_button_pos)) {
|
||||
moving_webcam_box = true;
|
||||
webcam_box_grab_offset = mouse_button_pos - webcam_box_drawn_pos;
|
||||
} else {
|
||||
moving_webcam_box = false;
|
||||
}
|
||||
} else if(event.mouse_button.button == mgl::Mouse::Right && !moving_webcam_box) {
|
||||
const mgl::vec2f mouse_button_pos(event.mouse_button.x, event.mouse_button.y);
|
||||
webcam_resize_start_pos = mouse_button_pos;
|
||||
webcam_box_pos_resize_start = webcam_box_pos;
|
||||
webcam_box_size_resize_start = webcam_box_size;
|
||||
webcam_box_grab_offset = mouse_button_pos - webcam_box_drawn_pos;
|
||||
|
||||
/*if(mgl::FloatRect(webcam_box_drawn_pos - bounding_box_size*0.5f, bounding_box_size).contains(mouse_button_pos)) {
|
||||
webcam_resize_corner = WebcamBoxResizeCorner::TOP_LEFT;
|
||||
fprintf(stderr, "top left\n");
|
||||
} else if(mgl::FloatRect(webcam_box_drawn_pos + mgl::vec2f(webcam_box_drawn_size.x, 0.0f) - bounding_box_size*0.5f, bounding_box_size).contains(mouse_button_pos)) {
|
||||
webcam_resize_corner = WebcamBoxResizeCorner::TOP_RIGHT;
|
||||
fprintf(stderr, "top right\n");
|
||||
} else if(mgl::FloatRect(webcam_box_drawn_pos + mgl::vec2f(0.0f, webcam_box_drawn_size.y) - bounding_box_size*0.5f, bounding_box_size).contains(mouse_button_pos)) {
|
||||
webcam_resize_corner = WebcamBoxResizeCorner::BOTTOM_LEFT;
|
||||
fprintf(stderr, "bottom left\n");
|
||||
} else */if(mgl::FloatRect(webcam_box_drawn_pos + webcam_box_drawn_size - bounding_box_size*0.5f - screen_border_size*0.5f, bounding_box_size).contains(mouse_button_pos)) {
|
||||
webcam_resize_corner = WebcamBoxResizeCorner::BOTTOM_RIGHT;
|
||||
} else {
|
||||
webcam_resize_corner = WebcamBoxResizeCorner::NONE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case mgl::Event::MouseButtonReleased: {
|
||||
if(event.mouse_button.button == mgl::Mouse::Left && webcam_resize_corner == WebcamBoxResizeCorner::NONE) {
|
||||
moving_webcam_box = false;
|
||||
} else if(event.mouse_button.button == mgl::Mouse::Right && !moving_webcam_box) {
|
||||
webcam_resize_corner = WebcamBoxResizeCorner::NONE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
return camera_location_widget;
|
||||
}
|
||||
|
||||
std::unique_ptr<CheckBox> SettingsPage::create_flip_camera_checkbox() {
|
||||
auto flip_camera_horizontally_checkbox = std::make_unique<CheckBox>(&get_theme().body_font, "Flip camera horizontally");
|
||||
flip_camera_horizontally_checkbox_ptr = flip_camera_horizontally_checkbox.get();
|
||||
return flip_camera_horizontally_checkbox;
|
||||
}
|
||||
|
||||
std::unique_ptr<List> SettingsPage::create_webcam_body() {
|
||||
auto body_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
webcam_body_list_ptr = body_list.get();
|
||||
body_list->set_visible(false);
|
||||
body_list->add_widget(create_webcam_location_widget());
|
||||
body_list->add_widget(std::make_unique<Label>(&get_theme().body_font, "* Right click in the bottom right corner to resize the webcam", get_color_theme().text_color));
|
||||
body_list->add_widget(create_flip_camera_checkbox());
|
||||
body_list->add_widget(create_webcam_video_format());
|
||||
return body_list;
|
||||
}
|
||||
|
||||
std::unique_ptr<Widget> SettingsPage::create_webcam_section() {
|
||||
auto ll = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
ll->add_widget(create_webcam_sources());
|
||||
ll->add_widget(create_webcam_body());
|
||||
return std::make_unique<Subsection>("Webcam", std::move(ll), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
static bool audio_device_is_output(const std::string &audio_device_id) {
|
||||
return audio_device_id == "default_output" || ends_with(audio_device_id, ".monitor");
|
||||
}
|
||||
@@ -618,6 +833,7 @@ namespace gsr {
|
||||
auto settings_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
settings_list->set_spacing(0.018f);
|
||||
settings_list->add_widget(create_capture_target_section());
|
||||
settings_list->add_widget(create_webcam_section());
|
||||
settings_list->add_widget(create_audio_section());
|
||||
settings_list->add_widget(create_video_section());
|
||||
settings_list_ptr = settings_list.get();
|
||||
@@ -830,6 +1046,16 @@ namespace gsr {
|
||||
settings_scrollable_page_ptr->reset_scroll();
|
||||
}
|
||||
|
||||
RecordOptions& SettingsPage::get_current_record_options() {
|
||||
switch(type) {
|
||||
default:
|
||||
assert(false);
|
||||
case Type::REPLAY: return config.replay_config.record_options;
|
||||
case Type::RECORD: return config.record_config.record_options;
|
||||
case Type::STREAM: return config.streaming_config.record_options;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -1200,6 +1426,17 @@ namespace gsr {
|
||||
show_notification_checkbox_ptr->set_checked(record_options.show_notifications);
|
||||
led_indicator_checkbox_ptr->set_checked(record_options.use_led_indicator);
|
||||
|
||||
webcam_sources_box_ptr->set_selected_item(record_options.webcam_source);
|
||||
flip_camera_horizontally_checkbox_ptr->set_checked(record_options.webcam_flip_horizontally);
|
||||
webcam_video_format_box_ptr->set_selected_item(record_options.webcam_video_format);
|
||||
webcam_box_pos.x = ((float)record_options.webcam_x / 100.0f) * screen_inner_size.x;
|
||||
webcam_box_pos.y = ((float)record_options.webcam_y / 100.0f) * screen_inner_size.y;
|
||||
webcam_box_size.x = ((float)record_options.webcam_width / 100.0f * screen_inner_size.x);
|
||||
webcam_box_size.y = ((float)record_options.webcam_height / 100.0f * screen_inner_size.y);
|
||||
|
||||
if(selected_camera.has_value())
|
||||
webcam_box_size = clamp_keep_aspect_ratio(selected_camera->size.to_vec2f(), webcam_box_size);
|
||||
|
||||
if(record_options.record_area_width == 0)
|
||||
record_options.record_area_width = 1920;
|
||||
|
||||
@@ -1332,6 +1569,17 @@ namespace gsr {
|
||||
record_options.show_notifications = show_notification_checkbox_ptr->is_checked();
|
||||
record_options.use_led_indicator = led_indicator_checkbox_ptr->is_checked();
|
||||
|
||||
if(selected_camera.has_value())
|
||||
webcam_box_size = clamp_keep_aspect_ratio(selected_camera->size.to_vec2f(), webcam_box_size);
|
||||
|
||||
record_options.webcam_source = webcam_sources_box_ptr->get_selected_id();
|
||||
record_options.webcam_flip_horizontally = flip_camera_horizontally_checkbox_ptr->is_checked();
|
||||
record_options.webcam_video_format = webcam_video_format_box_ptr->get_selected_id();
|
||||
record_options.webcam_x = std::round((webcam_box_pos.x / screen_inner_size.x) * 100.0f);
|
||||
record_options.webcam_y = std::round((webcam_box_pos.y / screen_inner_size.y) * 100.0f);
|
||||
record_options.webcam_width = std::round((webcam_box_size.x / screen_inner_size.x) * 100.0f);
|
||||
record_options.webcam_height = std::round((webcam_box_size.y / screen_inner_size.y) * 100.0f);
|
||||
|
||||
if(record_options.record_area_width == 0)
|
||||
record_options.record_area_width = 1920;
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
namespace gsr {
|
||||
static double frame_delta_seconds = 1.0;
|
||||
|
||||
static mgl::vec2i min_vec2i(mgl::vec2i a, mgl::vec2i b) {
|
||||
mgl::vec2i min_vec2i(mgl::vec2i a, mgl::vec2i b) {
|
||||
return { std::min(a.x, b.x), std::min(a.y, b.y) };
|
||||
}
|
||||
|
||||
static mgl::vec2i max_vec2i(mgl::vec2i a, mgl::vec2i b) {
|
||||
mgl::vec2i max_vec2i(mgl::vec2i a, mgl::vec2i b) {
|
||||
return { std::max(a.x, b.x), std::max(a.y, b.y) };
|
||||
}
|
||||
|
||||
static mgl::vec2i clamp_vec2i(mgl::vec2i value, mgl::vec2i min, mgl::vec2i max) {
|
||||
mgl::vec2i clamp_vec2i(mgl::vec2i value, mgl::vec2i min, mgl::vec2i max) {
|
||||
return min_vec2i(max, max_vec2i(value, min));
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace gsr {
|
||||
const mgl::vec2i pos = clamp_vec2i(child.position, parent.position, parent.position + parent.size);
|
||||
return mgl::Scissor{
|
||||
pos,
|
||||
min_vec2i(child.size, parent.position + parent.size - pos)
|
||||
max_vec2i(mgl::vec2i(0, 0), min_vec2i(child.position + child.size - pos, parent.position + parent.size - pos))
|
||||
};
|
||||
}
|
||||
}
|
||||
57
src/main.cpp
57
src/main.cpp
@@ -3,6 +3,7 @@
|
||||
#include "../include/gui/Utils.hpp"
|
||||
#include "../include/Process.hpp"
|
||||
#include "../include/Rpc.hpp"
|
||||
#include "../include/Theme.hpp"
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
@@ -23,8 +24,10 @@ extern "C" {
|
||||
}
|
||||
|
||||
static sig_atomic_t running = 1;
|
||||
static sig_atomic_t killed = 0;
|
||||
static void sigint_handler(int signal) {
|
||||
(void)signal;
|
||||
killed = 1;
|
||||
running = 0;
|
||||
}
|
||||
|
||||
@@ -162,9 +165,10 @@ static void set_display_server_environment_variables() {
|
||||
static void usage() {
|
||||
printf("usage: gsr-ui [action]\n");
|
||||
printf("OPTIONS:\n");
|
||||
printf(" action The launch action. Should be either \"launch-show\", \"launch-hide\" or \"launch-daemon\". Optional, defaults to \"launch-hide\".\n");
|
||||
printf(" action The launch action. Should be either \"launch-show\", \"launch-hide\", \"launch-hide-announce\" or \"launch-daemon\". Optional, defaults to \"launch-hide\".\n");
|
||||
printf(" If \"launch-show\" is used then the program starts and the UI is immediately opened and can be shown/hidden with Alt+Z.\n");
|
||||
printf(" If \"launch-hide\" is used then the program starts but the UI is not opened until Alt+Z is pressed. The UI will be opened if the program is already running in another process.\n");
|
||||
printf(" If \"launch-hide-announce\" is used then the program starts but the UI is not opened until Alt+Z is pressed and a notification tells the user to press Alt+Z. The UI will be opened if the program is already running in another process.\n");
|
||||
printf(" If \"launch-daemon\" is used then the program starts but the UI is not opened until Alt+Z is pressed. The UI will not be opened if the program is already running in another process.\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -172,6 +176,7 @@ static void usage() {
|
||||
enum class LaunchAction {
|
||||
LAUNCH_SHOW,
|
||||
LAUNCH_HIDE,
|
||||
LAUNCH_HIDE_ANNOUNCE,
|
||||
LAUNCH_DAEMON
|
||||
};
|
||||
|
||||
@@ -195,10 +200,12 @@ int main(int argc, char **argv) {
|
||||
launch_action = LaunchAction::LAUNCH_SHOW;
|
||||
} else if(strcmp(launch_action_opt, "launch-hide") == 0) {
|
||||
launch_action = LaunchAction::LAUNCH_HIDE;
|
||||
} else if(strcmp(launch_action_opt, "launch-hide-announce") == 0) {
|
||||
launch_action = LaunchAction::LAUNCH_HIDE_ANNOUNCE;
|
||||
} else if(strcmp(launch_action_opt, "launch-daemon") == 0) {
|
||||
launch_action = LaunchAction::LAUNCH_DAEMON;
|
||||
} else {
|
||||
printf("error: invalid action \"%s\", expected \"launch-show\", \"launch-hide\" or \"launch-daemon\".\n", launch_action_opt);
|
||||
printf("error: invalid action \"%s\", expected \"launch-show\", \"launch-hide\", \"launch-hide-announce\" or \"launch-daemon\".\n", launch_action_opt);
|
||||
usage();
|
||||
}
|
||||
} else {
|
||||
@@ -207,6 +214,19 @@ int main(int argc, char **argv) {
|
||||
|
||||
set_display_server_environment_variables();
|
||||
|
||||
std::string resources_path;
|
||||
if(access("sibs-build/linux_x86_64/debug/gsr-ui", F_OK) == 0) {
|
||||
resources_path = "./";
|
||||
} else {
|
||||
#ifdef GSR_UI_RESOURCES_PATH
|
||||
resources_path = GSR_UI_RESOURCES_PATH "/";
|
||||
#else
|
||||
resources_path = "/usr/share/gsr-ui/";
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::string gsr_icon_path = resources_path + "images/gpu_screen_recorder_logo.png";
|
||||
|
||||
auto rpc = std::make_unique<gsr::Rpc>();
|
||||
const gsr::RpcOpenResult rpc_open_result = rpc->open("gsr-ui");
|
||||
|
||||
@@ -218,7 +238,10 @@ int main(int argc, char **argv) {
|
||||
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");
|
||||
const char *args[] = { "gsr-notify", "--text", "Another instance of GPU Screen Recorder UI is already running.\nPress Alt+Z to open the UI.", "--timeout", "5.0", "--icon-color", "ff0000", "--bg-color", "ff0000", nullptr };
|
||||
const char *args[] = {
|
||||
"gsr-notify", "--text", "Another instance of GPU Screen Recorder UI is already running.\nPress Alt+Z to open the UI.", "--timeout", "5.0",
|
||||
"--icon-color", "ffffff", "--icon", gsr_icon_path.c_str(), "--bg-color", "ff0000", nullptr
|
||||
};
|
||||
gsr::exec_program_daemonized(args);
|
||||
}
|
||||
return 1;
|
||||
@@ -228,7 +251,10 @@ int main(int argc, char **argv) {
|
||||
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 };
|
||||
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", "ffffff", "--icon", gsr_icon_path.c_str(), "--bg-color", "ff0000", nullptr
|
||||
};
|
||||
gsr::exec_program_daemonized(args);
|
||||
}
|
||||
|
||||
@@ -282,17 +308,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
gsr::SupportedCaptureOptions capture_options = gsr::get_supported_capture_options(gsr_info);
|
||||
|
||||
std::string resources_path;
|
||||
if(access("sibs-build/linux_x86_64/debug/gsr-ui", F_OK) == 0) {
|
||||
resources_path = "./";
|
||||
} else {
|
||||
#ifdef GSR_UI_RESOURCES_PATH
|
||||
resources_path = GSR_UI_RESOURCES_PATH "/";
|
||||
#else
|
||||
resources_path = "/usr/share/gsr-ui/";
|
||||
#endif
|
||||
}
|
||||
|
||||
mgl_context *context = mgl_get_context();
|
||||
|
||||
egl_functions egl_funcs;
|
||||
@@ -311,6 +326,8 @@ int main(int argc, char **argv) {
|
||||
auto overlay = std::make_unique<gsr::Overlay>(resources_path, std::move(gsr_info), std::move(capture_options), egl_funcs);
|
||||
if(launch_action == LaunchAction::LAUNCH_SHOW)
|
||||
overlay->show();
|
||||
else if(launch_action == LaunchAction::LAUNCH_HIDE_ANNOUNCE)
|
||||
overlay->show_notification("Press Alt+Z to open the GPU Screen Recorder UI", 5.0, mgl::Color(255, 255, 255), gsr::get_color_theme().tint_color, gsr::NotificationType::NOTICE, nullptr, gsr::NotificationLevel::ERROR);
|
||||
|
||||
rpc_add_commands(rpc.get(), overlay.get());
|
||||
|
||||
@@ -331,6 +348,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
const bool connected_to_display_server = mgl_is_connected_to_display_server();
|
||||
|
||||
fprintf(stderr, "Info: shutting down!\n");
|
||||
rpc.reset();
|
||||
overlay.reset();
|
||||
@@ -344,5 +363,11 @@ int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mgl_is_connected_to_display_server() ? 0 : 1;
|
||||
if(killed)
|
||||
return 0;
|
||||
|
||||
if(connected_to_display_server)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -200,6 +200,9 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
|
||||
return;
|
||||
}
|
||||
|
||||
if(extra_data->is_non_keyboard_device)
|
||||
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);
|
||||
@@ -210,6 +213,8 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
|
||||
//fprintf(stderr, "fd: %d, type: %d, pressed %d, value: %d\n", fd, event.type, event.code, event.value);
|
||||
//}
|
||||
|
||||
const bool prev_grabbed = extra_data->grabbed;
|
||||
|
||||
const bool keyboard_key = is_keyboard_key(event.code);
|
||||
if(event.type == EV_KEY && keyboard_key) {
|
||||
keyboard_event_process_key_state_change(self, &event, extra_data, fd);
|
||||
@@ -228,7 +233,7 @@ 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)) {
|
||||
if(prev_grabbed && !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;
|
||||
}
|
||||
@@ -238,17 +243,6 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user