diff --git a/app/scrcpy.1 b/app/scrcpy.1 index f9ef3498..6478c9c5 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 c8e25c49..cac196ed 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; @@ -2342,7 +2373,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; @@ -2624,6 +2658,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 d6bf9158..28c65121 100644 --- a/app/src/options.c +++ b/app/src/options.c @@ -71,7 +71,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 1fb61ddf..11cef1b8 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)); @@ -257,7 +263,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 bf7d08a8..9b25ef13 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -688,13 +688,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 139e6fe6..a6b6bda8 100644 --- a/doc/control.md +++ b/doc/control.md @@ -93,11 +93,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