# Auto contrast adjustment on display names

**URL:** <https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312>\
**Category:** Pidgin\
**Tags:** development\
**Created:** [October 1, 2025, 9:24am UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312 "2025-10-01T09:24:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 1, 2025, 9:24am UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/1 "2025-10-01T09:24:41Z")

</div>

I realized we can calculate the colors because know the background colors for adwaita, so we just need to check light/dark and go from there.

But i saw something about some new algorithm and when I was looking I was having issues parsing the math and couldn’t find the links we were looking at previously for this.

I don’t suppose anyone remembers what they were or is able to find them again?

---

<div class="post-metadata">

**Author:** ![ivanhoe](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/ivanhoe/32/24_2.png) [@ivanhoe](https://discourse.imfreedom.org/u/ivanhoe)\
**Post date:** [October 1, 2025, 6:27pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/2 "2025-10-01T18:27:50Z")

</div>

Judging from [this and following](https://discord.com/channels/351558764417122305/624712166968131595/799210688902987778) you were looking at the algorithm Gajim is using.

---

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 1, 2025, 7:00pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/3 "2025-10-01T19:00:32Z")

</div>

Good call on searching discord and I’m sad I didn’t think of that. Clearly this is another reason why we should be having these discussions here too 😃

At any rate, this will help me pick this back up so thank you!

---

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 1, 2025, 7:36pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/4 "2025-10-01T19:36:18Z")

</div>

Looks like [this](https://github.com/hsluv/hsluv-c) has all the math we need for this. I’m not sure how this will handle the contrast stuff, but it’s at least a starting point.

More information on their web site [https://www.hsluv.org/](https://www.hsluv.org/)

---

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 2, 2025, 3:36am UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/5 "2025-10-02T03:36:41Z")

</div>

Sometimes the answers are already documented and you just need to look for them 🤦 [Pidgin.color\_calculate\_for\_text](https://docs.imfreedom.org/pidgin3/func.color_calculate_for_text.html)

---

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 2, 2025, 5:42am UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/6 "2025-10-02T05:42:04Z")

</div>

Which one looks better? They’re fuzzy because they’re zoomed in, click on them to see normal resolution.

current code

 ![image](https://canada1.discourse-cdn.com/flex007/uploads/imfreedom/original/1X/c18c942e820599029e7905e4d552091f119b99ca.png)  
 ![image](https://canada1.discourse-cdn.com/flex007/uploads/imfreedom/original/1X/8b42971ba5cacdaf32cced08df83bb01e7abdb0b.png)

new incomplete code

 ![image](https://canada1.discourse-cdn.com/flex007/uploads/imfreedom/original/1X/ff313b0a123b2fbbbb482b314a08d3137d6ae1cf.png)  
 ![image](https://canada1.discourse-cdn.com/flex007/uploads/imfreedom/original/1X/0343a2d3afd9f101378af8610cc54447d41ec23d.png)

---

<div class="post-metadata">

**Author:** ![Deledrius](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/deledrius/32/112_2.png) [@Deledrius](https://discourse.imfreedom.org/u/Deledrius)\
**Post date:** [October 2, 2025, 5:07pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/7 "2025-10-02T17:07:42Z")

</div>

The new code definitely looks better to my eyes. There are several names that are unreadable in at least one of the two windows for the current code, but they’re all readable in the new code.

---

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 2, 2025, 5:48pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/8 "2025-10-02T17:48:46Z")

</div>

Good to hear. This is the expected result as the new code uses a standard implementation, but you know, always good to ask others too 🙂

The “incompleteness” here is that it doesn’t auto detect light/dark mode yet so I just hard coded it for both screen shots.

---

<div class="post-metadata">

**Author:** ![ivanhoe](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/ivanhoe/32/24_2.png) [@ivanhoe](https://discourse.imfreedom.org/u/ivanhoe)\
**Post date:** [October 2, 2025, 5:50pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/9 "2025-10-02T17:50:02Z")

</div>

I also think the new code produced better results.

---

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 2, 2025, 5:51pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/10 "2025-10-02T17:51:50Z")

</div>

Cool! As I mentioned on discord and alluded to above, this is based on [XEP-0392](https://xmpp.org/extensions/xep-0392.html) so these colors should match other XMPP clients that implement this XEP and potentially other clients too.

---

<div class="post-metadata">

**Author:** ![grim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discourse.imfreedom.org/grim/32/4_2.png) [@grim](https://discourse.imfreedom.org/u/grim)\
**Post date:** [October 3, 2025, 9:53pm UTC](https://discourse.imfreedom.org/t/auto-contrast-adjustment-on-display-names/312/11 "2025-10-03T21:53:00Z")

</div>

This was landed in [/r/4211](https://reviews.imfreedom.org/r/4211/).
