How to create semi transparent white window in XLib

后端 未结 2 1515
遇见更好的自我
遇见更好的自我 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:20

    X11 expects pre-multiplied colours, i.e. real opaque colours need to be multiplied by the alpha value (and scaled accordingly, i.e. divided by 256 when channel widths is 8 bits). This format is easier to work with when you need to combine many levels. See formulas here. There's less computation when everything is pre-multiplied.

    So you need to multiply each of your R, G and B channels by the alpha value (0x80) and divide by 256.

    Setting the background to 0x80808080 gives the desired result:

    Note the result is different from what @patthoyts suggests: here only the window proper is semi-transparent, the WM decoration stays opaque; there both the window proper and the decoration are made transparent by the WM (and the WM does the necessary colour blending).

提交回复
热议问题