From f5e6b8092afd82bab402e7c2c3d00b1719f9bb57 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 24 Jun 2024 23:11:42 +0200 Subject: [PATCH] Forward all clicks by default for UHID/AOA By default, only the left click is forwarded to the device, and secondary clicks trigger shortcuts (the behavior can be configured by --mouse-bind=xxxx). But when the mouse mode is relative (AOA and UHID modes), forward all clicks by default. This makes more sense since the cursor is handled on the device side, the user expects all mouse buttons to be forwarded. Refs PR #5022 --- app/scrcpy.1 | 2 +- app/src/cli.c | 26 +++++++++++++++++++++++++- app/src/input_manager.c | 1 + app/src/options.c | 8 ++++---- app/src/options.h | 1 + doc/mouse.md | 16 +++++++++------- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 7a0b3dfb..b2021f26 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -272,7 +272,7 @@ Each character must be one of the following: - 's': trigger shortcut APP_SWITCH - 'n': trigger shortcut "expand notification panel" -Default is 'bhsn'. +Default is 'bhsn' for SDK mouse, and '++++' for AOA and UHID. .TP diff --git a/app/src/cli.c b/app/src/cli.c index 35230a9a..d3ba3463 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -504,7 +504,7 @@ static const struct sc_option options[] = { " 'h': trigger shortcut HOME\n" " 's': trigger shortcut APP_SWITCH\n" " 'n': trigger shortcut \"expand notification panel\"\n" - "Default is 'bhsn'.", + "Default is 'bhsn' for SDK mouse, and '++++' for AOA and UHID.", }, { .shortopt = 'n', @@ -2690,6 +2690,30 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], } } + // If mouse bindings are not explictly set, configure default bindings + if (opts->mouse_bindings.right_click == SC_MOUSE_BINDING_AUTO) { + assert(opts->mouse_bindings.middle_click == SC_MOUSE_BINDING_AUTO); + assert(opts->mouse_bindings.click4 == SC_MOUSE_BINDING_AUTO); + assert(opts->mouse_bindings.click5 == SC_MOUSE_BINDING_AUTO); + + // By default, forward all clicks only for UHID and AOA + if (opts->mouse_input_mode == SC_MOUSE_INPUT_MODE_SDK) { + opts->mouse_bindings = (struct sc_mouse_bindings) { + .right_click = SC_MOUSE_BINDING_BACK, + .middle_click = SC_MOUSE_BINDING_HOME, + .click4 = SC_MOUSE_BINDING_APP_SWITCH, + .click5 = SC_MOUSE_BINDING_EXPAND_NOTIFICATION_PANEL, + }; + } else { + opts->mouse_bindings = (struct sc_mouse_bindings) { + .right_click = SC_MOUSE_BINDING_CLICK, + .middle_click = SC_MOUSE_BINDING_CLICK, + .click4 = SC_MOUSE_BINDING_CLICK, + .click5 = SC_MOUSE_BINDING_CLICK, + }; + } + } + if (otg) { if (!opts->control) { LOGE("--no-control is not allowed in OTG mode"); diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 3166fbff..43b10d2d 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -753,6 +753,7 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im, enum sc_mouse_binding binding = sc_input_manager_get_binding(&im->mouse_bindings, event->button); + assert(binding != SC_MOUSE_BINDING_AUTO); switch (binding) { case SC_MOUSE_BINDING_DISABLED: // ignore click diff --git a/app/src/options.c b/app/src/options.c index 939108cf..352d9895 100644 --- a/app/src/options.c +++ b/app/src/options.c @@ -24,10 +24,10 @@ const struct scrcpy_options scrcpy_options_default = { .keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_AUTO, .mouse_input_mode = SC_MOUSE_INPUT_MODE_AUTO, .mouse_bindings = { - .right_click = SC_MOUSE_BINDING_BACK, - .middle_click = SC_MOUSE_BINDING_HOME, - .click4 = SC_MOUSE_BINDING_APP_SWITCH, - .click5 = SC_MOUSE_BINDING_EXPAND_NOTIFICATION_PANEL, + .right_click = SC_MOUSE_BINDING_AUTO, + .middle_click = SC_MOUSE_BINDING_AUTO, + .click4 = SC_MOUSE_BINDING_AUTO, + .click5 = SC_MOUSE_BINDING_AUTO, }, .camera_facing = SC_CAMERA_FACING_ANY, .port_range = { diff --git a/app/src/options.h b/app/src/options.h index 17615c75..d5b090b7 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -156,6 +156,7 @@ enum sc_mouse_input_mode { }; enum sc_mouse_binding { + SC_MOUSE_BINDING_AUTO, SC_MOUSE_BINDING_DISABLED, SC_MOUSE_BINDING_CLICK, SC_MOUSE_BINDING_BACK, diff --git a/doc/mouse.md b/doc/mouse.md index 146956f5..42d70766 100644 --- a/doc/mouse.md +++ b/doc/mouse.md @@ -72,12 +72,14 @@ process like the _adb daemon_). ## Mouse bindings -By default, right-click triggers BACK (or POWER on) and middle-click triggers -HOME. In addition, the 4th click triggers APP_SWITCH and the 5th click expands -the notification panel. +By default, with SDK mouse, right-click triggers BACK (or POWER on) and +middle-click triggers HOME. In addition, the 4th click triggers APP_SWITCH and +the 5th click expands the notification panel. -The shortcuts can be configured using `--mouse-bind=xxxx`. The argument must be -exactly 4 characters, one for each secondary click: +In AOA and UHID mouse modes, all clicks are forwarded by default. + +The shortcuts can be configured using `--mouse-bind=xxxx` for any mouse mode. +The argument must be exactly 4 characters, one for each secondary click: ``` --mouse-bind=xxxx @@ -101,8 +103,8 @@ Each character must be one of the following: For example: ```bash -scrcpy --mouse-bind=bhsn # the default mode -scrcpy --mouse-bind=++++ # forward all clicks +scrcpy --mouse-bind=bhsn # the default mode with SDK mouse +scrcpy --mouse-bind=++++ # forward all clicks (default for AOA/UHID) scrcpy --mouse-bind=++bh # forward right and middle clicks, # use 4th and 5th for BACK and HOME ```