Display and control your Android device
Use shortcut mods as mouse capture keys
Romain Vimontff9fb5994dbe
diff --git a/app/src/mouse_capture.c b/app/src/mouse_capture.cindex 1420bad6..ee96ae60 100644--- a/app/src/mouse_capture.c+++ b/app/src/mouse_capture.c@@ -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 modediff --git a/app/src/mouse_capture.h b/app/src/mouse_capture.hindex 53018c19..f352cc13 100644--- a/app/src/mouse_capture.h+++ b/app/src/mouse_capture.h@@ -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);voidsc_mouse_capture_set_active(struct sc_mouse_capture *mc, bool capture);diff --git a/app/src/screen.c b/app/src/screen.cindex 146f10a5..1d694f12 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -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_WORKAROUNDif (screen->video) {diff --git a/app/src/usb/scrcpy_otg.c b/app/src/usb/scrcpy_otg.cindex 9595face..1a7e9544 100644--- a/app/src/usb/scrcpy_otg.c+++ b/app/src/usb/scrcpy_otg.c@@ -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);diff --git a/app/src/usb/screen_otg.c b/app/src/usb/screen_otg.cindex aabb8a7f..18377074 100644--- a/app/src/usb/screen_otg.c+++ b/app/src/usb/screen_otg.c@@ -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 startdiff --git a/app/src/usb/screen_otg.h b/app/src/usb/screen_otg.hindex 850a6ae5..427723ad 100644--- a/app/src/usb/screen_otg.h+++ b/app/src/usb/screen_otg.h@@ -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