Gtk+/X11: semitransparent windows with and without composite managers?

徘徊边缘 提交于 2019-12-11 04:58:19

问题


I need some code for making my window (and preferably all widgets on it) semitransparent. I know i can play around with gtk_window_set_opacity(), but it works only when composite manager is running, but what if not? I've googled a lot, found lots of code that mostly doesn't even compile, doesn't work or just a proof of concept. No fulfilling solution. I don't want to mess with X11 Xlib awful API (I just don't have time to learn it).

Where to get such library/code snippet?


回答1:


There's no good answer to this (which is a good part of why compositing managers were invented). If you could already do this, people wouldn't have invented the whole compositing manager mechanism.

The only sort-of answer, used in old "transparent terminals" and the like, is based on making screenshots of the stuff underneath the window and then painting the screenshot in your own window. This is an Xlib-involving mess, hard to get mostly right, impossible to get completely correct, and inefficient. Still, you could do it perhaps. Look at old revisions of terminals supporting transparency, I think VTE used to have this code, ZVT widget certainly did. So did the Enlightenment terminal for example.

But really the way to go is to just fall back to no transparency for users without a CM.




回答2:


While modern X11 servers do support RGBA visuals this doesn't mean, they'll do alpha blending. X11 operates on the model, that a window is a mask on a single shared framebuffer. Z ordering may clip parts of a window so these areas are not drawn to at all.

To enable transparency a compositing manager must redirect the windows to off-screen rendering, then compose the final image you see on the screen from those off-screen rendered parts. The XDamage extension is used to keep track of which windows need re-compositing.



来源:https://stackoverflow.com/questions/4965219/gtk-x11-semitransparent-windows-with-and-without-composite-managers

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