diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-09-23 21:10:08 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-09-23 21:10:08 +0200 |
commit | a5524a7e3e8248a5a4baa8af62a1a758f1d07e7f (patch) | |
tree | 3dbb25931e1b9e3b2ba7f73d73eaf4933972ae3e /src/window | |
parent | 14e28f6107d9e9bae81eeee8d0a22abdc256a295 (diff) |
Make window rgba and set background transparent to allow window clear to work with transparency
Diffstat (limited to 'src/window')
-rw-r--r-- | src/window/window.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/window/window.c b/src/window/window.c index 8acd428..eeb2e43 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -184,12 +184,12 @@ static void set_vertical_sync_enabled(Window window, int enabled) { static int warned = 0; if (!warned) { warned = 1; - fprintf(stderr, "Warning: setting vertical sync not supported\n"); + fprintf(stderr, "mgl warning: setting vertical sync not supported\n"); } } if(result != 0) - fprintf(stderr, "Warning: setting vertical sync failed\n"); + fprintf(stderr, "mgl warning: setting vertical sync failed\n"); } static void mgl_window_on_resize(mgl_window *self, int width, int height) { @@ -223,13 +223,13 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window self->context = malloc(sizeof(x11_context)); if(!self->context) { - fprintf(stderr, "Failed to allocate x11 context\n"); + fprintf(stderr, "mgl error: failed to allocate x11 context\n"); return -1; } x11_context *x11_context = self->context; if(x11_context_init(x11_context) != 0) { - fprintf(stderr, "x11_context_init failed\n"); + fprintf(stderr, "mgl error: x11_context_init failed\n"); mgl_window_deinit(self); return -1; } @@ -240,16 +240,16 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window if(parent_window == 0) parent_window = DefaultRootWindow(context->connection); - x11_context->glx_context = context->gl.glXCreateContext(context->connection, context->visual_info, NULL, 1); + x11_context->glx_context = context->gl.glXCreateNewContext(context->connection, context->fbconfig, GLX_RGBA_TYPE, 0, True); if(!x11_context->glx_context) { - fprintf(stderr, "glXCreateContext failed\n"); + fprintf(stderr, "mgl error: glXCreateContext failed\n"); mgl_window_deinit(self); return -1; } 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"); + fprintf(stderr, "mgl error: XCreateColormap failed\n"); mgl_window_deinit(self); return -1; } @@ -257,6 +257,8 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window XSetWindowAttributes window_attr; window_attr.override_redirect = params ? params->override_redirect : false; window_attr.colormap = x11_context->color_map; + window_attr.background_pixmap = None; + window_attr.border_pixel = 0; window_attr.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | @@ -266,8 +268,8 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window const bool hide_window = params ? params->hidden : false; if(existing_window) { - if(!XChangeWindowAttributes(context->connection, existing_window, CWColormap | CWEventMask | CWOverrideRedirect, &window_attr)) { - fprintf(stderr, "XChangeWindowAttributes failed\n"); + if(!XChangeWindowAttributes(context->connection, existing_window, CWColormap | CWEventMask | CWOverrideRedirect | CWBorderPixel | CWBackPixmap, &window_attr)) { + fprintf(stderr, "mgl error: XChangeWindowAttributes failed\n"); mgl_window_deinit(self); return -1; } @@ -279,9 +281,9 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window 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 | CWOverrideRedirect, &window_attr); + CWColormap | CWEventMask | CWOverrideRedirect | CWBorderPixel | CWBackPixmap, &window_attr); if(!self->window) { - fprintf(stderr, "XCreateWindow failed\n"); + fprintf(stderr, "mgl error: XCreateWindow failed\n"); mgl_window_deinit(self); return -1; } @@ -310,7 +312,11 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window XFlush(context->connection); /* TODO: Check for failure? */ - context->gl.glXMakeCurrent(context->connection, self->window, x11_context->glx_context); + if(!context->gl.glXMakeContextCurrent(context->connection, self->window, self->window, x11_context->glx_context)) { + fprintf(stderr, "mgl error: failed to make opengl context current!\n"); + mgl_window_deinit(self); + return -1; + } set_vertical_sync_enabled(self->window, 1); context->gl.glEnable(GL_TEXTURE_2D); context->gl.glEnable(GL_BLEND); @@ -330,14 +336,14 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window x11_context->xim = XOpenIM(context->connection, NULL, NULL, NULL); if(!x11_context->xim) { - fprintf(stderr, "XOpenIM failed\n"); + fprintf(stderr, "mgl error: XOpenIM failed\n"); mgl_window_deinit(self); return -1; } x11_context->xic = XCreateIC(x11_context->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, self->window, NULL); if(!x11_context->xic) { - fprintf(stderr, "XCreateIC failed\n"); + fprintf(stderr, "mgl error: XCreateIC failed\n"); mgl_window_deinit(self); return -1; } @@ -893,7 +899,7 @@ void mgl_window_set_size_limits(mgl_window *self, mgl_vec2i minimum, mgl_vec2i m XFree(size_hints); XSync(context->connection, False); } else { - fprintf(stderr, "Warning: failed to set window size hints\n"); + fprintf(stderr, "mgl warning: failed to set window size hints\n"); } } @@ -911,13 +917,13 @@ void mgl_window_set_clipboard(mgl_window *self, const char *str, size_t size) { /* Check if setting the selection owner was successful */ if(XGetSelectionOwner(context->connection, x11_context->clipboard_atom) != self->window) { - fprintf(stderr, "Error: mgl_window_set_clipboard failed\n"); + fprintf(stderr, "mgl error: mgl_window_set_clipboard failed\n"); return; } self->clipboard_string = malloc(size + 1); if(!self->clipboard_string) { - fprintf(stderr, "Error: failed to allocate string for clipboard\n"); + fprintf(stderr, "mgl error: failed to allocate string for clipboard\n"); return; } memcpy(self->clipboard_string, str, size); |