From: <au...@us...> - 2012-08-06 01:39:48
|
Revision: 11476 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=11476&view=rev Author: auria Date: 2012-08-06 01:39:42 +0000 (Mon, 06 Aug 2012) Log Message: ----------- On Linux, with regards to feature 'remember window location', make sure to get the coordinate of the window including borders, not coordinates of the contents as was done before, which resulted in the window going down a bit on every launch Modified Paths: -------------- main/trunk/src/graphics/irr_driver.cpp Modified: main/trunk/src/graphics/irr_driver.cpp =================================================================== --- main/trunk/src/graphics/irr_driver.cpp 2012-08-06 01:20:55 UTC (rev 11475) +++ main/trunk/src/graphics/irr_driver.cpp 2012-08-06 01:39:42 UTC (rev 11476) @@ -102,6 +102,41 @@ // ---------------------------------------------------------------------------- +#if defined(__linux__) +/* +Returns the parent window of "window" (i.e. the ancestor of window +that is a direct child of the root, or window itself if it is a direct child). +If window is the root window, returns window. +*/ +X11::Window get_toplevel_parent(X11::Display* display, X11::Window window) +{ + X11::Window parent; + X11::Window root; + X11::Window * children; + unsigned int num_children; + + while (true) + { + if (0 == X11::XQueryTree(display, window, &root, + &parent, &children, &num_children)) + { + fprintf(stderr, "XQueryTree error\n"); + abort(); //change to whatever error handling you prefer + } + if (children) { //must test for null + X11::XFree(children); + } + if (window == root || parent == root) { + return window; + } + else { + window = parent; + } + } +} +#endif + + void IrrDriver::updateConfigIfRelevant() { if (!UserConfigParams::m_fullscreen && UserConfigParams::m_remember_window_location) @@ -138,15 +173,14 @@ #elif defined(__linux__) using namespace X11; const SExposedVideoData& videoData = m_device->getVideoDriver()->getExposedVideoData(); - //XWindowAttributes xwa; - //XGetWindowAttributes((Display*)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.X11Window, &xwa); - int wx = 0, wy = 0; - Window child; - XTranslateCoordinates((Display*)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.X11Window, - DefaultRootWindow((Display*)videoData.OpenGLLinux.X11Display), 0, 0, - &wx, &wy, &child); + Display* display = (Display*)videoData.OpenGLLinux.X11Display; + XWindowAttributes xwa; + XGetWindowAttributes(display, get_toplevel_parent(display, videoData.OpenGLLinux.X11Window), &xwa); + int wx = xwa.x; + int wy = xwa.y; printf("Retrieved window location for config : %i %i\n", wx, wy); - + + if (UserConfigParams::m_window_x != wx || UserConfigParams::m_window_y != wy) { UserConfigParams::m_window_x = wx; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |