Commit b2510d9cbcfbf81880c38536a6ead327957c113e

Ryan C. Gordon 2016-09-29T23:01:43

x11: fixed incorrect SDL_GetWindowPosition() after resize (thanks, Jason!). Fixes Bugzilla #3272.

diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index 51f2915..dd0287e 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -842,6 +842,20 @@ X11_DispatchEvent(_THIS)
                    xevent.xconfigure.x, xevent.xconfigure.y,
                    xevent.xconfigure.width, xevent.xconfigure.height);
 #endif
+            /* Real configure notify events are relative to the parent, synthetic events are absolute. */
+            if (!xevent.xconfigure.send_event) {
+                unsigned int NumChildren;
+                Window ChildReturn, Root, Parent;
+                Window * Children;
+                /* Translate these coodinates back to relative to root */
+                X11_XQueryTree(data->videodata->display, xevent.xconfigure.window, &Root, &Parent, &Children, &NumChildren);
+                X11_XTranslateCoordinates(xevent.xconfigure.display,
+                                        Parent, DefaultRootWindow(xevent.xconfigure.display),
+                                        xevent.xconfigure.x, xevent.xconfigure.y,
+                                        &xevent.xconfigure.x, &xevent.xconfigure.y,
+                                        &ChildReturn);
+            }
+                
             if (xevent.xconfigure.x != data->last_xconfigure.x ||
                 xevent.xconfigure.y != data->last_xconfigure.y) {
                 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h
index 5e76fe2..30af3f2 100644
--- a/src/video/x11/SDL_x11sym.h
+++ b/src/video/x11/SDL_x11sym.h
@@ -161,6 +161,7 @@ SDL_X11_SYM(SDL_X11_XSynchronizeRetType,XSynchronize,(Display* a,Bool b),(a,b),r
 SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,SDL_X11_XESetWireToEventRetType c),(a,b,c),return)
 SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
 SDL_X11_SYM(void,XRefreshKeyboardMapping,(XMappingEvent *a),(a),)
+SDL_X11_SYM(int,XQueryTree,(Display* a,Window b,Window* c,Window* d,Window** e,unsigned int* f),(a,b,c,d,e,f),return)
 
 #if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
 SDL_X11_SYM(Bool,XGetEventData,(Display* a,XGenericEventCookie* b),(a,b),return)