st + alpha + escape sequence to change background color gives opaque terminal
If you have st with the [alpha](https://st.suckless.org/patches/alpha/) patch and you change the background color using an escape sequence then the transparency is lost and the terminal becomes opaque. This is also the case when using tools like [pywal](https://github.com/dylanaraps/pywal) and I think a workaround was to use a different value for defaultbg to avoid this.
Example escape sequence to test this with:
printf "\033]4;258;#000000\033\\"
(the 258 value must be the same as the value of defaultbg in your config)
loiccoyle on github sent me a pull request to fix this and it's actually very simple, borrowing the alpha code from `xloadcols` and adding them to the end of the `xsetcolorname` function before the return.
int xsetcolorname(int x, const char *name) { ... if (x == defaultbg) { if (opt_alpha) alpha = strtof(opt_alpha, NULL); dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha); dc.col[defaultbg].pixel &= 0x00FFFFFF; dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24; } return 0; }
or if you are on an older version of the patch:
int xsetcolorname(int x, const char *name) { ... if (x == defaultbg && USE_ARGB) { dc.col[defaultbg].color.alpha = alpha << 8; dc.col[defaultbg].color.red = ((dc.col[defaultbg].color.red >> 8) * alpha / 255) << 8; dc.col[defaultbg].color.green = ((dc.col[defaultbg].color.green >> 8) * alpha / 255) << 8; dc.col[defaultbg].color.blue = ((dc.col[defaultbg].color.blue >> 8) * alpha / 255) << 8; } return 0; }
Posting in case someone might find this useful.