简体   繁体   中英

Create a layered window on Linux X11/Gtk

My question is generally how can I create and position layered windows on Linux using X11 or some toolkit such as Gtk. When I say layered window I mean a window which whose shape and transparency is defined by a pixel data containing rgb and alpha (transparency) channels. See the screenshot below.

I've used them extensively on Windows using the simple enough UpdateLayeredWindow API and am wondering how to do the same thing on Linux.

Thanks.

Windows上的分层蝴蝶

X11 originally supports only one-bit transparency (requires the SHAPE extension, but these days nearly all X11 servers implement it). Use XShapeCombineMask or gtk_widget_shape_combine_mask functions.

If you want antialiased transparency, then probably the simplest way is to use the cairo toolkit. An example can be found here .

To use transparency in X11 you need

  1. create window with 32 bit depth (you need to specify 32bit visual, backpixel, colormap and borderpixel when you create window)
  2. draw ARGB picture on window surface (or on window pixmap if you create it with background pixmap). Note that you need to use pre-multiplied ARGB ( a=128, r=255, g=255, b=255 is non-transparent white and a=128, r=128, g=128, b=128 is semi-transparent white). You can use standard drawing commands, XRender or just send ARGB bitmap using PutImage request.

In X11 there are two possible methods: Simple bitmap masking through the SHAPE extension (works even with very old X servers), or using ARGB visuals and a compositor. I provided sample code performing OpenGL rendering on a ARGB visual window in this answer:

https://stackoverflow.com/a/9215724/524368

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM