Allow remembering Window position. Useful for multi-monitor setups. Only works for Windows at this time I'm afraid - although the code for Linux is mostly there

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11046 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2012-03-29 01:04:07 +00:00
parent c8e85be0d3
commit 1b85ced4f9
6 changed files with 139 additions and 3 deletions

View File

@ -371,6 +371,16 @@ namespace UserConfigParams
&m_video_group) );
PARAM_PREFIX BoolUserConfigParam m_remember_window_location
PARAM_DEFAULT( BoolUserConfigParam(false, "remember_window_location",
&m_video_group) );
PARAM_PREFIX IntUserConfigParam m_window_x
PARAM_DEFAULT( IntUserConfigParam(-1, "window_x",
&m_video_group,"If remember_window_location is true") );
PARAM_PREFIX IntUserConfigParam m_window_y
PARAM_DEFAULT( IntUserConfigParam(-1, "window_y",
&m_video_group,"If remember_window_location is true") );
PARAM_PREFIX BoolUserConfigParam m_display_fps
PARAM_DEFAULT( BoolUserConfigParam(false, "show_fps",
&m_video_group, "Display frame per seconds") );

View File

@ -54,6 +54,15 @@ using namespace irr::video;
# define round(x) (floor(x+0.5f))
#endif
#ifdef WIN32
#include <Windows.h>
#endif
#if defined(__linux__)
namespace X11
{
#include <X11/Xlib.h>
}
#endif
/** singleton */
IrrDriver *irr_driver = NULL;
@ -82,11 +91,64 @@ IrrDriver::~IrrDriver()
{
m_post_processing.shut();
assert(m_device != NULL);
m_device->drop();
m_device = NULL;
m_modes.clear();
} // ~IrrDriver
// ----------------------------------------------------------------------------
void IrrDriver::updateConfigIfRelevant()
{
if (!UserConfigParams::m_fullscreen && UserConfigParams::m_remember_window_location)
{
#ifdef WIN32
const SExposedVideoData& videoData = m_device->getVideoDriver()->getExposedVideoData();
// this should work even if using DirectX in theory because the HWnd is
// always third pointer in the struct, no matter which union is used
HWND window = (HWND)videoData.OpenGLWin32.HWnd;
WINDOWPLACEMENT placement;
placement.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(window, &placement))
{
int x = (int)placement.rcNormalPosition.left;
int y = (int)placement.rcNormalPosition.top;
printf("Retrieved window location for config : %i %i\n", x, y);
if (UserConfigParams::m_window_x != x || UserConfigParams::m_window_y != y)
{
UserConfigParams::m_window_x = x;
UserConfigParams::m_window_y = y;
user_config->saveConfig();
}
}
else
{
printf("Could not retrieve window location\n");
}
#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);
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;
UserConfigParams::m_window_y = wy;
user_config->saveConfig();
}
#endif
}
}
// ----------------------------------------------------------------------------
/** Gets a list of supported video modes from the irrlicht device. This data
* is stored in m_modes.
@ -192,7 +254,7 @@ void IrrDriver::initDevice()
UserConfigParams::m_height);
if (UserConfigParams::m_fullscreen_antialiasing)
params.AntiAlias = 4;
m_device = createDeviceEx(params);
if(m_device) break;
@ -229,6 +291,44 @@ void IrrDriver::initDevice()
exit(-1);
}
if (!UserConfigParams::m_fullscreen && UserConfigParams::m_remember_window_location &&
UserConfigParams::m_window_x >= 0 && UserConfigParams::m_window_y >= 0)
{
#ifdef WIN32
const SExposedVideoData& videoData = m_device->getVideoDriver()->getExposedVideoData();
// this should work even if using DirectX in theory because the HWnd is
// always third pointer in the struct, no matter which union is used
HWND window = (HWND)videoData.OpenGLWin32.HWnd;
if (SetWindowPos(window, HWND_TOP, UserConfigParams::m_window_x, UserConfigParams::m_window_y,
-1, -1, SWP_NOOWNERZORDER | SWP_NOSIZE))
{
// everything OK
}
else
{
printf("[IrrDriver] WARNING: Could not set window location\n");
}
#elif defined(__linux__)
using namespace X11;
const SExposedVideoData& videoData = m_device->getVideoDriver()->getExposedVideoData();
//XSetWindowAttributes attr;
//attr.override_redirect = True;
//XChangeWindowAttributes( (Display*)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.X11Window, CWOverrideRedirect, &attr );
// FIXME: doesn't work
XMoveWindow((Display*)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.X11Window,
UserConfigParams::m_window_x, UserConfigParams::m_window_y);
//attr.override_redirect = False;
//XChangeWindowAttributes( (Display*)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.X11Window, CWOverrideRedirect, &attr );
#endif
}
m_scene_manager = m_device->getSceneManager();
m_gui_env = m_device->getGUIEnvironment();
m_video_driver = m_device->getVideoDriver();

View File

@ -111,7 +111,9 @@ private:
public:
IrrDriver();
~IrrDriver();
void initDevice();
void initDevice();
void updateConfigIfRelevant();
void setAllMaterialFlags(scene::IMesh *mesh) const;

View File

@ -494,6 +494,10 @@ Material::Material(const XMLNode *node, int index)
{
// Track version 4 uses a separate node:
m_zipper = true;
m_zipper_duration = 3.5f;
m_zipper_max_speed_increase = 15.0f;
m_zipper_fade_out_time = 3.0f;
m_zipper_speed_gain = 4.5f;
child_node->get("duration", &m_zipper_duration );
child_node->get("fade-out-time", &m_zipper_fade_out_time );
child_node->get("max-speed-increase",&m_zipper_max_speed_increase);

View File

@ -1103,6 +1103,8 @@ void initRest()
*/
void cleanSuperTuxKart()
{
irr_driver->updateConfigIfRelevant();
if(network_http)
network_http->stopNetworkThread();
//delete in reverse order of what they were created in.

View File

@ -117,6 +117,12 @@ void OptionsScreenVideo::init()
assert( full != NULL );
full->setState( UserConfigParams::m_fullscreen );
CheckBoxWidget* rememberWinpos = getWidget<CheckBoxWidget>("rememberWinpos");
rememberWinpos->setState(UserConfigParams::m_remember_window_location);
if (UserConfigParams::m_fullscreen) rememberWinpos->setDeactivated();
else rememberWinpos->setActivated();
// Enable back widgets if they were visited in-game previously
if (StateManager::get()->getGameState() != GUIEngine::INGAME_MENU)
{
@ -462,7 +468,19 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
assert( fbos != NULL );
UserConfigParams::m_fbo = fbos->getState();
}
else if (name == "rememberWinpos")
{
CheckBoxWidget* rememberWinpos = getWidget<CheckBoxWidget>("rememberWinpos");
UserConfigParams::m_remember_window_location = rememberWinpos->getState();
}
else if (name == "fullscreen")
{
CheckBoxWidget* fullscreen = getWidget<CheckBoxWidget>("fullscreen");
CheckBoxWidget* rememberWinpos = getWidget<CheckBoxWidget>("rememberWinpos");
if (fullscreen->getState()) rememberWinpos->setDeactivated();
else rememberWinpos->setActivated();
}
} // eventCallback
// ----------------------------------------------------------------------------