From: Simon Glass <simon.glass@canonical.com> In tests it is useful to fake a mouse click to check that expo handles it correctly. Create a function for this. Signed-off-by: Simon Glass <simon.glass@canonical.com> --- drivers/input/mouse-uclass.c | 13 +++++++++++++ include/mouse.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c index dea8babf5fe..99de94e68b0 100644 --- a/drivers/input/mouse-uclass.c +++ b/drivers/input/mouse-uclass.c @@ -107,6 +107,19 @@ int mouse_set_video(struct udevice *dev, struct udevice *video_dev) return 0; } +int mouse_queue_click_for_test(struct udevice *dev, int x, int y) +{ + struct mouse_uc_priv *uc_priv = dev_get_uclass_priv(dev); + + uc_priv->click_pending = true; + uc_priv->click_pos.x = x; + uc_priv->click_pos.y = y; + uc_priv->last_pos.x = x; + uc_priv->last_pos.y = y; + + return 0; +} + UCLASS_DRIVER(mouse) = { .id = UCLASS_MOUSE, .name = "mouse", diff --git a/include/mouse.h b/include/mouse.h index 92609cfd0e0..6180a2fc957 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -176,4 +176,18 @@ int mouse_set_ptr_visible(struct udevice *dev, bool visible); */ int mouse_set_video(struct udevice *dev, struct udevice *video_dev); +/** + * mouse_queue_click_for_test() - Queue a click event for testing + * + * This is a back-door function for tests to simulate a mouse click at a + * specific position. The click will be returned by the next call to + * mouse_get_click(). + * + * @dev: Mouse device + * @x: X coordinate of click + * @y: Y coordinate of click + * Returns: 0 if OK, -ve on error + */ +int mouse_queue_click_for_test(struct udevice *dev, int x, int y); + #endif -- 2.43.0