From: Simon Glass <sjg@chromium.org> Change the API to use struct vid_pos instead of separate x/y pointers. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/expo.c | 9 +++++---- drivers/input/mouse-uclass.c | 8 ++------ include/mouse.h | 5 ++--- test/dm/mouse.c | 29 ++++++++++++++--------------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/boot/expo.c b/boot/expo.c index 00924a19d27..1051133e200 100644 --- a/boot/expo.c +++ b/boot/expo.c @@ -413,18 +413,19 @@ static int poll_keys(struct expo *exp) static int poll_mouse(struct expo *exp, int *xp, int *yp) { - int ret, x, y; + struct vid_pos pos; + int ret; if (!exp->mouse_enabled) return -EAGAIN; /* First check if we have a click available */ - ret = mouse_get_click(exp->mouse, &x, &y); + ret = mouse_get_click(exp->mouse, &pos); if (ret) return log_msg_ret("epm", ret); - *xp = x; - *yp = y; + *xp = pos.x; + *yp = pos.y; return 0; /* Click available */ } diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c index 0e5faccf1e2..1bb836ff59d 100644 --- a/drivers/input/mouse-uclass.c +++ b/drivers/input/mouse-uclass.c @@ -23,7 +23,7 @@ int mouse_get_event(struct udevice *dev, struct mouse_event *evt) return 0; } -int mouse_get_click(struct udevice *dev, int *xp, int *yp) +int mouse_get_click(struct udevice *dev, struct vid_pos *pos) { struct mouse_uc_priv *uc_priv = dev_get_uclass_priv(dev); struct mouse_event event; @@ -53,11 +53,7 @@ int mouse_get_click(struct udevice *dev, int *xp, int *yp) /* If we just detected a click, return it */ if (pending) { - if (xp) - *xp = uc_priv->click_pos.x; - if (yp) - *yp = uc_priv->click_pos.y; - + *pos = uc_priv->click_pos; return 0; } } diff --git a/include/mouse.h b/include/mouse.h index 8e65ac79b94..76f9c789b7b 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -95,10 +95,9 @@ int mouse_get_event(struct udevice *dev, struct mouse_event *event); * mouse_get_click() - Check if a left mouse button click has occurred * * @dev: Mouse device - * @xp: Returns X coordinate of click (can be NULL) - * @yp: Returns Y coordinate of click (can be NULL) + * @pos: Returns position of click * Returns: 0 if a click has occurred, -EAGAIN if no click pending */ -int mouse_get_click(struct udevice *dev, int *xp, int *py); +int mouse_get_click(struct udevice *dev, struct vid_pos *pos); #endif diff --git a/test/dm/mouse.c b/test/dm/mouse.c index 1b4c2b5f60f..3efff4a0d7d 100644 --- a/test/dm/mouse.c +++ b/test/dm/mouse.c @@ -99,7 +99,7 @@ static int dm_test_mouse_click(struct unit_test_state *uts) { struct udevice *dev; struct mouse_event inject; - int x, y; + struct vid_pos pos; ut_assertok(uclass_first_device_err(UCLASS_MOUSE, &dev)); @@ -107,7 +107,7 @@ static int dm_test_mouse_click(struct unit_test_state *uts) sandbox_mouse_set_test_mode(dev, true); /* test that no click is detected initially */ - ut_asserteq(-EAGAIN, mouse_get_click(dev, &x, &y)); + ut_asserteq(-EAGAIN, mouse_get_click(dev, &pos)); /* inject a left button press */ inject.type = MOUSE_EV_BUTTON; @@ -123,7 +123,7 @@ static int dm_test_mouse_click(struct unit_test_state *uts) * calling mouse_get_click() should not detect a click yet (press * only) */ - ut_asserteq(-EAGAIN, mouse_get_click(dev, &x, &y)); + ut_asserteq(-EAGAIN, mouse_get_click(dev, &pos)); /* inject a left button release */ inject.type = MOUSE_EV_BUTTON; @@ -136,12 +136,12 @@ static int dm_test_mouse_click(struct unit_test_state *uts) sandbox_mouse_inject(dev, &inject); /* now mouse_get_click() should detect the click */ - ut_assertok(mouse_get_click(dev, &x, &y)); - ut_asserteq(300, x); - ut_asserteq(400, y); + ut_assertok(mouse_get_click(dev, &pos)); + ut_asserteq(300, pos.x); + ut_asserteq(400, pos.y); /* verify no more clicks are pending */ - ut_asserteq(-EAGAIN, mouse_get_click(dev, &x, &y)); + ut_asserteq(-EAGAIN, mouse_get_click(dev, &pos)); return 0; } @@ -151,6 +151,7 @@ static int dm_test_mouse_click_no_coordinates(struct unit_test_state *uts) { struct udevice *dev; struct mouse_event inject; + struct vid_pos pos; ut_assertok(uclass_first_device_err(UCLASS_MOUSE, &dev)); @@ -167,15 +168,13 @@ static int dm_test_mouse_click_no_coordinates(struct unit_test_state *uts) sandbox_mouse_inject(dev, &inject); /* process the press event */ - ut_asserteq(-EAGAIN, mouse_get_click(dev, NULL, NULL)); + ut_asserteq(-EAGAIN, mouse_get_click(dev, &pos)); inject.button.press_state = BUTTON_RELEASED; sandbox_mouse_inject(dev, &inject); - /* - * now test that click is detected without coordinate return - */ - ut_assertok(mouse_get_click(dev, NULL, NULL)); + /* now test that click is detected (coordinates are ignored) */ + ut_assertok(mouse_get_click(dev, &pos)); return 0; } @@ -185,7 +184,7 @@ static int dm_test_mouse_right_button(struct unit_test_state *uts) { struct udevice *dev; struct mouse_event inject; - int x, y; + struct vid_pos pos; ut_assertok(uclass_first_device_err(UCLASS_MOUSE, &dev)); @@ -204,13 +203,13 @@ static int dm_test_mouse_right_button(struct unit_test_state *uts) inject.button.y = 200; sandbox_mouse_inject(dev, &inject); - ut_asserteq(-EAGAIN, mouse_get_click(dev, &x, &y)); + ut_asserteq(-EAGAIN, mouse_get_click(dev, &pos)); inject.button.press_state = BUTTON_RELEASED; sandbox_mouse_inject(dev, &inject); /* still no click detected since it was right button */ - ut_asserteq(-EAGAIN, mouse_get_click(dev, &x, &y)); + ut_asserteq(-EAGAIN, mouse_get_click(dev, &pos)); return 0; } -- 2.43.0