From: Mikko Rasa Date: Sun, 20 Dec 2015 13:44:15 +0000 (+0200) Subject: Allow configuring window positions as well X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9c7ae47da64904c2aa9a9969870ca8befebe7d02;p=libs%2Fgui.git Allow configuring window positions as well --- diff --git a/source/graphics/window.cpp b/source/graphics/window.cpp index 5bc9a35..d116b69 100644 --- a/source/graphics/window.cpp +++ b/source/graphics/window.cpp @@ -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) { diff --git a/source/graphics/window.h b/source/graphics/window.h index 8065762..31fa248 100644 --- a/source/graphics/window.h +++ b/source/graphics/window.h @@ -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: diff --git a/source/graphics/windows/window.cpp b/source/graphics/windows/window.cpp index b148915..8d7a342 100644 --- a/source/graphics/windows/window.cpp +++ b/source/graphics/windows/window.cpp @@ -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(LOWORD(evnt.lparam)); options.y = static_cast(HIWORD(evnt.lparam)); + moving = false; signal_move.emit(options.x, options.y); break; case WM_CLOSE: diff --git a/source/graphics/x11/window.cpp b/source/graphics/x11/window.cpp index 9b46e4e..52f37a3 100644 --- a/source/graphics/x11/window.cpp +++ b/source/graphics/x11/window.cpp @@ -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); } }