有没有办法用Xlib创建一个窗口,它只显示边框线,标题,关闭按钮,你可以用鼠标移动?窗口的内容必须为空(或“完全透明”,尽管“透明度”听起来更像是我不需要的效果).基本上窗口应该显示背景区域.
解决方法
我不确定它是否是您想要的,但是下面的代码创建了一个透明背景的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;
}