From 115630b520668304af1ccd3eb0b13c06e17ecccc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 24 Oct 2021 04:52:30 +0200 Subject: Add function to load image from memory, initialize window from an existing window, allow creating text without font/string --- src/window/window.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'src/window') diff --git a/src/window/window.c b/src/window/window.c index 691a647..2e9a1ba 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -41,7 +41,7 @@ int mgl_window_create(mgl_window *self, const char *title, int width, int height return mgl_window_create_with_params(self, title, width, height, 0); } -int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window) { +static int mgl_window_init(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window, Window existing_window) { self->window = 0; mgl_context *context = mgl_get_context(); @@ -64,18 +64,29 @@ int mgl_window_create_with_params(mgl_window *self, const char *title, int width StructureNotifyMask; window_attr.bit_gravity = NorthWestGravity; - self->window = XCreateWindow(context->connection, parent_window, 0, 0, width, height, 0, - ((XVisualInfo*)context->visual_info)->depth, InputOutput, ((XVisualInfo*)context->visual_info)->visual, - CWColormap | CWEventMask | CWBitGravity, &window_attr); - XFreeColormap(context->connection, color_map); - if(!self->window) { - fprintf(stderr, "XCreateWindow failed\n"); - mgl_window_deinit(self); - return -1; + if(existing_window) { + if(!XChangeWindowAttributes(context->connection, existing_window, CWColormap | CWEventMask | CWBitGravity, &window_attr)) { + fprintf(stderr, "XChangeWindowAttributes failed\n"); + XFreeColormap(context->connection, color_map); + return -1; + } + XFreeColormap(context->connection, color_map); + self->window = existing_window; + } else { + self->window = XCreateWindow(context->connection, parent_window, 0, 0, width, height, 0, + ((XVisualInfo*)context->visual_info)->depth, InputOutput, ((XVisualInfo*)context->visual_info)->visual, + CWColormap | CWEventMask | CWBitGravity, &window_attr); + XFreeColormap(context->connection, color_map); + if(!self->window) { + fprintf(stderr, "XCreateWindow failed\n"); + mgl_window_deinit(self); + return -1; + } + + XStoreName(context->connection, self->window, title); + XMapWindow(context->connection, self->window); } - XStoreName(context->connection, self->window, title); - XMapWindow(context->connection, self->window); XFlush(context->connection); /* TODO: Switch current when rendering to another window, and set current to NULL when destroying the currently selected context */ @@ -102,6 +113,14 @@ int mgl_window_create_with_params(mgl_window *self, const char *title, int width return 0; } +int mgl_window_create_with_params(mgl_window *self, const char *title, int width, int height, mgl_window_handle parent_window) { + return mgl_window_init(self, title, width, height, parent_window, None); +} + +int mgl_window_init_from_existing_window(mgl_window *self, mgl_window_handle existing_window) { + return mgl_window_init(self, "", 0, 0, 0, existing_window); +} + void mgl_window_deinit(mgl_window *self) { mgl_context *context = mgl_get_context(); if(self->window) { -- cgit v1.2.3