mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-05-07 23:20:26 +09:00
Add more reliable mouse/keyboard grabbing to fix keyboard input not working in ui in some games
This commit is contained in:
@@ -60,6 +60,7 @@ namespace gsr {
|
|||||||
void xi_setup();
|
void xi_setup();
|
||||||
void handle_xi_events();
|
void handle_xi_events();
|
||||||
void process_key_bindings(mgl::Event &event);
|
void process_key_bindings(mgl::Event &event);
|
||||||
|
void grab_mouse_and_keyboard();
|
||||||
void xi_setup_fake_cursor();
|
void xi_setup_fake_cursor();
|
||||||
void xi_grab_all_devices();
|
void xi_grab_all_devices();
|
||||||
void xi_warp_pointer(mgl::vec2i position);
|
void xi_warp_pointer(mgl::vec2i position);
|
||||||
|
|||||||
@@ -601,6 +601,8 @@ namespace gsr {
|
|||||||
if(!window)
|
if(!window)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
grab_mouse_and_keyboard();
|
||||||
|
|
||||||
//force_window_on_top();
|
//force_window_on_top();
|
||||||
|
|
||||||
window->clear(bg_color);
|
window->clear(bg_color);
|
||||||
@@ -636,6 +638,21 @@ namespace gsr {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Overlay::grab_mouse_and_keyboard() {
|
||||||
|
// TODO: Remove these grabs when debugging with a debugger, or your X11 session will appear frozen.
|
||||||
|
// There should be a debug mode to not use these
|
||||||
|
mgl_context *context = mgl_get_context();
|
||||||
|
Display *display = (Display*)context->connection;
|
||||||
|
XGrabPointer(display, window->get_system_handle(), True,
|
||||||
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
|
||||||
|
Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask |
|
||||||
|
ButtonMotionMask,
|
||||||
|
GrabModeAsync, GrabModeAsync, None, default_cursor, CurrentTime);
|
||||||
|
// TODO: This breaks global hotkeys (when using x11 global hotkeys)
|
||||||
|
XGrabKeyboard(display, window->get_system_handle(), True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||||
|
XFlush(display);
|
||||||
|
}
|
||||||
|
|
||||||
void Overlay::xi_setup_fake_cursor() {
|
void Overlay::xi_setup_fake_cursor() {
|
||||||
if(!xi_display)
|
if(!xi_display)
|
||||||
return;
|
return;
|
||||||
@@ -898,20 +915,10 @@ namespace gsr {
|
|||||||
default_cursor = 0;
|
default_cursor = 0;
|
||||||
}
|
}
|
||||||
default_cursor = XCreateFontCursor(display, XC_arrow);
|
default_cursor = XCreateFontCursor(display, XC_arrow);
|
||||||
|
|
||||||
// TODO: Remove these grabs when debugging with a debugger, or your X11 session will appear frozen.
|
|
||||||
// There should be a debug mode to not use these
|
|
||||||
|
|
||||||
XGrabPointer(display, window->get_system_handle(), True,
|
|
||||||
ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
|
|
||||||
Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask |
|
|
||||||
ButtonMotionMask,
|
|
||||||
GrabModeAsync, GrabModeAsync, None, default_cursor, CurrentTime);
|
|
||||||
// TODO: This breaks global hotkeys (when using x11 global hotkeys)
|
|
||||||
XGrabKeyboard(display, window->get_system_handle(), True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
||||||
|
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
|
|
||||||
|
grab_mouse_and_keyboard();
|
||||||
|
|
||||||
// The real cursor doesn't move when all devices are grabbed, so we create our own cursor and diplay that while grabbed
|
// The real cursor doesn't move when all devices are grabbed, so we create our own cursor and diplay that while grabbed
|
||||||
xi_setup_fake_cursor();
|
xi_setup_fake_cursor();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user