mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-04-05 11:16:28 +09:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8a0b49bc2 | ||
|
|
34b9aad24b | ||
|
|
63b2b6cbc3 | ||
|
|
6c7158c06d | ||
|
|
7d1f6f9a25 | ||
|
|
3c8dd9c4db | ||
|
|
c7fcf251e3 | ||
|
|
6d58b2495d | ||
|
|
347eced060 | ||
|
|
6449133c57 | ||
|
|
1168e68278 | ||
|
|
4836c661ce | ||
|
|
f0bbbbe4a9 | ||
|
|
d9a1e5c2eb | ||
|
|
b6c59e1049 |
18
README.md
18
README.md
@@ -2,9 +2,7 @@
|
||||
|
||||
# GPU Screen Recorder UI
|
||||
A fullscreen overlay UI for [GPU Screen Recorder](https://git.dec05eba.com/gpu-screen-recorder/about/) in the style of ShadowPlay.\
|
||||
The application is currently primarly designed for X11 but it can run on Wayland as well through XWayland, with some caveats because of Wayland limitations.\
|
||||
Note: This software is still in early alpha. Expect bugs, and please report any if you experience them. Some are already known, but it doesn't hurt to report them anyways.\
|
||||
You can report an issue by emailing the issue to dec05eba@protonmail.com.
|
||||
The application is currently primarly designed for X11 but it can run on Wayland as well through XWayland, with some caveats because of Wayland limitations.
|
||||
|
||||
# Usage
|
||||
Run `gsr-ui` and press `Left Alt+Z` to show/hide the UI. You can start the overlay UI at system startup by running `systemctl enable --now --user gpu-screen-recorder-ui`.
|
||||
@@ -15,7 +13,7 @@ A program called `gsr-ui-cli` is also installed when installing this software. T
|
||||
# Installation
|
||||
If you are using an Arch Linux based distro then you can find gpu screen recorder ui on aur under the name gpu-screen-recorder-ui (`yay -S gpu-screen-recorder-ui`).\
|
||||
If you are running another distro then you can run `sudo ./install.sh`, but you need to manually install the dependencies, as described below.\
|
||||
You can also install gpu screen recorder (the gtk gui version) from [flathub](https://flathub.org/apps/details/com.dec05eba.gpu_screen_recorder). This flatpak includes both this UI and gpu-screen-recorder so no need to install that first.
|
||||
You can also install gpu screen recorder from [flathub](https://flathub.org/apps/details/com.dec05eba.gpu_screen_recorder). This flatpak includes both this UI and gpu-screen-recorder so no need to install that first.
|
||||
|
||||
# Dependencies
|
||||
GPU Screen Recorder UI uses meson build system so you need to install `meson` to build GPU Screen Recorder UI.
|
||||
@@ -23,7 +21,7 @@ GPU Screen Recorder UI uses meson build system so you need to install `meson` to
|
||||
## Build dependencies
|
||||
These are the dependencies needed to build GPU Screen Recorder UI:
|
||||
|
||||
* x11 (libx11, libxrandr, libxrender, libxcomposite, libxfixes, libxi)
|
||||
* x11 (libx11, libxrandr, libxrender, libxcomposite, libxfixes, libxext, libxi)
|
||||
* libxcursor
|
||||
* libglvnd (which provides libgl, libglx and libegl)
|
||||
* linux-api-headers
|
||||
@@ -42,6 +40,9 @@ This might cause issues for you if you use input remapping software. To workarou
|
||||
# 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`. `images/default.cur` it part of the [Adwaita icon theme](https://gitlab.gnome.org/GNOME/adwaita-icon-theme/-/tree/master) which is licensed under `Creative Commons Attribution-Share Alike 3.0`.
|
||||
|
||||
# Reporting bugs, contributing patches, questions or donation
|
||||
See [https://git.dec05eba.com/?p=about](https://git.dec05eba.com/?p=about).
|
||||
|
||||
# Demo
|
||||
[](https://www.youtube.com/watch?v=SOqXusCTXXA)
|
||||
|
||||
@@ -49,15 +50,10 @@ This software is licensed under GPL3.0-only. Files under `fonts/` directory belo
|
||||

|
||||

|
||||
|
||||
# Donations
|
||||
If you want to donate you can donate via bitcoin or monero.
|
||||
* Bitcoin: bc1qqvuqnwrdyppf707ge27fqz2n9y9gu7lf5ypyuf
|
||||
* Monero: 4An9kp2qW1C9Gah7ewv4JzcNFQ5TAX7ineGCqXWK6vQnhsGGcRpNgcn8r9EC3tMcgY7vqCKs3nSRXhejMHBaGvFdN2egYet
|
||||
|
||||
# Known issues
|
||||
* When the UI is open the wallpaper is shown instead of the game on Hyprland. This is an issue with Hyprland. It cant be fixed until the UI is redesigned to not be a fullscreen overlay.
|
||||
* Opening the UI when a game is fullscreened can mess up the game window a bit on Hyprland. I believe this is an issue with Hyprland.
|
||||
|
||||
# FAQ
|
||||
## I get an error when trying to start the gpu-screen-recorder-ui.service systemd service
|
||||
If you have previously used the flatpak version of GPU Screen Recorder with the new UI then non-flatpak version of the systemd service will conflict with that. Run `gsr-ui` to fix that.
|
||||
If you have previously used the flatpak version of GPU Screen Recorder with the new UI then the non-flatpak version of the systemd service will conflict with that. Run `gsr-ui` to fix that.
|
||||
|
||||
16
TODO
16
TODO
@@ -126,3 +126,19 @@ Add support for window capture. This should not prompt for window selection dire
|
||||
For screenshots window capture should exist but "follow focused" option should not exist.
|
||||
|
||||
Improve audio design. It should have a button to add/remove audio tracks and button to add audio into each audio track separately and "record audio from all applications except the selected ones" for each audio track. Then also remove the "merge audio tracks" option.
|
||||
|
||||
Make it possible to take a screenshot through a button in the ui instead of having to use hotkey.
|
||||
|
||||
Handle failing to save a replay. gsr should output "failed to save replay, or something like that" to make it possible to detect that.
|
||||
|
||||
Dont allow saving replay while a replay save is in progress.
|
||||
|
||||
Make input work with cjk input systems (such as fcitx).
|
||||
|
||||
System startup option should also support runit and some other init systems, not only soystemd.
|
||||
|
||||
Allow using a hotkey such as printscreen or any other non-alphanumeric key without a modifier. Allow that in gsr-ui and gsr-global-hotkeys. Update the ui to match that.
|
||||
|
||||
Use x11 shm instead of XGetImage (https://stackoverflow.com/questions/43442675/how-to-use-xshmgetimage-and-xshmputimage).
|
||||
|
||||
Add a hotkey to record/stream/replay/screenshot region.
|
||||
|
||||
Submodule depends/mglpp updated: 04a9fdec5a...241ebb9d03
Binary file not shown.
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.1 KiB |
@@ -11,6 +11,15 @@
|
||||
namespace gsr {
|
||||
struct SupportedCaptureOptions;
|
||||
|
||||
enum class ReplayStartupMode {
|
||||
DONT_TURN_ON_AUTOMATICALLY,
|
||||
TURN_ON_AT_SYSTEM_STARTUP,
|
||||
TURN_ON_AT_FULLSCREEN,
|
||||
TURN_ON_AT_POWER_SUPPLY_CONNECTED
|
||||
};
|
||||
|
||||
ReplayStartupMode replay_startup_string_to_type(const char *startup_mode_str);
|
||||
|
||||
struct ConfigHotkey {
|
||||
int64_t key = 0; // Mgl key
|
||||
uint32_t modifiers = 0; // HotkeyModifier
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace gsr {
|
||||
|
||||
struct SupportedCaptureOptions {
|
||||
bool window = false;
|
||||
bool region = false;
|
||||
bool focused = false;
|
||||
bool portal = false;
|
||||
std::vector<GsrMonitor> monitors;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include "Config.hpp"
|
||||
#include "window_texture.h"
|
||||
#include "WindowUtils.hpp"
|
||||
#include "GlobalHotkeysLinux.hpp"
|
||||
#include "GlobalHotkeysJoystick.hpp"
|
||||
#include "AudioPlayer.hpp"
|
||||
#include "RegionSelector.hpp"
|
||||
|
||||
#include <mglpp/window/Window.hpp>
|
||||
#include <mglpp/window/Event.hpp>
|
||||
@@ -78,7 +78,6 @@ namespace gsr {
|
||||
void process_key_bindings(mgl::Event &event);
|
||||
void grab_mouse_and_keyboard();
|
||||
void xi_setup_fake_cursor();
|
||||
void xi_grab_all_mouse_devices();
|
||||
|
||||
void close_gpu_screen_recorder_output();
|
||||
|
||||
@@ -92,6 +91,7 @@ namespace gsr {
|
||||
void replay_status_update_status();
|
||||
void update_focused_fullscreen_status();
|
||||
void update_power_supply_status();
|
||||
void update_system_startup_status();
|
||||
|
||||
void on_stop_recording(int exit_code);
|
||||
|
||||
@@ -108,10 +108,10 @@ namespace gsr {
|
||||
void update_ui_replay_stopped();
|
||||
|
||||
void on_press_save_replay();
|
||||
void on_press_start_replay(bool disable_notification);
|
||||
void on_press_start_record();
|
||||
void on_press_start_stream();
|
||||
void on_press_take_screenshot();
|
||||
bool on_press_start_replay(bool disable_notification, bool finished_region_selection);
|
||||
void on_press_start_record(bool finished_region_selection);
|
||||
void on_press_start_stream(bool finished_region_selection);
|
||||
void on_press_take_screenshot(bool finished_region_selection);
|
||||
bool update_compositor_texture(const Monitor &monitor);
|
||||
|
||||
void force_window_on_top();
|
||||
@@ -197,7 +197,12 @@ namespace gsr {
|
||||
|
||||
mgl::Clock replay_save_clock;
|
||||
bool replay_save_show_notification = false;
|
||||
ReplayStartupMode replay_startup_mode = ReplayStartupMode::TURN_ON_AT_SYSTEM_STARTUP;
|
||||
bool try_replay_startup = true;
|
||||
|
||||
AudioPlayer audio_player;
|
||||
RegionSelector region_selector;
|
||||
bool start_region_capture = false;
|
||||
std::function<void()> on_region_selected;
|
||||
};
|
||||
}
|
||||
@@ -12,14 +12,14 @@ namespace gsr {
|
||||
};
|
||||
|
||||
// Arguments ending with NULL
|
||||
bool exec_program_daemonized(const char **args);
|
||||
bool exec_program_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);
|
||||
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);
|
||||
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
|
||||
int exec_program_on_host_get_stdout(const char **args, std::string &result);
|
||||
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);
|
||||
}
|
||||
52
include/RegionSelector.hpp
Normal file
52
include/RegionSelector.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "WindowUtils.hpp"
|
||||
#include <mglpp/system/vec.hpp>
|
||||
#include <mglpp/graphics/Color.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
namespace gsr {
|
||||
struct Region {
|
||||
mgl::vec2i pos;
|
||||
mgl::vec2i size;
|
||||
};
|
||||
|
||||
class RegionSelector {
|
||||
public:
|
||||
RegionSelector();
|
||||
RegionSelector(const RegionSelector&) = delete;
|
||||
RegionSelector& operator=(const RegionSelector&) = delete;
|
||||
~RegionSelector();
|
||||
|
||||
bool start(mgl::Color border_color);
|
||||
void stop();
|
||||
bool is_started() const;
|
||||
|
||||
bool failed() const;
|
||||
bool poll_events();
|
||||
bool is_selected() const;
|
||||
bool take_selection();
|
||||
Region get_selection() const;
|
||||
private:
|
||||
void on_button_press(const void *de);
|
||||
void on_button_release(const void *de);
|
||||
void on_mouse_motion(const void *de);
|
||||
private:
|
||||
Display *dpy = nullptr;
|
||||
unsigned long region_window = 0;
|
||||
unsigned long cursor_window = 0;
|
||||
unsigned long region_window_colormap = 0;
|
||||
int xi_opcode = 0;
|
||||
GC region_gc = nullptr;
|
||||
GC cursor_gc = nullptr;
|
||||
|
||||
Region region;
|
||||
bool selecting_region = false;
|
||||
bool selected = false;
|
||||
bool is_wayland = false;
|
||||
std::vector<Monitor> monitors;
|
||||
mgl::vec2i cursor_pos;
|
||||
};
|
||||
}
|
||||
@@ -22,9 +22,19 @@ namespace gsr {
|
||||
std::string get_focused_window_name(Display *dpy, WindowCaptureType window_capture_type);
|
||||
std::string get_window_name_at_position(Display *dpy, mgl::vec2i position, Window ignore_window);
|
||||
std::string get_window_name_at_cursor_position(Display *dpy, Window ignore_window);
|
||||
void set_window_size_not_resizable(Display *dpy, Window window, int width, int height);
|
||||
mgl::vec2i get_cursor_position(Display *dpy, Window *window);
|
||||
mgl::vec2i create_window_get_center_position(Display *display);
|
||||
std::string get_window_manager_name(Display *display);
|
||||
bool is_compositor_running(Display *dpy, int screen);
|
||||
std::vector<Monitor> get_monitors(Display *dpy);
|
||||
void xi_grab_all_mouse_devices(Display *dpy);
|
||||
void xi_ungrab_all_mouse_devices(Display *dpy);
|
||||
void xi_warp_all_mouse_devices(Display *dpy, mgl::vec2i position);
|
||||
void window_set_fullscreen(Display *dpy, Window window, bool fullscreen);
|
||||
bool window_is_fullscreen(Display *display, Window window);
|
||||
bool set_window_wm_state(Display *dpy, Window window, Atom atom);
|
||||
void make_window_click_through(Display *display, Window window);
|
||||
bool make_window_sticky(Display *dpy, Window window);
|
||||
bool hide_window_from_taskbar(Display *dpy, Window window);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.2.0', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.3.0', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
|
||||
if get_option('buildtype') == 'debug'
|
||||
add_project_arguments('-g3', language : ['c', 'cpp'])
|
||||
@@ -33,6 +33,7 @@ src = [
|
||||
'src/gui/Subsection.cpp',
|
||||
'src/Utils.cpp',
|
||||
'src/WindowUtils.cpp',
|
||||
'src/RegionSelector.cpp',
|
||||
'src/Config.cpp',
|
||||
'src/GsrInfo.cpp',
|
||||
'src/Process.cpp',
|
||||
@@ -54,7 +55,7 @@ datadir = get_option('datadir')
|
||||
gsr_ui_resources_path = join_paths(prefix, datadir, 'gsr-ui')
|
||||
|
||||
add_project_arguments('-DGSR_UI_VERSION="' + meson.project_version() + '"', language: ['c', 'cpp'])
|
||||
add_project_arguments('-DGSR_FLATPAK_VERSION="5.1.5"', language: ['c', 'cpp'])
|
||||
add_project_arguments('-DGSR_FLATPAK_VERSION="5.2.0"', language: ['c', 'cpp'])
|
||||
|
||||
executable(
|
||||
meson.project_name(),
|
||||
@@ -65,6 +66,7 @@ executable(
|
||||
dependency('threads'),
|
||||
dependency('xcomposite'),
|
||||
dependency('xfixes'),
|
||||
dependency('xext'),
|
||||
dependency('xi'),
|
||||
dependency('xcursor'),
|
||||
dependency('libpulse-simple'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "gsr-ui"
|
||||
type = "executable"
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
platforms = ["posix"]
|
||||
|
||||
[lang.cpp]
|
||||
@@ -13,6 +13,7 @@ ignore_dirs = ["build", "tools"]
|
||||
[dependencies]
|
||||
xcomposite = ">=0"
|
||||
xfixes = ">=0"
|
||||
xext = ">=0"
|
||||
xi = ">=0"
|
||||
xcursor = ">=1"
|
||||
libpulse-simple = ">=0"
|
||||
libpulse-simple = ">=0"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <limits.h>
|
||||
#include <inttypes.h>
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <mglpp/window/Keyboard.hpp>
|
||||
|
||||
@@ -45,6 +46,19 @@ namespace gsr {
|
||||
}
|
||||
}
|
||||
|
||||
ReplayStartupMode replay_startup_string_to_type(const char *startup_mode_str) {
|
||||
if(strcmp(startup_mode_str, "dont_turn_on_automatically") == 0)
|
||||
return ReplayStartupMode::DONT_TURN_ON_AUTOMATICALLY;
|
||||
else if(strcmp(startup_mode_str, "turn_on_at_system_startup") == 0)
|
||||
return ReplayStartupMode::TURN_ON_AT_SYSTEM_STARTUP;
|
||||
else if(strcmp(startup_mode_str, "turn_on_at_fullscreen") == 0)
|
||||
return ReplayStartupMode::TURN_ON_AT_FULLSCREEN;
|
||||
else if(strcmp(startup_mode_str, "turn_on_at_power_supply_connected") == 0)
|
||||
return ReplayStartupMode::TURN_ON_AT_POWER_SUPPLY_CONNECTED;
|
||||
else
|
||||
return ReplayStartupMode::DONT_TURN_ON_AUTOMATICALLY;
|
||||
}
|
||||
|
||||
bool ConfigHotkey::operator==(const ConfigHotkey &other) const {
|
||||
return key == other.key && modifiers == other.modifiers;
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace gsr {
|
||||
|
||||
std::string stdout_str;
|
||||
const char *args[] = { "gpu-screen-recorder", "--list-audio-devices", nullptr };
|
||||
if(exec_program_get_stdout(args, stdout_str) != 0) {
|
||||
if(exec_program_get_stdout(args, stdout_str, false) != 0) {
|
||||
fprintf(stderr, "error: 'gpu-screen-recorder --list-audio-devices' failed\n");
|
||||
return audio_devices;
|
||||
}
|
||||
@@ -310,6 +310,8 @@ namespace gsr {
|
||||
static void parse_capture_options_line(SupportedCaptureOptions &capture_options, std::string_view line) {
|
||||
if(line == "window")
|
||||
capture_options.window = true;
|
||||
else if(line == "region")
|
||||
capture_options.region = true;
|
||||
else if(line == "focused")
|
||||
capture_options.focused = true;
|
||||
else if(line == "portal")
|
||||
|
||||
435
src/Overlay.cpp
435
src/Overlay.cpp
@@ -13,6 +13,7 @@
|
||||
#include "../include/gui/PageStack.hpp"
|
||||
#include "../include/WindowUtils.hpp"
|
||||
#include "../include/GlobalHotkeys.hpp"
|
||||
#include "../include/GlobalHotkeysLinux.hpp"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
@@ -22,6 +23,7 @@
|
||||
#include <poll.h>
|
||||
#include <malloc.h>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
@@ -29,7 +31,7 @@
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/shapeconst.h>
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
#include <mglpp/system/Rect.hpp>
|
||||
#include <mglpp/window/Event.hpp>
|
||||
@@ -41,8 +43,10 @@ extern "C" {
|
||||
namespace gsr {
|
||||
static const mgl::Color bg_color(0, 0, 0, 100);
|
||||
static const double force_window_on_top_timeout_seconds = 1.0;
|
||||
static const double replay_status_update_check_timeout_seconds = 1.0;
|
||||
static const double replay_status_update_check_timeout_seconds = 1.5;
|
||||
static const double replay_saving_notification_timeout_seconds = 0.5;
|
||||
static const double notification_timeout_seconds = 2.0;
|
||||
static const double notification_error_timeout_seconds = 5.0;
|
||||
|
||||
static mgl::Texture texture_from_ximage(XImage *img) {
|
||||
uint8_t *texture_data = (uint8_t*)malloc(img->width * img->height * 3);
|
||||
@@ -200,77 +204,6 @@ namespace gsr {
|
||||
return false;
|
||||
}*/
|
||||
|
||||
static bool window_is_fullscreen(Display *display, Window window) {
|
||||
const Atom wm_state_atom = XInternAtom(display, "_NET_WM_STATE", False);
|
||||
const Atom wm_state_fullscreen_atom = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
|
||||
Atom type = None;
|
||||
int format = 0;
|
||||
unsigned long num_items = 0;
|
||||
unsigned long bytes_after = 0;
|
||||
unsigned char *properties = nullptr;
|
||||
if(XGetWindowProperty(display, window, wm_state_atom, 0, 1024, False, XA_ATOM, &type, &format, &num_items, &bytes_after, &properties) < Success) {
|
||||
fprintf(stderr, "Failed to get window wm state property\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!properties)
|
||||
return false;
|
||||
|
||||
bool is_fullscreen = false;
|
||||
Atom *atoms = (Atom*)properties;
|
||||
for(unsigned long i = 0; i < num_items; ++i) {
|
||||
if(atoms[i] == wm_state_fullscreen_atom) {
|
||||
is_fullscreen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XFree(properties);
|
||||
return is_fullscreen;
|
||||
}
|
||||
|
||||
#define _NET_WM_STATE_REMOVE 0
|
||||
#define _NET_WM_STATE_ADD 1
|
||||
#define _NET_WM_STATE_TOGGLE 2
|
||||
|
||||
static Bool set_window_wm_state(Display *dpy, Window window, Atom atom) {
|
||||
const Atom net_wm_state_atom = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||
|
||||
XClientMessageEvent xclient;
|
||||
memset(&xclient, 0, sizeof(xclient));
|
||||
|
||||
xclient.type = ClientMessage;
|
||||
xclient.window = window;
|
||||
xclient.message_type = net_wm_state_atom;
|
||||
xclient.format = 32;
|
||||
xclient.data.l[0] = _NET_WM_STATE_ADD;
|
||||
xclient.data.l[1] = atom;
|
||||
xclient.data.l[2] = 0;
|
||||
xclient.data.l[3] = 0;
|
||||
xclient.data.l[4] = 0;
|
||||
|
||||
XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent*)&xclient);
|
||||
XFlush(dpy);
|
||||
return True;
|
||||
}
|
||||
|
||||
static void make_window_click_through(Display *display, Window window) {
|
||||
XRectangle rect;
|
||||
memset(&rect, 0, sizeof(rect));
|
||||
XserverRegion region = XFixesCreateRegion(display, &rect, 1);
|
||||
XFixesSetWindowShapeRegion(display, window, ShapeInput, 0, 0, region);
|
||||
XFixesDestroyRegion(display, region);
|
||||
}
|
||||
|
||||
static Bool make_window_sticky(Display *dpy, Window window) {
|
||||
return set_window_wm_state(dpy, window, XInternAtom(dpy, "_NET_WM_STATE_STICKY", False));
|
||||
}
|
||||
|
||||
static Bool hide_window_from_taskbar(Display *dpy, Window window) {
|
||||
return set_window_wm_state(dpy, window, XInternAtom(dpy, "_NET_WM_STATE_SKIP_TASKBAR", False));
|
||||
}
|
||||
|
||||
// Returns the first monitor if not found. Assumes there is at least one monitor connected.
|
||||
static const Monitor* find_monitor_at_position(const std::vector<Monitor> &monitors, mgl::vec2i pos) {
|
||||
assert(!monitors.empty());
|
||||
@@ -436,9 +369,7 @@ namespace gsr {
|
||||
init_color_theme(config, this->gsr_info);
|
||||
|
||||
power_supply_online_filepath = get_power_supply_online_filepath();
|
||||
|
||||
if(config.replay_config.turn_on_replay_automatically_mode == "turn_on_at_system_startup")
|
||||
on_press_start_replay(true);
|
||||
replay_startup_mode = replay_startup_string_to_type(config.replay_config.turn_on_replay_automatically_mode.c_str());
|
||||
|
||||
if(config.main_config.hotkeys_enable_option == "enable_hotkeys")
|
||||
global_hotkeys = register_linux_hotkeys(this, GlobalHotkeysLinux::GrabType::ALL);
|
||||
@@ -660,6 +591,11 @@ namespace gsr {
|
||||
global_hotkeys_js->poll_events();
|
||||
|
||||
handle_keyboard_mapping_event();
|
||||
region_selector.poll_events();
|
||||
if(region_selector.take_selection() && on_region_selected) {
|
||||
on_region_selected();
|
||||
on_region_selected = nullptr;
|
||||
}
|
||||
|
||||
if(!visible || !window)
|
||||
return;
|
||||
@@ -695,6 +631,20 @@ namespace gsr {
|
||||
update_gsr_screenshot_process_status();
|
||||
replay_status_update_status();
|
||||
|
||||
if(start_region_capture) {
|
||||
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, 0), mgl::Color(255, 0, 0, 0), NotificationType::RECORD);
|
||||
on_region_selected = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if(region_selector.is_started()) {
|
||||
usleep(5 * 1000); // 5 ms
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!visible)
|
||||
return false;
|
||||
|
||||
@@ -820,52 +770,13 @@ namespace gsr {
|
||||
XcursorImageDestroy(cursor_image);
|
||||
}
|
||||
|
||||
static bool device_is_mouse(const XIDeviceInfo *dev) {
|
||||
for(int i = 0; i < dev->num_classes; ++i) {
|
||||
if(dev->classes[i]->type == XIMasterPointer || dev->classes[i]->type == XISlavePointer)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Overlay::xi_grab_all_mouse_devices() {
|
||||
if(!xi_display)
|
||||
return;
|
||||
|
||||
int num_devices = 0;
|
||||
XIDeviceInfo *info = XIQueryDevice(xi_display, XIAllDevices, &num_devices);
|
||||
if(!info)
|
||||
return;
|
||||
|
||||
unsigned char mask[XIMaskLen(XI_LASTEVENT)];
|
||||
memset(mask, 0, sizeof(mask));
|
||||
XISetMask(mask, XI_Motion);
|
||||
//XISetMask(mask, XI_RawMotion);
|
||||
XISetMask(mask, XI_ButtonPress);
|
||||
XISetMask(mask, XI_ButtonRelease);
|
||||
XISetMask(mask, XI_KeyPress);
|
||||
XISetMask(mask, XI_KeyRelease);
|
||||
|
||||
for (int i = 0; i < num_devices; ++i) {
|
||||
const XIDeviceInfo *dev = &info[i];
|
||||
if(!device_is_mouse(dev))
|
||||
continue;
|
||||
|
||||
XIEventMask xi_masks;
|
||||
xi_masks.deviceid = dev->deviceid;
|
||||
xi_masks.mask_len = sizeof(mask);
|
||||
xi_masks.mask = mask;
|
||||
XIGrabDevice(xi_display, dev->deviceid, window->get_system_handle(), CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, XIOwnerEvents, &xi_masks);
|
||||
}
|
||||
|
||||
XFlush(xi_display);
|
||||
XIFreeDeviceInfo(info);
|
||||
}
|
||||
|
||||
void Overlay::show() {
|
||||
if(visible)
|
||||
return;
|
||||
|
||||
if(region_selector.is_started())
|
||||
return;
|
||||
|
||||
drawn_first_frame = false;
|
||||
window.reset();
|
||||
window = std::make_unique<mgl::Window>();
|
||||
@@ -989,7 +900,7 @@ namespace gsr {
|
||||
|
||||
// We want to grab all devices to prevent any other application below the UI from receiving events.
|
||||
// Owlboy seems to use xi events and XGrabPointer doesn't prevent owlboy from receiving events.
|
||||
xi_grab_all_mouse_devices();
|
||||
xi_grab_all_mouse_devices(xi_display);
|
||||
|
||||
if(!is_wlroots)
|
||||
window->set_fullscreen(true);
|
||||
@@ -1070,14 +981,15 @@ namespace gsr {
|
||||
if(id == "settings") {
|
||||
auto replay_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::REPLAY, &gsr_info, config, &page_stack);
|
||||
replay_settings_page->on_config_changed = [this]() {
|
||||
replay_startup_mode = replay_startup_string_to_type(config.replay_config.turn_on_replay_automatically_mode.c_str());
|
||||
if(recording_status == RecordingStatus::REPLAY)
|
||||
show_notification("Replay settings have been modified.\nYou may need to restart replay to apply the changes.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification("Replay settings have been modified.\nYou may need to restart replay to apply the changes.", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
};
|
||||
page_stack.push(std::move(replay_settings_page));
|
||||
} else if(id == "save") {
|
||||
on_press_save_replay();
|
||||
} else if(id == "start") {
|
||||
on_press_start_replay(false);
|
||||
on_press_start_replay(false, false);
|
||||
}
|
||||
};
|
||||
main_buttons_list->add_widget(std::move(button));
|
||||
@@ -1097,13 +1009,13 @@ namespace gsr {
|
||||
auto record_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::RECORD, &gsr_info, config, &page_stack);
|
||||
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.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::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);
|
||||
};
|
||||
page_stack.push(std::move(record_settings_page));
|
||||
} else if(id == "pause") {
|
||||
toggle_pause();
|
||||
} else if(id == "start") {
|
||||
on_press_start_record();
|
||||
on_press_start_record(false);
|
||||
}
|
||||
};
|
||||
main_buttons_list->add_widget(std::move(button));
|
||||
@@ -1121,11 +1033,11 @@ namespace gsr {
|
||||
auto stream_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::STREAM, &gsr_info, config, &page_stack);
|
||||
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.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::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);
|
||||
};
|
||||
page_stack.push(std::move(stream_settings_page));
|
||||
} else if(id == "start") {
|
||||
on_press_start_stream();
|
||||
on_press_start_stream(false);
|
||||
}
|
||||
};
|
||||
main_buttons_list->add_widget(std::move(button));
|
||||
@@ -1151,12 +1063,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.", 10.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup.\nThis option only works on systems that use systemd.\nYou have to manually add \"gsr-ui\" to system startup on systems that uses another init system.", 7.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
} else {
|
||||
if(enable)
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
else
|
||||
show_notification("Failed to remove GPU Screen Recorder from system startup", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
show_notification("Failed to remove GPU Screen Recorder from system startup", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1282,6 +1194,7 @@ namespace gsr {
|
||||
|
||||
visible = false;
|
||||
drawn_first_frame = false;
|
||||
start_region_capture = false;
|
||||
|
||||
if(xi_input_xev) {
|
||||
free(xi_input_xev);
|
||||
@@ -1294,20 +1207,21 @@ namespace gsr {
|
||||
}
|
||||
|
||||
if(xi_display) {
|
||||
XCloseDisplay(xi_display);
|
||||
xi_display = nullptr;
|
||||
|
||||
if(window) {
|
||||
mgl_context *context = mgl_get_context();
|
||||
Display *display = (Display*)context->connection;
|
||||
|
||||
const mgl::vec2i new_cursor_position = mgl::vec2i(window->internal_window()->pos.x, window->internal_window()->pos.y) + window->get_mouse_position();
|
||||
XWarpPointer(display, DefaultRootWindow(display), DefaultRootWindow(display), 0, 0, 0, 0, new_cursor_position.x, new_cursor_position.y);
|
||||
xi_warp_all_mouse_devices(xi_display, new_cursor_position);
|
||||
XFlush(display);
|
||||
|
||||
XFixesShowCursor(display, DefaultRootWindow(display));
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
XCloseDisplay(xi_display);
|
||||
xi_display = nullptr;
|
||||
}
|
||||
|
||||
if(window) {
|
||||
@@ -1343,7 +1257,7 @@ namespace gsr {
|
||||
}
|
||||
|
||||
void Overlay::toggle_record() {
|
||||
on_press_start_record();
|
||||
on_press_start_record(false);
|
||||
}
|
||||
|
||||
void Overlay::toggle_pause() {
|
||||
@@ -1352,10 +1266,10 @@ namespace gsr {
|
||||
|
||||
if(paused) {
|
||||
update_ui_recording_unpaused();
|
||||
show_notification("Recording has been unpaused", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
show_notification("Recording has been unpaused", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
} else {
|
||||
update_ui_recording_paused();
|
||||
show_notification("Recording has been paused", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
show_notification("Recording has been paused", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
}
|
||||
|
||||
kill(gpu_screen_recorder_process, SIGUSR2);
|
||||
@@ -1363,11 +1277,11 @@ namespace gsr {
|
||||
}
|
||||
|
||||
void Overlay::toggle_stream() {
|
||||
on_press_start_stream();
|
||||
on_press_start_stream(false);
|
||||
}
|
||||
|
||||
void Overlay::toggle_replay() {
|
||||
on_press_start_replay(false);
|
||||
on_press_start_replay(false, false);
|
||||
}
|
||||
|
||||
void Overlay::save_replay() {
|
||||
@@ -1375,7 +1289,7 @@ namespace gsr {
|
||||
}
|
||||
|
||||
void Overlay::take_screenshot() {
|
||||
on_press_take_screenshot();
|
||||
on_press_take_screenshot(false);
|
||||
}
|
||||
|
||||
static const char* notification_type_to_string(NotificationType notification_type) {
|
||||
@@ -1539,7 +1453,7 @@ namespace gsr {
|
||||
case NotificationType::STREAM:
|
||||
break;
|
||||
}
|
||||
show_notification(text.c_str(), 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, notification_type);
|
||||
show_notification(text.c_str(), notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, notification_type);
|
||||
}
|
||||
|
||||
void Overlay::on_replay_saved(const char *replay_saved_filepath) {
|
||||
@@ -1548,14 +1462,14 @@ namespace gsr {
|
||||
save_video_in_current_game_directory(replay_saved_filepath, NotificationType::REPLAY);
|
||||
} else {
|
||||
const std::string text = "Saved replay to '" + filepath_get_filename(replay_saved_filepath) + "'";
|
||||
show_notification(text.c_str(), 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification(text.c_str(), notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
}
|
||||
}
|
||||
|
||||
void Overlay::update_gsr_replay_save() {
|
||||
if(replay_save_show_notification && replay_save_clock.get_elapsed_time_seconds() >= replay_saving_notification_timeout_seconds) {
|
||||
replay_save_show_notification = false;
|
||||
show_notification("Saving replay, this might take some time", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification("Saving replay, this might take some time", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
}
|
||||
|
||||
if(gpu_screen_recorder_process_output_file) {
|
||||
@@ -1598,10 +1512,10 @@ namespace gsr {
|
||||
update_ui_replay_stopped();
|
||||
if(exit_code == 0) {
|
||||
if(config.replay_config.show_replay_stopped_notifications)
|
||||
show_notification("Replay stopped", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification("Replay stopped", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
} else {
|
||||
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_process, exit_code);
|
||||
show_notification("Replay stopped because of an error. Verify if settings are correct", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY);
|
||||
show_notification("Replay stopped because of an error. Verify if settings are correct", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::REPLAY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1614,10 +1528,10 @@ namespace gsr {
|
||||
update_ui_streaming_stopped();
|
||||
if(exit_code == 0) {
|
||||
if(config.streaming_config.show_streaming_stopped_notifications)
|
||||
show_notification("Streaming has stopped", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
show_notification("Streaming has stopped", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
} else {
|
||||
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_process, exit_code);
|
||||
show_notification("Streaming stopped because of an error. Verify if settings are correct", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM);
|
||||
show_notification("Streaming stopped because of an error. Verify if settings are correct", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::STREAM);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1646,16 +1560,43 @@ namespace gsr {
|
||||
save_video_in_current_game_directory(screenshot_filepath.c_str(), NotificationType::SCREENSHOT);
|
||||
} else {
|
||||
const std::string text = "Saved screenshot to '" + filepath_get_filename(screenshot_filepath.c_str()) + "'";
|
||||
show_notification(text.c_str(), 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::SCREENSHOT);
|
||||
show_notification(text.c_str(), notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::SCREENSHOT);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_screenshot_process, exit_code);
|
||||
show_notification("Failed to take a screenshot. Verify if settings are correct", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT);
|
||||
show_notification("Failed to take a screenshot. Verify if settings are correct", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::SCREENSHOT);
|
||||
}
|
||||
|
||||
gpu_screen_recorder_screenshot_process = -1;
|
||||
}
|
||||
|
||||
static bool starts_with(std::string_view str, const char *substr) {
|
||||
size_t len = strlen(substr);
|
||||
return str.size() >= len && memcmp(str.data(), substr, len) == 0;
|
||||
}
|
||||
|
||||
static bool are_all_audio_tracks_available_to_capture(const std::vector<std::string> &audio_tracks) {
|
||||
const auto audio_devices = get_audio_devices();
|
||||
for(const std::string &audio_track : audio_tracks) {
|
||||
std::string_view audio_track_name(audio_track.c_str());
|
||||
const bool is_app_audio = starts_with(audio_track_name, "app:");
|
||||
if(is_app_audio)
|
||||
continue;
|
||||
|
||||
if(starts_with(audio_track_name, "device:"))
|
||||
audio_track_name.remove_prefix(7);
|
||||
|
||||
auto it = std::find_if(audio_devices.begin(), audio_devices.end(), [&](const auto &audio_device) {
|
||||
return audio_device.name == audio_track_name;
|
||||
});
|
||||
if(it == audio_devices.end()) {
|
||||
//fprintf(stderr, "Audio not ready\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Overlay::replay_status_update_status() {
|
||||
if(replay_status_update_clock.get_elapsed_time_seconds() < replay_status_update_check_timeout_seconds)
|
||||
return;
|
||||
@@ -1663,10 +1604,11 @@ namespace gsr {
|
||||
replay_status_update_clock.restart();
|
||||
update_focused_fullscreen_status();
|
||||
update_power_supply_status();
|
||||
update_system_startup_status();
|
||||
}
|
||||
|
||||
void Overlay::update_focused_fullscreen_status() {
|
||||
if(config.replay_config.turn_on_replay_automatically_mode != "turn_on_at_fullscreen")
|
||||
if(replay_startup_mode != ReplayStartupMode::TURN_ON_AT_FULLSCREEN)
|
||||
return;
|
||||
|
||||
mgl_context *context = mgl_get_context();
|
||||
@@ -1679,39 +1621,51 @@ namespace gsr {
|
||||
const bool prev_focused_window_is_fullscreen = focused_window_is_fullscreen;
|
||||
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)
|
||||
on_press_start_replay(false);
|
||||
else if(recording_status == RecordingStatus::REPLAY && !focused_window_is_fullscreen)
|
||||
on_press_start_replay(true);
|
||||
if(recording_status == RecordingStatus::NONE && focused_window_is_fullscreen) {
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks))
|
||||
on_press_start_replay(false, false);
|
||||
} else if(recording_status == RecordingStatus::REPLAY && !focused_window_is_fullscreen) {
|
||||
on_press_start_replay(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Instead of checking power supply status periodically listen to power supply event
|
||||
void Overlay::update_power_supply_status() {
|
||||
if(config.replay_config.turn_on_replay_automatically_mode != "turn_on_at_power_supply_connected")
|
||||
if(replay_startup_mode != ReplayStartupMode::TURN_ON_AT_POWER_SUPPLY_CONNECTED)
|
||||
return;
|
||||
|
||||
const bool prev_power_supply_status = power_supply_connected;
|
||||
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)
|
||||
on_press_start_replay(false);
|
||||
else if(recording_status == RecordingStatus::REPLAY && !power_supply_connected)
|
||||
on_press_start_replay(false);
|
||||
if(recording_status == RecordingStatus::NONE && power_supply_connected) {
|
||||
if(are_all_audio_tracks_available_to_capture(config.replay_config.record_options.audio_tracks))
|
||||
on_press_start_replay(false, false);
|
||||
} else if(recording_status == RecordingStatus::REPLAY && !power_supply_connected) {
|
||||
on_press_start_replay(false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Overlay::update_system_startup_status() {
|
||||
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))
|
||||
on_press_start_replay(true, false);
|
||||
}
|
||||
|
||||
void Overlay::on_stop_recording(int exit_code) {
|
||||
if(exit_code == 0) {
|
||||
if(config.record_config.save_video_in_game_folder) {
|
||||
save_video_in_current_game_directory(record_filepath.c_str(), NotificationType::RECORD);
|
||||
} else {
|
||||
const std::string text = "Saved recording to '" + filepath_get_filename(record_filepath.c_str()) + "'";
|
||||
show_notification(text.c_str(), 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
show_notification(text.c_str(), notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Warning: gpu-screen-recorder (%d) exited with exit status %d\n", (int)gpu_screen_recorder_process, exit_code);
|
||||
show_notification("Failed to start/save recording. Verify if settings are correct", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
|
||||
show_notification("Failed to start/save recording. Verify if settings are correct", notification_timeout_seconds, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::RECORD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1816,11 +1770,6 @@ namespace gsr {
|
||||
return container;
|
||||
}
|
||||
|
||||
static bool starts_with(std::string_view str, const char *substr) {
|
||||
size_t len = strlen(substr);
|
||||
return str.size() >= len && memcmp(str.data(), substr, len) == 0;
|
||||
}
|
||||
|
||||
static std::vector<std::string> create_audio_tracks_real_names(const std::vector<std::string> &audio_tracks, bool application_audio_invert, const GsrInfo &gsr_info) {
|
||||
std::vector<std::string> result;
|
||||
for(const std::string &audio_track : audio_tracks) {
|
||||
@@ -1847,7 +1796,18 @@ namespace gsr {
|
||||
return result;
|
||||
}
|
||||
|
||||
static void add_common_gpu_screen_recorder_args(std::vector<const char*> &args, const RecordOptions &record_options, const std::vector<std::string> &audio_tracks, const std::string &video_bitrate, const char *region, const std::string &audio_devices_merged) {
|
||||
static void add_region_command(std::vector<const char*> &args, char *region_str, int region_str_size, const RegionSelector ®ion_selector) {
|
||||
Region region = region_selector.get_selection();
|
||||
if(region.size.x <= 32 && region.size.y <= 32) {
|
||||
region.size.x = 0;
|
||||
region.size.y = 0;
|
||||
}
|
||||
snprintf(region_str, region_str_size, "%dx%d+%d+%d", region.size.x, region.size.y, region.pos.x, region.pos.y);
|
||||
args.push_back("-region");
|
||||
args.push_back(region_str);
|
||||
}
|
||||
|
||||
static void add_common_gpu_screen_recorder_args(std::vector<const char*> &args, const RecordOptions &record_options, const std::vector<std::string> &audio_tracks, const std::string &video_bitrate, const char *region, const std::string &audio_devices_merged, char *region_str, int region_str_size, const RegionSelector ®ion_selector) {
|
||||
if(record_options.video_quality == "custom") {
|
||||
args.push_back("-bm");
|
||||
args.push_back("cbr");
|
||||
@@ -1879,12 +1839,17 @@ namespace gsr {
|
||||
args.push_back("-restore-portal-session");
|
||||
args.push_back("yes");
|
||||
}
|
||||
|
||||
if(record_options.record_area_option == "region")
|
||||
add_region_command(args, region_str, region_str_size, region_selector);
|
||||
}
|
||||
|
||||
static bool validate_capture_target(const GsrInfo &gsr_info, const std::string &capture_target) {
|
||||
const SupportedCaptureOptions capture_options = get_supported_capture_options(gsr_info);
|
||||
// TODO: Also check x11 window when enabled (check if capture_target is a decminal/hex number)
|
||||
if(capture_target == "focused") {
|
||||
if(capture_target == "region") {
|
||||
return capture_options.region;
|
||||
} else if(capture_target == "focused") {
|
||||
return capture_options.focused;
|
||||
} else if(capture_target == "portal") {
|
||||
return capture_options.portal;
|
||||
@@ -1906,21 +1871,25 @@ namespace gsr {
|
||||
kill(gpu_screen_recorder_process, SIGUSR1);
|
||||
}
|
||||
|
||||
void Overlay::on_press_start_replay(bool disable_notification) {
|
||||
bool Overlay::on_press_start_replay(bool disable_notification, bool finished_region_selection) {
|
||||
if(region_selector.is_started())
|
||||
return false;
|
||||
|
||||
switch(recording_status) {
|
||||
case RecordingStatus::NONE:
|
||||
case RecordingStatus::REPLAY:
|
||||
break;
|
||||
case RecordingStatus::RECORD:
|
||||
show_notification("Unable to start replay when recording.\nStop recording before starting replay.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
return;
|
||||
show_notification("Unable to start replay when recording.\nStop recording before starting replay.", notification_error_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
return false;
|
||||
case RecordingStatus::STREAM:
|
||||
show_notification("Unable to start replay when streaming.\nStop streaming before starting replay.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
return;
|
||||
show_notification("Unable to start replay when streaming.\nStop streaming before starting replay.", notification_error_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
return false;
|
||||
}
|
||||
|
||||
paused = false;
|
||||
replay_save_show_notification = false;
|
||||
try_replay_startup = false;
|
||||
|
||||
// window->close();
|
||||
// usleep(1000 * 50); // 50 milliseconds
|
||||
@@ -1941,15 +1910,24 @@ namespace gsr {
|
||||
|
||||
// TODO: Show this with a slight delay to make sure it doesn't show up in the video
|
||||
if(!disable_notification && config.replay_config.show_replay_stopped_notifications)
|
||||
show_notification("Replay stopped", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
return;
|
||||
show_notification("Replay stopped", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!validate_capture_target(gsr_info, config.replay_config.record_options.record_area_option)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to start replay, capture target \"%s\" is invalid. Please change capture target in settings", config.replay_config.record_options.record_area_option.c_str());
|
||||
show_notification(err_msg, 3.0, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::REPLAY);
|
||||
return;
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::REPLAY);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(config.replay_config.record_options.record_area_option == "region" && !finished_region_selection) {
|
||||
start_region_capture = true;
|
||||
on_region_selected = [disable_notification, this]() {
|
||||
on_press_start_replay(disable_notification, true);
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Validate input, fallback to valid values
|
||||
@@ -1967,13 +1945,13 @@ namespace gsr {
|
||||
encoder = "cpu";
|
||||
}
|
||||
|
||||
char region[64];
|
||||
region[0] = '\0';
|
||||
char size[64];
|
||||
size[0] = '\0';
|
||||
if(config.replay_config.record_options.record_area_option == "focused")
|
||||
snprintf(region, sizeof(region), "%dx%d", (int)config.replay_config.record_options.record_area_width, (int)config.replay_config.record_options.record_area_height);
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.replay_config.record_options.record_area_width, (int)config.replay_config.record_options.record_area_height);
|
||||
|
||||
if(config.replay_config.record_options.record_area_option != "focused" && config.replay_config.record_options.change_video_resolution)
|
||||
snprintf(region, sizeof(region), "%dx%d", (int)config.replay_config.record_options.video_width, (int)config.replay_config.record_options.video_height);
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.replay_config.record_options.video_width, (int)config.replay_config.record_options.video_height);
|
||||
|
||||
std::vector<const char*> args = {
|
||||
"gpu-screen-recorder", "-w", config.replay_config.record_options.record_area_option.c_str(),
|
||||
@@ -1995,7 +1973,8 @@ namespace gsr {
|
||||
args.push_back("yes");
|
||||
}
|
||||
|
||||
add_common_gpu_screen_recorder_args(args, config.replay_config.record_options, audio_tracks, video_bitrate, region, audio_tracks_merged);
|
||||
char region_str[128];
|
||||
add_common_gpu_screen_recorder_args(args, config.replay_config.record_options, audio_tracks, video_bitrate, size, audio_tracks_merged, region_str, sizeof(region_str), region_selector);
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
@@ -2023,19 +2002,24 @@ namespace gsr {
|
||||
// program and start another one. This can also be used to check when the notification has finished by checking with waitpid NOWAIT
|
||||
// to see when the program has exit.
|
||||
if(!disable_notification && config.replay_config.show_replay_started_notifications)
|
||||
show_notification("Replay has started", 3.0, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification("Replay has started", notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Overlay::on_press_start_record() {
|
||||
void Overlay::on_press_start_record(bool finished_region_selection) {
|
||||
if(region_selector.is_started())
|
||||
return;
|
||||
|
||||
switch(recording_status) {
|
||||
case RecordingStatus::NONE:
|
||||
case RecordingStatus::RECORD:
|
||||
break;
|
||||
case RecordingStatus::REPLAY:
|
||||
show_notification("Unable to start recording when replay is turned on.\nTurn off replay before starting recording.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification("Unable to start recording when replay is turned on.\nTurn off replay before starting recording.", notification_error_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
return;
|
||||
case RecordingStatus::STREAM:
|
||||
show_notification("Unable to start recording when streaming.\nStop streaming before starting recording.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
show_notification("Unable to start recording when streaming.\nStop streaming before starting recording.", notification_error_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2067,7 +2051,15 @@ namespace gsr {
|
||||
if(!validate_capture_target(gsr_info, config.record_config.record_options.record_area_option)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to start recording, capture target \"%s\" is invalid. Please change capture target in settings", config.record_config.record_options.record_area_option.c_str());
|
||||
show_notification(err_msg, 3.0, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::RECORD);
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::RECORD);
|
||||
return;
|
||||
}
|
||||
|
||||
if(config.record_config.record_options.record_area_option == "region" && !finished_region_selection) {
|
||||
start_region_capture = true;
|
||||
on_region_selected = [this]() {
|
||||
on_press_start_record(true);
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2087,13 +2079,13 @@ namespace gsr {
|
||||
encoder = "cpu";
|
||||
}
|
||||
|
||||
char region[64];
|
||||
region[0] = '\0';
|
||||
char size[64];
|
||||
size[0] = '\0';
|
||||
if(config.record_config.record_options.record_area_option == "focused")
|
||||
snprintf(region, sizeof(region), "%dx%d", (int)config.record_config.record_options.record_area_width, (int)config.record_config.record_options.record_area_height);
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.record_config.record_options.record_area_width, (int)config.record_config.record_options.record_area_height);
|
||||
|
||||
if(config.record_config.record_options.record_area_option != "focused" && config.record_config.record_options.change_video_resolution)
|
||||
snprintf(region, sizeof(region), "%dx%d", (int)config.record_config.record_options.video_width, (int)config.record_config.record_options.video_height);
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.record_config.record_options.video_width, (int)config.record_config.record_options.video_height);
|
||||
|
||||
std::vector<const char*> args = {
|
||||
"gpu-screen-recorder", "-w", config.record_config.record_options.record_area_option.c_str(),
|
||||
@@ -2109,7 +2101,8 @@ namespace gsr {
|
||||
"-o", output_file.c_str()
|
||||
};
|
||||
|
||||
add_common_gpu_screen_recorder_args(args, config.record_config.record_options, audio_tracks, video_bitrate, region, audio_tracks_merged);
|
||||
char region_str[128];
|
||||
add_common_gpu_screen_recorder_args(args, config.record_config.record_options, audio_tracks, video_bitrate, size, audio_tracks_merged, region_str, sizeof(region_str), region_selector);
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
@@ -2129,7 +2122,7 @@ namespace gsr {
|
||||
// 2...
|
||||
// 1...
|
||||
if(config.record_config.show_recording_started_notifications)
|
||||
show_notification("Recording has started", 3.0, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::RECORD);
|
||||
show_notification("Recording has started", notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::RECORD);
|
||||
}
|
||||
|
||||
static std::string streaming_get_url(const Config &config) {
|
||||
@@ -2164,16 +2157,19 @@ namespace gsr {
|
||||
return url;
|
||||
}
|
||||
|
||||
void Overlay::on_press_start_stream() {
|
||||
void Overlay::on_press_start_stream(bool finished_region_selection) {
|
||||
if(region_selector.is_started())
|
||||
return;
|
||||
|
||||
switch(recording_status) {
|
||||
case RecordingStatus::NONE:
|
||||
case RecordingStatus::STREAM:
|
||||
break;
|
||||
case RecordingStatus::REPLAY:
|
||||
show_notification("Unable to start streaming when replay is turned on.\nTurn off replay before starting streaming.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
show_notification("Unable to start streaming when replay is turned on.\nTurn off replay before starting streaming.", notification_error_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY);
|
||||
return;
|
||||
case RecordingStatus::RECORD:
|
||||
show_notification("Unable to start streaming when recording.\nStop recording before starting streaming.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
show_notification("Unable to start streaming when recording.\nStop recording before starting streaming.", notification_error_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2196,14 +2192,22 @@ namespace gsr {
|
||||
|
||||
// TODO: Show this with a slight delay to make sure it doesn't show up in the video
|
||||
if(config.streaming_config.show_streaming_stopped_notifications)
|
||||
show_notification("Streaming has stopped", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
show_notification("Streaming has stopped", notification_timeout_seconds, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!validate_capture_target(gsr_info, config.streaming_config.record_options.record_area_option)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to start streaming, capture target \"%s\" is invalid. Please change capture target in settings", config.streaming_config.record_options.record_area_option.c_str());
|
||||
show_notification(err_msg, 3.0, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::STREAM);
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::STREAM);
|
||||
return;
|
||||
}
|
||||
|
||||
if(config.streaming_config.record_options.record_area_option == "region" && !finished_region_selection) {
|
||||
start_region_capture = true;
|
||||
on_region_selected = [this]() {
|
||||
on_press_start_stream(true);
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2226,13 +2230,13 @@ namespace gsr {
|
||||
|
||||
const std::string url = streaming_get_url(config);
|
||||
|
||||
char region[64];
|
||||
region[0] = '\0';
|
||||
char size[64];
|
||||
size[0] = '\0';
|
||||
if(config.record_config.record_options.record_area_option == "focused")
|
||||
snprintf(region, sizeof(region), "%dx%d", (int)config.streaming_config.record_options.record_area_width, (int)config.streaming_config.record_options.record_area_height);
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.streaming_config.record_options.record_area_width, (int)config.streaming_config.record_options.record_area_height);
|
||||
|
||||
if(config.record_config.record_options.record_area_option != "focused" && config.streaming_config.record_options.change_video_resolution)
|
||||
snprintf(region, sizeof(region), "%dx%d", (int)config.streaming_config.record_options.video_width, (int)config.streaming_config.record_options.video_height);
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.streaming_config.record_options.video_width, (int)config.streaming_config.record_options.video_height);
|
||||
|
||||
std::vector<const char*> args = {
|
||||
"gpu-screen-recorder", "-w", config.streaming_config.record_options.record_area_option.c_str(),
|
||||
@@ -2248,7 +2252,8 @@ namespace gsr {
|
||||
};
|
||||
|
||||
config.streaming_config.record_options.merge_audio_tracks = true;
|
||||
add_common_gpu_screen_recorder_args(args, config.streaming_config.record_options, audio_tracks, video_bitrate, region, audio_tracks_merged);
|
||||
char region_str[128];
|
||||
add_common_gpu_screen_recorder_args(args, config.streaming_config.record_options, audio_tracks, video_bitrate, size, audio_tracks_merged, region_str, sizeof(region_str), region_selector);
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
@@ -2270,10 +2275,13 @@ namespace gsr {
|
||||
// program and start another one. This can also be used to check when the notification has finished by checking with waitpid NOWAIT
|
||||
// to see when the program has exit.
|
||||
if(config.streaming_config.show_streaming_started_notifications)
|
||||
show_notification("Streaming has started", 3.0, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::STREAM);
|
||||
show_notification("Streaming has started", notification_timeout_seconds, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::STREAM);
|
||||
}
|
||||
|
||||
void Overlay::on_press_take_screenshot() {
|
||||
void Overlay::on_press_take_screenshot(bool finished_region_selection) {
|
||||
if(region_selector.is_started())
|
||||
return;
|
||||
|
||||
if(gpu_screen_recorder_screenshot_process > 0) {
|
||||
fprintf(stderr, "Error: failed to take screenshot, another screenshot is currently being saved\n");
|
||||
return;
|
||||
@@ -2282,7 +2290,16 @@ namespace gsr {
|
||||
if(!validate_capture_target(gsr_info, config.screenshot_config.record_area_option)) {
|
||||
char err_msg[256];
|
||||
snprintf(err_msg, sizeof(err_msg), "Failed to take a screenshot, capture target \"%s\" is invalid. Please change capture target in settings", config.screenshot_config.record_area_option.c_str());
|
||||
show_notification(err_msg, 3.0, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::SCREENSHOT);
|
||||
show_notification(err_msg, notification_error_timeout_seconds, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::SCREENSHOT);
|
||||
return;
|
||||
}
|
||||
|
||||
if(config.screenshot_config.record_area_option == "region" && !finished_region_selection) {
|
||||
start_region_capture = true;
|
||||
on_region_selected = [this]() {
|
||||
usleep(200 * 1000); // Hack: wait 0.2 seconds before taking a screenshot to allow user to move cursor away. TODO: Remove this
|
||||
on_press_take_screenshot(true);
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2297,12 +2314,12 @@ namespace gsr {
|
||||
"-o", output_file.c_str()
|
||||
};
|
||||
|
||||
char region[64];
|
||||
region[0] = '\0';
|
||||
char size[64];
|
||||
size[0] = '\0';
|
||||
if(config.screenshot_config.change_image_resolution) {
|
||||
snprintf(region, sizeof(region), "%dx%d", (int)config.screenshot_config.image_width, (int)config.screenshot_config.image_height);
|
||||
snprintf(size, sizeof(size), "%dx%d", (int)config.screenshot_config.image_width, (int)config.screenshot_config.image_height);
|
||||
args.push_back("-s");
|
||||
args.push_back(region);
|
||||
args.push_back(size);
|
||||
}
|
||||
|
||||
if(config.screenshot_config.restore_portal_session) {
|
||||
@@ -2310,6 +2327,10 @@ namespace gsr {
|
||||
args.push_back("yes");
|
||||
}
|
||||
|
||||
char region_str[128];
|
||||
if(config.screenshot_config.record_area_option == "region")
|
||||
add_region_command(args, region_str, sizeof(region_str), region_selector);
|
||||
|
||||
args.push_back(nullptr);
|
||||
|
||||
screenshot_filepath = output_file;
|
||||
|
||||
@@ -40,12 +40,13 @@ namespace gsr {
|
||||
return num_args;
|
||||
}
|
||||
|
||||
bool exec_program_daemonized(const char **args) {
|
||||
bool exec_program_daemonized(const char **args, bool debug) {
|
||||
/* 1 argument */
|
||||
if(args[0] == nullptr)
|
||||
return false;
|
||||
|
||||
debug_print_args(args);
|
||||
if(debug)
|
||||
debug_print_args(args);
|
||||
|
||||
const pid_t pid = vfork();
|
||||
if(pid == -1) {
|
||||
@@ -72,7 +73,7 @@ namespace gsr {
|
||||
return true;
|
||||
}
|
||||
|
||||
pid_t exec_program(const char **args, int *read_fd) {
|
||||
pid_t exec_program(const char **args, int *read_fd, bool debug) {
|
||||
if(read_fd)
|
||||
*read_fd = -1;
|
||||
|
||||
@@ -84,7 +85,8 @@ namespace gsr {
|
||||
if(pipe(fds) == -1)
|
||||
return -1;
|
||||
|
||||
debug_print_args(args);
|
||||
if(debug)
|
||||
debug_print_args(args);
|
||||
|
||||
const pid_t pid = vfork();
|
||||
if(pid == -1) {
|
||||
@@ -110,10 +112,10 @@ namespace gsr {
|
||||
}
|
||||
}
|
||||
|
||||
int exec_program_get_stdout(const char **args, std::string &result) {
|
||||
int exec_program_get_stdout(const char **args, std::string &result, bool debug) {
|
||||
result.clear();
|
||||
int read_fd = -1;
|
||||
const pid_t process_id = exec_program(args, &read_fd);
|
||||
const pid_t process_id = exec_program(args, &read_fd, debug);
|
||||
if(process_id == -1)
|
||||
return -1;
|
||||
|
||||
@@ -152,7 +154,7 @@ namespace gsr {
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
int exec_program_on_host_get_stdout(const char **args, std::string &result) {
|
||||
int exec_program_on_host_get_stdout(const char **args, std::string &result, 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;
|
||||
@@ -170,9 +172,9 @@ namespace gsr {
|
||||
}
|
||||
modified_args[i] = arg;
|
||||
}
|
||||
return exec_program_get_stdout(modified_args, result);
|
||||
return exec_program_get_stdout(modified_args, result, debug);
|
||||
} else {
|
||||
return exec_program_get_stdout(args, result);
|
||||
return exec_program_get_stdout(args, result, debug);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
437
src/RegionSelector.cpp
Normal file
437
src/RegionSelector.cpp
Normal file
@@ -0,0 +1,437 @@
|
||||
#include "../include/RegionSelector.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
|
||||
namespace gsr {
|
||||
static const int cursor_window_size = 32;
|
||||
static const int cursor_thickness = 5;
|
||||
static const int region_border_size = 2;
|
||||
|
||||
static bool xinput_is_supported(Display *dpy, int *xi_opcode) {
|
||||
*xi_opcode = 0;
|
||||
int query_event = 0;
|
||||
int query_error = 0;
|
||||
if(!XQueryExtension(dpy, "XInputExtension", xi_opcode, &query_event, &query_error)) {
|
||||
fprintf(stderr, "error: RegionSelector: X Input extension not available\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int major = 2;
|
||||
int minor = 1;
|
||||
int retval = XIQueryVersion(dpy, &major, &minor);
|
||||
if(retval != Success) {
|
||||
fprintf(stderr, "error: RegionSelector: XInput 2.1 is not supported\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int max_int(int a, int b) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
static void set_region_rectangle(Display *dpy, Window window, int x, int y, int width, int height, int border_size) {
|
||||
if(width < 0) {
|
||||
x += width;
|
||||
width = abs(width);
|
||||
}
|
||||
|
||||
if(height < 0) {
|
||||
y += height;
|
||||
height = abs(height);
|
||||
}
|
||||
|
||||
XRectangle rectangles[] = {
|
||||
{
|
||||
(short)max_int(0, x), (short)max_int(0, y),
|
||||
(unsigned short)max_int(0, border_size), (unsigned short)max_int(0, height)
|
||||
}, // Left
|
||||
{
|
||||
(short)max_int(0, x + width - border_size), (short)max_int(0, y),
|
||||
(unsigned short)max_int(0, border_size), (unsigned short)max_int(0, height)
|
||||
}, // Right
|
||||
{
|
||||
(short)max_int(0, x + border_size), (short)max_int(0, y),
|
||||
(unsigned short)max_int(0, width - border_size*2), (unsigned short)max_int(0, border_size)
|
||||
}, // Top
|
||||
{
|
||||
(short)max_int(0, x + border_size), (short)max_int(0, y + height - border_size),
|
||||
(unsigned short)max_int(0, width - border_size*2), (unsigned short)max_int(0, border_size)
|
||||
}, // Bottom
|
||||
};
|
||||
XShapeCombineRectangles(dpy, window, ShapeBounding, 0, 0, rectangles, 4, ShapeSet, Unsorted);
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
static void set_window_shape_cross(Display *dpy, Window window, int window_width, int window_height, int thickness) {
|
||||
XRectangle rectangles[] = {
|
||||
{
|
||||
(short)(window_width / 2 - thickness / 2), (short)0,
|
||||
(unsigned short)thickness, (unsigned short)window_height
|
||||
}, // Vertical
|
||||
{
|
||||
(short)(0), (short)(window_height / 2 - thickness / 2),
|
||||
(unsigned short)window_width, (unsigned short)thickness
|
||||
}, // Horizontal
|
||||
};
|
||||
XShapeCombineRectangles(dpy, window, ShapeBounding, 0, 0, rectangles, 2, ShapeSet, Unsorted);
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
static void draw_rectangle(Display *dpy, Window window, GC gc, int x, int y, int width, int height) {
|
||||
if(width < 0) {
|
||||
x += width;
|
||||
width = abs(width);
|
||||
}
|
||||
|
||||
if(height < 0) {
|
||||
y += height;
|
||||
height = abs(height);
|
||||
}
|
||||
|
||||
XDrawRectangle(dpy, window, gc, x, y, width, height);
|
||||
}
|
||||
|
||||
static Window create_cursor_window(Display *dpy, int width, int height, XVisualInfo *vinfo, unsigned long background_pixel) {
|
||||
XSetWindowAttributes window_attr;
|
||||
window_attr.background_pixel = background_pixel;
|
||||
window_attr.border_pixel = 0;
|
||||
window_attr.override_redirect = true;
|
||||
window_attr.event_mask = StructureNotifyMask | PointerMotionMask;
|
||||
window_attr.colormap = XCreateColormap(dpy, DefaultRootWindow(dpy), vinfo->visual, AllocNone);
|
||||
const Window window = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, width, height, 0, vinfo->depth, InputOutput, vinfo->visual, CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWEventMask | CWColormap, &window_attr);
|
||||
if(window) {
|
||||
set_window_size_not_resizable(dpy, window, width, height);
|
||||
set_window_shape_cross(dpy, window, width, height, 5);
|
||||
make_window_click_through(dpy, window);
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
static void draw_rectangle_around_selected_monitor(Display *dpy, Window window, GC region_gc, int region_border_size, bool is_wayland, const std::vector<Monitor> &monitors, mgl::vec2i cursor_pos) {
|
||||
const Monitor *focused_monitor = nullptr;
|
||||
for(const Monitor &monitor : monitors) {
|
||||
if(cursor_pos.x >= monitor.position.x && cursor_pos.x <= monitor.position.x + monitor.size.x
|
||||
&& cursor_pos.y >= monitor.position.y && cursor_pos.y <= monitor.position.y + monitor.size.y)
|
||||
{
|
||||
focused_monitor = &monitor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
if(focused_monitor) {
|
||||
x = focused_monitor->position.x;
|
||||
y = focused_monitor->position.y;
|
||||
width = focused_monitor->size.x;
|
||||
height = focused_monitor->size.y;
|
||||
}
|
||||
|
||||
if(is_wayland)
|
||||
draw_rectangle(dpy, window, region_gc, x, y, width, height);
|
||||
else
|
||||
set_region_rectangle(dpy, window, x, y, width, height, region_border_size);
|
||||
}
|
||||
|
||||
static void update_cursor_window(Display *dpy, Window window, Window cursor_window, bool is_wayland, int cursor_x, int cursor_y, int cursor_window_size, int thickness, GC cursor_gc) {
|
||||
if(is_wayland) {
|
||||
const int x = cursor_x - cursor_window_size / 2;
|
||||
const int y = cursor_y - cursor_window_size / 2;
|
||||
XFillRectangle(dpy, window, cursor_gc, x + cursor_window_size / 2 - thickness / 2 , y, thickness, cursor_window_size);
|
||||
XFillRectangle(dpy, window, cursor_gc, x, y + cursor_window_size / 2 - thickness / 2, cursor_window_size, thickness);
|
||||
} else {
|
||||
XMoveWindow(dpy, cursor_window, cursor_x - cursor_window_size / 2, cursor_y - cursor_window_size / 2);
|
||||
}
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
static bool is_xwayland(Display *dpy) {
|
||||
int opcode, event, error;
|
||||
return XQueryExtension(dpy, "XWAYLAND", &opcode, &event, &error);
|
||||
}
|
||||
|
||||
static unsigned long mgl_color_to_x11_color(mgl::Color color) {
|
||||
if(color.a == 0)
|
||||
return 0;
|
||||
return ((uint32_t)color.a << 24) | (((uint32_t)color.r * color.a / 0xFF) << 16) | (((uint32_t)color.g * color.a / 0xFF) << 8) | ((uint32_t)color.b * color.a / 0xFF);
|
||||
}
|
||||
|
||||
RegionSelector::RegionSelector() {
|
||||
|
||||
}
|
||||
|
||||
RegionSelector::~RegionSelector() {
|
||||
stop();
|
||||
}
|
||||
|
||||
bool RegionSelector::start(mgl::Color border_color) {
|
||||
if(dpy)
|
||||
return false;
|
||||
|
||||
const unsigned long border_color_x11 = mgl_color_to_x11_color(border_color);
|
||||
dpy = XOpenDisplay(nullptr);
|
||||
if(!dpy) {
|
||||
fprintf(stderr, "Error: RegionSelector::start: failed to connect to the X11 server\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
xi_opcode = 0;
|
||||
if(!xinput_is_supported(dpy, &xi_opcode)) {
|
||||
fprintf(stderr, "Error: RegionSelector::start: xinput not supported on your system\n");
|
||||
stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
is_wayland = is_xwayland(dpy);
|
||||
monitors = get_monitors(dpy);
|
||||
|
||||
Window x11_cursor_window = None;
|
||||
cursor_pos = get_cursor_position(dpy, &x11_cursor_window);
|
||||
region.pos = {0, 0};
|
||||
region.size = {0, 0};
|
||||
|
||||
XVisualInfo vinfo;
|
||||
memset(&vinfo, 0, sizeof(vinfo));
|
||||
XMatchVisualInfo(dpy, DefaultScreen(dpy), 32, TrueColor, &vinfo);
|
||||
region_window_colormap = XCreateColormap(dpy, DefaultRootWindow(dpy), vinfo.visual, AllocNone);
|
||||
|
||||
XSetWindowAttributes window_attr;
|
||||
window_attr.background_pixel = is_wayland ? 0 : border_color_x11;
|
||||
window_attr.border_pixel = 0;
|
||||
window_attr.override_redirect = true;
|
||||
window_attr.event_mask = StructureNotifyMask | PointerMotionMask;
|
||||
window_attr.colormap = region_window_colormap;
|
||||
|
||||
Screen *screen = XDefaultScreenOfDisplay(dpy);
|
||||
region_window = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, XWidthOfScreen(screen), XHeightOfScreen(screen), 0,
|
||||
vinfo.depth, InputOutput, vinfo.visual, CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWEventMask | CWColormap, &window_attr);
|
||||
if(!region_window) {
|
||||
fprintf(stderr, "Error: RegionSelector::start: failed to create region window\n");
|
||||
stop();
|
||||
return false;
|
||||
}
|
||||
set_window_size_not_resizable(dpy, region_window, XWidthOfScreen(screen), XHeightOfScreen(screen));
|
||||
|
||||
if(!is_wayland) {
|
||||
cursor_window = create_cursor_window(dpy, cursor_window_size, cursor_window_size, &vinfo, border_color_x11);
|
||||
if(!cursor_window)
|
||||
fprintf(stderr, "Warning: RegionSelector::start: failed to create cursor window\n");
|
||||
set_region_rectangle(dpy, region_window, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
XGCValues region_gc_values;
|
||||
memset(®ion_gc_values, 0, sizeof(region_gc_values));
|
||||
region_gc_values.foreground = border_color_x11;
|
||||
region_gc_values.line_width = region_border_size;
|
||||
region_gc_values.line_style = LineSolid;
|
||||
region_gc = XCreateGC(dpy, region_window, GCForeground | GCLineWidth | GCLineStyle, ®ion_gc_values);
|
||||
|
||||
XGCValues cursor_gc_values;
|
||||
memset(&cursor_gc_values, 0, sizeof(cursor_gc_values));
|
||||
cursor_gc_values.foreground = border_color_x11;
|
||||
cursor_gc_values.line_width = cursor_thickness;
|
||||
cursor_gc_values.line_style = LineSolid;
|
||||
cursor_gc = XCreateGC(dpy, region_window, GCForeground | GCLineWidth | GCLineStyle, &cursor_gc_values);
|
||||
|
||||
if(!region_gc || !cursor_gc) {
|
||||
fprintf(stderr, "Error: RegionSelector::start: failed to create gc\n");
|
||||
stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
XMapWindow(dpy, region_window);
|
||||
make_window_sticky(dpy, region_window);
|
||||
hide_window_from_taskbar(dpy, region_window);
|
||||
XFixesHideCursor(dpy, region_window);
|
||||
XGrabPointer(dpy, DefaultRootWindow(dpy), True, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
||||
xi_grab_all_mouse_devices(dpy);
|
||||
XFlush(dpy);
|
||||
|
||||
window_set_fullscreen(dpy, region_window, true);
|
||||
|
||||
if(!is_wayland || x11_cursor_window)
|
||||
update_cursor_window(dpy, region_window, cursor_window, is_wayland, cursor_pos.x, cursor_pos.y, cursor_window_size, cursor_thickness, cursor_gc);
|
||||
|
||||
if(cursor_window) {
|
||||
XMapWindow(dpy, cursor_window);
|
||||
make_window_sticky(dpy, cursor_window);
|
||||
hide_window_from_taskbar(dpy, cursor_window);
|
||||
}
|
||||
|
||||
draw_rectangle_around_selected_monitor(dpy, region_window, region_gc, region_border_size, is_wayland, monitors, cursor_pos);
|
||||
|
||||
XFlush(dpy);
|
||||
selected = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegionSelector::stop() {
|
||||
if(!dpy)
|
||||
return;
|
||||
|
||||
XWarpPointer(dpy, DefaultRootWindow(dpy), DefaultRootWindow(dpy), 0, 0, 0, 0, cursor_pos.x, cursor_pos.y);
|
||||
xi_warp_all_mouse_devices(dpy, cursor_pos);
|
||||
XFixesShowCursor(dpy, region_window);
|
||||
|
||||
XUngrabPointer(dpy, CurrentTime);
|
||||
xi_ungrab_all_mouse_devices(dpy);
|
||||
XFlush(dpy);
|
||||
|
||||
if(region_gc) {
|
||||
XFreeGC(dpy, region_gc);
|
||||
region_gc = nullptr;
|
||||
}
|
||||
|
||||
if(cursor_gc) {
|
||||
XFreeGC(dpy, cursor_gc);
|
||||
cursor_gc = nullptr;
|
||||
}
|
||||
|
||||
if(region_window_colormap) {
|
||||
XFreeColormap(dpy, region_window_colormap);
|
||||
region_window_colormap = 0;
|
||||
}
|
||||
|
||||
if(region_window) {
|
||||
XDestroyWindow(dpy, region_window);
|
||||
region_window = 0;
|
||||
}
|
||||
|
||||
XCloseDisplay(dpy);
|
||||
dpy = nullptr;
|
||||
selecting_region = false;
|
||||
}
|
||||
|
||||
bool RegionSelector::is_started() const {
|
||||
return dpy != nullptr;
|
||||
}
|
||||
|
||||
bool RegionSelector::failed() const {
|
||||
return !dpy;
|
||||
}
|
||||
|
||||
bool RegionSelector::poll_events() {
|
||||
if(!dpy || selected)
|
||||
return false;
|
||||
|
||||
XEvent xev;
|
||||
while(XPending(dpy)) {
|
||||
XNextEvent(dpy, &xev);
|
||||
XGenericEventCookie *cookie = &xev.xcookie;
|
||||
if(cookie->type != GenericEvent || cookie->extension != xi_opcode || !XGetEventData(dpy, cookie))
|
||||
continue;
|
||||
|
||||
const XIDeviceEvent *de = (XIDeviceEvent*)cookie->data;
|
||||
switch(cookie->evtype) {
|
||||
case XI_ButtonPress: {
|
||||
on_button_press(de);
|
||||
break;
|
||||
}
|
||||
case XI_ButtonRelease: {
|
||||
on_button_release(de);
|
||||
break;
|
||||
}
|
||||
case XI_Motion: {
|
||||
on_mouse_motion(de);
|
||||
break;
|
||||
}
|
||||
}
|
||||
XFreeEventData(dpy, cookie);
|
||||
|
||||
if(selected) {
|
||||
stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegionSelector::is_selected() const {
|
||||
return selected;
|
||||
}
|
||||
|
||||
bool RegionSelector::take_selection() {
|
||||
const bool result = selected;
|
||||
selected = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
Region RegionSelector::get_selection() const {
|
||||
return region;
|
||||
}
|
||||
|
||||
void RegionSelector::on_button_press(const void *de) {
|
||||
const XIDeviceEvent *device_event = (XIDeviceEvent*)de;
|
||||
if(device_event->detail != Button1)
|
||||
return;
|
||||
|
||||
region.pos = { (int)device_event->root_x, (int)device_event->root_y };
|
||||
selecting_region = true;
|
||||
}
|
||||
|
||||
void RegionSelector::on_button_release(const void *de) {
|
||||
const XIDeviceEvent *device_event = (XIDeviceEvent*)de;
|
||||
if(device_event->detail != Button1)
|
||||
return;
|
||||
|
||||
if(!selecting_region)
|
||||
return;
|
||||
|
||||
if(is_wayland) {
|
||||
XClearWindow(dpy, region_window);
|
||||
XFlush(dpy);
|
||||
} else {
|
||||
set_region_rectangle(dpy, region_window, 0, 0, 0, 0, 0);
|
||||
}
|
||||
selecting_region = false;
|
||||
|
||||
cursor_pos = region.pos + region.size;
|
||||
|
||||
if(region.size.x < 0) {
|
||||
region.pos.x += region.size.x;
|
||||
region.size.x = abs(region.size.x);
|
||||
}
|
||||
|
||||
if(region.size.y < 0) {
|
||||
region.pos.y += region.size.y;
|
||||
region.size.y = abs(region.size.y);
|
||||
}
|
||||
|
||||
if(region.size.x > 0)
|
||||
region.size.x += 1;
|
||||
|
||||
if(region.size.y > 0)
|
||||
region.size.y += 1;
|
||||
|
||||
selected = true;
|
||||
}
|
||||
|
||||
void RegionSelector::on_mouse_motion(const void *de) {
|
||||
const XIDeviceEvent *device_event = (XIDeviceEvent*)de;
|
||||
XClearWindow(dpy, region_window);
|
||||
if(selecting_region) {
|
||||
region.size.x = device_event->root_x - region.pos.x;
|
||||
region.size.y = device_event->root_y - region.pos.y;
|
||||
cursor_pos = region.pos + region.size;
|
||||
|
||||
if(is_wayland)
|
||||
draw_rectangle(dpy, region_window, region_gc, region.pos.x, region.pos.y, region.size.x, region.size.y);
|
||||
else
|
||||
set_region_rectangle(dpy, region_window, region.pos.x, region.pos.y, region.size.x, region.size.y, region_border_size);
|
||||
} else {
|
||||
cursor_pos = { (int)device_event->root_x, (int)device_event->root_y };
|
||||
draw_rectangle_around_selected_monitor(dpy, region_window, region_gc, region_border_size, is_wayland, monitors, cursor_pos);
|
||||
}
|
||||
update_cursor_window(dpy, region_window, cursor_window, is_wayland, cursor_pos.x, cursor_pos.y, cursor_window_size, cursor_thickness, cursor_gc);
|
||||
XFlush(dpy);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "../include/WindowUtils.hpp"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
#include <X11/extensions/shapeconst.h>
|
||||
|
||||
#include <mglpp/system/Utf8.hpp>
|
||||
|
||||
@@ -301,6 +303,21 @@ namespace gsr {
|
||||
return get_window_name_at_position(dpy, cursor_position, ignore_window);
|
||||
}
|
||||
|
||||
void set_window_size_not_resizable(Display *dpy, Window window, int width, int height) {
|
||||
XSizeHints *size_hints = XAllocSizeHints();
|
||||
if(size_hints) {
|
||||
size_hints->width = width;
|
||||
size_hints->height = height;
|
||||
size_hints->min_width = width;
|
||||
size_hints->min_height = height;
|
||||
size_hints->max_width = width;
|
||||
size_hints->max_height = height;
|
||||
size_hints->flags = PSize | PMinSize | PMaxSize;
|
||||
XSetWMNormalHints(dpy, window, size_hints);
|
||||
XFree(size_hints);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned long flags;
|
||||
unsigned long functions;
|
||||
@@ -348,17 +365,7 @@ namespace gsr {
|
||||
XChangeProperty(display, window, net_wm_window_opacity, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1L);
|
||||
|
||||
window_set_decorations_visible(display, window, false);
|
||||
|
||||
XSizeHints *size_hints = XAllocSizeHints();
|
||||
size_hints->width = size;
|
||||
size_hints->height = size;
|
||||
size_hints->min_width = size;
|
||||
size_hints->min_height = size;
|
||||
size_hints->max_width = size;
|
||||
size_hints->max_height = size;
|
||||
size_hints->flags = PSize | PMinSize | PMaxSize;
|
||||
XSetWMNormalHints(display, window, size_hints);
|
||||
XFree(size_hints);
|
||||
set_window_size_not_resizable(display, window, size, size);
|
||||
|
||||
XMapWindow(display, window);
|
||||
XFlush(display);
|
||||
@@ -412,17 +419,7 @@ namespace gsr {
|
||||
XChangeProperty(display, window, net_wm_window_opacity, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1L);
|
||||
|
||||
window_set_decorations_visible(display, window, false);
|
||||
|
||||
XSizeHints *size_hints = XAllocSizeHints();
|
||||
size_hints->width = size;
|
||||
size_hints->height = size;
|
||||
size_hints->min_width = size;
|
||||
size_hints->min_height = size;
|
||||
size_hints->max_width = size;
|
||||
size_hints->max_height = size;
|
||||
size_hints->flags = PSize | PMinSize | PMaxSize;
|
||||
XSetWMNormalHints(display, window, size_hints);
|
||||
XFree(size_hints);
|
||||
set_window_size_not_resizable(display, window, size, size);
|
||||
|
||||
XMapWindow(display, window);
|
||||
XFlush(display);
|
||||
@@ -531,4 +528,172 @@ namespace gsr {
|
||||
mgl_for_each_active_monitor_output(dpy, get_monitors_callback, &monitors);
|
||||
return monitors;
|
||||
}
|
||||
|
||||
static bool device_is_mouse(const XIDeviceInfo *dev) {
|
||||
for(int i = 0; i < dev->num_classes; ++i) {
|
||||
if(dev->classes[i]->type == XIMasterPointer || dev->classes[i]->type == XISlavePointer)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void xi_grab_all_mouse_devices(Display *dpy, bool grab) {
|
||||
if(!dpy)
|
||||
return;
|
||||
|
||||
int num_devices = 0;
|
||||
XIDeviceInfo *info = XIQueryDevice(dpy, XIAllDevices, &num_devices);
|
||||
if(!info)
|
||||
return;
|
||||
|
||||
unsigned char mask[XIMaskLen(XI_LASTEVENT)];
|
||||
memset(mask, 0, sizeof(mask));
|
||||
XISetMask(mask, XI_Motion);
|
||||
//XISetMask(mask, XI_RawMotion);
|
||||
XISetMask(mask, XI_ButtonPress);
|
||||
XISetMask(mask, XI_ButtonRelease);
|
||||
XISetMask(mask, XI_KeyPress);
|
||||
XISetMask(mask, XI_KeyRelease);
|
||||
|
||||
for (int i = 0; i < num_devices; ++i) {
|
||||
const XIDeviceInfo *dev = &info[i];
|
||||
if(!device_is_mouse(dev))
|
||||
continue;
|
||||
|
||||
XIEventMask xi_masks;
|
||||
xi_masks.deviceid = dev->deviceid;
|
||||
xi_masks.mask_len = sizeof(mask);
|
||||
xi_masks.mask = mask;
|
||||
if(grab)
|
||||
XIGrabDevice(dpy, dev->deviceid, DefaultRootWindow(dpy), CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, XIOwnerEvents, &xi_masks);
|
||||
else
|
||||
XIUngrabDevice(dpy, dev->deviceid, CurrentTime);
|
||||
}
|
||||
|
||||
XFlush(dpy);
|
||||
XIFreeDeviceInfo(info);
|
||||
}
|
||||
|
||||
void xi_grab_all_mouse_devices(Display *dpy) {
|
||||
xi_grab_all_mouse_devices(dpy, true);
|
||||
}
|
||||
|
||||
void xi_ungrab_all_mouse_devices(Display *dpy) {
|
||||
xi_grab_all_mouse_devices(dpy, false);
|
||||
}
|
||||
|
||||
void xi_warp_all_mouse_devices(Display *dpy, mgl::vec2i position) {
|
||||
if(!dpy)
|
||||
return;
|
||||
|
||||
int num_devices = 0;
|
||||
XIDeviceInfo *info = XIQueryDevice(dpy, XIAllDevices, &num_devices);
|
||||
if(!info)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < num_devices; ++i) {
|
||||
const XIDeviceInfo *dev = &info[i];
|
||||
if(!device_is_mouse(dev))
|
||||
continue;
|
||||
|
||||
XIWarpPointer(dpy, dev->deviceid, DefaultRootWindow(dpy), DefaultRootWindow(dpy), 0, 0, 0, 0, position.x, position.y);
|
||||
}
|
||||
|
||||
XFlush(dpy);
|
||||
XIFreeDeviceInfo(info);
|
||||
}
|
||||
|
||||
void window_set_fullscreen(Display *dpy, Window window, bool fullscreen) {
|
||||
const Atom net_wm_state_atom = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||
const Atom net_wm_state_fullscreen_atom = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
|
||||
XEvent xev;
|
||||
xev.type = ClientMessage;
|
||||
xev.xclient.window = window;
|
||||
xev.xclient.message_type = net_wm_state_atom;
|
||||
xev.xclient.format = 32;
|
||||
xev.xclient.data.l[0] = fullscreen ? 1 : 0;
|
||||
xev.xclient.data.l[1] = net_wm_state_fullscreen_atom;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
xev.xclient.data.l[3] = 1;
|
||||
xev.xclient.data.l[4] = 0;
|
||||
|
||||
if(!XSendEvent(dpy, DefaultRootWindow(dpy), 0, SubstructureRedirectMask | SubstructureNotifyMask, &xev)) {
|
||||
fprintf(stderr, "mgl warning: failed to change window fullscreen state\n");
|
||||
return;
|
||||
}
|
||||
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
bool window_is_fullscreen(Display *display, Window window) {
|
||||
const Atom wm_state_atom = XInternAtom(display, "_NET_WM_STATE", False);
|
||||
const Atom wm_state_fullscreen_atom = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
|
||||
Atom type = None;
|
||||
int format = 0;
|
||||
unsigned long num_items = 0;
|
||||
unsigned long bytes_after = 0;
|
||||
unsigned char *properties = nullptr;
|
||||
if(XGetWindowProperty(display, window, wm_state_atom, 0, 1024, False, XA_ATOM, &type, &format, &num_items, &bytes_after, &properties) < Success) {
|
||||
fprintf(stderr, "Failed to get window wm state property\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!properties)
|
||||
return false;
|
||||
|
||||
bool is_fullscreen = false;
|
||||
Atom *atoms = (Atom*)properties;
|
||||
for(unsigned long i = 0; i < num_items; ++i) {
|
||||
if(atoms[i] == wm_state_fullscreen_atom) {
|
||||
is_fullscreen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XFree(properties);
|
||||
return is_fullscreen;
|
||||
}
|
||||
|
||||
#define _NET_WM_STATE_REMOVE 0
|
||||
#define _NET_WM_STATE_ADD 1
|
||||
#define _NET_WM_STATE_TOGGLE 2
|
||||
|
||||
bool set_window_wm_state(Display *dpy, Window window, Atom atom) {
|
||||
const Atom net_wm_state_atom = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||
|
||||
XClientMessageEvent xclient;
|
||||
memset(&xclient, 0, sizeof(xclient));
|
||||
|
||||
xclient.type = ClientMessage;
|
||||
xclient.window = window;
|
||||
xclient.message_type = net_wm_state_atom;
|
||||
xclient.format = 32;
|
||||
xclient.data.l[0] = _NET_WM_STATE_ADD;
|
||||
xclient.data.l[1] = atom;
|
||||
xclient.data.l[2] = 0;
|
||||
xclient.data.l[3] = 0;
|
||||
xclient.data.l[4] = 0;
|
||||
|
||||
XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent*)&xclient);
|
||||
XFlush(dpy);
|
||||
return true;
|
||||
}
|
||||
|
||||
void make_window_click_through(Display *display, Window window) {
|
||||
XRectangle rect;
|
||||
memset(&rect, 0, sizeof(rect));
|
||||
XserverRegion region = XFixesCreateRegion(display, &rect, 1);
|
||||
XFixesSetWindowShapeRegion(display, window, ShapeInput, 0, 0, region);
|
||||
XFixesDestroyRegion(display, region);
|
||||
}
|
||||
|
||||
bool make_window_sticky(Display *dpy, Window window) {
|
||||
return set_window_wm_state(dpy, window, XInternAtom(dpy, "_NET_WM_STATE_STICKY", False));
|
||||
}
|
||||
|
||||
bool hide_window_from_taskbar(Display *dpy, Window window) {
|
||||
return set_window_wm_state(dpy, window, XInternAtom(dpy, "_NET_WM_STATE_SKIP_TASKBAR", False));
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ namespace gsr {
|
||||
|
||||
mgl::Text title_text("Press a key combination to use for the hotkey \"" + hotkey_configure_action_name + "\":", get_theme().title_font);
|
||||
mgl::Text hotkey_text(configure_hotkey_button->get_text(), get_theme().top_bar_font);
|
||||
mgl::Text description_text("The hotkey has to contain one or more of these keys: Alt, Ctrl, Shift and Super. Press Esc to cancel.", get_theme().body_font);
|
||||
mgl::Text description_text("The hotkey has to contain one or more of these keys: Alt, Ctrl, Shift and Super. Press Esc to cancel or Backspace to remove the hotkey.", get_theme().body_font);
|
||||
const float text_max_width = std::max(title_text.get_bounds().size.x, std::max(hotkey_text.get_bounds().size.x, description_text.get_bounds().size.x));
|
||||
|
||||
const float padding_horizontal = int(get_theme().window_height * 0.01f);
|
||||
@@ -470,6 +470,13 @@ namespace gsr {
|
||||
if(event.key.code == mgl::Keyboard::Escape)
|
||||
return false;
|
||||
|
||||
if(event.key.code == mgl::Keyboard::Backspace) {
|
||||
configure_config_hotkey = {mgl::Keyboard::Unknown, 0};
|
||||
configure_hotkey_button->set_text("");
|
||||
configure_hotkey_stop_and_save();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mgl::Keyboard::key_is_modifier(event.key.code)) {
|
||||
configure_config_hotkey.modifiers |= mgl_modifier_to_hotkey_modifier(event.key.code);
|
||||
configure_hotkey_button->set_text(configure_config_hotkey.to_string());
|
||||
@@ -612,10 +619,12 @@ namespace gsr {
|
||||
ConfigHotkey *config_hotkey = configure_hotkey_get_config_by_active_type();
|
||||
if(config_hotkey_button && config_hotkey) {
|
||||
bool hotkey_used_by_another_action = false;
|
||||
for_each_config_hotkey([&](ConfigHotkey *config_hotkey_item) {
|
||||
if(config_hotkey_item != config_hotkey && *config_hotkey_item == configure_config_hotkey)
|
||||
hotkey_used_by_another_action = true;
|
||||
});
|
||||
if(configure_config_hotkey.key != mgl::Keyboard::Unknown) {
|
||||
for_each_config_hotkey([&](ConfigHotkey *config_hotkey_item) {
|
||||
if(config_hotkey_item != config_hotkey && *config_hotkey_item == configure_config_hotkey)
|
||||
hotkey_used_by_another_action = true;
|
||||
});
|
||||
}
|
||||
|
||||
if(hotkey_used_by_another_action) {
|
||||
const std::string error_msg = "The hotkey \"" + configure_config_hotkey.to_string() + " is already used for something else";
|
||||
|
||||
@@ -38,6 +38,8 @@ namespace gsr {
|
||||
// TODO: Enable this
|
||||
//if(capture_options.window)
|
||||
// record_area_box->add_item("Window", "window");
|
||||
if(capture_options.region)
|
||||
record_area_box->add_item("Region", "region");
|
||||
for(const auto &monitor : capture_options.monitors) {
|
||||
char name[256];
|
||||
snprintf(name, sizeof(name), "Monitor %s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y);
|
||||
@@ -191,8 +193,10 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<ComboBox> ScreenshotSettingsPage::create_image_format_box() {
|
||||
auto box = std::make_unique<ComboBox>(&get_theme().body_font);
|
||||
box->add_item("jpg", "jpg");
|
||||
box->add_item("png", "png");
|
||||
if(gsr_info->supported_image_formats.jpeg)
|
||||
box->add_item("jpg", "jpg");
|
||||
if(gsr_info->supported_image_formats.png)
|
||||
box->add_item("png", "png");
|
||||
image_format_box_ptr = box.get();
|
||||
return box;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ namespace gsr {
|
||||
// TODO: Enable this
|
||||
//if(capture_options.window)
|
||||
// record_area_box->add_item("Window", "window");
|
||||
if(capture_options.region)
|
||||
record_area_box->add_item("Region", "region");
|
||||
if(capture_options.focused)
|
||||
record_area_box->add_item("Follow focused window", "focused");
|
||||
for(const auto &monitor : capture_options.monitors) {
|
||||
@@ -351,14 +353,14 @@ namespace gsr {
|
||||
list->add_widget(std::move(video_bitrate_entry));
|
||||
|
||||
if(type == Type::STREAM) {
|
||||
auto size_mb_label = std::make_unique<Label>(&get_theme().body_font, "1.92MB", get_color_theme().text_color);
|
||||
auto size_mb_label = std::make_unique<Label>(&get_theme().body_font, "1.64MB", get_color_theme().text_color);
|
||||
Label *size_mb_label_ptr = size_mb_label.get();
|
||||
list->add_widget(std::move(size_mb_label));
|
||||
|
||||
video_bitrate_entry_ptr->on_changed = [size_mb_label_ptr](const std::string &text) {
|
||||
const double video_bitrate_mb_per_seconds = (double)atoi(text.c_str()) / 1000LL / 8LL * 1.024;
|
||||
const double video_bitrate_mbits_per_seconds = (double)atoi(text.c_str()) / 1024.0;
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "%.2fMB", video_bitrate_mb_per_seconds);
|
||||
snprintf(buffer, sizeof(buffer), "%.2fMbps", video_bitrate_mbits_per_seconds);
|
||||
size_mb_label_ptr->set_text(buffer);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -294,7 +294,11 @@ static bool keyboard_event_try_add_device_if_keyboard(keyboard_event *self, cons
|
||||
unsigned char key_bits[KEY_MAX/8 + 1] = {0};
|
||||
ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), &key_bits);
|
||||
|
||||
const bool supports_key_events = key_bits[KEY_A/8] & (1 << (KEY_A % 8));
|
||||
const bool supports_key_a = key_bits[KEY_A/8] & (1 << (KEY_A % 8));
|
||||
const bool supports_key_esc = key_bits[KEY_ESC/8] & (1 << (KEY_ESC % 8));
|
||||
const bool supports_key_volume_up = key_bits[KEY_VOLUMEUP/8] & (1 << (KEY_VOLUMEUP % 8));
|
||||
const bool supports_key_events = supports_key_a || supports_key_esc || supports_key_volume_up;
|
||||
|
||||
const bool supports_mouse_events = key_bits[BTN_MOUSE/8] & (1 << (BTN_MOUSE % 8));
|
||||
//const bool supports_touch_events = key_bits[BTN_TOUCH/8] & (1 << (BTN_TOUCH % 8));
|
||||
const bool supports_joystick_events = key_bits[BTN_JOYSTICK/8] & (1 << (BTN_JOYSTICK % 8));
|
||||
|
||||
Reference in New Issue
Block a user