mouse: Track last mouse position
Add tracking of the last mouse position received, separate from the click position. This allows callers to query the current mouse position using mouse_get_pos() regardless of whether a click occurred. The position is updated in mouse_get_event() for both motion and button events, ensuring it always reflects the most recent mouse coordinates. This avoid the problem of mouse_get_click() 'swallowing' motion events so that a position change is not noticed, e.g. for showing a pointer. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
int mouse_get_event(struct udevice *dev, struct mouse_event *evt)
|
||||
{
|
||||
struct mouse_uc_priv *uc_priv = dev_get_uclass_priv(dev);
|
||||
struct mouse_ops *ops = mouse_get_ops(dev);
|
||||
int ret;
|
||||
|
||||
@@ -20,6 +21,18 @@ int mouse_get_event(struct udevice *dev, struct mouse_event *evt)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Update last position for motion events */
|
||||
if (evt->type == MOUSE_EV_MOTION) {
|
||||
uc_priv->last_pos.x = evt->motion.x;
|
||||
uc_priv->last_pos.y = evt->motion.y;
|
||||
}
|
||||
|
||||
/* Update last position for button events */
|
||||
if (evt->type == MOUSE_EV_BUTTON) {
|
||||
uc_priv->last_pos.x = evt->button.x;
|
||||
uc_priv->last_pos.y = evt->button.y;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,6 +74,15 @@ int mouse_get_click(struct udevice *dev, struct vid_pos *pos)
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
int mouse_get_pos(struct udevice *dev, struct vid_pos *pos)
|
||||
{
|
||||
struct mouse_uc_priv *uc_priv = dev_get_uclass_priv(dev);
|
||||
|
||||
*pos = uc_priv->last_pos;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UCLASS_DRIVER(mouse) = {
|
||||
.id = UCLASS_MOUSE,
|
||||
.name = "mouse",
|
||||
|
||||
Reference in New Issue
Block a user