From 8974be43a3c7f672a34291049bb543d01960de28 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 17 Oct 2021 00:33:37 +0200 Subject: Parent window = 0 = root window --- README.md | 1 - include/mgl/window.h | 27 --------------------------- include/mgl/window/window.h | 28 ++++++++++++++++++++++++++++ src/mgl.c | 1 - src/window.c | 7 +++++-- 5 files changed, 33 insertions(+), 31 deletions(-) delete mode 100644 include/mgl/window.h create mode 100644 include/mgl/window/window.h diff --git a/README.md b/README.md index 9d567aa..fa9db3b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Minimal Graphics Library Written in C and uses legacy OpenGL to support as many platforms as possible.\ Right now mgl only supports x11. - # Dependencies ## Build `xlib` diff --git a/include/mgl/window.h b/include/mgl/window.h deleted file mode 100644 index 0184577..0000000 --- a/include/mgl/window.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MGL_WINDOW_H -#define MGL_WINDOW_H - -#include "system/vec.h" - -typedef struct mgl_window mgl_window; - -typedef struct { - void *userdata; - void (*draw)(mgl_window *window, void *userdata); -} mgl_window_callback; - -struct mgl_window { - unsigned long window; - mgl_window_callback callback; - mgl_vec2i size; - mgl_vec2i cursor_position; -}; - -int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback); -int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, unsigned long parent_window, mgl_window_callback *callback); -void mgl_window_deinit(mgl_window *self); - -void mgl_window_events_poll(mgl_window *self); -void mgl_window_draw(mgl_window *self); - -#endif /* MGL_WINDOW_H */ diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h new file mode 100644 index 0000000..5232260 --- /dev/null +++ b/include/mgl/window/window.h @@ -0,0 +1,28 @@ +#ifndef MGL_WINDOW_H +#define MGL_WINDOW_H + +#include "../system/vec.h" + +typedef struct mgl_window mgl_window; + +typedef struct { + void *userdata; + void (*draw)(mgl_window *window, void *userdata); +} mgl_window_callback; + +struct mgl_window { + unsigned long window; + mgl_window_callback callback; + mgl_vec2i size; + mgl_vec2i cursor_position; +}; + +int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback); +/* if |parent_window| is 0 then the root window is used */ +int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, unsigned long parent_window, mgl_window_callback *callback); +void mgl_window_deinit(mgl_window *self); + +void mgl_window_events_poll(mgl_window *self); +void mgl_window_draw(mgl_window *self); + +#endif /* MGL_WINDOW_H */ diff --git a/src/mgl.c b/src/mgl.c index cbdfb41..549121f 100644 --- a/src/mgl.c +++ b/src/mgl.c @@ -89,7 +89,6 @@ void mgl_deinit(void) { if(init_count == 1) { glx_context_deinit(); mgl_gl_unload(&context.gl); - mgl_gl_unload(&context.gl); XSetErrorHandler(prev_xerror); if(context.connection) { XCloseDisplay(context.connection); diff --git a/src/window.c b/src/window.c index 5e09261..8042ad3 100644 --- a/src/window.c +++ b/src/window.c @@ -1,4 +1,4 @@ -#include "../include/mgl/window.h" +#include "../include/mgl/window/window.h" #include "../include/mgl/mgl.h" #include #include @@ -38,7 +38,7 @@ static void mgl_window_on_resize(mgl_window *self, int width, int height) { } int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback) { - return mgl_window_create_with_params(self, title, width, height, DefaultRootWindow(mgl_get_context()->connection), callback); + return mgl_window_create_with_params(self, title, width, height, 0, callback); } int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, unsigned long parent_window, mgl_window_callback *callback) { @@ -47,6 +47,9 @@ int mgl_window_create_with_params(mgl_window *self, const char *title, int width mgl_context *context = mgl_get_context(); + if(parent_window == 0) + parent_window = DefaultRootWindow(context->connection); + Colormap color_map = XCreateColormap(context->connection, DefaultRootWindow(context->connection), ((XVisualInfo*)context->visual_info)->visual, AllocNone); if(!color_map) { fprintf(stderr, "XCreateColormap failed\n"); -- cgit v1.2.3