aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-05 07:56:36 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-05 07:56:36 +0200
commitc20af6ad5ef7ad92febe4e952e48853df577f421 (patch)
tree27cf10ba44fefe8ff1d082e56f1ec9167c5a2631
parent3fda2cec15e0be4fce1f55875d93c26dc06b151d (diff)
Fix window texture not working for certain window (like termite)
-rw-r--r--window_texture.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/window_texture.c b/window_texture.c
index e854290..96e82f7 100644
--- a/window_texture.c
+++ b/window_texture.c
@@ -1,5 +1,6 @@
#include "window_texture.h"
#include <X11/extensions/Xcomposite.h>
+#include <stdio.h>
static int x11_supports_composite_named_window_pixmap(Display *display) {
int extension_major;
@@ -72,10 +73,41 @@ int window_texture_on_resize(WindowTexture *self) {
None
};
+ XWindowAttributes attr;
+ if (!XGetWindowAttributes(self->display, self->window, &attr)) {
+ fprintf(stderr, "Failed to get window attributes\n");
+ return 1;
+ }
+
int c;
GLXFBConfig *configs = glXChooseFBConfig(self->display, 0, pixmap_config, &c);
- if(!configs)
+ if(!configs) {
+ fprintf(stderr, "Failed to choose fb config\n");
return 1;
+ }
+
+ int found = 0;
+ GLXFBConfig config;
+ for (int i = 0; i < c; i++) {
+ config = configs[i];
+ XVisualInfo *visual = glXGetVisualFromFBConfig(self->display, config);
+ if (!visual)
+ continue;
+
+ if (attr.depth != visual->depth) {
+ XFree(visual);
+ continue;
+ }
+ XFree(visual);
+ found = 1;
+ break;
+ }
+
+ if(!found) {
+ fprintf(stderr, "No matching fb config found\n");
+ result = 1;
+ goto cleanup;
+ }
self->pixmap = XCompositeNameWindowPixmap(self->display, self->window);
if(!self->pixmap) {
@@ -83,7 +115,7 @@ int window_texture_on_resize(WindowTexture *self) {
goto cleanup;
}
- self->glx_pixmap = glXCreatePixmap(self->display, configs[0], self->pixmap, pixmap_attribs);
+ self->glx_pixmap = glXCreatePixmap(self->display, config, self->pixmap, pixmap_attribs);
if(!self->glx_pixmap) {
result = 3;
goto cleanup;