]> git.tdb.fi Git - libs/gui.git/commitdiff
Various fixes to Window resizing and fullscreen handling on X11
authorMikko Rasa <tdb@tdb.fi>
Mon, 3 Aug 2009 12:26:54 +0000 (12:26 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 3 Aug 2009 12:26:54 +0000 (12:26 +0000)
Add fullscreen parameter to SimpleWindow constructors

source/gbase/simplewindow.cpp
source/gbase/simplewindow.h
source/gbase/window.cpp
source/gbase/window.h

index aa34c04cfa046eec2bceb92df1e1070a9f8ae6b1..406090d760319fe03d280a983ffc7d79250654ad 100644 (file)
@@ -10,13 +10,13 @@ Distributed under the LGPL
 namespace Msp {
 namespace Graphics {
 
-SimpleWindow::SimpleWindow(unsigned w, unsigned h):
-       Window(dpy, w, h)
+SimpleWindow::SimpleWindow(unsigned w, unsigned h, bool fs):
+       Window(dpy, w, h, fs)
 { }
 
 
-SimpleGLWindow::SimpleGLWindow(unsigned w, unsigned h):
-       SimpleWindow(w, h),
+SimpleGLWindow::SimpleGLWindow(unsigned w, unsigned h, bool fs):
+       SimpleWindow(w, h, fs),
        gl_ctx(*this)
 { }
 
index a506636a4ae8047b6823210c0bb4c0518ae7eb58..1f5bb7dbf00f94654a131f4b6390f80e2936a362 100644 (file)
@@ -33,7 +33,7 @@ A simplified Window that encapsulates a Display.
 class SimpleWindow: public SimpleWindowBase, public Window
 {
 public:
-       SimpleWindow(unsigned, unsigned);
+       SimpleWindow(unsigned, unsigned, bool =false);
 };
 
 
@@ -46,7 +46,7 @@ private:
        GLContext gl_ctx;
 
 public:
-       SimpleGLWindow(unsigned, unsigned);
+       SimpleGLWindow(unsigned, unsigned, bool =false);
        GLContext &get_gl_context() { return gl_ctx; }
        void swap_buffers();
 };
index 08cb74db081807edd765c6a0115a40684c913696..06af1ae7662fae81ed8b18c07db8b05ecd4aee0a 100644 (file)
@@ -9,6 +9,9 @@ Distributed under the LGPL
 #ifndef WIN32
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
+#ifdef WITH_XF86VIDMODE
+#include <X11/extensions/xf86vmode.h>
+#endif
 #else
 #include <windowsx.h>
 #endif
@@ -84,6 +87,7 @@ void Window::init()
 {
        visible=false;
        kbd_autorepeat=true;
+       resizing=false;
        priv=new Private;
 
 #ifdef WIN32
@@ -210,6 +214,7 @@ void Window::set_title(const string &title)
 void Window::reconfigure(const WindowOptions &opts)
 {
        bool fullscreen_changed=(opts.fullscreen!=options.fullscreen);
+       resizing=(opts.width!=options.width || opts.height!=options.height);
 
        options=opts;
 
@@ -238,10 +243,9 @@ void Window::reconfigure(const WindowOptions &opts)
 #else
        ::Display *dpy=display.get_private().display;
 
+       bool was_visible=visible;
        if(fullscreen_changed)
        {
-               bool was_visible=visible;
-
                if(was_visible)
                {
                        hide();
@@ -254,9 +258,6 @@ void Window::reconfigure(const WindowOptions &opts)
                XSetWindowAttributes attr;
                attr.override_redirect=options.fullscreen;
                XChangeWindowAttributes(dpy, priv->window, CWOverrideRedirect, &attr);
-
-               if(was_visible)
-                       show();
        }
 
        XSizeHints hints;
@@ -274,6 +275,12 @@ void Window::reconfigure(const WindowOptions &opts)
                XMoveResizeWindow(dpy, priv->window, 0, 0, options.width, options.height);
        else
                XResizeWindow(dpy, priv->window, options.width, options.height);
+
+       if(fullscreen_changed)
+       {
+               if(was_visible)
+                       show();
+       }
 #endif
 
        if(visible)
@@ -442,9 +449,19 @@ bool Window::event(const Event &evnt)
                signal_key_release.emit(XKeycodeToKeysym(display.get_private().display, ev.xkey.keycode, 0), ev.xkey.state);
                break;
        case ConfigureNotify:
-               options.width=ev.xconfigure.width;
-               options.height=ev.xconfigure.height;
-               signal_resize.emit(options.width, options.height);
+               if((ev.xconfigure.width==static_cast<int>(options.width) && ev.xconfigure.height==static_cast<int>(options.height)) == resizing)
+               {
+                       options.width=ev.xconfigure.width;
+                       options.height=ev.xconfigure.height;
+                       resizing=false;
+                       signal_resize.emit(options.width, options.height);
+               }
+               if(options.fullscreen)
+               {
+                       ::Display *dpy=display.get_private().display;
+                       int screen=DefaultScreen(dpy);
+                       XF86VidModeSetViewPort(dpy, screen, ev.xconfigure.x, ev.xconfigure.y);
+               }
                break;
        case ClientMessage:
                if(ev.xclient.data.l[0]==static_cast<long>(priv->wm_delete_window))
index ad575af1ab236cbf92d2e77aaa192cf87b67b72e..38ffb6d5aee967ad81121f8bde8a1abc34b971b6 100644 (file)
@@ -45,6 +45,7 @@ protected:
        WindowOptions options;
        bool visible;
        bool kbd_autorepeat;
+       bool resizing;
        Private *priv;
 
 public: