From patchwork Tue Oct 7 17:05:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 554 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=1759856796; bh=aPMqsABCVTkGUM1GzbQ4PanJqGFkzGnoamdLZkyaysw=; 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=mdlK3ZA+qqrA97eSEhoiqi4GKoNdx6ayqIFsM2lwY1TGIwUTS0hBsgB+egQSVvEiX 5g4PklcX8KepZZFg8r/K0hWU864Xw4X0n2KrrQRWUuk4NoxXy5d9sN4ZIUuzUmPYLr x7A8xHh2OSj9EG7epyZqwziHBlK21tC4kD4hVGz97szRnCFd3RS4A+mfklvaNhV1TX OiKltfhPfTjwsBXdszXUndtLw/fiu4MBQUunOAiyhvJoP7EJv86f/OcuyhPP/+n2mA zUttmr4Nq4+X3Wc7EDk3QEZ3omi2T7E9jg2oriqvDQCiddnfOoSTK2J752POONAP/G VouZM+j0UccGA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8D3C268013 for ; Tue, 7 Oct 2025 11:06:36 -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 47zrrgB0fZm5 for ; Tue, 7 Oct 2025 11:06:36 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856795; bh=aPMqsABCVTkGUM1GzbQ4PanJqGFkzGnoamdLZkyaysw=; 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=hGFLDb6VXALPyJZ7wk5cQtJHbTUNbtCauQakfytZnxhMWDTdaAMcVRcYlYXNJhJ9j sua46GJLtxsRTaR+s+/jTsoc8pguLufocUtjFqip/zGciVoHtASDJuNkA13VeWm9ZQ XYyWb1sokYcRBxf66jGx0hgRD7XZrD/ROUsAGCKHnGXv/Z8s1xgyvnREAAwIoOCWBy /SPfZIC5OALCTACz6V3KVj1R1zQ2OWJCKPcdHgnycB2G4p3Z9aYyQjzHRb5YrUKh4J 8912MgMezwLVUgiIWCp6soaRI9JC/qewgIABJjdIa2svvV9TvUSLfCb4wW6HrdNU03 3s7l4e7DMR95Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 78AD468015 for ; Tue, 7 Oct 2025 11:06:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856792; bh=pMzt9Vo5WtPY5L3v4fYD00daHsB98QLlQ4csaVriFPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5Vmkp9itnnL6LFrjBLZaGlZ8/27Qn4Dz1GGtCEO4jZdkBfwDQxzkOU9sT9ArK1Wz xFCjSs7Xchmzmm/lO5UbX/MlyM5LbMaI6EZdhcHu4q4HyXU3aLWSXiDFFEMvqHKfi6 OqBSfdL8vltvU8q0sheXE1T4w9vDPebbVxx3MPQIiYw8LRgD8MIt00DcEppkqasJYK UsDiFs1m7F2cOYTifXu9iop098JoXROYf/taGPbdPoXNfC/IXtvGtIoj6B6471MAcW WYthj4tLa/L8GX6nnGinIlgR95NUSi4/XCCGXhLU/CeC9rMZ5pOmLbqW1vxZ5cAAnV L5k0EgKEO7BCA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 89E7267DD0; Tue, 7 Oct 2025 11:06:32 -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 Gl4f6TJBD6bt; Tue, 7 Oct 2025 11:06:32 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856791; bh=C+gAp1jw6qKoF/XK5px/Z968DCqQaT0T6NRj/GI+V/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bXnQLhcYVN2lvudf18bhdCqHObfO/GhCs2pLjK+eatkLK/D5nPdgm1vbY+Nx8fbJv y0nJlNgJibrmmZUqLvGsExGYULSMHJlcXWAVrna0GNYS3zH+0mqP1iUOtc1Aoyg+nS 9V2nAiK9r6DOOhV6dLuSeDpsMAYnAI0jyjZfCXfdG3/46qPkbcVuVYa0FDjdXqYkmi AzHvSYN/LuZLMXrBVaOkIzTAMqwGJh+juPVbQu/lv24vns3xOVFmNsfisk4T2ujNp3 bBwmDpGy0jelEhTfO2Glh9p7fX8kJrn3xggIJhsiMP7fowv6zDVm/Z9bngx7phPNKw LFekgUC8g02Xg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 98A9A67F1E; Tue, 7 Oct 2025 11:06:31 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 7 Oct 2025 11:05:21 -0600 Message-ID: <20251007170549.541981-8-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: REH4CKH5X4IU5PO5VLN6UQCYBL2SEDEG X-Message-ID-Hash: REH4CKH5X4IU5PO5VLN6UQCYBL2SEDEG 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 07/20] mouse: Move click detection into mouse_get_event() 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 Currently mouse_get_click() processes events by calling mouse_get_event() and tracking the press->release transition. But if other code calls mouse_get_event() directly, those button events are consumed and mouse_get_click() never sees them. Fix this by moving the click detection logic into mouse_get_event() itself. Add a click_pending flag to track when a click has been detected, and simplify mouse_get_click() to just check and clear this flag. This ensures clicks are properly registered regardless of whether callers use mouse_get_event() or mouse_get_click(). Co-developed-by: Claude Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to move click detection into mouse_get_event() drivers/input/mouse-uclass.c | 48 +++++++++++++++++------------------- include/mouse.h | 2 ++ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c index 6bfce915e2b..7cbe961af35 100644 --- a/drivers/input/mouse-uclass.c +++ b/drivers/input/mouse-uclass.c @@ -28,10 +28,23 @@ int mouse_get_event(struct udevice *dev, struct mouse_event *evt) uc_priv->last_pos.y = evt->motion.y; } - /* Update last position for button events */ + /* Update last position for button events and detect clicks */ if (evt->type == MOUSE_EV_BUTTON) { uc_priv->last_pos.x = evt->button.x; uc_priv->last_pos.y = evt->button.y; + + /* Process left-button clicks */ + if (evt->button.button == BUTTON_LEFT) { + /* Detect press->release transition (click) */ + if (uc_priv->left_pressed && !evt->button.pressed) { + uc_priv->click_pending = true; + uc_priv->click_pos.x = evt->button.x; + uc_priv->click_pos.y = evt->button.y; + } + + /* Update button state */ + uc_priv->left_pressed = evt->button.pressed; + } } return 0; @@ -41,36 +54,21 @@ int mouse_get_click(struct udevice *dev, struct vid_pos *pos) { struct mouse_uc_priv *uc_priv = dev_get_uclass_priv(dev); struct mouse_event event; - int ret; - /* Get one mouse event */ - ret = mouse_get_event(dev, &event); - if (ret) - return -EAGAIN; /* No event available */ - - /* Only process button events for left button */ - if (event.type == MOUSE_EV_BUTTON && - event.button.button == BUTTON_LEFT) { - bool pending = false; - - /* Detect press->release transition (click) */ - if (uc_priv->left_pressed && !event.button.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_pressed = event.button.pressed; + /* Process all available events until we find a click */ + while (true) { + if (mouse_get_event(dev, &event)) + return -EAGAIN; /* No more events */ - /* If we just detected a click, return it */ - if (pending) { + /* Check if this event resulted in a click */ + if (uc_priv->click_pending) { *pos = uc_priv->click_pos; - return 0; + uc_priv->click_pending = false; + break; } } - return -EAGAIN; + return 0; } int mouse_get_pos(struct udevice *dev, struct vid_pos *pos) diff --git a/include/mouse.h b/include/mouse.h index 62cabf24769..1a3a93801e2 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -31,6 +31,7 @@ enum mouse_state_t { * struct mouse_uc_priv - pre-device private data for mouse uclass * * @left_pressed: True if left button is currently pressed + * @click_pending: True if a click has occurred but not yet retrieved * @click_pos: Position where the click occurred * @last_pos: Last position received from mouse * @video_dev: Video device for coordinate scaling @@ -39,6 +40,7 @@ enum mouse_state_t { */ struct mouse_uc_priv { bool left_pressed; + bool click_pending; struct vid_pos click_pos; struct vid_pos last_pos; struct udevice *video_dev;