From e3edb522e4d08579256258e64a374255a1ce88be Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 23 Apr 2024 09:42:32 +0200 Subject: [PATCH] Forward all clicks by default for UHID and AOA 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 PR #4877 --- app/scrcpy.1 | 9 ++++++++- app/src/cli.c | 51 +++++++++++++++++++++++++++++++++++++++++++---- app/src/options.c | 2 +- app/src/options.h | 8 +++++++- app/src/scrcpy.c | 7 ++++++- doc/control.md | 15 +++++++++++--- 6 files changed, 81 insertions(+), 11 deletions(-) diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 2be9ef59d6..b17a674afc 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -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 diff --git a/app/src/cli.c b/app/src/cli.c index a0c0b33801..47ebceb02b 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -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', @@ -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; @@ -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; @@ -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) { diff --git a/app/src/options.c b/app/src/options.c index 4b75ed6a81..9ecf1be294 100644 --- a/app/src/options.c +++ b/app/src/options.c @@ -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, diff --git a/app/src/options.h b/app/src/options.h index 85817341c9..22155b8b2c 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -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)); @@ -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; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 5f13ee538c..98935e14da 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -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, diff --git a/doc/control.md b/doc/control.md index 87897894cd..9088f1d057 100644 --- a/doc/control.md +++ b/doc/control.md @@ -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