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 65425c1b8ed19212
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
     1.1 --- a/src/video/x11/SDL_x11events.c	Wed Oct 03 12:33:42 2012 -0700
     1.2 +++ b/src/video/x11/SDL_x11events.c	Wed Oct 03 13:37:44 2012 -0700
     1.3 @@ -365,14 +365,22 @@
     1.4          /* Have we been resized or moved? */
     1.5      case ConfigureNotify:{
     1.6  #ifdef DEBUG_XEVENTS
     1.7 -            printf("window %p: ConfigureNotify! (resize: %dx%d)\n", data,
     1.8 +            printf("window %p: ConfigureNotify! (position: %d,%d, size: %dx%d)\n", data,
     1.9 +                   xevent.xconfigure.x, xevent.xconfigure.y,
    1.10                     xevent.xconfigure.width, xevent.xconfigure.height);
    1.11  #endif
    1.12 -            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
    1.13 -                                xevent.xconfigure.x, xevent.xconfigure.y);
    1.14 -            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
    1.15 -                                xevent.xconfigure.width,
    1.16 -                                xevent.xconfigure.height);
    1.17 +            if (xevent.xconfigure.x != data->last_xconfigure.x ||
    1.18 +                xevent.xconfigure.y != data->last_xconfigure.y) {
    1.19 +                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
    1.20 +                                    xevent.xconfigure.x, xevent.xconfigure.y);
    1.21 +            }
    1.22 +            if (xevent.xconfigure.width != data->last_xconfigure.width ||
    1.23 +                xevent.xconfigure.height != data->last_xconfigure.height) {
    1.24 +                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
    1.25 +                                    xevent.xconfigure.width,
    1.26 +                                    xevent.xconfigure.height);
    1.27 +            }
    1.28 +            data->last_xconfigure = xevent.xconfigure;
    1.29          }
    1.30          break;
    1.31  
     2.1 --- a/src/video/x11/SDL_x11window.h	Wed Oct 03 12:33:42 2012 -0700
     2.2 +++ b/src/video/x11/SDL_x11window.h	Wed Oct 03 13:37:44 2012 -0700
     2.3 @@ -55,6 +55,7 @@
     2.4      SDL_bool created;
     2.5      PendingFocusEnum pending_focus;
     2.6      Uint32 pending_focus_time;
     2.7 +    XConfigureEvent last_xconfigure;
     2.8      struct SDL_VideoData *videodata;
     2.9  } SDL_WindowData;
    2.10