aboutsummaryrefslogtreecommitdiff
path: root/src/window/window.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-02 06:01:36 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-02 06:01:36 +0200
commitf2da59054cedd1c07779e72537da4d7b14616b48 (patch)
treeb6c8606c1e7494d2fc17439552db30f55b97fd26 /src/window/window.c
parent470dac0e891c1ec59dfe52e77861cf068837976d (diff)
Ensure correct blending function for transparent window
Diffstat (limited to 'src/window/window.c')
-rw-r--r--src/window/window.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/window/window.c b/src/window/window.c
index 586719d..ccbf8ef 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -85,6 +85,7 @@ typedef struct {
GLXFBConfig *fbconfigs;
GLXFBConfig fbconfig;
XVisualInfo *visual_info;
+ bool support_alpha;
/* This only contains connected and active monitors */
mgl_monitor monitors[MAX_MONITORS];
@@ -185,6 +186,7 @@ static int x11_context_init(x11_context *self, bool alpha) {
self->fbconfigs = NULL;
self->fbconfig = NULL;
self->visual_info = NULL;
+ self->support_alpha = alpha;
memset(self->monitors, 0, sizeof(self->monitors));
self->num_monitors = 0;
@@ -574,6 +576,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
self->num_monitors = 0;
mgl_context *context = mgl_get_context();
+ context->current_window = self;
Window parent_window = params ? params->parent_window : None;
if(parent_window == 0)
@@ -700,7 +703,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
context->gl.glEnable(GL_TEXTURE_2D);
context->gl.glEnable(GL_BLEND);
context->gl.glEnable(GL_SCISSOR_TEST);
- context->gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ mgl_window_set_render_blend_func(self);
context->gl.glEnableClientState(GL_VERTEX_ARRAY);
context->gl.glEnableClientState(GL_TEXTURE_COORD_ARRAY);
context->gl.glEnableClientState(GL_COLOR_ARRAY);
@@ -765,6 +768,10 @@ void mgl_window_deinit(mgl_window *self) {
self->clipboard_size = 0;
self->open = false;
+
+ mgl_context *context = mgl_get_context();
+ if(context->current_window == self)
+ context->current_window = NULL;
}
/* Returns MGL_KEY_UNKNOWN on no match */
@@ -1256,7 +1263,13 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event
void mgl_window_clear(mgl_window *self, mgl_color color) {
mgl_context *context = mgl_get_context();
- context->gl.glClearColor((float)color.r / 255.0f, (float)color.g / 255.0f, (float)color.b / 255.0f, (float)color.a / 255.0f);
+ x11_context *x11_context = self->context;
+
+ const float alpha = (float)color.a / 255.0f;
+ if(x11_context->support_alpha)
+ context->gl.glClearColor(((float)color.r / 255.0f) * alpha, ((float)color.g / 255.0f) * alpha, ((float)color.b / 255.0f) * alpha, alpha);
+ else
+ context->gl.glClearColor((float)color.r / 255.0f, (float)color.g / 255.0f, (float)color.b / 255.0f, alpha);
context->gl.glClear(GL_COLOR_BUFFER_BIT);
}
@@ -1783,6 +1796,17 @@ void mgl_window_set_key_repeat_enabled(mgl_window *self, bool enabled) {
self->key_repeat_enabled = enabled;
}
+void mgl_window_set_texture_blend_func(mgl_window *self) {
+ mgl_context *context = mgl_get_context();
+ context->gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+
+void mgl_window_set_render_blend_func(mgl_window *self) {
+ mgl_context *context = mgl_get_context();
+ x11_context *x11_context = self->context;
+ context->gl.glBlendFunc(x11_context->support_alpha ? GL_ONE : GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+
void mgl_window_flush(mgl_window *self) {
mgl_context *context = mgl_get_context();
XFlush(context->connection);