ref: 4fa9b9a395c8ea38e83d84e0d483fe3a329958ea
parent: c987c7dcb71bb3fd9d5388f5573209ae63f52f38
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue May 2 18:50:11 EDT 2023
sdl2: get the screen size correctly; be more careful when changing physical window size
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -102,6 +102,8 @@
if(npe_sdl_init_input() != 0)
goto err;
npe_sdl.scale = 1;
+ physw = Dx(screen->r);
+ physh = Dy(screen->r);
return 0;
err:
@@ -942,17 +944,23 @@
{
int f, n;
+ if(w == 0 || h == 0)
+ return;
if(physw != w || physh != h){
- physw = w;
- physh = h;
if((f = open("/dev/wctl", OWRITE|OCEXEC)) >= 0){
n = fprint(f, "resize -dx %d -dy %d", w+Borderwidth*2, h+Borderwidth*2);
- close(f);
if(n > 0){
while(getwindow(display, Refnone) != 1)
;
+ physw = w;
+ physh = h;
npe_sdl.fullredraw = 1;
+ }else{
+ fprint(2, "SDL_SetWindowSize: resize: %r\n");
}
+ close(f);
+ }else{
+ fprint(2, "SDL_SetWindowSize: open: %r\n");
}
}
}
@@ -1004,8 +1012,8 @@
if(displayIndex != 0)
return -1;
- mode->w = physw;
- mode->h = physh;
+ mode->w = Dx(display->image->r);
+ mode->h = Dy(display->image->r);
mode->format = SDL_PIXELFORMAT_ARGB8888;
mode->refresh_rate = 0;
@@ -1030,8 +1038,6 @@
SDL_GetDisplayMode(int displayIndex, int modeIndex, SDL_DisplayMode *mode)
{
USED(modeIndex);
- physw = 1280;
- physh = 960;
return SDL_GetDesktopDisplayMode(displayIndex, mode);
}