WindowSystemAdapter::setWSA(new WindowSystemAdapter);
}
-// Noop
void fgOSFullScreen()
{
+ std::vector<osgViewer::GraphicsWindow*> windows;
+ viewer->getWindows(windows);
+
+ if (windows.size() == 0)
+ return; // Huh?!?
+
+ /* Toggling window fullscreen is only supported for the main GUI window.
+ * The other windows should use fixed setup from the camera.xml file anyway. */
+ osgViewer::GraphicsWindow* window = windows[0];
+
+ {
+ osg::GraphicsContext::WindowingSystemInterface *wsi = osg::GraphicsContext::getWindowingSystemInterface();
+
+ if (wsi == NULL)
+ {
+ SG_LOG(SG_VIEW, SG_ALERT, "ERROR: No WindowSystemInterface available. Cannot toggle window fullscreen.");
+ return;
+ }
+
+ static int previous_x = 0;
+ static int previous_y = 0;
+ static int previous_width = 800;
+ static int previous_height = 600;
+
+ unsigned int screenWidth;
+ unsigned int screenHeight;
+ wsi->getScreenResolution(*(window->getTraits()), screenWidth, screenHeight);
+
+ int x;
+ int y;
+ int width;
+ int height;
+ window->getWindowRectangle(x, y, width, height);
+
+ bool isFullScreen = x == 0 && y == 0 && width == (int)screenWidth && height == (int)screenHeight;
+
+ SG_LOG(SG_VIEW, SG_DEBUG, "Toggling fullscreen. Previous window rectangle ("
+ << x << ", " << y << ") x (" << width << ", " << height << "), fullscreen: " << isFullScreen);
+ if (isFullScreen)
+ {
+ // limit x,y coordinates and window size to screen area
+ if (previous_x + previous_width > (int)screenWidth)
+ previous_x = 0;
+ if (previous_y + previous_height > (int)screenHeight)
+ previous_y = 0;
+
+ // disable fullscreen mode, restore previous window size/coordinates
+ x = previous_x;
+ y = previous_y;
+ width = previous_width;
+ height = previous_height;
+ }
+ else
+ {
+ // remember previous setting
+ previous_x = x;
+ previous_y = y;
+ previous_width = width;
+ previous_height = height;
+
+ // enable fullscreen mode, set new width/height
+ x = 0;
+ y = 0;
+ width = screenWidth;
+ height = screenHeight;
+ }
+
+ // set xsize/ysize properties to adapt GUI planes
+ fgSetInt("/sim/startup/xsize", width);
+ fgSetInt("/sim/startup/ysize", height);
+
+ // reconfigure window
+ window->setWindowDecoration(isFullScreen);
+ window->setWindowRectangle(x, y, width, height);
+ window->grabFocusIfPointerInWindow();
+ }
}
static void setMouseCursor(osgViewer::GraphicsWindow* gw, int cursor)