From c20af6ad5ef7ad92febe4e952e48853df577f421 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 5 Jul 2020 07:56:36 +0200 Subject: Fix window texture not working for certain window (like termite) --- window_texture.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file 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 +#include 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; -- cgit v1.2.3