2012-11-15 80 views
5

有没有办法创建一个窗口与Xlib只显示边框线,标题,关闭按钮,你可以用鼠标移动?窗口的内容必须为空(或“完全透明”,尽管“透明度”听起来更像是我不需要的效果)。基本上窗口应该显示背景区域。空的或透明的窗口与Xlib只显示边框线

回答

11

我不确定它是否是你想要的,但下面的代码创建了一个透明背景的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, 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; 
}