Keep track of the configure events we've received from the X server.
authorSam Lantinga <slouken@libsdl.org>
Wed, 03 Oct 2012 13:37:44 -0700
changeset 6542 5c1b8ed19212
parent 6541 be103236441d
child 6543 44a83e1a48f9
Keep track of the configure events we've received from the X server. When programmatically resizing a window on Unity 3D, we'll get a move event with the old size before we get a size event with the new size, and we don't want to clobber our internal state with the old size.
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11window.h
--- a/src/video/x11/SDL_x11events.c	Wed Oct 03 12:33:42 2012 -0700
+++ b/src/video/x11/SDL_x11events.c	Wed Oct 03 13:37:44 2012 -0700
@@ -365,14 +365,22 @@
         /* Have we been resized or moved? */
     case ConfigureNotify:{
 #ifdef DEBUG_XEVENTS
-            printf("window %p: ConfigureNotify! (resize: %dx%d)\n", data,
+            printf("window %p: ConfigureNotify! (position: %d,%d, size: %dx%d)\n", data,
+                   xevent.xconfigure.x, xevent.xconfigure.y,
                    xevent.xconfigure.width, xevent.xconfigure.height);
 #endif
-            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
-                                xevent.xconfigure.x, xevent.xconfigure.y);
-            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
-                                xevent.xconfigure.width,
-                                xevent.xconfigure.height);
+            if (xevent.xconfigure.x != data->last_xconfigure.x ||
+                xevent.xconfigure.y != data->last_xconfigure.y) {
+                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
+                                    xevent.xconfigure.x, xevent.xconfigure.y);
+            }
+            if (xevent.xconfigure.width != data->last_xconfigure.width ||
+                xevent.xconfigure.height != data->last_xconfigure.height) {
+                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
+                                    xevent.xconfigure.width,
+                                    xevent.xconfigure.height);
+            }
+            data->last_xconfigure = xevent.xconfigure;
         }
         break;
 
--- a/src/video/x11/SDL_x11window.h	Wed Oct 03 12:33:42 2012 -0700
+++ b/src/video/x11/SDL_x11window.h	Wed Oct 03 13:37:44 2012 -0700
@@ -55,6 +55,7 @@
     SDL_bool created;
     PendingFocusEnum pending_focus;
     Uint32 pending_focus_time;
+    XConfigureEvent last_xconfigure;
     struct SDL_VideoData *videodata;
 } SDL_WindowData;