aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-24 04:52:30 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-24 04:52:30 +0200
commit115630b520668304af1ccd3eb0b13c06e17ecccc (patch)
treee3949bd4fe36ae3b43c11d4e9ecd0bf523a6e910 /src/window
parent898b8c95f1f904307c02e978b57301cf1cb0560f (diff)
Add function to load image from memory, initialize window from an existing window, allow creating text without font/string
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c41
1 files changed, 30 insertions, 11 deletions
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) {