Skip to content

Commit

Permalink
Forward all clicks by default for UHID/AOA
Browse files Browse the repository at this point in the history
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 <#4727 (comment)>
PR #5022 <#5022>
  • Loading branch information
rom1v committed Jun 24, 2024
1 parent 035d60c commit f5e6b80
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 9 additions & 7 deletions doc/mouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

0 comments on commit f5e6b80

Please sign in to comment.