Workaround for sRGB Colour Issue for Powerline on OS X May 29, 2015
Powerline for Emacs on OS X has a problem with its XPM arrows and sRGB colours. There is a rather lengthy discussion on Emacs’ mailing list about the root cause of the issue but without any substantial outcome.
In the meantime I thought I should take the matter to my own hands. I figure if the colour for the XPM arrow image is off by a little, maybe I can just apply a certain amount of offset to the colours used by the XPM image.
First I sampled the various wrong colours from a screenshot:
In my case I’m using Solarized Dark, but this technique should be applicable to other themes as well. Also I find sampling from screenshot give more accurate colours than sampling directly with a live sampling app (i.e. LittleSanpper).
Next I noticed that powerline gets the colours it uses for the XPM images from the
pl/background-color function. The
pl/background-color function receives as parameter the name of
the face (i.e.
"powerline-active1", etc.) and returns the colour for that face. So
I created an advice function around
pl/background-color. And in my advice function it looks up the
wrong colour from my previous measurements and compare that to the supposedly right colour
returned by the original
pl/background-color. From the two colours I then calculate the difference
between them and apply the difference back to the right colour to come up with the right colour
with offset. And the end result looks rather nice:
Note the end result isn’t absolutely perfect. If you look very closely you can see a very slight difference in colour between the arrows and the text’s background. But since I can’t really tell most of the time, that’s good enough for me.
The measurements for the wrong colours are taken from one of my computers, however they seem to work well across my other computers (2009 iMac, MacBook Air and MacBook Pro).
You can grab the extension here: powerline-srgb-offset.el.
Be sure to activate the fix before activating a powerline theme:
(load-library "powerline-srgb-offset") (powerline-srgb-offset-activate "solarized-dark") (powerline-default-theme)
Currently the extension comes with colours for
solarized-light. You can
register additional colours by calling the
(powerline-srgb-offset-add-theme "solarized-light" '('("mode-line" "#6A8188") '("powerline-active1" "#96A5A6") '("powerline-active2" "#788E95") '("mode-line-inactive" "#96A5A6") '("powerline-inactive1" "#F2ECDD") '("powerline-inactive2" "#A4B0B1")))
Just remember, the colour values above need to be of the wrong colours.