Use shortcut mods as mouse capture keys
Instead of using separate hardcoded keys for mouse capture/uncapture, use the shortcut mods. By changing the shortcut mods (for example --shortcut-mod=rctrl), it allows to forward Alt and Super to the device. Fixes #5318 <https://github.com/Genymobile/scrcpy/issues/5318> PR #5322 <https://github.com/Genymobile/scrcpy/pull/5322>
This commit is contained in:
parent
a36de26969
commit
ff9fb5994d
@ -1,16 +1,19 @@
|
||||
#include "mouse_capture.h"
|
||||
|
||||
#include "shortcut_mod.h"
|
||||
#include "util/log.h"
|
||||
|
||||
void
|
||||
sc_mouse_capture_init(struct sc_mouse_capture *mc, SDL_Window *window) {
|
||||
sc_mouse_capture_init(struct sc_mouse_capture *mc, SDL_Window *window,
|
||||
uint8_t shortcut_mods) {
|
||||
mc->window = window;
|
||||
mc->sdl_mouse_capture_keys = sc_shortcut_mods_to_sdl(shortcut_mods);
|
||||
mc->mouse_capture_key_pressed = SDLK_UNKNOWN;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
sc_mouse_capture_is_capture_key(SDL_Keycode key) {
|
||||
return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI;
|
||||
sc_mouse_capture_is_capture_key(struct sc_mouse_capture *mc, SDL_Keycode key) {
|
||||
return sc_shortcut_mods_is_shortcut_key(mc->sdl_mouse_capture_keys, key);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -25,7 +28,7 @@ sc_mouse_capture_handle_event(struct sc_mouse_capture *mc,
|
||||
break;
|
||||
case SDL_KEYDOWN: {
|
||||
SDL_Keycode key = event->key.keysym.sym;
|
||||
if (sc_mouse_capture_is_capture_key(key)) {
|
||||
if (sc_mouse_capture_is_capture_key(mc, key)) {
|
||||
if (!mc->mouse_capture_key_pressed) {
|
||||
mc->mouse_capture_key_pressed = key;
|
||||
} else {
|
||||
@ -42,7 +45,7 @@ sc_mouse_capture_handle_event(struct sc_mouse_capture *mc,
|
||||
SDL_Keycode key = event->key.keysym.sym;
|
||||
SDL_Keycode cap = mc->mouse_capture_key_pressed;
|
||||
mc->mouse_capture_key_pressed = 0;
|
||||
if (sc_mouse_capture_is_capture_key(key)) {
|
||||
if (sc_mouse_capture_is_capture_key(mc, key)) {
|
||||
if (key == cap) {
|
||||
// A mouse capture key has been pressed then released:
|
||||
// toggle the capture mouse mode
|
||||
|
@ -9,14 +9,17 @@
|
||||
|
||||
struct sc_mouse_capture {
|
||||
SDL_Window *window;
|
||||
uint16_t sdl_mouse_capture_keys;
|
||||
|
||||
// To enable/disable mouse capture, a mouse capture key (LALT, LGUI or
|
||||
// RGUI) must be pressed. This variable tracks the pressed capture key.
|
||||
SDL_Keycode mouse_capture_key_pressed;
|
||||
|
||||
};
|
||||
|
||||
void
|
||||
sc_mouse_capture_init(struct sc_mouse_capture *mc, SDL_Window *window);
|
||||
sc_mouse_capture_init(struct sc_mouse_capture *mc, SDL_Window *window,
|
||||
uint8_t shortcut_mods);
|
||||
|
||||
void
|
||||
sc_mouse_capture_set_active(struct sc_mouse_capture *mc, bool capture);
|
||||
|
@ -445,7 +445,7 @@ sc_screen_init(struct sc_screen *screen,
|
||||
sc_input_manager_init(&screen->im, &im_params);
|
||||
|
||||
// Initialize even if not used for simplicity
|
||||
sc_mouse_capture_init(&screen->mc, screen->window);
|
||||
sc_mouse_capture_init(&screen->mc, screen->window, params->shortcut_mods);
|
||||
|
||||
#ifdef CONTINUOUS_RESIZING_WORKAROUND
|
||||
if (screen->video) {
|
||||
|
@ -185,6 +185,7 @@ scrcpy_otg(struct scrcpy_options *options) {
|
||||
.window_width = options->window_width,
|
||||
.window_height = options->window_height,
|
||||
.window_borderless = options->window_borderless,
|
||||
.shortcut_mods = options->shortcut_mods,
|
||||
};
|
||||
|
||||
ok = sc_screen_otg_init(&s->screen_otg, ¶ms);
|
||||
|
@ -70,7 +70,7 @@ sc_screen_otg_init(struct sc_screen_otg *screen,
|
||||
LOGW("Could not load icon");
|
||||
}
|
||||
|
||||
sc_mouse_capture_init(&screen->mc, screen->window);
|
||||
sc_mouse_capture_init(&screen->mc, screen->window, params->shortcut_mods);
|
||||
|
||||
if (screen->mouse) {
|
||||
// Capture mouse on start
|
||||
|
@ -35,6 +35,7 @@ struct sc_screen_otg_params {
|
||||
uint16_t window_width;
|
||||
uint16_t window_height;
|
||||
bool window_borderless;
|
||||
uint8_t shortcut_mods; // OR of enum sc_shortcut_mod values
|
||||
};
|
||||
|
||||
bool
|
||||
|
Loading…
x
Reference in New Issue
Block a user