From 18ed06b01363e674d81e8afd5773188b900b50ec Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 17 Apr 2025 16:36:38 +0200 Subject: Move x11 code to separate place for main window code to prepare for wayland support --- depends/mgl | 2 +- include/mglpp/window/Window.hpp | 1 + src/window/Window.cpp | 24 +++++++++++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/depends/mgl b/depends/mgl index 0243be4..506c271 160000 --- a/depends/mgl +++ b/depends/mgl @@ -1 +1 @@ -Subproject commit 0243be4eebe488b449742474d4301a39f00ac67f +Subproject commit 506c271eafec23bf469caf6c29431191fa885e58 diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index 6bd77f8..eb14e23 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -123,6 +123,7 @@ namespace mgl { mgl_window* internal_window(); private: mgl_window window; + bool window_created = false; }; } diff --git a/src/window/Window.cpp b/src/window/Window.cpp index ab42de0..fffacca 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -16,24 +16,34 @@ namespace mgl { } Window::Window() { - window.window = 0; + } Window::~Window() { - if(window.window) + if(window_created) mgl_window_deinit(&window); } bool Window::create(const char *title, CreateParams create_params) { - if(window.window) + if(window_created) return false; - return mgl_window_create(&window, title, (const mgl_window_create_params*)&create_params) == 0; + + if(mgl_window_create(&window, title, (const mgl_window_create_params*)&create_params) == 0) { + window_created = true; + return true; + } + return false; } bool Window::create(WindowHandle existing_window) { - if(window.window) + if(window_created) return false; - return mgl_window_init_from_existing_window(&window, existing_window) == 0; + + if(mgl_window_init_from_existing_window(&window, existing_window) == 0) { + window_created = true; + return true; + } + return false; } bool Window::poll_event(Event &event) { @@ -197,7 +207,7 @@ namespace mgl { } WindowHandle Window::get_system_handle() const { - return window.window; + return mgl_window_get_system_handle(&window); } mgl_window* Window::internal_window() { -- cgit v1.2.3-70-g09d2