artemsen / swayimg

Image viewer for Wayland
MIT License
367 stars 30 forks source link

allow for translucent colors on window and image backgrounds #143

Closed an-prata closed 4 months ago

an-prata commented 4 months ago

Allows for colors in the format #RRGGBBAA in addition to the already permitted #RRGGBB for window and transparent image backgrounds. This change makes the none config option exactly equivilent to #00000000, and both are acceptable - this PR does not (to my knowledge) make any breaking changes. This format is disallowed for other config options still.

Implemented via a slightly modified config_to_color function called config_to_translucent_color, which will make the numeric conversion from hex to a 32 bit integer as usual, then masks out the alpha and shifts some bits to match the format of argb_t if the input string is longer than 6 characters.

Since the alpha channel was used for a sentinal value indicating a grid background for images - the indication of this option is now a bool in viewer.c's viewer struct.

Am happy to hear feedback in case any changes are sub-optimal or have a prefered alternative - thanks!

artemsen commented 4 months ago

Yeah, I forgot about that hacks with special values in color. We need to get rid of them, but may be not in this PR. Anyway, my vacation doesn't allow me to deep into the code in next two weeks :)

On Tue, Jun 18, 2024, 02:24 Evan Overman @.***> wrote:

@.**** commented on this pull request.

In src/config.h https://github.com/artemsen/swayimg/pull/143#discussion_r1643540076:

  • @param text text to convert
    • @param color output variable
    • @return false if text has invalid format / bool config_to_color(const char text, argb_t* color);
    • +/**

      • Convert text value to ARGB color which may be any alpha.
      • @param text text to convert
      • @param color output variable
      • @return false if text has invalid format
    • */

I may be mistaken about the cause, but if the config_to_translucent_color is used for all colors then I get some weird effects on the overlay's font. I imagine this is because the alpha value is used in text.c for special meanings (absence/presence of shadow), unfortunately mirroring the original behavior of giving an alpha of 0x00 when none is given would result in background colors not working correctly when given an opaque color, as it would translate to being transparent (alpha of 0x00), rather than opaque (alpha of 0xff) like in the new function.

Could easily be paramterized, but behavior must differ between parsing

RRGGBB and #RRGGBBAA. I didn't parameterize it in order to minimize the

PR's changes.

— Reply to this email directly, view it on GitHub https://github.com/artemsen/swayimg/pull/143#discussion_r1643540076, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI5UODYGFMPOORQCUZK3BTZH5VZJAVCNFSM6AAAAABJMLCI32VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCMRUGA3DONJXG4 . You are receiving this because you commented.Message ID: @.***>

artemsen commented 4 months ago

Could you squash these commits? And add Signed-off-by to the commit message please.