Commits

thecoshman committed be1e3d8

Bordered windows are now created to the correct size, though they are not placed at the correct location

Comments (0)

Files changed (2)

src/linux/template_visitors.hpp

+#pragma once
+
+// #include "windows_sdk.hpp"
+#include <tuple>
+#include <boost/variant.hpp>
+
+namespace glskel { namespace detail { namespace linux {
+    struct intermediate_template {
+        bool fullscreen;
+        /*DWORD*/ unsigned int window_styles, extended_styles;
+        unsigned x, y, width, height;
+        unsigned bpp, refresh;
+    };
+
+    struct mode_visitor : boost::static_visitor<> {
+        mode_visitor(const mode_visitor&) = delete;
+        mode_visitor(mode_visitor&&) = delete;
+
+        mode_visitor(intermediate_template& template_) : template_(template_) {}
+        intermediate_template& template_;
+
+        void operator()(const glskel::fullscreen& mode) const {
+//            if (mode.desktop) {
+//                DEVMODE current_display_mode {};
+//                current_display_mode.dmSize = sizeof(DEVMODE);
+//                EnumDisplaySettingsEx(nullptr, ENUM_CURRENT_SETTINGS, &current_display_mode, 0);
+//
+//                template_.width   = current_display_mode.dmPelsWidth;
+//                template_.height  = current_display_mode.dmPelsHeight;
+//                template_.bpp     = current_display_mode.dmBitsPerPel;
+//                template_.refresh = current_display_mode.dmDisplayFrequency;
+//            } else {
+//                template_.width   = mode.width;
+//                template_.height  = mode.height;
+//                template_.bpp     = mode.bpp;
+//                template_.refresh = mode.refresh;
+//            }
+//
+            template_.x = template_.y = 0;
+//            template_.window_styles   = WS_POPUP;
+//            template_.extended_styles = WS_EX_TOPMOST;
+            template_.fullscreen      = true;
+        }
+
+        void operator()(const glskel::bordered& mode) const {
+//            template_.window_styles   = WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_MAXIMIZEBOX;
+//            template_.extended_styles = WS_EX_OVERLAPPEDWINDOW;
+            template_.width           = mode.width;
+            template_.height          = mode.height;
+        }
+
+        void operator()(const glskel::borderless& mode) const {
+//            template_.window_styles = WS_POPUP;
+            template_.width         = mode.width;
+            template_.height        = mode.height;
+        }
+    };
+
+    struct position_visitor : boost::static_visitor<> {
+        position_visitor(const position_visitor&) = delete;
+        position_visitor(position_visitor&&) = delete;
+
+        position_visitor(intermediate_template& template_) : template_(template_) {}
+        intermediate_template& template_;
+
+        void operator()(const glskel::centered&) const {
+//            RECT desktop_rect;
+//            GetClientRect(GetDesktopWindow(), &desktop_rect);
+//            int desktop_width  = desktop_rect.right - desktop_rect.left;
+//            int desktop_height = desktop_rect.bottom - desktop_rect.top;
+//
+//            template_.x = (desktop_width  / 2) - (template_.width  / 2);
+//            template_.y = (desktop_height / 2) - (template_.height / 2);
+//             Need to properly research how to find the desktop size, for now assuming a size 800 * 600
+            int desktop_width  = 800;
+            int desktop_height = 600;
+            template_.x = (desktop_width  / 2) - (template_.width  / 2);
+            template_.y = (desktop_height / 2) - (template_.height / 2);
+        }
+
+        void operator()(const glskel::absolute& position) const {
+            template_.x = position.x;
+            template_.y = position.y;
+        }
+    };
+} } } // glskel::detail::linux

src/linux/window_factory_impl.cpp

 
 #include "window_factory_impl.hpp"
 #include "window_impl.hpp"
+#include "template_visitors.hpp"
 
 namespace glskel { namespace detail { namespace linux {
     window_factory_impl::window_factory_impl() : glskel::window_factory(), display(XOpenDisplay(nullptr)) {
 
     // XXX RAIIfy, make safe
     glskel::window_ptr window_factory_impl::make_window(const glskel::window_template& template_) {
+        intermediate_template int_template = { 0 };
+        boost::apply_visitor(mode_visitor(int_template), template_.mode);
+
         int visual_attribs[] = {
             GLX_X_RENDERABLE,  True,
             GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
         window_attribs.colormap   = colormap;
         window_attribs.event_mask = event_mask;
 
+        if (!int_template.fullscreen) {
+            boost::apply_visitor(position_visitor(int_template), template_.position);
+        }
+
         // XXX template_.position and template_.mode
         Window window = XCreateWindow(
-            display, RootWindow(display, visual->screen), 0, 0, 100, 100, 0, visual->depth,
+            display, RootWindow(display, visual->screen), int_template.x, int_template.y, int_template.width, int_template.height, 0, visual->depth,
             InputOutput, visual->visual, CWColormap | CWEventMask, &window_attribs
         );
         GLSKEL_THROW_IF(!window, "Could not create a window.");