解决方法
我不确定它是否是您想要的,但是下面的代码创建了一个透明背景的X窗口,但仍然使用窗口管理器的窗口装饰.
只有当您的X11和图形硬件配置支持深度为32位的视觉效果时,它才会起作用.
#include <X11/Xlib.h> #include <X11/Xutil.h> int main(int argc,char* argv[]) { Display* display = XOpenDisplay(NULL); XVisualInfo vinfo; XMatchVisualInfo(display,DefaultScreen(display),32,TrueColor,&vinfo); XSetWindowAttributes attr; attr.colormap = XCreateColormap(display,DefaultRootWindow(display),vinfo.visual,AllocNone); attr.border_pixel = 0; attr.background_pixel = 0; Window win = XCreateWindow(display,300,200,vinfo.depth,InputOutput,CWColormap | CWBorderPixel | CWBackPixel,&attr); XSelectInput(display,win,StructureNotifyMask); GC gc = XCreateGC(display,0); Atom wm_delete_window = XInternAtom(display,"WM_DELETE_WINDOW",0); XSetWMProtocols(display,&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,1)) keep_running = 0; break; default: break; } } XDestroyWindow(display,win); XCloseDisplay(display); return 0; }