diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | TODO | 1 | ||||
m--------- | depends/mgl | 0 | ||||
-rw-r--r-- | include/mglpp/mglpp.hpp | 12 | ||||
-rw-r--r-- | include/mglpp/window/Window.hpp | 3 | ||||
-rw-r--r-- | meson.build | 26 | ||||
-rw-r--r-- | src/mglpp.cpp | 4 | ||||
-rw-r--r-- | src/window/Window.cpp | 24 |
8 files changed, 38 insertions, 43 deletions
@@ -2,10 +2,13 @@ C++ wrapper for [mgl](https://git.dec05eba.com/mgl/about/) # Dependencies ## Build -`x11, libxrender, libxrandr` +`libx11, libxrender, libxrandr`\ +`wayland-client, wayland-egl, wayland-scanner` ## Runtime -`libglvnd (libGL.so, libEGL.so)` +`libglvnd (libGL.so, libGLX.so, libEGL.so)` # Notes -Every window _get_ function is cached from the last event poll, no calls to x11 is made. +Every window _get_ function is cached from the last event poll, no calls to x11/wayland is made.\ Only one window can be created and used at once.\ -mglpp needs to be initialized first and then a window created, before other functions are called. +mglpp needs to be initialized first and then a window has to be created before other functions are called. +# TODO +Wayland support is not finished yet. Use MGL_WINDOW_SYSTEM_X11 for now in mgl::Init.
\ No newline at end of file @@ -0,0 +1 @@ +Change Init(window_system) default value to WindowSystem::NATIVE. diff --git a/depends/mgl b/depends/mgl -Subproject 0243be4eebe488b449742474d4301a39f00ac67 +Subproject c990594a93e953854b0a224a22f7e0a7db8ffe1 diff --git a/include/mglpp/mglpp.hpp b/include/mglpp/mglpp.hpp index 2e49da5..730ddf5 100644 --- a/include/mglpp/mglpp.hpp +++ b/include/mglpp/mglpp.hpp @@ -1,9 +1,15 @@ #ifndef MGLPP_MGLPP_HPP #define MGLPP_MGLPP_HPP -#include <stdexcept> +#include <exception> namespace mgl { + enum class WindowSystem { + NATIVE, // Use X11 on X11 and Wayland on Wayland + X11, // Use X11 on X11 and XWayland on Wayland + WAYLAND, // Use Wayland. If user runs on X11 then it fails to connect + }; + class InitException : public std::exception { public: const char* what() const noexcept override { @@ -13,8 +19,8 @@ namespace mgl { class Init { public: - // Throws InitException on failure - Init(); + // Throws InitException on failure. + Init(WindowSystem window_system = WindowSystem::X11); ~Init(); bool is_connected_to_display_server(); diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index 6bd77f8..8458d71 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -55,7 +55,7 @@ namespace mgl { const char *class_name = nullptr; mgl_window_type window_type = MGL_WINDOW_TYPE_NORMAL; WindowHandle transient_for_window = 0; /* 0 = none */ - mgl_render_api render_api = MGL_RENDER_API_GLX; + mgl_graphics_api graphics_api = MGL_GRAPHICS_API_EGL; }; Window(); @@ -123,6 +123,7 @@ namespace mgl { mgl_window* internal_window(); private: mgl_window window; + bool window_created = false; }; } diff --git a/meson.build b/meson.build index 258fae0..829957c 100644 --- a/meson.build +++ b/meson.build @@ -23,32 +23,6 @@ src = [ 'src/mglpp.cpp', ] -project_headers = [ - 'include/mglpp/graphics/Text.hpp', - 'include/mglpp/graphics/PrimitiveType.hpp', - 'include/mglpp/graphics/Vertex.hpp', - 'include/mglpp/graphics/Drawable.hpp', - 'include/mglpp/graphics/Texture.hpp', - 'include/mglpp/graphics/Shader.hpp', - 'include/mglpp/graphics/Sprite.hpp', - 'include/mglpp/graphics/Color.hpp', - 'include/mglpp/graphics/VertexBuffer.hpp', - 'include/mglpp/graphics/Image.hpp', - 'include/mglpp/graphics/Font.hpp', - 'include/mglpp/graphics/Rectangle.hpp', - 'include/mglpp/system/Utf8.hpp', - 'include/mglpp/system/vec.hpp', - 'include/mglpp/system/Clock.hpp', - 'include/mglpp/system/MemoryMappedFile.hpp', - 'include/mglpp/system/FloatRect.hpp', - 'include/mglpp/mglpp.hpp', - 'include/mglpp/window/Window.hpp', - 'include/mglpp/window/Mouse.hpp', - 'include/mglpp/window/Event.hpp', - 'include/mglpp/window/Keyboard.hpp', - 'include/mglpp/window/Clipboard.hpp', -] - mgl_proj = subproject('mgl') mgl_dep = mgl_proj.get_variable('mgl_dep') diff --git a/src/mglpp.cpp b/src/mglpp.cpp index ca0845d..2f0670a 100644 --- a/src/mglpp.cpp +++ b/src/mglpp.cpp @@ -4,8 +4,8 @@ extern "C" { } namespace mgl { - Init::Init() { - if(mgl_init() != 0) + Init::Init(WindowSystem window_system) { + if(mgl_init((mgl_window_system)window_system) != 0) throw InitException(); } 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() { |