shithub: npe

Download patch

ref: cb0be8727657184bc7e3f61125eddef7024b8f38
parent: 090b7a5e6744afa35aa1a8ca66071748c228a776
author: qwx <qwx@sciops.net>
date: Mon Mar 2 19:11:11 EST 2026

sdl2: send size-changed window event on resize instead of just expose

just works in wipeout and nanobsp, which parse those events.
SDL_WINDOWEVENT_SIZE_CHANGED and SDL_WINDOWEVENT_RESIZED are
not strictly equivalent but currently aliased as applications
may be dealing with (or ignoring) any combinations of the two
events.

--- a/libnpe_sdl2/_sdl.h
+++ b/libnpe_sdl2/_sdl.h
@@ -34,3 +34,4 @@
 
 int npe_sdl_init_input(void);
 void *npe_sdl_scale(u32int *src, int iw, int ih, u32int *dst, int ow, int oh);
+int npe_sdl_windowresized(int*, int*);
--- a/libnpe_sdl2/events.c
+++ b/libnpe_sdl2/events.c
@@ -216,11 +216,11 @@
 
 	case Cresize:
 		memset(e, 0, sizeof(*e));
-		npe_sdl.fullredraw = 1;
-		while(getwindow(display, Refnone) != 1)
-			;
 		e->type = SDL_WINDOWEVENT;
-		e->window.event = SDL_WINDOWEVENT_EXPOSED;
+		if(npe_sdl_windowresized(&e->window.data1, &e->window.data2))
+			e->window.event = SDL_WINDOWEVENT_SIZE_CHANGED;
+		else
+			e->window.event = SDL_WINDOWEVENT_EXPOSED;
 		e->window.windowID = 1; //TODO more then one?
 		goto Filter;
 
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -1294,6 +1294,25 @@
 	rect->h = r->logih;
 }
 
+int
+npe_sdl_windowresized(int *w, int *h)
+{
+	int r;
+
+	while(getwindow(display, Refnone) != 1)
+		;
+	npe_sdl.fullredraw = 1;
+	if(r = (Dx(screen->r) != physw || Dy(screen->r) != physh)){
+		physw = Dx(screen->r);
+		physh = Dy(screen->r);
+	}
+	if(w != nil)
+		*w = physw;
+	if(h != nil)
+		*h = physh;
+	return r;
+}
+
 void
 SDL_SetWindowSize(SDL_Window *, int w, int h)
 {
@@ -1305,11 +1324,9 @@
 		if((f = open("/dev/wctl", OWRITE|OCEXEC)) >= 0){
 			n = fprint(f, "resize -dx %d -dy %d", w+Borderwidth*2, h+Borderwidth*2);
 			if(n > 0){
-				while(getwindow(display, Refnone) != 1)
-					;
 				physw = w;
 				physh = h;
-				npe_sdl.fullredraw = 1;
+				npe_sdl_windowresized(nil, nil);
 			}else{
 				fprint(2, "SDL_SetWindowSize: resize: %r\n");
 			}
--