Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corner Radius Fix for GLX #1261

Open
wants to merge 25 commits into
base: next
Choose a base branch
from
Open

Corner Radius Fix for GLX #1261

wants to merge 25 commits into from

Conversation

pijulius
Copy link

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

@pijulius pijulius changed the title Corder Radius Fix for GLX Corner Radius Fix for GLX May 18, 2024
@yshui
Copy link
Owner

yshui commented May 18, 2024

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

what corner radius did you use to get these screenshots?

@pijulius
Copy link
Author

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

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

@yshui
Copy link
Owner

yshui commented May 19, 2024

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
Copy link
Author

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
Copy link
Owner

yshui commented May 19, 2024

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%

This adds support for desktop switching animations by keeping track of _NET_CURRENT_DESKTOP atom on the root window. 

As far as I understand this atom is set by window managers and so if it changes we can know that it's a desktop switch happening. Unfortunately window manager may need to set this BEFORE hiding/showing windows so we can animate correctly, me personally using FluxBox and this quick change pijulius/fluxbox@83ee4db  makes it work just fine.

It adds the following animation triggers:
* workspace-out
* workspace-out-inverse
* workspace-in
* workspace-in-inverse

Unfortunately had to add inverse variables too as you may navigate to the next workspace from for e.g. 1st to 2nd but you may also go to 2nd from 1st and in that case the animations have to be totally different.

Here is a config example for switching workspace:

animations = ({
    triggers = ["workspace-out"];
    offset-y = {
        timing = "0.2s cubic-bezier(0.21, 0.02, 0.76, 0.36)";
        start = "0";
        end = "-window-height";
    };
    shadow-offset-y = "offset-y";
    opacity = {
        timing = "0.2s linear";
        start = "window-raw-opacity-before";
        end = "window-raw-opacity";
    };
    blur-opacity = "opacity";
    shadow-opacity = "opacity";
},
{
    triggers = ["workspace-out-inverse"];
    offset-y = {
        timing = "0.2s cubic-bezier(0.21, 0.02, 0.76, 0.36)";
        start = "0";
        end = "window-height + window-y";
    };
    shadow-offset-y = "offset-y";
    opacity = {
        timing = "0.2s linear";
        start = "window-raw-opacity-before";
        end = "window-raw-opacity";
    };
    blur-opacity = "opacity";
    shadow-opacity = "opacity";
},
{
    triggers = ["workspace-in"];
    offset-y = {
        timing = "0.2s cubic-bezier(0.24, 0.64, 0.79, 0.98)";
        start = "window-height + window-y";
        end = "0";
    };
    shadow-offset-y = "offset-y";
    opacity = {
        timing = "0.2s linear";
        start = "0";
        end = "window-raw-opacity";
    };
    blur-opacity = "opacity";
    shadow-opacity = "opacity";
},
{
    triggers = ["workspace-in-inverse"];
    offset-y = {
        timing = "0.2s cubic-bezier(0.24, 0.64, 0.79, 0.98)";
        start = "-window-height";
        end = "0";
    };
    shadow-offset-y = "offset-y";
    opacity = {
        timing = "0.2s linear";
        start = "0";
        end = "window-raw-opacity";
    };
    blur-opacity = "opacity";
    shadow-opacity = "opacity";
})
This adds the possibility to define the frame opacity but also include all colors in the window that match the frame color and make those also transparent. It even supports the possibility to define the tolerance for color difference between the frame and other parts of the window and make those or gradually more opaque or also transparent just like the frame.

NOTE: tested with flat window frame so not sure how it will work with gradient frames and also only added for GLX atm, lets see if it's interesting enough to be included in the core or otherwise will just keep it for myself.

It adds the following config options:

# Enable frame opacity for colors that match the frame
frame-opacity-for-same-colors = true;

# Tolerance for similar colors (0 exact match, 1 all colors, default 0.5)
frame-opacity-for-same-colors-constraint = 0.5;

# Make different colors opaque by a factor of x (default 5)
frame-opacity-for-same-colors-multiplier = 5;

and for them to work you will have to active frame opacity for e.g.
frame-opacity = 0.7;

With these options you can now have blurred transparent frame + menubar + toolbar or on popup like File Open have transparent window background but list of files be opaque and so on.
@pijulius
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants