From ff6d302d7b0ef4c32dca6e2d0ce12927d517875a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 17 Nov 2021 23:51:47 +0100 Subject: Fix window not being visible on kde because color map is deleted while the window is in use --- src/window/window.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/window/window.c b/src/window/window.c index c6dab51..25e3ff2 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -63,6 +63,7 @@ typedef struct { Cursor invisible_cursor; unsigned int prev_keycode_pressed; bool key_was_released; + Colormap color_map; /* Used to stack text event on top of key press/release events and other text events. For example pressing a key should give the user both key press and text events @@ -93,6 +94,7 @@ static int x11_context_init(x11_context *self) { self->prev_keycode_pressed = 0; self->key_was_released = false; + self->color_map = None; self->default_cursor = XCreateFontCursor(context->connection, XC_arrow); if(!self->default_cursor) { @@ -129,6 +131,11 @@ static int x11_context_init(x11_context *self) { void x11_context_deinit(x11_context *self) { mgl_context *context = mgl_get_context(); + if(self->color_map) { + XFreeColormap(context->connection, self->color_map); + self->color_map = None; + } + if(self->invisible_cursor) { XFreeCursor(context->connection, self->invisible_cursor); self->invisible_cursor = None; @@ -270,38 +277,34 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window return -1; } - Colormap color_map = XCreateColormap(context->connection, DefaultRootWindow(context->connection), ((XVisualInfo*)context->visual_info)->visual, AllocNone); - if(!color_map) { + x11_context->color_map = XCreateColormap(context->connection, DefaultRootWindow(context->connection), ((XVisualInfo*)context->visual_info)->visual, AllocNone); + if(!x11_context->color_map) { fprintf(stderr, "XCreateColormap failed\n"); mgl_window_deinit(self); return -1; } XSetWindowAttributes window_attr; - window_attr.colormap = color_map; + window_attr.colormap = x11_context->color_map; window_attr.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | VisibilityChangeMask | PropertyChangeMask | FocusChangeMask; - window_attr.bit_gravity = NorthWestGravity; if(existing_window) { - if(!XChangeWindowAttributes(context->connection, existing_window, CWColormap | CWEventMask | CWBitGravity, &window_attr)) { + if(!XChangeWindowAttributes(context->connection, existing_window, CWColormap | CWEventMask, &window_attr)) { fprintf(stderr, "XChangeWindowAttributes failed\n"); - XFreeColormap(context->connection, color_map); mgl_window_deinit(self); return -1; } - XFreeColormap(context->connection, color_map); self->window = existing_window; } else { self->window = XCreateWindow(context->connection, parent_window, params->position.x, params->position.y, window_size.x, window_size.y, 0, ((XVisualInfo*)context->visual_info)->depth, InputOutput, ((XVisualInfo*)context->visual_info)->visual, - CWColormap | CWEventMask | CWBitGravity, &window_attr); - XFreeColormap(context->connection, color_map); + CWColormap | CWEventMask, &window_attr); if(!self->window) { fprintf(stderr, "XCreateWindow failed\n"); mgl_window_deinit(self); -- cgit v1.2.3