]> git.tdb.fi Git - libs/gui.git/commitdiff
Allow configuring window positions as well
authorMikko Rasa <tdb@tdb.fi>
Sun, 20 Dec 2015 13:44:15 +0000 (15:44 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 20 Dec 2015 13:44:15 +0000 (15:44 +0200)
source/graphics/window.cpp
source/graphics/window.h
source/graphics/windows/window.cpp
source/graphics/x11/window.cpp

index 5bc9a358e2786d99e7ba7e4be1c63b6dce20afa8..d116b691c14bcbf11592bca91d9edcb647eca792 100644 (file)
@@ -11,6 +11,7 @@ namespace Graphics {
 WindowOptions::WindowOptions():
        x(0),
        y(0),
+       user_position(false),
        width(640),
        height(480),
        fullscreen(false),
@@ -41,6 +42,7 @@ void Window::init()
        kbd_autorepeat = true;
        touch_input = false;
        resizing = false;
+       moving = false;
        priv = new Private;
 
        platform_init();
@@ -70,6 +72,8 @@ void Window::reconfigure(const WindowOptions &opts)
        bool fullscreen_changed = (opts.fullscreen!=options.fullscreen);
        if(opts.width!=options.width || opts.height!=options.height)
                resizing = true;
+       if(opts.x!=options.x || opts.y!=options.y)
+               moving = true;
 
        if(visible)
        {
index 8065762a4b2cc57d826db9f904f594de17365b96..31fa248a65e2a7080fdbfeebfd1a4d290e39d689 100644 (file)
@@ -13,6 +13,7 @@ struct WindowOptions
 {
        int x;
        int y;
+       bool user_position;
        unsigned width;
        unsigned height;
        bool fullscreen;
@@ -44,6 +45,7 @@ protected:
        bool kbd_autorepeat;
        bool touch_input;
        bool resizing;
+       bool moving;
        Private *priv;
 
 public:
index b148915d9bc94b6581037a682c3982c0bf78212f..8d7a342621635dd3e3c738abad67939ddf5c8ac0 100644 (file)
@@ -76,7 +76,8 @@ void Window::platform_init()
                "mspgui",
                "Window",
                style,
-               CW_USEDEFAULT, CW_USEDEFAULT,
+               (options.user_position ? options.x : CW_USEDEFAULT),
+               (options.user_position ? options.y : CW_USEDEFAULT),
                rect.right-rect.left, rect.bottom-rect.top,
                0,
                0,
@@ -118,6 +119,8 @@ void Window::platform_reconfigure(bool fullscreen_changed)
 
        if(options.fullscreen)
                SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
+       else if(options.user_position)
+               SetWindowPos(priv->window, 0, options.x, options.y, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
        else
                SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOMOVE|SWP_NOZORDER);
 }
@@ -183,6 +186,7 @@ bool Window::event(const Event &evnt)
        case WM_MOVE:
                options.x = static_cast<short>(LOWORD(evnt.lparam));
                options.y = static_cast<short>(HIWORD(evnt.lparam));
+               moving = false;
                signal_move.emit(options.x, options.y);
                break;
        case WM_CLOSE:
index 9b46e4e16593cfe4abe1e760d2cdf832a4593d26..52f37a35137e986e81fcf840e32b64e4b33a01e0 100644 (file)
@@ -36,7 +36,7 @@ void Window::platform_init()
 
        priv->window = XCreateWindow(dpy,
                display.get_private().root_window,
-               0, 0,
+               0, 0,    // User position is set when the window is mapped
                options.width, options.height,
                0,
                CopyFromParent,
@@ -112,6 +112,8 @@ void Window::platform_reconfigure(bool fullscreen_changed)
 
        if(options.fullscreen)
                XMoveResizeWindow(dpy, priv->window, 0, 0, options.width, options.height);
+       else if(options.user_position)
+               XMoveResizeWindow(dpy, priv->window, options.x, options.y, options.width, options.height);
        else
                XResizeWindow(dpy, priv->window, options.width, options.height);
 
@@ -160,7 +162,10 @@ void Window::platform_set_touch_input()
 
 void Window::platform_show()
 {
-       XMapRaised(display.get_private().display, priv->window);
+       DisplayHandle dpy = display.get_private().display;
+       XMapRaised(dpy, priv->window);
+       if(options.user_position)
+               XMoveWindow(dpy, priv->window, options.x, options.y);
 }
 
 void Window::platform_hide()
@@ -212,10 +217,11 @@ bool Window::event(const Event &evnt)
                                y -= priv->rel_y;
                        }
 
-                       if(x!=options.x || y!=options.y)
+                       if((x==options.x && y==options.y) == moving)
                        {
                                options.x = x;
                                options.y = y;
+                               moving = false;
                                signal_move.emit(options.x, options.y);
                        }
                }