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",
|
||||
|
||||
@@ -37,10 +37,12 @@ enum mouse_press_state_t {
|
||||
*
|
||||
* @left_button_state: Current state of left button (BUTTON_PRESSED/BUTTON_RELEASED)
|
||||
* @click_pos: Position where the click occurred
|
||||
* @last_pos: Last position received from mouse
|
||||
*/
|
||||
struct mouse_uc_priv {
|
||||
enum mouse_press_state_t left_button_state;
|
||||
struct vid_pos click_pos;
|
||||
struct vid_pos last_pos;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -100,4 +102,13 @@ int mouse_get_event(struct udevice *dev, struct mouse_event *event);
|
||||
*/
|
||||
int mouse_get_click(struct udevice *dev, struct vid_pos *pos);
|
||||
|
||||
/**
|
||||
* mouse_get_pos() - Get the current mouse position
|
||||
*
|
||||
* @dev: Mouse device
|
||||
* @pos: Returns last position
|
||||
* Returns: 0 if position is available, -ve on error
|
||||
*/
|
||||
int mouse_get_pos(struct udevice *dev, struct vid_pos *pos);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user