From patchwork Tue Oct 7 17:05:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 552 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856793; bh=fyUsW/om7+SbFWcfrjTLbO4laS1KjC8MfRuYOoJ4FeY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=KXCZYFg20x4pfmD3DeN80oyx/GQJdIbGQLiOe13uhvuL2Ek/ozWc4KbOkLbTRFbhP Rx/siFgX9PWaE/RmeAmXyh2lGb+XunW0nypkBABtnxfKu2Tw1NnpatUM7Q/4zHj5Hu DMaPyhj5r4N+VSLfxLVax32M2plD1kaW7bdelX4kunEsYMe9E8AvImHdJe6P24oLF1 7UI01nffkJFRp5uojtkjzFRB58qA6Hg4sEPBeFDuci4/daykE35iRY9EymA97xWA+G M+UNB3e6b517fYJ8lM18tew0bpmN+wyLx7f4jA0VuQHnJZii207JoMdRgrE4hwyTkR +iD82cE5ZCjIg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BEB1C68000 for ; Tue, 7 Oct 2025 11:06:33 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id QY0IV2ZNRLhz for ; Tue, 7 Oct 2025 11:06:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856793; bh=fyUsW/om7+SbFWcfrjTLbO4laS1KjC8MfRuYOoJ4FeY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=KXCZYFg20x4pfmD3DeN80oyx/GQJdIbGQLiOe13uhvuL2Ek/ozWc4KbOkLbTRFbhP Rx/siFgX9PWaE/RmeAmXyh2lGb+XunW0nypkBABtnxfKu2Tw1NnpatUM7Q/4zHj5Hu DMaPyhj5r4N+VSLfxLVax32M2plD1kaW7bdelX4kunEsYMe9E8AvImHdJe6P24oLF1 7UI01nffkJFRp5uojtkjzFRB58qA6Hg4sEPBeFDuci4/daykE35iRY9EymA97xWA+G M+UNB3e6b517fYJ8lM18tew0bpmN+wyLx7f4jA0VuQHnJZii207JoMdRgrE4hwyTkR +iD82cE5ZCjIg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AE1E267EE5 for ; Tue, 7 Oct 2025 11:06:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856791; bh=ROyNTlPe5YyZ3zfpkr236873CWANqSvm87WLkDKsE/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9504q5nV2Tu3/+boptgj5MZehlWmuW2epDkoqrPskInW1h7ceeymXjL71PmX9ReT DxPht2Vfp6/5OMZPGhzz4ft8rj0N/0vRY38nkKQ8RlRpTiL16mcAtaXRWJiYEYwS++ xTszvyihwRACPa7+QdrAiYoqqZg5b+1zcevy1sqk4sAuFBaCSgndqrmxlTtaUoc4cO 5jSDNj0Qyt/sxRVXodoV2izD3gR+jPLy0qy1C3d8gA/4n0YvRzuzHUqpmjn0dyJwf5 wL/RaiDF4/UMEPNo3TqNcF/MKUrta2Aj6xhfngU8/tKMTrpHiX0e0OwIC7lCyuJ8/K KlvOm+eDMXPRQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D00E067F72; Tue, 7 Oct 2025 11:06:31 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id UJYW_sZrv35V; Tue, 7 Oct 2025 11:06:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856786; bh=8JW+FVPY6t1Nl/H5E+NDMil/DV0dJ3h1z7YwFsZ9HXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sirWEhd8wwF55QzG8R5zT4ID9GJ4oo5RR3f2/BtY1KoL86Qawaa9/HI6wdF0aSItb MSCTH/7g4gC9r9yEMrjPvF89G5YH6jWX+tpmSvR84EZtSHl1l3Aa13SELbcyvQreDJ XNIo6E1RfyYS6OsJQMy2FzgElWs4a1AuSS4AZhbzNalpUXHynYLyH0xSP/v/3rKyDX clprQHE/aLi040fRlEuVB96Y2EaSgU2SppJcxDRt9r8DZVdd7WyndE8dWGcIxV59w0 QL6dqHT2fQOfyLbnQJiqIEZ1VmKPf/SrnSctpeQih55Z8+7SXGqgGX/jbzevHgyutf OSeZ/NdpQcXBw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id ACBF967EE5; Tue, 7 Oct 2025 11:06:25 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 7 Oct 2025 11:05:19 -0600 Message-ID: <20251007170549.541981-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251007170549.541981-1-sjg@u-boot.org> References: <20251007170549.541981-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: TX5MVTCO5T2X7LSNLEDXN7JA6I26LAKK X-Message-ID-Hash: TX5MVTCO5T2X7LSNLEDXN7JA6I26LAKK X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 05/20] mouse: Replace mouse_press_state_t enum with bool List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 Signed-off-by: Simon Glass --- 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(-) 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;