background - 如何设置Xlib窗口背景透明?

标签 background transparent xlib

我想创建一个具有透明背景的窗口。怎么做?

我使用XSetBackground(display, gc, 0),背景是黑色。我将屏幕深度更改为 32。结果还是黑的。这是我的代码:

    display = XOpenDisplay(getenv("DISPALY"));
    screen = DefaultScreen(display);
    depth = DefaultDepth(display,screen);
    printf("depth: %d\n", depth);
    rootwindow = RootWindow(display,screen);

    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 = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 1440, 900, 0, vinfo.depth, InputOutput,
                    vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr);

    gc = XCreateGC (display, window, 0, NULL);
   XSetBackground(display, gc, 0L);

最佳答案

你需要

  • 确保窗口深度为 32
  • 设置透明区域的 alpha 位值
  • 确保您运行的复合管理器可以正确处理透明度

查看我的问题"How to upload 32bit pixmap to server"作为如何设置 Alpha channel 值的示例

更新:还要确保您的窗口是使用关联的颜色图创建的(我不知道这背后的原因,但我无法在没有颜色图的情况下正确显示 32 位窗口)

关于background - 如何设置Xlib窗口背景透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23051594/

相关文章:

css - 大背景图像和屏幕尺寸

android - 如何在 Android 中创建 'fog of war' 位图覆盖

c - _NET_ACTIVE_WINDOW 和 XGetInputFocus 之间的 Xlib 区别

c++ - X11 XMoveWindow with SDL 1.2 不移动窗口

c - 使用 XDrawString 垂直显示文本

iphone - NSFileManager:继续在后台写入磁盘吗?

android - Xamarin ContentPage BackgroundImage属性在Android上使应用程序崩溃

css - 为什么文本不会在 <section> 背景中居中对齐?

android - Flex Air For Android 中的透明背景?

C# - 击败键盘记录器的透明窗口