aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--TODO8
-rw-r--r--src/Overlay.cpp51
3 files changed, 52 insertions, 8 deletions
diff --git a/README.md b/README.md
index 7a615fa..ce0117a 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,5 @@ If you want to donate you can donate via bitcoin or monero.
* Monero: 4An9kp2qW1C9Gah7ewv4JzcNFQ5TAX7ineGCqXWK6vQnhsGGcRpNgcn8r9EC3tMcgY7vqCKs3nSRXhejMHBaGvFdN2egYet
# Known issues
-* The UI always opens on the same (incorrect) monitor when using multiple monitors on Wayland
* Some games receive mouse input while the UI is open
* Global hotkeys on Wayland can clash with keys used by other applications. This is primarly because Wayland compositors are missing support for global hotkey so this software uses a global hotkey system that works on all Wayland compositors. \ No newline at end of file
diff --git a/TODO b/TODO
index a1cc4dc..e70013e 100644
--- a/TODO
+++ b/TODO
@@ -22,7 +22,7 @@ Add nvidia overclock option.
Add support for window selection in capture.
-Add option to record the focused monitor. This works on wayland too when using kms capture since we can get cursor position without root and see which monitor (crtc) the cursor is on.
+Add option to record the focused monitor. This works on wayland too when using kms capture since we can get cursor position without root and see which monitor (crtc) the cursor is on. Or use create_window_get_center_position.
Make hotkeys configurable.
@@ -76,8 +76,6 @@ Add profile option. Convert view to profile, add an option at the bottom that sa
Verify monitor/audio when starting recording. Give an error if the options are no longer valid.
-Add option to record focused monitor. This is less error prone when plugging in monitors, etc.
-
Get focused window when opening gsr-ui and pass that to the save replay script, to ignore gsr-ui when getting game name.
gsr ui window has _NET_WM_STATE _NET_WM_STATE_ABOVE, not _NET_WM_STATE_FULLSCREEN
@@ -103,4 +101,6 @@ Fix cursor grab not working in owlboy, need to use xigrab.
Dont allow autostart of replay if capture option is window recording (when window recording is added).
-Use global shortcuts desktop portal protocol on wayland when available. \ No newline at end of file
+Use global shortcuts desktop portal protocol on wayland when available.
+
+Use `gpu-screen-recorder --list-capture-options` instead of gsr_info.supported_capture_options.monitors and update it everytime when opening setting page and when starting recording. \ No newline at end of file
diff --git a/src/Overlay.cpp b/src/Overlay.cpp
index 86d87a0..5a2783b 100644
--- a/src/Overlay.cpp
+++ b/src/Overlay.cpp
@@ -285,17 +285,60 @@ namespace gsr {
}
// Returns the first monitor if not found. Assumes there is at least one monitor connected.
- static const mgl_monitor* find_monitor_by_cursor_position(mgl::Window &window) {
+ static const mgl_monitor* find_monitor_at_position(mgl::Window &window, mgl::vec2i pos) {
const mgl_window *win = window.internal_window();
assert(win->num_monitors > 0);
for(int i = 0; i < win->num_monitors; ++i) {
const mgl_monitor *mon = &win->monitors[i];
- if(mgl::IntRect({ mon->pos.x, mon->pos.y }, { mon->size.x, mon->size.y }).contains({ win->cursor_position.x, win->cursor_position.y }))
+ if(mgl::IntRect({ mon->pos.x, mon->pos.y }, { mon->size.x, mon->size.y }).contains(pos))
return mon;
}
return &win->monitors[0];
}
+ static mgl::vec2i create_window_get_center_position(Display *display) {
+ const int screen = DefaultScreen(display);
+ XSetWindowAttributes window_attr;
+ window_attr.event_mask = StructureNotifyMask;
+ const Window window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 32, 32, 0, DefaultDepth(display, screen), InputOutput, DefaultVisual(display, screen), CWEventMask, &window_attr);
+ if(!window)
+ return {0, 0};
+
+ const Atom net_wm_window_type_atom = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
+ const Atom net_wm_window_type_notification_atom = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
+ const Atom net_wm_window_type_utility = XInternAtom(display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
+ const Atom net_wm_window_opacity = XInternAtom(display, "_NET_WM_WINDOW_OPACITY", False);
+
+ const Atom window_type_atoms[2] = {
+ net_wm_window_type_notification_atom,
+ net_wm_window_type_utility
+ };
+ XChangeProperty(display, window, net_wm_window_type_atom, XA_ATOM, 32, PropModeReplace, (const unsigned char*)window_type_atoms, 2L);
+
+ const double alpha = 0.0;
+ const unsigned long opacity = (unsigned long)(0xFFFFFFFFul * alpha);
+ XChangeProperty(display, window, net_wm_window_opacity, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1L);
+
+ XMapWindow(display, window);
+ XFlush(display);
+
+ mgl::vec2i window_pos;
+ XEvent xev;
+ while(true) {
+ XNextEvent(display, &xev);
+ if(xev.type == ConfigureNotify) {
+ window_pos.x = xev.xconfigure.x + xev.xconfigure.width / 2;
+ window_pos.y = xev.xconfigure.y + xev.xconfigure.height / 2;
+ break;
+ }
+ }
+
+ XDestroyWindow(display, window);
+ XFlush(display);
+
+ return window_pos;
+ }
+
static bool is_compositor_running(Display *dpy, int screen) {
char prop_name[20];
snprintf(prop_name, sizeof(prop_name), "_NET_WM_CM_S%d", screen);
@@ -774,7 +817,9 @@ namespace gsr {
return;
}
- const mgl_monitor *focused_monitor = find_monitor_by_cursor_position(*window);
+ // The cursor position is wrong on wayland if an x11 window is not focused. On wayland we instead create a window and get the position where the wayland compositor puts it
+ const mgl::vec2i monitor_position_query_value = gsr_info.system_info.display_server == DisplayServer::WAYLAND ? create_window_get_center_position(display) : mgl::vec2i(win->cursor_position.x, win->cursor_position.y);
+ const mgl_monitor *focused_monitor = find_monitor_at_position(*window, monitor_position_query_value);
window_pos = {focused_monitor->pos.x, focused_monitor->pos.y};
window_size = {focused_monitor->size.x, focused_monitor->size.y};
get_theme().set_window_size(window_size);