From patchwork Mon Aug 25 20:40:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 140 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=1756154438; bh=wRDT9DdHK/PHOlJGNt9XL1HergSUOgWy6ATcxw5+aMI=; 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=kNNpIZjTsJJ1cyKm+3rorMMtf9RNWDSIaSrHKh/aCya6gL3RhkLPbgWfWYDsiO203 n53n9Dkxrl0Y4DQcLpPlzWOSRPwO45Jt7nt40lyyrrZb5E2My/gJGPzEyXJCK+yqPt vYbZyu6NC3T4/1RguAiYT/8DCGiYP6CbqLwLes14aQT1QTIN6gZDdaREz0ei07YDNV gGSMs7IMZHzEbnacXyufOKLSW0NxVSHT2D3ujNBQ/oDS4KDec0siZ2cHusoU5ZHAen 3LlvIuqW+7riFBWygxisNtCokBtO6CC92++WAc+LZTrSuFt3yAqnvpqY131k5uH3b5 IzwXFmlbEus2g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8CA8C67797 for ; Mon, 25 Aug 2025 14:40:38 -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 zaXC7vTLNjX6 for ; Mon, 25 Aug 2025 14:40:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756154437; bh=wRDT9DdHK/PHOlJGNt9XL1HergSUOgWy6ATcxw5+aMI=; 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=Sw+tUdhIxpBMEu4upobKb45dF5/0TcU4pbxDnewz+gojZNVLcn2ynxIpR6M+yAeOR /ODIaI81LAvShBUPETrxDS7uRUvtFhpGNBFYzMBjmdAWVDZ5BEpBw9mJEI1sWIwVMK BohtEuVJrb+/PHOS5yKWxJbWmM3v7J9DFo6TGFhKJbv0FZ0fWWiKkG+5XktRqzL97G xP788xqxaWocBg7ks+FAFpM0Te7Vcb+HiFQ0oPLDCqaYly5ZJ0d4bdfj2TytfbKyKI H+DYOmGbhn9ttERPx1D2tz9AGbtTAYA7fuICtLKyrmEyVXD2ipBZm/gS14rqKz1rtJ Ur0w1CAne82MQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A7F3D6779F for ; Mon, 25 Aug 2025 14:40:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756154435; bh=AD3u+9LBYQqAFD8yDCYyRZ0+GwL26HhNiYW8Jy3dR5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uU+UQMHA4Usm3VtK99kRcEQRPE2keU5l37RpX22lqgZluirYEPlfEg1TmAN/D9Aqg 0/cnhuxzrJBzTUBVxF1mRpPG2r2mmpjJQ2qkSMLj8JfVUqKQK+whaGwZERMzzlJWJ2 L+Y85PIo/BDmS8nU0cPLn6qjldw4PRrj/NRDxN++JRKLLqS6slsK05k5MKuDavIpCG PuowJJgpKiW2xBzUL5wzkHuxewRDGhk+LaWfMNhHvguI/YQfuXb7xC6DkrN9Fow9XT 7AuJ4izPGnrwBbTWLdeQr7ogCUndWzT6/wNg4BYE5prK/kxRIWo1gJX0vdRk7ep0JJ x5vR/2a+VRpVA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7F8BB67787; Mon, 25 Aug 2025 14:40: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 0eOf5kWyabRH; Mon, 25 Aug 2025 14:40:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756154435; bh=PmFeBTMsS5rbWNqITKAeMhNI90ZFXbEixXv8sXQA8I4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a+QUmRd4OVoquPVZHOFfOgRjStyUQ8BtHAGbjx/E9LWsbemY+boPgKrP5R/PuY1Nw eHmq0OlMBEWSbEpZF28qj4rEo7QIN5AsGGDnL8+xUR+s5mkDLQsGnRf5mr1NhPSfW4 g9jwf0qp9KKJ1pfnjWfqmRs9+3jelcmgHKoxq4y+bxSl6aB1VNj0Slgqlgvq75S9oW 7OHnwNSjwXyQG+LZEWOpl4lLAbcI2y5PycPlLFV/UuJgSnLt4i3HBZTdkGTiYCw0FS Cj0pZm3QXWFKX0laN/MGGvuy9X06rp+l6JzAwYMhhrR73zaVDDFAggOeULGmfDv+Ug mcriq51HXobQA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F008067709; Mon, 25 Aug 2025 14:40:34 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 25 Aug 2025 14:40:16 -0600 Message-ID: <20250825204022.3655799-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250825204022.3655799-1-sjg@u-boot.org> References: <20250825204022.3655799-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6XHEJEIIBJCG7LRZENJ2VZMI7NNBONTY X-Message-ID-Hash: 6XHEJEIIBJCG7LRZENJ2VZMI7NNBONTY 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 3/6] 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 | 48 ++++++++++++++++++++++++++++++---- arch/sandbox/include/asm/sdl.h | 4 +++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index ed84646bdab..b705e15cf9c 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -67,15 +68,11 @@ 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) { - /* - * We don't want to include cpu_func.h in this file since it uses - * system headers. So add a declation here. - */ - extern void reset_cpu(void); SDL_Event event; while (SDL_PollEvent(&event)) { @@ -84,10 +81,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) { @@ -521,6 +558,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..190b52bd407 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)