mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix unresponsive SDL GUI by handling SDL_QUIT events
@ 2024-10-27  8:17 alaanourali
  2024-10-27  9:35 ` Ahmad Fatoum
  2024-10-28 12:30 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: alaanourali @ 2024-10-27  8:17 UTC (permalink / raw)
  To: barebox; +Cc: A.fatoum, Alaa Ali

From: Alaa Ali <alaanourali@gmail.com>

The SDL GUI in the scanout function can appear unresponsive to the
operating system, as it lacks an event handler. This patch adds a
new function, handle_sdl_events(), which processes SDL events to
ensure the window can respond to close requests.

This addresses issues where Linux might think the SDL window is
unresponsive, allowing it to handle SDL_QUIT events properly and
initiate shutdown.

Signed-off-by: Alaa Ali <alaanourali@gmail.com>
---
 arch/sandbox/os/sdl.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/sandbox/os/sdl.c b/arch/sandbox/os/sdl.c
index 13178abfc0..0fc281b7b8 100644
--- a/arch/sandbox/os/sdl.c
+++ b/arch/sandbox/os/sdl.c
@@ -13,6 +13,15 @@ static void sdl_perror(const char *what)
 	printf("SDL: Could not %s: %s.\n", what, SDL_GetError());
 }
 
+static void handle_sdl_events(void)
+{
+    SDL_Event event;
+    while (SDL_PollEvent(&event)) {
+        if (event.type == SDL_QUIT)
+        	SDL_AtomicSet(&shutdown, true);
+    }
+}
+
 static struct sdl_fb_info info;
 static SDL_atomic_t shutdown;
 SDL_Window *window;
@@ -47,6 +56,7 @@ static int scanout(void *ptr)
 	while (!SDL_AtomicGet(&shutdown)) {
 		SDL_Delay(100);
 
+		handle_sdl_events();  /* Handle events like window close */
 		SDL_UpdateTexture(texture, NULL, buf, surface->pitch);
 		SDL_RenderClear(renderer);
 		SDL_RenderCopy(renderer, texture, NULL, NULL);
-- 
2.43.0




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix unresponsive SDL GUI by handling SDL_QUIT events
  2024-10-27  8:17 [PATCH] Fix unresponsive SDL GUI by handling SDL_QUIT events alaanourali
@ 2024-10-27  9:35 ` Ahmad Fatoum
  2024-10-28 12:30 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-10-27  9:35 UTC (permalink / raw)
  To: alaanourali, barebox; +Cc: A.fatoum

Hi,

alternative title suggestion:

sandbox: sdl: fix unresponsive GUI by handling SDL_QUIT events

You can check git log for individual files to see the style of commit
message titles. No need to resend for just that though, I think.

On 27.10.24 09:17, alaanourali@gmail.com wrote:
> From: Alaa Ali <alaanourali@gmail.com>
> 
> The SDL GUI in the scanout function can appear unresponsive to the
> operating system, as it lacks an event handler. This patch adds a
> new function, handle_sdl_events(), which processes SDL events to
> ensure the window can respond to close requests.
> 
> This addresses issues where Linux might think the SDL window is
> unresponsive, allowing it to handle SDL_QUIT events properly and
> initiate shutdown.
> 
> Signed-off-by: Alaa Ali <alaanourali@gmail.com>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Cheers,
Ahmad

> ---
>  arch/sandbox/os/sdl.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/sandbox/os/sdl.c b/arch/sandbox/os/sdl.c
> index 13178abfc0..0fc281b7b8 100644
> --- a/arch/sandbox/os/sdl.c
> +++ b/arch/sandbox/os/sdl.c
> @@ -13,6 +13,15 @@ static void sdl_perror(const char *what)
>  	printf("SDL: Could not %s: %s.\n", what, SDL_GetError());
>  }
>  
> +static void handle_sdl_events(void)
> +{
> +    SDL_Event event;
> +    while (SDL_PollEvent(&event)) {
> +        if (event.type == SDL_QUIT)
> +        	SDL_AtomicSet(&shutdown, true);
> +    }
> +}
> +
>  static struct sdl_fb_info info;
>  static SDL_atomic_t shutdown;
>  SDL_Window *window;
> @@ -47,6 +56,7 @@ static int scanout(void *ptr)
>  	while (!SDL_AtomicGet(&shutdown)) {
>  		SDL_Delay(100);
>  
> +		handle_sdl_events();  /* Handle events like window close */
>  		SDL_UpdateTexture(texture, NULL, buf, surface->pitch);
>  		SDL_RenderClear(renderer);
>  		SDL_RenderCopy(renderer, texture, NULL, NULL);


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix unresponsive SDL GUI by handling SDL_QUIT events
  2024-10-27  8:17 [PATCH] Fix unresponsive SDL GUI by handling SDL_QUIT events alaanourali
  2024-10-27  9:35 ` Ahmad Fatoum
@ 2024-10-28 12:30 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-10-28 12:30 UTC (permalink / raw)
  To: barebox, alaanourali; +Cc: A.fatoum


On Sun, 27 Oct 2024 11:17:53 +0300, alaanourali@gmail.com wrote:
> The SDL GUI in the scanout function can appear unresponsive to the
> operating system, as it lacks an event handler. This patch adds a
> new function, handle_sdl_events(), which processes SDL events to
> ensure the window can respond to close requests.
> 
> This addresses issues where Linux might think the SDL window is
> unresponsive, allowing it to handle SDL_QUIT events properly and
> initiate shutdown.
> 
> [...]

Applied, thanks!

[1/1] Fix unresponsive SDL GUI by handling SDL_QUIT events
      https://git.pengutronix.de/cgit/barebox/commit/?id=231c906e52df (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-28 12:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-27  8:17 [PATCH] Fix unresponsive SDL GUI by handling SDL_QUIT events alaanourali
2024-10-27  9:35 ` Ahmad Fatoum
2024-10-28 12:30 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox