yshui / picom

A lightweight compositor for X11
Other
3.92k stars 576 forks source link

Corner Radius Fix for GLX #1261

Open pijulius opened 1 month ago

pijulius commented 1 month ago

This should fix the corner radius in the glx backend to be almost exactly the same as xrender. Not that good at math myself but I think the problem lies behind the circle already being the right size just the center of it was positioned off a bit and that's why it looked a bit "rectanglish".

Please see attached screenshots. corner-glxfix corner-glxfix-zoomed

yshui commented 1 month ago

hmmm, thanks for the patch, but i want to understand this problem better.

what corner radius did you use to get these screenshots?

pijulius commented 1 month ago

hi @yshui , for sure! I used: corner-radius = 10

and tested with corner radius 1 too and indeed looks fine with that too.

yshui commented 1 month ago

hmm, i wonder if the off by 1 error is actually here:

        if (rect_distance > 0.0f) { // <----
            c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * rim_color;
        } else {
            float factor = clamp(rect_distance + border_width, 0.0f, 1.0f);
            c = (1.0f - factor) * c + factor * border_color;
        }

maybe it should be

        if (rect_distance > -0.5f) { // <----
            c = (0.5f - clamp(rect_distance, -0.5f, 0.5f)) * rim_color;
        } else {
            float factor = clamp(rect_distance + border_width, 0.0f, 1.0f);
            c = (1.0f - factor) * c + factor * border_color;
        }

?

pijulius commented 1 month ago

Hmmm, I tried that change but it makes shadows disappear, ok, not disappear but to see them I need to set shadow-opacity to 0.9 or so, so it affects the shadow in big way. The -1 I added doesn't seem to affect the shadow at all.

yshui commented 1 month ago

So my current thought is this: texcoord is at center of pixels (I think this is the case for fragment shaders), so rect_distance == 0 means the pixel center is right at the edge of the circle, which means it should be color at approx. 50%. But we are currently coloring it 100%

pijulius commented 1 month ago

FYI: have now fixed rounded corners for the mask too, please see: Fix GLX corner radis for the mask too

Also added this new feature: Add possibility for frame opacity to include menubar/toolbar and so on

screenshot-20240526123536

not sure what you think about it, if you like it at all can work on formatting and other backends too but for now to showcase and for myself this was enough to achieve what I wanted.