From patchwork Mon Sep 15 10:46:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 304 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=1757933257; bh=YHfiYQ3vfrqdjEFAZR6fD+BBRlnRg16s7w5NbZMhYPU=; 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=mRSdkOWU5VyX2IRLSuPUCA4HLW84/34EEeygK72Dox37/tB9+R/5/JFyEIP93qgRp QhPSUG1tmJRw89G7EB2hFd1sOoonGfShx1Dh4Uk3Hr/sF1yNNJKzpdG1TmzTvmxb5N du1b4GI5tPTX29O3mGtXVxViDwnLtnpFKZ+beCQmEmIW/Ju7inCo6iE1qtwlelvvg5 kjm2bTUzoui5dETOhk/xxHCdpXtkvA0eaEUeJHF6aEHRUVjskU0f66nlI7uSX0lTHz hwAM3ZwGT4PZDU1l1zioBZBp717WHlhFm/R5byzaRcDETYDPzjHnlo0kwoKcaY+8Mw uz+IR5s4qzC9Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A834A67BB5 for ; Mon, 15 Sep 2025 04:47:37 -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 SnP23wWB_yFT for ; Mon, 15 Sep 2025 04:47:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933257; bh=YHfiYQ3vfrqdjEFAZR6fD+BBRlnRg16s7w5NbZMhYPU=; 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=mRSdkOWU5VyX2IRLSuPUCA4HLW84/34EEeygK72Dox37/tB9+R/5/JFyEIP93qgRp QhPSUG1tmJRw89G7EB2hFd1sOoonGfShx1Dh4Uk3Hr/sF1yNNJKzpdG1TmzTvmxb5N du1b4GI5tPTX29O3mGtXVxViDwnLtnpFKZ+beCQmEmIW/Ju7inCo6iE1qtwlelvvg5 kjm2bTUzoui5dETOhk/xxHCdpXtkvA0eaEUeJHF6aEHRUVjskU0f66nlI7uSX0lTHz hwAM3ZwGT4PZDU1l1zioBZBp717WHlhFm/R5byzaRcDETYDPzjHnlo0kwoKcaY+8Mw uz+IR5s4qzC9Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 49C5167B04 for ; Mon, 15 Sep 2025 04:47:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933255; bh=gAF92bNdTK9cHr2lfOshluGkMNeQg0r8s1w8Qw+HaPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Na9SgGEUrqPzJ/IYbH4D636puDtAEGYRsPR89IR0Wsk5XUrvdsGa1B3BXU/BmFi7r 5oJ4+vmIG7AZI9MD8f2k1TVlH2XzMsFZid6Wexq4D0Vn7dQp0KyCYvxtywYaLfyTjx ChS3QqlXX5zWxhDTxtIwabOa9hHsEsKwQGGkXDHZxbe4MFwziUxie4wqkEXeleK1+X 1C5WHzEPoM/CU7sFFLalj2Oq2t24YgqD443vY9D8wGyF5gN/1yjKo2suVnjADMjtMB A07mmVyNeZn8z4b6GgSCF2LTQ5uD/Taxp0QnBjFxpP5fTEfLBmcpY4vNpQAfUcMz0h 8zxQNwmFZNofw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4FEE867BBC; Mon, 15 Sep 2025 04:47:35 -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 m8Tkv8GCaWsi; Mon, 15 Sep 2025 04:47:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933253; bh=KeTD5IUtLk5S2xsqsUALndGUCzSL9EAGdbS7Sb5/w00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jc1ajGggUpSwQgzIHuKyfF1a8F79ukqP9MKKbokJzdkKZp4zPbJCC/dwJiF0iAyZj Pk5+9DcOWgNjIGPLXn0WJMTVEP362WYLXlhXkhojlRgPcUhwoyn6dGGOTumsaPjQ3B JLKXsIZqfcTbMfIUgaCIOi2Yvhtl2lwC3aVjKxJSiam+74lnV8vzCHwiADgVp5VFO7 nPsAKy8b8nZq7Z2WccKRR/t780gB3fSrqpJZyYZ1usQeFBM5MdmT/DU3TpC7+rxiO6 B4ymVuVMdElZX9eEWubAYBUcPx/XNItuAwxv55EZXKWs1z+ZpO+5cb35IMZmh6GvHu 4MFE1d0Ne0rNw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E128867B04; Mon, 15 Sep 2025 04:47:32 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 15 Sep 2025 04:46:46 -0600 Message-ID: <20250915104705.937780-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915104705.937780-1-sjg@u-boot.org> References: <20250915104705.937780-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: CXF6IAUNEEDIZIMUZIUZMTABV7ULG5X4 X-Message-ID-Hash: CXF6IAUNEEDIZIMUZIUZMTABV7ULG5X4 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/17] sandbox: sdl: Add support for mouse input 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 Allow mouse input to be reported from sandbox using SDL. Signed-off-by: Simon Glass --- arch/sandbox/cpu/sdl.c | 43 ++++++++++++++++++++++++++++++++++ arch/sandbox/include/asm/sdl.h | 9 +++++++ 2 files changed, 52 insertions(+) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index 5a323a607f1..fa431010b11 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -67,6 +68,7 @@ static struct sdl_info { SDL_Renderer *renderer; SDL_Window *screen; int src_depth; + struct mouse_event mouse; } sdl; static void sandbox_sdl_poll_events(void) @@ -84,10 +86,50 @@ static void sandbox_sdl_poll_events(void) puts("LCD window closed - quitting\n"); sysreset_walk(SYSRESET_POWER_OFF); break; + case SDL_MOUSEMOTION: { + struct mouse_event *m = &sdl.mouse; + + m->type = MOUSE_EV_MOTION; + m->motion.state = 0; + m->motion.x = event.motion.x; + m->motion.y = event.motion.y; + m->motion.xrel = event.motion.xrel; + m->motion.yrel = event.motion.yrel; + break; + } + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: { + struct mouse_event *m = &sdl.mouse; + + m->type = MOUSE_EV_BUTTON; + if (event.button.button == SDL_BUTTON_LEFT) + m->button.button = BUTTON_LEFT; + else if (event.button.button == SDL_BUTTON_MIDDLE) + m->button.button = BUTTON_MIDDLE; + else if (event.button.button == SDL_BUTTON_RIGHT) + m->button.button = BUTTON_RIGHT; + m->button.press_state = event.type == + SDL_MOUSEBUTTONDOWN ? + BUTTON_PRESSED : BUTTON_RELEASED; + m->button.x = event.button.x; + m->button.y = event.motion.y; + break; + } } } } +int sandbox_sdl_get_mouse_event(struct mouse_event *evt) +{ + if (sdl.mouse.type == MOUSE_EV_NULL) + return -EAGAIN; + + *evt = sdl.mouse; + sdl.mouse.type = MOUSE_EV_NULL; + + return 0; +} + static int sandbox_sdl_ensure_init(void) { if (!sdl.inited) { @@ -522,6 +564,7 @@ int sandbox_sdl_sound_init(int rate, int channels) sdl.sample_rate = wanted.freq; sdl.cur_buf = 0; sdl.running = false; + sdl.mouse.type = MOUSE_EV_NULL; return 0; diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h index ee4991f7c24..86368c8a0a6 100644 --- a/arch/sandbox/include/asm/sdl.h +++ b/arch/sandbox/include/asm/sdl.h @@ -9,6 +9,8 @@ #include #include +struct mouse_event; + #ifdef CONFIG_SANDBOX_SDL /** @@ -104,6 +106,8 @@ int sandbox_sdl_sound_init(int rate, int channels); */ int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp); +int sandbox_sdl_get_mouse_event(struct mouse_event *evt); + #else static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp, bool double_size) @@ -157,6 +161,11 @@ static inline int sandbox_sdl_set_bpp(struct udevice *dev, return -ENOSYS; } +static inline int sandbox_sdl_get_mouse_event(struct mouse_event *evt) +{ + return -ENODEV; +} + #endif #endif