From f4f0372e57cd954b9e90a580dc4728a0c290d198 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 11 Jan 2025 15:36:00 +0100 Subject: [PATCH 1/3] sdl: Set window title --- libs/graphics/lcd_sdl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/graphics/lcd_sdl.c b/libs/graphics/lcd_sdl.c index 927a205dd..1f646ec16 100644 --- a/libs/graphics/lcd_sdl.c +++ b/libs/graphics/lcd_sdl.c @@ -91,6 +91,7 @@ void lcdInit_SDL(JsGraphics *gfx) { SDL_Quit(); exit(1); } + SDL_WM_SetCaption("Espruino", NULL); } void lcdIdle_SDL() { From ea791c73e420412cce028d676678266d2f062b6c Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 11 Jan 2025 15:42:21 +0100 Subject: [PATCH 2/3] sdl: Add SDL input handling --- libs/graphics/lcd_sdl.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/libs/graphics/lcd_sdl.c b/libs/graphics/lcd_sdl.c index 1f646ec16..22356ed41 100644 --- a/libs/graphics/lcd_sdl.c +++ b/libs/graphics/lcd_sdl.c @@ -14,6 +14,8 @@ #include "platform_config.h" #include "jsutils.h" +#include "jsparse.h" +#include "jsinteractive.h" #include "lcd_sdl.h" #include @@ -95,10 +97,41 @@ void lcdInit_SDL(JsGraphics *gfx) { } void lcdIdle_SDL() { + SDL_Event event; + bool sendEvent = false; + static bool down; + if (needsFlip) { needsFlip = false; SDL_Flip(screen); } + + if (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_MOUSEMOTION: + if (down) { + sendEvent = true; + } + break; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + down = event.type == SDL_MOUSEBUTTONDOWN; + sendEvent = true; + break; + } + } + + if (sendEvent) { + JsVar *E = jsvObjectGetChildIfExists(execInfo.root, "E"); + if (E) { + JsVar *o = jsvNewObject(); + jsvObjectSetChildAndUnLock(o,"x", jsvNewFromInteger(event.button.x)); + jsvObjectSetChildAndUnLock(o,"y", jsvNewFromInteger(event.button.y)); + jsvObjectSetChildAndUnLock(o,"b", jsvNewFromInteger(down?1:0)); + jsiQueueObjectCallbacks(E, JS_EVENT_PREFIX"touch", &o, 1); + jsvUnLock2(E,o); + } + } } void lcdSetCallbacks_SDL(JsGraphics *gfx) { From 19d632ef33b41f8a1971804b3afbb8610ca12296 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 16 Jan 2025 12:29:54 +0100 Subject: [PATCH 3/3] sdl: add quit handling --- libs/graphics/lcd_sdl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/graphics/lcd_sdl.c b/libs/graphics/lcd_sdl.c index 22356ed41..75e9ea9ff 100644 --- a/libs/graphics/lcd_sdl.c +++ b/libs/graphics/lcd_sdl.c @@ -97,9 +97,10 @@ void lcdInit_SDL(JsGraphics *gfx) { } void lcdIdle_SDL() { + static bool down; + extern void nativeQuit(); SDL_Event event; bool sendEvent = false; - static bool down; if (needsFlip) { needsFlip = false; @@ -108,6 +109,9 @@ void lcdIdle_SDL() { if (SDL_PollEvent(&event)) { switch (event.type) { + case SDL_QUIT: + nativeQuit(); + break; case SDL_MOUSEMOTION: if (down) { sendEvent = true;