Ignore old ConfigureNotify events during X11 window resize. SDL-1.2
authorRyan C. Gordon
Sun, 21 Aug 2011 11:27:37 -0400
branchSDL-1.2
changeset 5620ad4ed9f0336f
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
     1.1 --- a/src/video/x11/SDL_x11events.c	Sun Aug 21 10:10:42 2011 -0400
     1.2 +++ b/src/video/x11/SDL_x11events.c	Sun Aug 21 11:27:37 2011 -0400
     1.3 @@ -57,6 +57,12 @@
     1.4  static SDLKey MISC_keymap[256];
     1.5  SDLKey X11_TranslateKeycode(Display *display, KeyCode kc);
     1.6  
     1.7 +/*
     1.8 + Pending resize target for ConfigureNotify (so outdated events don't
     1.9 + cause inappropriate resize events)
    1.10 +*/
    1.11 +int X11_PendingConfigureNotifyWidth = -1;
    1.12 +int X11_PendingConfigureNotifyHeight = -1;
    1.13  
    1.14  #ifdef X_HAVE_UTF8_STRING
    1.15  Uint32 Utf8ToUcs4(const Uint8 *utf8)
    1.16 @@ -819,6 +825,16 @@
    1.17  #ifdef DEBUG_XEVENTS
    1.18  printf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);
    1.19  #endif
    1.20 +		if ((X11_PendingConfigureNotifyWidth != -1) &&
    1.21 +		    (X11_PendingConfigureNotifyHeight != -1)) {
    1.22 +		    if ((xevent.xconfigure.width != X11_PendingConfigureNotifyWidth) &&
    1.23 +			(xevent.xconfigure.height != X11_PendingConfigureNotifyHeight)) {
    1.24 +			    /* Event is from before the resize, so ignore. */
    1.25 +			    break;
    1.26 +		    }
    1.27 +		    X11_PendingConfigureNotifyWidth = -1;
    1.28 +		    X11_PendingConfigureNotifyHeight = -1;
    1.29 +		}
    1.30  		if ( SDL_VideoSurface ) {
    1.31  		    if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||
    1.32  		        (xevent.xconfigure.height != SDL_VideoSurface->h)) {
     2.1 --- a/src/video/x11/SDL_x11events_c.h	Sun Aug 21 10:10:42 2011 -0400
     2.2 +++ b/src/video/x11/SDL_x11events_c.h	Sun Aug 21 11:27:37 2011 -0400
     2.3 @@ -27,3 +27,8 @@
     2.4  extern void X11_InitOSKeymap(_THIS);
     2.5  extern void X11_PumpEvents(_THIS);
     2.6  extern void X11_SetKeyboardState(Display *display, const char *key_vec);
     2.7 +
     2.8 +/* Variables to be exported */
     2.9 +extern int X11_PendingConfigureNotifyWidth;
    2.10 +extern int X11_PendingConfigureNotifyHeight;
    2.11 +
     3.1 --- a/src/video/x11/SDL_x11video.c	Sun Aug 21 10:10:42 2011 -0400
     3.2 +++ b/src/video/x11/SDL_x11video.c	Sun Aug 21 11:27:37 2011 -0400
     3.3 @@ -1161,6 +1161,8 @@
     3.4  			current = NULL;
     3.5  			goto done;
     3.6  		}
     3.7 +		X11_PendingConfigureNotifyWidth = width;
     3.8 +		X11_PendingConfigureNotifyHeight = height;
     3.9  	} else {
    3.10  		if (X11_CreateWindow(this,current,width,height,bpp,flags) < 0) {
    3.11  			current = NULL;