Pass screen instance to mouse capture functions
Using the screen instance or not in these functions is an implementation
detail. Further changes will require the screen instance.
Refs 7848a387c8
PR #3031 <https://github.com/Genymobile/scrcpy/pull/3031>
This commit is contained in:
parent
82a99f69ec
commit
9db42341e4
2 changed files with 30 additions and 22 deletions
|
@ -163,7 +163,8 @@ sc_screen_is_relative_mode(struct sc_screen *screen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sc_screen_set_mouse_capture(bool capture) {
|
sc_screen_set_mouse_capture(struct sc_screen *screen, bool capture) {
|
||||||
|
(void) screen;
|
||||||
if (SDL_SetRelativeMouseMode(capture)) {
|
if (SDL_SetRelativeMouseMode(capture)) {
|
||||||
LOGE("Could not set relative mouse mode to %s: %s",
|
LOGE("Could not set relative mouse mode to %s: %s",
|
||||||
capture ? "true" : "false", SDL_GetError());
|
capture ? "true" : "false", SDL_GetError());
|
||||||
|
@ -171,13 +172,16 @@ sc_screen_set_mouse_capture(bool capture) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
sc_screen_get_mouse_capture(void) {
|
sc_screen_get_mouse_capture(struct sc_screen *screen) {
|
||||||
|
(void) screen;
|
||||||
return SDL_GetRelativeMouseMode();
|
return SDL_GetRelativeMouseMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
sc_screen_toggle_mouse_capture(void) {
|
sc_screen_toggle_mouse_capture(struct sc_screen *screen) {
|
||||||
sc_screen_set_mouse_capture(!sc_screen_get_mouse_capture());
|
(void) screen;
|
||||||
|
bool new_value = !sc_screen_get_mouse_capture(screen);
|
||||||
|
sc_screen_set_mouse_capture(screen, new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -721,7 +725,7 @@ sc_screen_update_frame(struct sc_screen *screen) {
|
||||||
|
|
||||||
if (sc_screen_is_relative_mode(screen)) {
|
if (sc_screen_is_relative_mode(screen)) {
|
||||||
// Capture mouse on start
|
// Capture mouse on start
|
||||||
sc_screen_set_mouse_capture(true);
|
sc_screen_set_mouse_capture(screen, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -834,7 +838,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||||
if (relative_mode) {
|
if (relative_mode) {
|
||||||
sc_screen_set_mouse_capture(false);
|
sc_screen_set_mouse_capture(screen, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -864,7 +868,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||||
if (key == cap) {
|
if (key == cap) {
|
||||||
// A mouse capture key has been pressed then released:
|
// A mouse capture key has been pressed then released:
|
||||||
// toggle the capture mouse mode
|
// toggle the capture mouse mode
|
||||||
sc_screen_toggle_mouse_capture();
|
sc_screen_toggle_mouse_capture(screen);
|
||||||
}
|
}
|
||||||
// Mouse capture keys are never forwarded to the device
|
// Mouse capture keys are never forwarded to the device
|
||||||
return;
|
return;
|
||||||
|
@ -874,7 +878,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
if (relative_mode && !sc_screen_get_mouse_capture()) {
|
if (relative_mode && !sc_screen_get_mouse_capture(screen)) {
|
||||||
// Do not forward to input manager, the mouse will be captured
|
// Do not forward to input manager, the mouse will be captured
|
||||||
// on SDL_MOUSEBUTTONUP
|
// on SDL_MOUSEBUTTONUP
|
||||||
return;
|
return;
|
||||||
|
@ -890,8 +894,8 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if (relative_mode && !sc_screen_get_mouse_capture()) {
|
if (relative_mode && !sc_screen_get_mouse_capture(screen)) {
|
||||||
sc_screen_set_mouse_capture(true);
|
sc_screen_set_mouse_capture(screen, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sc_screen_otg_set_mouse_capture(bool capture) {
|
sc_screen_otg_set_mouse_capture(struct sc_screen_otg *screen, bool capture) {
|
||||||
|
(void) screen;
|
||||||
if (SDL_SetRelativeMouseMode(capture)) {
|
if (SDL_SetRelativeMouseMode(capture)) {
|
||||||
LOGE("Could not set relative mouse mode to %s: %s",
|
LOGE("Could not set relative mouse mode to %s: %s",
|
||||||
capture ? "true" : "false", SDL_GetError());
|
capture ? "true" : "false", SDL_GetError());
|
||||||
|
@ -13,13 +14,16 @@ sc_screen_otg_set_mouse_capture(bool capture) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
sc_screen_otg_get_mouse_capture(void) {
|
sc_screen_otg_get_mouse_capture(struct sc_screen_otg *screen) {
|
||||||
|
(void) screen;
|
||||||
return SDL_GetRelativeMouseMode();
|
return SDL_GetRelativeMouseMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
sc_screen_otg_toggle_mouse_capture(void) {
|
sc_screen_otg_toggle_mouse_capture(struct sc_screen_otg *screen) {
|
||||||
sc_screen_otg_set_mouse_capture(!sc_screen_otg_get_mouse_capture());
|
(void) screen;
|
||||||
|
bool new_value = !sc_screen_otg_get_mouse_capture(screen);
|
||||||
|
sc_screen_otg_set_mouse_capture(screen, new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -86,7 +90,7 @@ sc_screen_otg_init(struct sc_screen_otg *screen,
|
||||||
|
|
||||||
if (screen->mouse) {
|
if (screen->mouse) {
|
||||||
// Capture mouse on start
|
// Capture mouse on start
|
||||||
sc_screen_otg_set_mouse_capture(true);
|
sc_screen_otg_set_mouse_capture(screen, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -198,7 +202,7 @@ sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event) {
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||||
if (screen->mouse) {
|
if (screen->mouse) {
|
||||||
sc_screen_otg_set_mouse_capture(false);
|
sc_screen_otg_set_mouse_capture(screen, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +236,7 @@ sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event) {
|
||||||
if (key == cap) {
|
if (key == cap) {
|
||||||
// A mouse capture key has been pressed then released:
|
// A mouse capture key has been pressed then released:
|
||||||
// toggle the capture mouse mode
|
// toggle the capture mouse mode
|
||||||
sc_screen_otg_toggle_mouse_capture();
|
sc_screen_otg_toggle_mouse_capture(screen);
|
||||||
}
|
}
|
||||||
// Mouse capture keys are never forwarded to the device
|
// Mouse capture keys are never forwarded to the device
|
||||||
return;
|
return;
|
||||||
|
@ -244,26 +248,26 @@ sc_screen_otg_handle_event(struct sc_screen_otg *screen, SDL_Event *event) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
if (screen->mouse && sc_screen_otg_get_mouse_capture()) {
|
if (screen->mouse && sc_screen_otg_get_mouse_capture(screen)) {
|
||||||
sc_screen_otg_process_mouse_motion(screen, &event->motion);
|
sc_screen_otg_process_mouse_motion(screen, &event->motion);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
if (screen->mouse && sc_screen_otg_get_mouse_capture()) {
|
if (screen->mouse && sc_screen_otg_get_mouse_capture(screen)) {
|
||||||
sc_screen_otg_process_mouse_button(screen, &event->button);
|
sc_screen_otg_process_mouse_button(screen, &event->button);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if (screen->mouse) {
|
if (screen->mouse) {
|
||||||
if (sc_screen_otg_get_mouse_capture()) {
|
if (sc_screen_otg_get_mouse_capture(screen)) {
|
||||||
sc_screen_otg_process_mouse_button(screen, &event->button);
|
sc_screen_otg_process_mouse_button(screen, &event->button);
|
||||||
} else {
|
} else {
|
||||||
sc_screen_otg_set_mouse_capture(true);
|
sc_screen_otg_set_mouse_capture(screen, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
if (screen->mouse && sc_screen_otg_get_mouse_capture()) {
|
if (screen->mouse && sc_screen_otg_get_mouse_capture(screen)) {
|
||||||
sc_screen_otg_process_mouse_wheel(screen, &event->wheel);
|
sc_screen_otg_process_mouse_wheel(screen, &event->wheel);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue