mouse: Replace mouse_press_state_t enum with bool

Replace the mouse_press_state_t enum with a simpler bool left_pressed
field in mouse_uc_priv. Convert BUTTON_PRESSED/BUTTON_RELEASED to defines
since they're still used in the mouse_event button structure.

This simplifies the code by directly tracking whether the left button
is pressed rather than using an enum to represent a binary state.

Clarify the comment to struct mouse_uc_priv while here.

Series-changes: 2
- Add new patch to replace mouse_press_state_t enum with bool

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-10-07 05:59:41 -06:00
parent fae5a7c0fc
commit 90964bf740
2 changed files with 8 additions and 11 deletions

View File

@@ -51,19 +51,18 @@ int mouse_get_click(struct udevice *dev, struct vid_pos *pos)
/* Only process button events for left button */
if (event.type == MOUSE_EV_BUTTON &&
event.button.button == BUTTON_LEFT) {
enum mouse_press_state_t new_state = event.button.press_state;
bool pressed = event.button.press_state == BUTTON_PRESSED;
bool pending = false;
/* Detect press->release transition (click) */
if (uc_priv->left_button_state == BUTTON_PRESSED &&
new_state == BUTTON_RELEASED) {
if (uc_priv->left_pressed && !pressed) {
pending = true;
uc_priv->click_pos.x = event.button.x;
uc_priv->click_pos.y = event.button.y;
}
/* Update button state */
uc_priv->left_button_state = new_state;
uc_priv->left_pressed = pressed;
/* If we just detected a click, return it */
if (pending) {

View File

@@ -27,15 +27,13 @@ enum mouse_state_t {
BUTTON_SCROLL_MINUS = 1 << 4,
};
enum mouse_press_state_t {
BUTTON_RELEASED = 0,
BUTTON_PRESSED,
};
#define BUTTON_RELEASED 0
#define BUTTON_PRESSED 1
/**
* struct mouse_uc_priv - private data for mouse uclass
* struct mouse_uc_priv - pre-device private data for mouse uclass
*
* @left_button_state: Current state of left button (BUTTON_PRESSED/BUTTON_RELEASED)
* @left_pressed: True if left button is currently pressed
* @click_pos: Position where the click occurred
* @last_pos: Last position received from mouse
* @video_dev: Video device for coordinate scaling
@@ -43,7 +41,7 @@ enum mouse_press_state_t {
* @video_height: Height of video display
*/
struct mouse_uc_priv {
enum mouse_press_state_t left_button_state;
bool left_pressed;
struct vid_pos click_pos;
struct vid_pos last_pos;
struct udevice *video_dev;