From 6e9f50ffe464f755eb5756e1c8c36193ead20636 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 14 Jul 2023 11:57:36 +0900 Subject: [PATCH] [vid] Ensure window size gets sent after init This fixes a pile of window size related issues I've seen for a while, but most importantly, some nastiness with division by 0 and segfaults. --- include/QF/vid.h | 3 +++ include/vid_internal.h | 2 +- libs/video/targets/context_x11.c | 13 +------------ libs/video/targets/vid.c | 33 ++++++++++++++++++++++++++------ nq/source/cl_main.c | 2 ++ qw/source/cl_main.c | 2 ++ 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/QF/vid.h b/include/QF/vid.h index 757bd2adf..3c11c202a 100644 --- a/include/QF/vid.h +++ b/include/QF/vid.h @@ -45,6 +45,8 @@ typedef struct { unsigned short *colormap16; // 256 * VID_GRADES size unsigned int *colormap32; // 256 * VID_GRADES size int fullbright; // index of first fullbright color + int x; + int y; unsigned width; unsigned height; int numpages; @@ -71,6 +73,7 @@ void VID_Init_Cvars (void); // the palette data will go away after the call, so it must be copied off if // the video driver will need it again void VID_Init (byte *palette, byte *colormap); +void VID_SendSize (void); void VID_SetPalette (byte *palette, byte *colormap); void VID_SetCaption (const char *text); void VID_SetCursor (bool visible); diff --git a/include/vid_internal.h b/include/vid_internal.h index d99a57525..8231c934c 100644 --- a/include/vid_internal.h +++ b/include/vid_internal.h @@ -38,7 +38,7 @@ extern int vid_system_gamma; extern float vid_gamma; void VID_GetWindowSize (int def_w, int def_h); -void VID_SetWindowSize (int width, int height); +void VID_SetWindow (int x, int y, int width, int height); void VID_InitGamma (const byte *); bool VID_SetGamma (double); diff --git a/libs/video/targets/context_x11.c b/libs/video/targets/context_x11.c index 95b251435..fcebd8326 100644 --- a/libs/video/targets/context_x11.c +++ b/libs/video/targets/context_x11.c @@ -177,18 +177,7 @@ configure_notify (XEvent *event) c->serial, c->send_event, c->event, c->window, c->x, c->y, c->width, c->height, c->border_width, c->above, c->override_redirect); - IE_event_t ie_event = { - .type = ie_app_window, - .when = Sys_LongTime (), - .app_window = { - .xpos = c->x, - .ypos = c->y, - .xlen = c->width, - .ylen = c->height, - }, - }; - IE_Send_Event (&ie_event); - VID_SetWindowSize (c->width, c->height); + VID_SetWindow (c->x, c->y, c->width, c->height); } bool diff --git a/libs/video/targets/vid.c b/libs/video/targets/vid.c index 56195010c..e3b5acad6 100644 --- a/libs/video/targets/vid.c +++ b/libs/video/targets/vid.c @@ -41,6 +41,7 @@ #include "QF/qargs.h" #include "QF/sys.h" #include "QF/va.h" +#include "QF/input/event.h" #include "QF/ui/view.h" #include "compat.h" @@ -149,18 +150,38 @@ VID_GetWindowSize (int def_w, int def_h) viddef.height = vid_height; } +VISIBLE void +VID_SendSize (void) +{ + IE_event_t ie_event = { + .type = ie_app_window, + .when = Sys_LongTime (), + .app_window = { + .xpos = viddef.x, + .ypos = viddef.y, + .xlen = viddef.width, + .ylen = viddef.height, + }, + }; + IE_Send_Event (&ie_event); + if (viddef.onVidResize) { + LISTENER_INVOKE (viddef.onVidResize, &viddef); + } +} + void -VID_SetWindowSize (int width, int height) +VID_SetWindow (int x, int y, int width, int height) { if (width < 0 || height < 0) { - Sys_Error ("VID_SetWindowSize: invalid size: %d, %d", width, height); + Sys_Error ("VID_SetWindow: invalid size: %d, %d", width, height); } - if (width != (int) viddef.width || height != (int) viddef.height) { + if (x != viddef.x || y !=viddef.y + ||width != (int) viddef.width || height != (int) viddef.height) { + viddef.x = x; + viddef.y = y; viddef.width = width; viddef.height = height; - if (viddef.onVidResize) { - LISTENER_INVOKE (viddef.onVidResize, &viddef); - } + VID_SendSize (); } } diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index c24ed6e15..b82c74f77 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -725,6 +725,8 @@ CL_Init (cbuf_t *cbuf) CL_World_Init (); CL_ClearState (); + VID_SendSize (); + V_Init (&cl.viewstate); Cmd_AddCommand ("pointfile", pointfile_f, diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 3a10815d8..51222a43c 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1492,6 +1492,8 @@ CL_Init (void) CL_ClearState (); Pmove_Init (); + VID_SendSize (); + SL_Init (); CL_Skin_Init ();