This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 10ce31d6e graphics/input: Add scroll command with Android-style syntax.
10ce31d6e is described below
commit 10ce31d6e322c35c4969ae5c103007ec4dbe7516
Author: liuchan3 <[email protected]>
AuthorDate: Tue Apr 28 18:09:17 2026 +0800
graphics/input: Add scroll command with Android-style syntax.
Add input scroll <value> and input scroll --axis SCROLL,<value> to
inject a sequence of mouse wheel reports. Send an initial activation
report followed by paced reports that split the requested value into
smaller steps.
Provide input_gen_scroll() for chunked writes with a configurable
interval and GRAPHICS_INPUT_TOOL_SCROLL_THRESHOLD for applications
that require a scroll activation threshold. Keep the existing wheel
command for a single report.
Assisted-by: OpenCode:claude-opus-5-5
Signed-off-by: liuchan3 <[email protected]>
---
graphics/input/Kconfig | 10 +++
graphics/input/generator/input.c | 107 +++++++++++++++++++++++++++--
graphics/input/generator/input_gen_event.c | 76 +++++++++++++++++++-
include/graphics/input_gen.h | 30 +++++++-
4 files changed, 216 insertions(+), 7 deletions(-)
diff --git a/graphics/input/Kconfig b/graphics/input/Kconfig
index adf754bcb..22e79da30 100644
--- a/graphics/input/Kconfig
+++ b/graphics/input/Kconfig
@@ -56,6 +56,16 @@ config GRAPHICS_INPUT_TOOL_PRIORITY
---help---
The priority of the input task.
+config GRAPHICS_INPUT_TOOL_SCROLL_THRESHOLD
+ int "Scroll activation threshold"
+ default 10
+ range 0 32766
+ depends on INPUT_MOUSE_WHEEL
+ ---help---
+ The threshold value that must be exceeded to begin scrolling.
+ This should match the scroll activation threshold used by
+ the application receiving the generated events.
+
endif # GRAPHICS_INPUT_TOOL
menuconfig GRAPHICS_INPUT_GETEVENT
diff --git a/graphics/input/generator/input.c b/graphics/input/generator/input.c
index a501acfdc..bda41f7c8 100644
--- a/graphics/input/generator/input.c
+++ b/graphics/input/generator/input.c
@@ -39,9 +39,16 @@
#define SWIPE_DEFAULT_DURATION 300
#define DRAG_DEFAULT_DURATION 500
#define BUTTON_LONGPRESS_DEFAULT_DURATION 1000
+#define SCROLL_DEFAULT_INTERVAL_MS 30
+#define SCROLL_DEFAULT_EVENTS 10
+
+#ifdef CONFIG_GRAPHICS_INPUT_TOOL_SCROLL_THRESHOLD
+#define SCROLL_THRESHOLD CONFIG_GRAPHICS_INPUT_TOOL_SCROLL_THRESHOLD
+#else
+#define SCROLL_THRESHOLD 10
+#endif
#define DELAY_MS(ms) usleep((ms) * 1000)
-#define ABS(a) ((a) > 0 ? (a) : -(a))
/****************************************************************************
* Private Types
@@ -67,6 +74,7 @@ static int input_help(input_gen_ctx_t ctx, int argc, char
**argv);
static int input_sleep(input_gen_ctx_t ctx, int argc, char **argv);
static int input_utouch_tap(input_gen_ctx_t ctx, int argc, char **argv);
static int input_utouch_swipe(input_gen_ctx_t ctx, int argc, char **argv);
+static int input_scroll(input_gen_ctx_t ctx, int argc, char **argv);
static int input_wheel(input_gen_ctx_t ctx, int argc, char **argv);
/****************************************************************************
@@ -82,6 +90,7 @@ static const struct input_cmd_s g_input_cmd_list[] =
{"drag", input_utouch_swipe},
{"draganddrop", input_utouch_swipe},
{"button", input_button },
+ {"scroll", input_scroll },
{"wheel", input_wheel },
{NULL, NULL }
};
@@ -101,7 +110,7 @@ static int parse_arg_to_int16(const char *arg, int16_t
*result)
if (!arg || arg[0] == '\0')
{
- return 1;
+ return -EINVAL;
}
errno = 0;
@@ -110,7 +119,7 @@ static int parse_arg_to_int16(const char *arg, int16_t
*result)
if (errno != 0 || *endptr != '\0' || arg == endptr ||
val < -32768 || val > 32767)
{
- return 1;
+ return -EINVAL;
}
*result = (int16_t)val;
@@ -128,7 +137,7 @@ static int parse_arg_to_uint32(const char *arg, uint32_t
*result)
if (!arg || arg[0] == '\0')
{
- return 1;
+ return -EINVAL;
}
errno = 0;
@@ -136,7 +145,7 @@ static int parse_arg_to_uint32(const char *arg, uint32_t
*result)
if (errno != 0 || *endptr != '\0' || arg == endptr || val > UINT32_MAX)
{
- return 1;
+ return -EINVAL;
}
*result = (uint32_t)val;
@@ -259,6 +268,92 @@ static int input_button(input_gen_ctx_t ctx, int argc,
char **argv)
return result;
}
+/****************************************************************************
+ * Name: parse_scroll_value
+ ****************************************************************************/
+
+static int parse_scroll_value(int argc, char **argv, int16_t *value)
+{
+ int i;
+
+ *value = 0;
+
+ /* Simple form: scroll <value> */
+
+ if (argc >= 2 && strncmp(argv[1], "--", 2) != 0)
+ {
+ return parse_arg_to_int16(argv[1], value);
+ }
+
+ /* Android-style form: scroll --axis SCROLL,<value> */
+
+ for (i = 1; i < argc; i++)
+ {
+ if (strcmp(argv[i], "--axis") == 0 && i + 1 < argc)
+ {
+ FAR char *arg = argv[i + 1];
+ FAR char *comma = strchr(arg, ',');
+
+ if (comma == NULL)
+ {
+ return -EINVAL;
+ }
+
+ return parse_arg_to_int16(comma + 1, value);
+ }
+ }
+
+ return -EINVAL;
+}
+
+/****************************************************************************
+ * Name: input_scroll
+ ****************************************************************************/
+
+static int input_scroll(input_gen_ctx_t ctx, int argc, char **argv)
+{
+ int16_t value;
+ int16_t step;
+ int16_t sign;
+ int ret;
+
+ ret = parse_scroll_value(argc, argv, &value);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ if (value == 0)
+ {
+ return 0;
+ }
+
+ sign = value > 0 ? 1 : -1;
+ step = MAX(1, abs(value) / SCROLL_DEFAULT_EVENTS);
+
+ /* sign and step are unused when input_gen_scroll() is a stub
+ * (CONFIG_INPUT_MOUSE_WHEEL=n).
+ */
+
+ UNUSED(sign);
+ UNUSED(step);
+
+ /* Activation: exceed threshold to trigger SCROLL_BEGIN */
+
+ ret = input_gen_scroll(ctx, sign * (SCROLL_THRESHOLD + 1),
+ SCROLL_THRESHOLD + 1, 0);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ DELAY_MS(SCROLL_DEFAULT_INTERVAL_MS);
+
+ /* Actual scroll events */
+
+ return input_gen_scroll(ctx, value, step, SCROLL_DEFAULT_INTERVAL_MS);
+}
+
/****************************************************************************
* Name: input_wheel
****************************************************************************/
@@ -294,6 +389,8 @@ static int input_help(input_gen_ctx_t ctx, int argc, char
**argv)
"\tswipe <x1> <y1> <x2> <y2> [duration(ms)]\n"
"\tdrag | draganddrop <x1> <y1> <x2> <y2> [duration(ms)]\n"
"\tbutton <buttonvalue> [duration(ms)]\n"
+ "\tscroll <value>\n"
+ "\tscroll --axis SCROLL,<value>\n"
"\twheel <wheelvalue>\n"
"\tduration: Duration of sliding\n"
"\tbuttonvalue: button value in hex format\n"
diff --git a/graphics/input/generator/input_gen_event.c
b/graphics/input/generator/input_gen_event.c
index 23399e087..a1c1181c7 100644
--- a/graphics/input/generator/input_gen_event.c
+++ b/graphics/input/generator/input_gen_event.c
@@ -492,7 +492,7 @@ out:
* Name: input_gen_mouse_wheel
*
* Description:
- * Perform a mouse wheel operation.
+ * Perform a single mouse wheel write operation.
*
* Input Parameters:
* ctx - The input generator context.
@@ -517,6 +517,80 @@ int input_gen_mouse_wheel(input_gen_ctx_t ctx, int16_t
wheel)
return input_gen_umouse_write(dev->fd, wheel);
}
+
+/****************************************************************************
+ * Name: input_gen_scroll
+ *
+ * Description:
+ * Perform a scroll operation by splitting total value into multiple
+ * writes with timing control.
+ *
+ * Input Parameters:
+ * ctx - The input generator context.
+ * value - Total scroll value (positive/negative for direction).
+ * Zero sends no reports.
+ * step - Positive number of units per write.
+ * If step >= |value|, writes once with full value.
+ * interval_ms - Delay in milliseconds between each write.
+ *
+ * Returned Value:
+ * Zero (OK) is returned on success. On failure, a negated errno value is
+ * returned.
+ *
+ ****************************************************************************/
+
+int input_gen_scroll(input_gen_ctx_t ctx, int16_t value,
+ int16_t step, uint32_t interval_ms)
+{
+ FAR struct input_gen_dev_s *dev;
+ int16_t sign;
+ int32_t remaining;
+ int16_t chunk;
+ int ret;
+
+ if (step <= 0)
+ {
+ return -EINVAL;
+ }
+
+ if (value == 0)
+ {
+ return 0;
+ }
+
+ dev = input_gen_search_dev(ctx, INPUT_GEN_DEV_UMOUSE);
+ if (dev == NULL)
+ {
+ return -ENODEV;
+ }
+
+ sign = value > 0 ? 1 : -1;
+ remaining = value > 0 ? (int32_t)value : -(int32_t)value;
+
+ input_gen_grab(dev);
+
+ while (remaining > 0)
+ {
+ chunk = remaining >= step ? step : (int16_t)remaining;
+ ret = input_gen_umouse_write(dev->fd, sign * chunk);
+ if (ret < 0)
+ {
+ goto out;
+ }
+
+ remaining -= chunk;
+ if (remaining > 0 && interval_ms > 0)
+ {
+ usleep(interval_ms * 1000);
+ }
+ }
+
+ ret = 0;
+
+out:
+ input_gen_ungrab(dev);
+ return ret;
+}
#endif
/****************************************************************************
diff --git a/include/graphics/input_gen.h b/include/graphics/input_gen.h
index f227ab050..206ebca6a 100644
--- a/include/graphics/input_gen.h
+++ b/include/graphics/input_gen.h
@@ -238,7 +238,7 @@ int input_gen_button_longpress(input_gen_ctx_t ctx,
btn_buttonset_t mask,
* Name: input_gen_mouse_wheel
*
* Description:
- * Perform a mouse wheel operation.
+ * Perform a single mouse wheel write operation.
*
* Input Parameters:
* ctx - The input generator context.
@@ -256,6 +256,34 @@ int input_gen_mouse_wheel(input_gen_ctx_t ctx, int16_t
wheel);
#define input_gen_mouse_wheel(ctx, wheel) (-ENODEV)
#endif
+/****************************************************************************
+ * Name: input_gen_scroll
+ *
+ * Description:
+ * Perform a scroll operation by splitting total value into multiple
+ * writes with timing control.
+ *
+ * Input Parameters:
+ * ctx - The input generator context.
+ * value - Total scroll value (positive/negative for direction).
+ * Zero sends no reports.
+ * step - Positive number of units per write.
+ * If step >= |value|, writes once with full value.
+ * interval_ms - Delay in milliseconds between each write.
+ *
+ * Returned Value:
+ * Zero (OK) is returned on success. On failure, a negated errno value is
+ * returned.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_INPUT_MOUSE_WHEEL
+int input_gen_scroll(input_gen_ctx_t ctx, int16_t value,
+ int16_t step, uint32_t interval_ms);
+#else
+#define input_gen_scroll(ctx, value, step, interval_ms) (-ENODEV)
+#endif
+
/****************************************************************************
* Name: input_gen_fill_point
*