[Xcb] Window transparency and clearing a window

Ingo Bürk admin at airblader.de
Tue Oct 17 19:46:35 UTC 2017


Hi,

> since documentation on X11 is hard to find
Yes, and IMHO the best approach is to find software doing what you want
to do and see how they do it – when it comes to windows, window managers
might be a good choice (such as awesome or i3, shameless plug for Uli
and me here).

Another thing to watch out for with (true) transparency is that you need
to define both a back pixel and a border pixel in the window attributes.
I'm not sure whether this changed in recent releases of Xorg, but it
used to be the case. See [1], beautifully demonstrating that even Uli
went through these problems before, albeit many years ago. :-)

> For true transparency, I can't seem to set the depth properly using
> xcb_create_window(...), since I have no idea what unit the depth
> parameter is even supposed to be! Giving it 32 does not work, the only
> value that seems to work for me is XCB_COPY_FROM_PARENT. 
As I mentioned above, just look at the code of existing software. For
the case of i3 (only one of many!), you will find what you're looking
for in x_con_init() in src/x.c.

> Essentially, I have no idea if my window already has a depth of 32-bit
> or not.
You can check the depth of a window using "xwininfo -frame", for example.

> However, once the root pixmap changes, I would have to copy the pixmap
> then redo the drawing process.
Well, that's the nature of fake transparency. It doesn't do well with
changing backgrounds, in particular quickly changing backgrounds. It
will always look sloppy; it's fake transparency, after all. If you want
it to be correct, use true transparency (requiring compositing). There's
only so much you can do.

> I'm curious as to if there is a better way that I haven't though of.
One improvement you could make is to render your window's content to a
separate pixmap (or, in this case, cairo surface) and do the same for
the root window. When the background changes, you don't need to rerender
your own content, but only overlay the updated background and your
content's surface.

There's certainly a lot one can do, but I wouldn't bother with that
quite yet. Drawing a few rectangles and some text isn't so expensive
that any machine from this decade should have serious problem with it,
assuming you've done everything else correctly. X11 protocol can be
frickle, especially if you don't understand it, so I'd focus on getting
an understanding of how it works and how your client should behave
first; also to ensure it actually adheres to the specifications.

[1] https://stackoverflow.com/questions/3645632


Regards

Ingo


On 10/17/2017 03:04 AM, Sheheryar Parvaz wrote:
>
> First of all, thank you very much for your response, it is very
> helpful since documentation on X11 is hard to find. In my case, I want
> to be able to use pseudo-transparency and true transparency depending
> on what is available, so help on both methods is appreciated.
>
>
> > You want a window with depth 32. If you have that (and correctly tell
> > cairo about it), you can just cairo to draw a transparent background
> > [1].
>
>
> For true transparency, I can't seem to set the depth properly using
> xcb_create_window(...), since I have no idea what unit the depth
> parameter is even supposed to be! Giving it 32 does not work, the only
> value that seems to work for me is XCB_COPY_FROM_PARENT. Essentially,
> I have no idea if my window already has a depth of 32-bit or not.
>
> I'm assuming it isn't since cairo seems to be drawing a black
> background. By the way, the only mask I have set is CW_EVENT_MASK.
> This could be the reason why, but I have no idea.
>
>
> I am also having trouble thinking about how to do pseudo-transparency.
> For now, I am copying the root pixmap to the window, then telling
> cairo to draw over it, using the default cairo operator. However, once
> the root pixmap changes, I would have to copy the pixmap then redo the
> drawing process. This is not the most efficient way, and I'm curious
> as to if there is a better way that I haven't though of.
>
>
> Thank you again, and hopefully this is the right place to discuss this.
> ------------------------------------------------------------------------
>
>
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/xcb

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20171017/bab58510/attachment.html>


More information about the Xcb mailing list