Gtk+/X11:带或不带复合管理器的半透明窗口?
我需要一些代码来使我的窗口(最好是其上的所有小部件)半透明。 我知道我可以使用 gtk_window_set_opacity(),但它仅在复合管理器运行时才有效,但如果不运行怎么办? 我在谷歌上搜索了很多,发现很多代码大多数甚至无法编译、无法工作或者只是概念证明。没有令人满意的解决方案。我不想搞乱 X11 Xlib 糟糕的 API(我只是没有时间学习它)。
哪里可以获得这样的库/代码片段?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对此没有好的答案(这也是发明合成管理器的一个重要原因)。如果你已经能做到这一点,人们就不会发明整个合成管理器机制。
在旧的“透明终端”等中使用的唯一答案是基于对窗口下方的内容进行屏幕截图,然后在您自己的窗口中绘制屏幕截图。这是一个涉及 Xlib 的混乱,很难大部分正确,不可能完全正确,而且效率低下。不过,你也许可以做到。看看支持透明的终端的旧版本,我认为 VTE 曾经有这个代码,ZVT 小部件当然也有。例如,启蒙终端也是如此。
但真正要走的路是在没有 CM 的情况下,对用户不再透明。
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.
虽然现代 X11 服务器确实支持 RGBA 视觉效果,但这并不意味着它们会进行 Alpha 混合。 X11 运行的模型是,窗口是单个共享帧缓冲区上的掩码。 Z 排序可能会剪切窗口的某些部分,因此这些区域根本不会被绘制。
为了实现透明度,合成管理器必须将窗口重定向到离屏渲染,然后从那些离屏渲染的部分合成您在屏幕上看到的最终图像。 XDamage 扩展用于跟踪哪些窗口需要重新合成。
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.