diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index 07057867ab..8ef28ef19e 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -30,6 +30,7 @@ static Atom XA_NET_WM_STATE; static Atom XA_NET_WM_STATE_FULLSCREEN; static Atom XA_NET_MOVERESIZE_WINDOW; +Colormap g_x11_cmap; Atom g_x11_quit_atom; static volatile sig_atomic_t g_x11_quit; bool g_x11_has_focus; @@ -555,5 +556,14 @@ void x11_window_destroy(bool fullscreen) XUnmapWindow(g_x11_dpy, g_x11_win); if (!fullscreen) XDestroyWindow(g_x11_dpy, g_x11_win); - g_x11_win = 0; + g_x11_win = None; +} + +void x11_colormap_destroy(void) +{ + if (!g_x11_cmap) + return; + + XFreeColormap(g_x11_dpy, g_x11_cmap); + g_x11_cmap = None; } diff --git a/gfx/common/x11_common.h b/gfx/common/x11_common.h index ddf2913a80..5d49ddd451 100644 --- a/gfx/common/x11_common.h +++ b/gfx/common/x11_common.h @@ -40,6 +40,7 @@ extern bool g_x11_has_focus; extern Window g_x11_win; extern Display *g_x11_dpy; extern bool g_x11_true_full; +extern Colormap g_x11_cmap; void x11_show_mouse(Display *dpy, Window win, bool state); void x11_windowed_fullscreen(Display *dpy, Window win); @@ -87,5 +88,7 @@ void x11_input_ctx_destroy(void); void x11_window_destroy(bool fullscreen); +void x11_colormap_destroy(void); + #endif diff --git a/gfx/drivers/xvideo.c b/gfx/drivers/xvideo.c index 850faa0745..74deb257c6 100644 --- a/gfx/drivers/xvideo.c +++ b/gfx/drivers/xvideo.c @@ -42,7 +42,6 @@ typedef struct xv { GC gc; - Colormap colormap; XShmSegmentInfo shminfo; XvPortID port; @@ -485,10 +484,10 @@ static void *xv_init(const video_info_t *video, goto error; } - xv->colormap = XCreateColormap(g_x11_dpy, + g_x11_cmap = XCreateColormap(g_x11_dpy, DefaultRootWindow(g_x11_dpy), visualinfo->visual, AllocNone); - attributes.colormap = xv->colormap; + attributes.colormap = g_x11_cmap; attributes.border_pixel = 0; attributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonReleaseMask | ButtonPressMask | DestroyNotify | ClientMessage; @@ -827,8 +826,7 @@ static void xv_free(void *data) XFree(xv->image); x11_window_destroy(true); - if (xv->colormap) - XFreeColormap(g_x11_dpy, xv->colormap); + x11_colormap_destroy(); XCloseDisplay(g_x11_dpy); diff --git a/gfx/drivers_context/glx_ctx.c b/gfx/drivers_context/glx_ctx.c index 65ddf6d58f..fb650a8237 100644 --- a/gfx/drivers_context/glx_ctx.c +++ b/gfx/drivers_context/glx_ctx.c @@ -39,7 +39,6 @@ typedef struct gfx_ctx_glx_data bool g_is_double; GLXWindow g_glx_win; - Colormap g_cmap; unsigned g_screen; unsigned g_interval; @@ -127,11 +126,7 @@ static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx) x11_window_destroy(false); } - if (glx->g_cmap) - { - XFreeColormap(g_x11_dpy, glx->g_cmap); - glx->g_cmap = None; - } + x11_colormap_destroy(); if (glx->g_should_reset_mode) { @@ -323,7 +318,7 @@ static bool gfx_ctx_glx_set_video_mode(void *data, if (!vi) goto error; - swa.colormap = glx->g_cmap = XCreateColormap(g_x11_dpy, + swa.colormap = g_x11_cmap = XCreateColormap(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen), vi->visual, AllocNone); swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonReleaseMask | ButtonPressMask; diff --git a/gfx/drivers_context/xegl_ctx.c b/gfx/drivers_context/xegl_ctx.c index ce04803534..67def61972 100644 --- a/gfx/drivers_context/xegl_ctx.c +++ b/gfx/drivers_context/xegl_ctx.c @@ -33,7 +33,6 @@ #define EGL_OPENGL_ES3_BIT_KHR 0x0040 #endif -static Colormap g_cmap; static unsigned g_screen; static bool g_use_hw_ctx; @@ -337,7 +336,7 @@ static bool gfx_ctx_xegl_set_video_mode(void *data, if (!vi) goto error; - swa.colormap = g_cmap = XCreateColormap(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen), + swa.colormap = g_x11_cmap = XCreateColormap(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen), vi->visual, AllocNone); swa.event_mask = StructureNotifyMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | KeyReleaseMask; swa.override_redirect = fullscreen ? True : False; @@ -536,11 +535,7 @@ static void gfx_ctx_xegl_destroy(void *data) x11_window_destroy(false); } - if (g_cmap) - { - XFreeColormap(g_x11_dpy, g_cmap); - g_cmap = None; - } + x11_colormap_destroy(); if (g_should_reset_mode) {