Xlib的空或透明窗口仅显示边框线

时间:2012-11-15 10:04:53

标签: c image-processing x11 transparent xlib

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

1 个答案:

答案 0 :(得分:13)

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