X11/Xlib: Create “GlassPane”-Window

烈酒焚心 提交于 2019-11-30 10:11:01
Havoc P

You can create an output-only window by setting its input shape to empty.

The API is XFixesSetWindowShapeRegion() and you can set ShapeInput separately from ShapeBounding. XFixesCreateRegion() is used to get a region to pass in.

Then you need an RGBA (with-alpha-channel) visual so you can draw transparent pixels into most of the window.

A compositing window manager will be required in order for the transparency to work.

You need overlay visual support for this in you X Server, or else performance will be absolutely abysmal, since you'd have to map / unmap your window continuously and/or do the get/putimage dance all the time.

You have to have the main/root plane non-overlay and create an overlay visual on top of that. Everything that's clear in the overlay plane will pass the "main screen" through.

Documentation on how to do this in "plain X" is very sparse, the simpler way would be via OpenGL / GLX, http://www.opengl.org/sdk/docs/man/xhtml/glXChooseVisual.xml - simply try:

int query[] = { /* GLX_RGBA, */ GLX_LEVEL, 1, 0 };
overlayVisual = glXChooseVisual(mydisplay, DefaultScreen(mydisplay), query);
myWindow = XCreateWindow(..., overlayVisual, ...);

Then You should be able to clear the window to make the "main root" visible, and draw into it to cover it. In "olden times" the overlay often was required to be a non-RGB (color indexed / palettized) visual and chroma keying was used for the transparent parts. OpenGL RGBA should support transparency / blending via the alpha channel, though ...

I haven't tried, my current framebuffer doesn't support overlays. Nvidia mentions them in the documentation for their X11 drivers / their config files hence I assume they're still around, and still usable in this fashion.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!