【问题标题】:How to set Xlib window background transparent?如何设置 Xlib 窗口背景透明?
【发布时间】:2014-04-14 03:43:26
【问题描述】:

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

我用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);

【问题讨论】:

    标签: background transparent xlib


    【解决方案1】:

    你需要

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

    请参阅我的问题"How to upload 32bit pixmap to server" 作为如何设置 Alpha 通道值的示例

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

    【讨论】:

    • 我之前看过你的页面。XMatchVisualInfo func使深度32。接下来的两个步骤我不知道怎么做。你能给我一个简单的例子,创建一个透明背景的窗口。我使用 XClearArea 使一个区域显示窗口的背景。我想将窗口的背景设置为透明。所以,我可以得到一个透明的子区域。
    • 我得到了一个页面,示例如下:a link 但是背景还是黑的。谁有好的解决方案?
    • 只传输透明像素(不是黑色)。在客户端预填充RGBA32像素图,将A设置为某个值,然后执行XPutImage
    • 是否应该通过合成客户端(如 Metacity、Compiz 等)或独立合成器(如 compton 或 xcompmgr)来完成?我可以使用纯xlib及其扩展--xrender来完成这项工作吗?看起来很难,甚至没有效果。
    猜你喜欢
    • 1970-01-01
    • 2014-05-29
    • 2018-04-23
    • 2011-04-23
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多