[Concept,v2,05/20] mouse: Replace mouse_press_state_t enum with bool

Message ID 20251007170549.541981-6-sjg@u-boot.org
State New
Headers
Series expo: Complete mouse operation in the EFI app |

Commit Message

Simon Glass Oct. 7, 2025, 5:05 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

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.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Add new patch to replace mouse_press_state_t enum with bool

 drivers/input/mouse-uclass.c |  7 +++----
 include/mouse.h              | 12 +++++-------
 2 files changed, 8 insertions(+), 11 deletions(-)
  

Patch

diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c
index 4ade394d68a..43b6514f926 100644
--- a/drivers/input/mouse-uclass.c
+++ b/drivers/input/mouse-uclass.c
@@ -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) {
diff --git a/include/mouse.h b/include/mouse.h
index 560c7d14587..96b75ae1fa6 100644
--- a/include/mouse.h
+++ b/include/mouse.h
@@ -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;