From patchwork Mon Oct 6 16:54:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 509 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=1759769727; bh=6ix9ma/Y/Pu5LQOzfmuwiVLLsc4N4p82Y+W/0iRt7Fo=; 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=B+4O80rjt2nK6VdWTIdkdMNyUQB+6zAHWtoHI4I2uvtTOZAEen+KN0fz9TTrJtYeR uFBnrfut6g2v0a/xH6LymTgMEd8U7XvOdlga7+rNSTTObzm8K8UU+IFpHB3bBTIVlh KfUeOYfq65Gy25Jnif/ds0i6dbrudgexDu5nzAYjHmmNYzuLmI/8kVJA7KkWc7rU7B kxiphmcfnSyqEsJZooVSbM6IxdaHTek/dhXXsJmPLeVxB58ds1V0swPL1trz20tbgG KIdncE+dS/PvUVoLLtqp2uSGwT+wJ6XCLYwFHrm85DLJNRlpNrUeHhbMI+dID53H9V 5Wdlv7gj/f+uQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3C7D167ECE for ; Mon, 6 Oct 2025 10:55:27 -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 q83EkQ91Mqm0 for ; Mon, 6 Oct 2025 10:55:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759769727; bh=6ix9ma/Y/Pu5LQOzfmuwiVLLsc4N4p82Y+W/0iRt7Fo=; 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=B+4O80rjt2nK6VdWTIdkdMNyUQB+6zAHWtoHI4I2uvtTOZAEen+KN0fz9TTrJtYeR uFBnrfut6g2v0a/xH6LymTgMEd8U7XvOdlga7+rNSTTObzm8K8UU+IFpHB3bBTIVlh KfUeOYfq65Gy25Jnif/ds0i6dbrudgexDu5nzAYjHmmNYzuLmI/8kVJA7KkWc7rU7B kxiphmcfnSyqEsJZooVSbM6IxdaHTek/dhXXsJmPLeVxB58ds1V0swPL1trz20tbgG KIdncE+dS/PvUVoLLtqp2uSGwT+wJ6XCLYwFHrm85DLJNRlpNrUeHhbMI+dID53H9V 5Wdlv7gj/f+uQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2CC3A67F8B for ; Mon, 6 Oct 2025 10:55:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759769725; bh=D9O3vWm3DuSvyCoa/X4H5wlhCsFLNyOXKif/ELeKvD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CQWMJs/ybXiZ6sdT+nMrmTQY0VUYqHi51fmGshvIZq5pary+lzhtyGFqPSK+NQ/3n BaC5ZU2vPCBpbc2PGVOQhu4HSVJKFneX8CU4hxzjj6skp2BpHr+i5NvATzCyEWp2Br ZkYH1qo4S9G6pvpmk9MXPQOaWeBN9ti4Tr2cPj7LraPiFZ7cU0o2/6b2idCZZdFApJ vyuRB3aghhhLPywm9ErA52iYXhjlfbAWaLotmIL+JPWZ+/b3/mB3lnTRiE6ZZbbkqq ESpN0LleVrRqKINWCOIDbs8z51PdWxqpgw8hmSgl90+29CgkOJakFxcFd5pKFnlnf3 u4glXBYuzIOeQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E696567F1D; Mon, 6 Oct 2025 10:55:25 -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 peFuR08pidl3; Mon, 6 Oct 2025 10:55:25 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759769719; bh=JH53SJYN958Onl0a5uuCgit4I6S2Roxh6inmAK4Y7ew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sk/F2fM3ZRK30oPzMYPSf+toTHcMHzFa5U7uRPPY+7fEzlHkT3HpN0lA69sCGbvOp +pVCO9UuhS8NrQbZOCoH451520U43gdiu+f4+TH5QYZLoKZfpQ6FQPwn+MuqkZXw8W K/tDDVolFBmlqAPju+T/oY1K8EyNAq0+T3kfKFB1l8t1F+q8ce0FogKTkU1PZcmEFZ pJFS+qxfEpqx02+cETKysjabnhA5+IY9X9SKJ91ujFli8NIkJZPp/kdEmqaX/Vo2uw kzRiDGYa2xvsmro+oEbxb6FOP6axKoHJPtTcCTOPS9Z9bYwEm22eRxL8eWcwgHTCzk i+75eAxWnNOOQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2846C67F09; Mon, 6 Oct 2025 10:55:19 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 6 Oct 2025 10:54:38 -0600 Message-ID: <20251006165452.1675349-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251006165452.1675349-1-sjg@u-boot.org> References: <20251006165452.1675349-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6YDIYKPGQPC3JCMQ23DVN6JSSWIQX5GM X-Message-ID-Hash: 6YDIYKPGQPC3JCMQ23DVN6JSSWIQX5GM 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 06/14] mouse: Track last mouse position 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 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 Signed-off-by: Simon Glass --- drivers/input/mouse-uclass.c | 22 ++++++++++++++++++++++ include/mouse.h | 11 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c index 1bb836ff59d..ee983397ef3 100644 --- a/drivers/input/mouse-uclass.c +++ b/drivers/input/mouse-uclass.c @@ -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", diff --git a/include/mouse.h b/include/mouse.h index 76f9c789b7b..7fe263b289f 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -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