shithub: npe

Download patch

ref: 4c064ed6565ece34dd6d5194afec9a5f715a301f
parent: 251e5dcb47809aaf3a7f88f5c924b356ee9a991e
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue May 18 07:38:17 EDT 2021

sdl2: keep subevents out of union, reset the entire event on poll

--- a/include/npe/SDL2/SDL_events.h
+++ b/include/npe/SDL2/SDL_events.h
@@ -26,34 +26,32 @@
 
 struct SDL_Event {
 	int type;
-	union {
+	struct {
+		int event;
+	}window;
+	struct {
 		struct {
-			int event;
-		}window;
-		struct {
-			struct {
-				SDL_Scancode scancode;
-				SDL_Keycode sym;
-			}keysym;
-			int repeat;
-		}key;
-		struct {
-			int x, y;
-			int button;
-		}button;
-		struct {
-			int x, y;
-		}motion;
-		struct {
-			char text[SDL_TEXTINPUTEVENT_TEXT_SIZE+1];
-		}text;
-		struct {
-			int x, y;
-		}wheel;
-		struct {
-			char *file;
-		}drop;
-	};
+			SDL_Scancode scancode;
+			SDL_Keycode sym;
+		}keysym;
+		int repeat;
+	}key;
+	struct {
+		int x, y;
+		int button;
+	}button;
+	struct {
+		int x, y;
+	}motion;
+	struct {
+		char text[SDL_TEXTINPUTEVENT_TEXT_SIZE+1];
+	}text;
+	struct {
+		int x, y;
+	}wheel;
+	struct {
+		char *file;
+	}drop;
 };
 
 int SDL_EventState(Uint32, int);
--- a/libnpe_sdl2/events.c
+++ b/libnpe_sdl2/events.c
@@ -76,6 +76,7 @@
 
 	switch(alt(salt)){
 	case Ckey:
+		memset(e, 0, sizeof(*e));
 		recv(salt[Ckeytype].c, &t);
 		if(npe_sdl.textinput && (kmod & ~KMOD_LSHIFT) == 0 && rune >= 0x20 && (rune < KF || rune >= KF+0x1000)){
 			if(t != Rrepeat)
@@ -96,6 +97,7 @@
 		return 1;
 
 	case Cmouse:
+		memset(e, 0, sizeof(*e));
 		e->motion.x = npe_sdl.m.xy.x - screen->r.min.x;
 		e->motion.y = npe_sdl.m.xy.y - screen->r.min.y;
 		if(!eqpt(npe_sdl.m.xy, npe_sdl.om.xy)){
@@ -135,6 +137,7 @@
 		break;
 
 	case Cresize:
+		memset(e, 0, sizeof(*e));
 		npe_sdl.fullredraw = 1;
 		if(getwindow(display, Refnone) < 0){
 			fprint(2, "%r\n");