如何在xlib中制作透明窗口?

如何在xlib中制作透明窗口?

我在网上浏览了有关如何在 xlib 中制作透明窗口的信息。我的目标是让 Imlib2 图像显示为透明背景。我有一个具有透明背景的图像,现在您只能看到窗口背景颜色。我想让该颜色透明,以便可以看到窗口后面的东西,图像仍然显示。

我有以下代码:

XVisualInfo vinfo;
XMatchVisualInfo(DISPLAY, DefaultScreen(DISPLAY), 32, TrueColor, &vinfo);

XSetWindowAttributes attr;
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(DISPLAY, ROOT, vinfo.visual, AllocNone);

window = XCreateWindow(
    DISPLAY,
    parent_window,
    0,
    0,
    button_geometry.width,
    button_geometry.height,
    0,
    32,
    InputOutput,
    vinfo.visual,
    CWBackPixmap | CWBackPixel | CWBorderPixel,
    &attr
);
XSelectInput(DISPLAY, window, StructureNotifyMask);
XMapWindow(DISPLAY, window);
XSync(DISPLAY, false);

这确实创建了一个窗口,我可以与它交互(因为它有单击、释放和运动事件),但我根本看不到它。我怎样才能只让我的背景颜色是透明的,这样我仍然可以看到 xlib 图像。

相关内容