Ignore old ConfigureNotify events during X11 window resize. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Sun, 21 Aug 2011 11:27:37 -0400
branchSDL-1.2
changeset 5620 ad4ed9f0336f
parent 5619 8e0dd46ad0e0
child 5621 8b2b7f4009e5
Ignore old ConfigureNotify events during X11 window resize. Fixes Bugzilla #1049. Thanks to Andrew Church for the patch!
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11events_c.h
src/video/x11/SDL_x11video.c
--- a/src/video/x11/SDL_x11events.c	Sun Aug 21 10:10:42 2011 -0400
+++ b/src/video/x11/SDL_x11events.c	Sun Aug 21 11:27:37 2011 -0400
@@ -57,6 +57,12 @@
 static SDLKey MISC_keymap[256];
 SDLKey X11_TranslateKeycode(Display *display, KeyCode kc);
 
+/*
+ Pending resize target for ConfigureNotify (so outdated events don't
+ cause inappropriate resize events)
+*/
+int X11_PendingConfigureNotifyWidth = -1;
+int X11_PendingConfigureNotifyHeight = -1;
 
 #ifdef X_HAVE_UTF8_STRING
 Uint32 Utf8ToUcs4(const Uint8 *utf8)
@@ -819,6 +825,16 @@
 #ifdef DEBUG_XEVENTS
 printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);
 #endif
+		if ((X11_PendingConfigureNotifyWidth != -1) &&
+		    (X11_PendingConfigureNotifyHeight != -1)) {
+		    if ((xevent.xconfigure.width != X11_PendingConfigureNotifyWidth) &&
+			(xevent.xconfigure.height != X11_PendingConfigureNotifyHeight)) {
+			    /* Event is from before the resize, so ignore. */
+			    break;
+		    }
+		    X11_PendingConfigureNotifyWidth = -1;
+		    X11_PendingConfigureNotifyHeight = -1;
+		}
 		if ( SDL_VideoSurface ) {
 		    if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
 		        (xevent.xconfigure.height != SDL_VideoSurface->h)) {
--- a/src/video/x11/SDL_x11events_c.h	Sun Aug 21 10:10:42 2011 -0400
+++ b/src/video/x11/SDL_x11events_c.h	Sun Aug 21 11:27:37 2011 -0400
@@ -27,3 +27,8 @@
 extern void X11_InitOSKeymap(_THIS);
 extern void X11_PumpEvents(_THIS);
 extern void X11_SetKeyboardState(Display *display, const char *key_vec);
+
+/* Variables to be exported */
+extern int X11_PendingConfigureNotifyWidth;
+extern int X11_PendingConfigureNotifyHeight;
+
--- a/src/video/x11/SDL_x11video.c	Sun Aug 21 10:10:42 2011 -0400
+++ b/src/video/x11/SDL_x11video.c	Sun Aug 21 11:27:37 2011 -0400
@@ -1161,6 +1161,8 @@
 			current = NULL;
 			goto done;
 		}
+		X11_PendingConfigureNotifyWidth = width;
+		X11_PendingConfigureNotifyHeight = height;
 	} else {
 		if (X11_CreateWindow(this,current,width,height,bpp,flags) < 0) {
 			current = NULL;