How to create semi transparent white window in XLib

后端 未结 2 1537
遇见更好的自我
遇见更好的自我 2020-12-19 04:57

I would like to create a semi transparent white window in XLib, but the window is not semi translucent, it remains fully opaque. I use the compton compositor and there are t

2条回答
  •  误落风尘
    2020-12-19 05:21

    You need to set _NET_WM_WINDOW_OPACITY. Here is a snippet to add in before you map the window:

    double alpha = 0.8;
    unsigned long opacity = (unsigned long)(0xFFFFFFFFul * alpha);
    Atom XA_NET_WM_WINDOW_OPACITY = XInternAtom(display, "_NET_WM_WINDOW_OPACITY", False);
    XChangeProperty(display, win, XA_NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32,
                    PropModeReplace, (unsigned char *)&opacity, 1L);
    

    Note you should add #include to get the declaration of XA_CARDINAL.

    I'm not entirely sure how stable this interface is. This appears to be a proposed extension to the Extended Window Manager Hints specification but has not made it into any final revision from what I can see. I know that this is how Tk implements transparency support on unix though.

    The result looks like:

提交回复
热议问题