Pourquoi j’ai défini l’échec d’arrière-plan de la fenêtre xlib transparente?

J’utilise le code suivant pour obtenir une fenêtre transparente, mais le résultat est noir. Qu’est-ce qui ne va pas avec moi? Et est-ce que quelqu’un peut me donner un exemple simple pour créer une fenêtre avec un fond transparent? MERCI!

#include  #include  int main(int argc, char* argv[]) { Display* display = XOpenDisplay(NULL); XVisualInfo vinfo; XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo); XSetWindowAtsortingbutes attr; attr.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone); attr.border_pixel = 0; attr.background_pixel = 0; Window win = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 300, 200, 0, vinfo.depth, InputOutput, vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr); XSelectInput(display, win, StructureNotifyMask); GC gc = XCreateGC(display, win, 0, 0); Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", 0); XSetWMProtocols(display, win, &wm_delete_window, 1); XMapWindow(display, win); int keep_running = 1; XEvent event; while (keep_running) { XNextEvent(display, &event); switch(event.type) { case ClientMessage: if (event.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", 1) && (Atom)event.xclient.data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", 1)) keep_running = 0; break; default: break; } } XDestroyWindow(display, win); XCloseDisplay(display); return 0; } 

Votre code fonctionne bien pour moi:

kde:

entrez la description de l'image ici

openbox + xcompmgr:

entrez la description de l'image ici

Très probablement, vous n’exécutez pas le gestionnaire composite. Essayez de lancer la commande xcompmgr

Vérifiez _NET_WM_CM_S0 propriétaire de la sélection _NET_WM_CM_S0 – il devrait pointer vers une fenêtre créée par le gestionnaire composite .

 #include  #include  #include  int main(int argc, char* argv[]) { Display* display = XOpenDisplay(NULL); Atom cmAtom = XInternAtom(display, "_NET_WM_CM_S0", 0); Window cmOwner = XGetSelectionOwner(display, cmAtom); printf("Composite manager window: %i\n", cmOwner); XCloseDisplay(display); return 0; } 

Mettre à jour:

Essayez de définir override-redirect pour empêcher les décorations WM de masquer votre fenêtre.

 attr.border_pixel = 0; attr.background_pixel = 0; attr.override_redirect = 1; /* this line added */ Window win = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 300, 200, 0, vinfo.depth, InputOutput, vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel | CWOverrideRedirect /* and this one*/, &attr);