Skip to content

Commit ff62571

Browse files
committed
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 <liuchan3@xiaomi.com>
1 parent 6dce52b commit ff62571

4 files changed

Lines changed: 209 additions & 3 deletions

File tree

‎graphics/input/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ config GRAPHICS_INPUT_TOOL_PRIORITY
5656
---help---
5757
The priority of the input task.
5858

59+
config GRAPHICS_INPUT_TOOL_SCROLL_THRESHOLD
60+
int "Scroll activation threshold"
61+
default 10
62+
range 0 32766
63+
depends on INPUT_MOUSE_WHEEL
64+
---help---
65+
The threshold value that must be exceeded to begin scrolling.
66+
This should match the scroll activation threshold used by
67+
the application receiving the generated events.
68+
5969
endif # GRAPHICS_INPUT_TOOL
6070

6171
menuconfig GRAPHICS_INPUT_GETEVENT

‎graphics/input/generator/input.c‎

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@
3939
#define SWIPE_DEFAULT_DURATION 300
4040
#define DRAG_DEFAULT_DURATION 500
4141
#define BUTTON_LONGPRESS_DEFAULT_DURATION 1000
42+
#define SCROLL_DEFAULT_INTERVAL_MS 30
43+
#define SCROLL_DEFAULT_EVENTS 10
44+
45+
#ifdef CONFIG_GRAPHICS_INPUT_TOOL_SCROLL_THRESHOLD
46+
#define SCROLL_THRESHOLD CONFIG_GRAPHICS_INPUT_TOOL_SCROLL_THRESHOLD
47+
#else
48+
#define SCROLL_THRESHOLD 10
49+
#endif
4250

4351
#define DELAY_MS(ms) usleep((ms) * 1000)
44-
#define ABS(a) ((a) > 0 ? (a) : -(a))
4552

4653
/****************************************************************************
4754
* Private Types
@@ -67,6 +74,7 @@ static int input_help(input_gen_ctx_t ctx, int argc, char **argv);
6774
static int input_sleep(input_gen_ctx_t ctx, int argc, char **argv);
6875
static int input_utouch_tap(input_gen_ctx_t ctx, int argc, char **argv);
6976
static int input_utouch_swipe(input_gen_ctx_t ctx, int argc, char **argv);
77+
static int input_scroll(input_gen_ctx_t ctx, int argc, char **argv);
7078
static int input_wheel(input_gen_ctx_t ctx, int argc, char **argv);
7179

7280
/****************************************************************************
@@ -82,6 +90,7 @@ static const struct input_cmd_s g_input_cmd_list[] =
8290
{"drag", input_utouch_swipe},
8391
{"draganddrop", input_utouch_swipe},
8492
{"button", input_button },
93+
{"scroll", input_scroll },
8594
{"wheel", input_wheel },
8695
{NULL, NULL }
8796
};
@@ -259,6 +268,96 @@ static int input_button(input_gen_ctx_t ctx, int argc, char **argv)
259268
return result;
260269
}
261270

271+
/****************************************************************************
272+
* Name: parse_scroll_value
273+
****************************************************************************/
274+
275+
static int parse_scroll_value(int argc, char **argv, int16_t *value)
276+
{
277+
int i;
278+
279+
*value = 0;
280+
281+
/* Simple form: scroll <value> */
282+
283+
if (argc >= 2 && strncmp(argv[1], "--", 2) != 0)
284+
{
285+
return parse_arg_to_int16(argv[1], value);
286+
}
287+
288+
/* Android-style form: scroll --axis SCROLL,<value> */
289+
290+
for (i = 1; i < argc; i++)
291+
{
292+
if (strcmp(argv[i], "--axis") == 0 && i + 1 < argc)
293+
{
294+
FAR char *arg = argv[i + 1];
295+
FAR char *comma = strchr(arg, ',');
296+
297+
if (comma == NULL)
298+
{
299+
return 1;
300+
}
301+
302+
return parse_arg_to_int16(comma + 1, value);
303+
}
304+
}
305+
306+
return 1;
307+
}
308+
309+
/****************************************************************************
310+
* Name: input_scroll
311+
****************************************************************************/
312+
313+
static int input_scroll(input_gen_ctx_t ctx, int argc, char **argv)
314+
{
315+
int16_t value;
316+
int16_t step;
317+
int16_t sign;
318+
int ret;
319+
320+
if (argc < 2)
321+
{
322+
return -EINVAL;
323+
}
324+
325+
if (parse_scroll_value(argc, argv, &value))
326+
{
327+
return -EINVAL;
328+
}
329+
330+
if (value == 0)
331+
{
332+
return 0;
333+
}
334+
335+
sign = value > 0 ? 1 : -1;
336+
step = MAX(1, abs(value) / SCROLL_DEFAULT_EVENTS);
337+
338+
/* sign and step are unused when input_gen_scroll() is a stub
339+
* (CONFIG_INPUT_MOUSE_WHEEL=n).
340+
*/
341+
342+
UNUSED(sign);
343+
UNUSED(step);
344+
345+
/* Activation: exceed threshold to trigger SCROLL_BEGIN */
346+
347+
ret = input_gen_scroll(ctx, sign * (SCROLL_THRESHOLD + 1),
348+
SCROLL_THRESHOLD + 1, 0);
349+
if (ret < 0)
350+
{
351+
return ret;
352+
}
353+
354+
DELAY_MS(SCROLL_DEFAULT_INTERVAL_MS);
355+
356+
/* Actual scroll events */
357+
358+
return input_gen_scroll(ctx, value, step, SCROLL_DEFAULT_INTERVAL_MS);
359+
}
360+
262361
/****************************************************************************
263362
* Name: input_wheel
264363
****************************************************************************/
@@ -294,6 +393,8 @@ static int input_help(input_gen_ctx_t ctx, int argc, char **argv)
294393
"\tswipe <x1> <y1> <x2> <y2> [duration(ms)]\n"
295394
"\tdrag | draganddrop <x1> <y1> <x2> <y2> [duration(ms)]\n"
296395
"\tbutton <buttonvalue> [duration(ms)]\n"
396+
"\tscroll <value>\n"
397+
"\tscroll --axis SCROLL,<value>\n"
297398
"\twheel <wheelvalue>\n"
298399
"\tduration: Duration of sliding\n"
299400
"\tbuttonvalue: button value in hex format\n"

‎graphics/input/generator/input_gen_event.c‎

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ int input_gen_button_longpress(input_gen_ctx_t ctx, btn_buttonset_t mask,
492492
* Name: input_gen_mouse_wheel
493493
*
494494
* Description:
495-
* Perform a mouse wheel operation.
495+
* Perform a single mouse wheel write operation.
496496
*
497497
* Input Parameters:
498498
* ctx - The input generator context.
@@ -517,6 +517,74 @@ int input_gen_mouse_wheel(input_gen_ctx_t ctx, int16_t wheel)
517517

518518
return input_gen_umouse_write(dev->fd, wheel);
519519
}
520+
521+
/****************************************************************************
522+
* Name: input_gen_scroll
523+
*
524+
* Description:
525+
* Perform a scroll operation by splitting total value into multiple
526+
* writes with timing control.
527+
*
528+
* Input Parameters:
529+
* ctx - The input generator context.
530+
* value - Total scroll value (positive/negative for direction).
531+
* step - Units per write (sign is determined by value).
532+
* If step >= |value|, writes once with full value.
533+
* interval_ms - Delay in milliseconds between each write.
534+
*
535+
* Returned Value:
536+
* Zero (OK) is returned on success. On failure, a negated errno value is
537+
* returned.
538+
*
539+
****************************************************************************/
540+
541+
int input_gen_scroll(input_gen_ctx_t ctx, int16_t value,
542+
int16_t step, uint32_t interval_ms)
543+
{
544+
FAR struct input_gen_dev_s *dev;
545+
int16_t sign;
546+
int32_t remaining;
547+
int16_t chunk;
548+
int ret;
549+
550+
if (value == 0 || step <= 0)
551+
{
552+
return -EINVAL;
553+
}
554+
555+
dev = input_gen_search_dev(ctx, INPUT_GEN_DEV_UMOUSE);
556+
if (dev == NULL)
557+
{
558+
return -ENODEV;
559+
}
560+
561+
sign = value > 0 ? 1 : -1;
562+
remaining = value > 0 ? (int32_t)value : -(int32_t)value;
563+
564+
input_gen_grab(dev);
565+
566+
while (remaining > 0)
567+
{
568+
chunk = remaining >= step ? step : (int16_t)remaining;
569+
ret = input_gen_umouse_write(dev->fd, sign * chunk);
570+
if (ret < 0)
571+
{
572+
goto out;
573+
}
574+
575+
remaining -= chunk;
576+
if (remaining > 0 && interval_ms > 0)
577+
{
578+
usleep(interval_ms * 1000);
579+
}
580+
}
581+
582+
ret = 0;
583+
584+
out:
585+
input_gen_ungrab(dev);
586+
return ret;
587+
}
520588
#endif
521589

522590
/****************************************************************************

‎include/graphics/input_gen.h‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ int input_gen_button_longpress(input_gen_ctx_t ctx, btn_buttonset_t mask,
238238
* Name: input_gen_mouse_wheel
239239
*
240240
* Description:
241-
* Perform a mouse wheel operation.
241+
* Perform a single mouse wheel write operation.
242242
*
243243
* Input Parameters:
244244
* ctx - The input generator context.
@@ -256,6 +256,33 @@ int input_gen_mouse_wheel(input_gen_ctx_t ctx, int16_t wheel);
256256
#define input_gen_mouse_wheel(ctx, wheel) (-ENODEV)
257257
#endif
258258

259+
/****************************************************************************
260+
* Name: input_gen_scroll
261+
*
262+
* Description:
263+
* Perform a scroll operation by splitting total value into multiple
264+
* writes with timing control.
265+
*
266+
* Input Parameters:
267+
* ctx - The input generator context.
268+
* value - Total scroll value (positive/negative for direction).
269+
* step - Units per write (sign is determined by value).
270+
* If step >= |value|, writes once with full value.
271+
* interval_ms - Delay in milliseconds between each write.
272+
*
273+
* Returned Value:
274+
* Zero (OK) is returned on success. On failure, a negated errno value is
275+
* returned.
276+
*
277+
****************************************************************************/
278+
279+
#ifdef CONFIG_INPUT_MOUSE_WHEEL
280+
int input_gen_scroll(input_gen_ctx_t ctx, int16_t value,
281+
int16_t step, uint32_t interval_ms);
282+
#else
283+
#define input_gen_scroll(ctx, value, step, interval_ms) (-ENODEV)
284+
#endif
285+
259286
/****************************************************************************
260287
* Name: input_gen_fill_point
261288
*

0 commit comments

Comments
 (0)