Skip to content

Commit

Permalink
Forward all clicks by default for UHID and AOA
Browse files Browse the repository at this point in the history
In relative mouse modes (when the cursor appears on the device), it
makes more sense to forward all clicks (disable HOME/BACK shortcuts on
secondary clicks).

Transform the boolean option --forward-all-clicks into a 3-state option:
 - --forward-all-clicks=true or --forward-all-clicks: enable
 - --forward-all-clicks=false: disable
 - --forward-all-clicks=auto (default): enable only for UHID and AOA

That way, by default, all clicks are forwarded with `scrcpy -M`.

Refs <#4727 (comment)>
PR #4877 <#4877>
  • Loading branch information
rom1v committed Jun 23, 2024
1 parent 0b92692 commit e3edb52
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
9 changes: 8 additions & 1 deletion app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ Do not attempt to use "adb reverse" to connect to the device.

.TP
.B \-\-forward\-all\-clicks
By default, right-click triggers BACK (or POWER on) and middle-click triggers HOME. This option disables these shortcuts and forward the clicks to the device instead.
Two behaviors are possible: either right-click triggers BACK (or POWER on) and middle-click triggers HOME, or these shortcuts are disabled and the clicks are forwarded to the device.

Possible values are "auto" (forward all clicks only for UHID and AOA mouse modes), "true" (fordward all clicks) and "false" (enable shortcuts for right-click and middle-click).

Default is "auto".

Passing the option without argument is equivalent to passing "true".


.TP
.B \-h, \-\-help
Expand Down
51 changes: 47 additions & 4 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,18 @@ static const struct sc_option options[] = {
{
.longopt_id = OPT_FORWARD_ALL_CLICKS,
.longopt = "forward-all-clicks",
.text = "By default, right-click triggers BACK (or POWER on) and "
"middle-click triggers HOME. This option disables these "
"shortcuts and forwards the clicks to the device instead.",
.argdesc = "value",
.optional_arg = true,
.text = "Two behaviors are possible: either right-click triggers BACK "
"(or POWER on) and middle-click triggers HOME, or these "
"shortcuts are disabled and the clicks are forwarded to the "
"device.\n"
"Possible values are \"auto\" (forward all clicks only for "
"UHID and AOA mouse modes), \"true\" (forward all clicks) and "
"\"false\" (enable shortcuts for right and middle clicks).\n"
"Default is \"auto\".\n"
"Passing the option without argument is equivalent to passing "
"\"true\".",
},
{
.shortopt = 'h',
Expand Down Expand Up @@ -1531,6 +1540,28 @@ parse_lock_video_orientation(const char *s,
return false;
}

static bool
parse_forward_all_clicks(const char *s, enum sc_forward_all_clicks *value) {
if (!s || !strcmp(s, "true")) {
*value = SC_FORWARD_ALL_CLICKS_TRUE;
return true;
}

if (!strcmp(s, "false")) {
*value = SC_FORWARD_ALL_CLICKS_FALSE;
return true;
}

if (!strcmp(s, "auto")) {
*value = SC_FORWARD_ALL_CLICKS_AUTO;
return true;
}

LOGE("Unsupported --forward-all-clicks value: %s (expected auto, true or "
"false).", s);
return false;
}

static bool
parse_rotation(const char *s, uint8_t *rotation) {
long value;
Expand Down Expand Up @@ -2322,7 +2353,10 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
}
break;
case OPT_FORWARD_ALL_CLICKS:
opts->forward_all_clicks = true;
if (!parse_forward_all_clicks(optarg,
&opts->forward_all_clicks)) {
return false;
}
break;
case OPT_LEGACY_PASTE:
opts->legacy_paste = true;
Expand Down Expand Up @@ -2608,6 +2642,15 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
LOGE("SDK mouse mode requires video playback. Try --mouse=uhid.");
return false;
}

if (opts->forward_all_clicks == SC_FORWARD_ALL_CLICKS_AUTO) {
// By default, forward all clicks only for UHID and AOA
if (opts->mouse_input_mode == SC_MOUSE_INPUT_MODE_SDK) {
opts->forward_all_clicks = SC_FORWARD_ALL_CLICKS_FALSE;
} else {
opts->forward_all_clicks = SC_FORWARD_ALL_CLICKS_TRUE;
}
}
}

if (otg) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const struct scrcpy_options scrcpy_options_default = {
.force_adb_forward = false,
.disable_screensaver = false,
.forward_key_repeat = true,
.forward_all_clicks = false,
.forward_all_clicks = SC_FORWARD_ALL_CLICKS_AUTO,
.legacy_paste = false,
.power_off_on_close = false,
.clipboard_autosync = true,
Expand Down
8 changes: 7 additions & 1 deletion app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ enum sc_orientation { // v v v
SC_ORIENTATION_FLIP_270, // 1 1 1
};

enum sc_forward_all_clicks {
SC_FORWARD_ALL_CLICKS_AUTO,
SC_FORWARD_ALL_CLICKS_TRUE,
SC_FORWARD_ALL_CLICKS_FALSE,
};

static inline bool
sc_orientation_is_mirror(enum sc_orientation orientation) {
assert(!(orientation & ~7));
Expand Down Expand Up @@ -250,7 +256,7 @@ struct scrcpy_options {
bool force_adb_forward;
bool disable_screensaver;
bool forward_key_repeat;
bool forward_all_clicks;
enum sc_forward_all_clicks forward_all_clicks;
bool legacy_paste;
bool power_off_on_close;
bool clipboard_autosync;
Expand Down
7 changes: 6 additions & 1 deletion app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,18 @@ scrcpy(struct scrcpy_options *options) {
const char *window_title =
options->window_title ? options->window_title : info->device_name;

// The option forward_all_clicks must have been resolved at this point
assert(options->forward_all_clicks != SC_FORWARD_ALL_CLICKS_AUTO);
bool forward_all_clicks =
options->forward_all_clicks == SC_FORWARD_ALL_CLICKS_TRUE;

struct sc_screen_params screen_params = {
.video = options->video_playback,
.controller = controller,
.fp = fp,
.kp = kp,
.mp = mp,
.forward_all_clicks = options->forward_all_clicks,
.forward_all_clicks = forward_all_clicks,
.legacy_paste = options->legacy_paste,
.clipboard_autosync = options->clipboard_autosync,
.shortcut_mods = options->shortcut_mods,
Expand Down
15 changes: 12 additions & 3 deletions doc/control.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,20 @@ This only works for the default mouse mode (`--mouse=sdk`).

## Right-click and middle-click

By default, right-click triggers BACK (or POWER on) and middle-click triggers
HOME. To disable these shortcuts and forward the clicks to the device instead:
Two behaviors are possible:

- either right-click triggers BACK (or POWER on) and middle-click triggers
HOME, or
- these shortcuts are disabled and the clicks are forwarded to the device.

By default, the clicks are forwarded only for UHID and AOA [mouse
modes](mouse.md).

```bash
scrcpy --forward-all-clicks
scrcpy --forward-all-clicks # enable
scrcpy --forward-all-clicks=auto # enable only for UHID and AOA (default)
scrcpy --forward-all-clicks=true # enable (equivalent to no argument)
scrcpy --forward-all-clicks=false # disable
```

## File drop
Expand Down

0 comments on commit e3edb52

Please sign in to comment.