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

feat: Add gradient borders #22

Merged
merged 4 commits into from
Nov 25, 2023
Merged

feat: Add gradient borders #22

merged 4 commits into from
Nov 25, 2023

Conversation

mizlan
Copy link
Contributor

@mizlan mizlan commented Nov 23, 2023

Very initial, incomplete, hardcoded HACK as of right now.

  • Work with square borders
  • Support top-left to bottom-right corner gradient too
  • (Maybe?) 4 corner gradient—this would be implemented differently
  • Commandline option support

Creates a gradient that is clipped to the stroke path as described in the SO thread in #19.

I also noticed frame dropping with Yabai resizing (i.e., it would only have maybe 3 intermediate frames that animate in a choppy manner) (fixed by restarting Yabai) which may or may not be related to this.

@mizlan
Copy link
Contributor Author

mizlan commented Nov 23, 2023

  • Arithmetic manipulation of the frame size can be used to neatly support {top,bottom}-{left-right} directions for gradients.
  • Would you want to use a more heavy argument parser, or do you think the current sscanf method is sufficient?
  • Square borders shouldn't be very hard to add. It is in fact easier since it relies on the fill, not stroke, which is already supported by the CGContextDrawLinearGradient API (indeed it is stroke that needs the SO-thread "hack")

@FelixKratz
Copy link
Owner

I was thinking in terms of configuration syntax it would be sufficient to have something like this for now where we only allow diagonal gradients but can easily extend support to further gradient configurations:

borders active_color=gradient(top_right=<color_hex>,bottom_left=<color_hex>)
borders active_color=gradient(top_left=<color_hex>,bottom_right=<color_hex>)

which would of course also work for the inactive_color.

In the future, further special colors could be supported with this system as well, i.e. active_color=stripes(...) etc.

For the moment the sscanf method is sufficient, it can easily be extended to support even this more complex configuration syntax.

@FelixKratz FelixKratz linked an issue Nov 24, 2023 that may be closed by this pull request
@mizlan mizlan marked this pull request as ready for review November 24, 2023 21:23
@mizlan
Copy link
Contributor Author

mizlan commented Nov 24, 2023

@FelixKratz Can you explain why this is?

JankyBorders/src/border.c

Lines 118 to 120 in 09ec919

CGRect square_rect = CGRectInset(path_rect,
-g_settings.border_width / 2.f,
-g_settings.border_width / 2.f );

Currently style=square gradient renders twice as thick as it should, and I suspect it has to do with this

@mizlan
Copy link
Contributor Author

mizlan commented Nov 24, 2023

I will probably change the type/field names of the new stuff I introduced, if you have suggestions let me know.

@FelixKratz
Copy link
Owner

FelixKratz commented Nov 25, 2023

I have made a cleanup pass through the code, fixed some memory leaks, changed some some things around, implemented the directionality and fixed the double wide square gradient borders. Once you sign off on those changes I will merge.

@mizlan
Copy link
Contributor Author

mizlan commented Nov 25, 2023

Looks great! Thanks for doing all that.

One thing: the current syntax is not nice for adding arbitrary number of gradient color "stops"—not sure if you wanted to think more about that (e.g., red one corner -> green in the middle -> blue other corner) or if the current approach is fine.

@FelixKratz FelixKratz merged commit 23fbe36 into FelixKratz:main Nov 25, 2023
@FelixKratz
Copy link
Owner

Thanks!

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.

[Request] Gradient
2 participants