Add mode 2031 support (automatic dark/light mode).

Co-Author: Nicholas Marriott <nicholas.marriott@gmail.com>
This commit is contained in:
Jonathan Slenders
2024-12-11 21:56:28 +00:00
parent ef68debc8d
commit e536f48d0e
11 changed files with 338 additions and 93 deletions

View File

@@ -182,6 +182,38 @@ colour_tostring(int c)
return ("invalid");
}
/* Convert background colour to theme. */
enum client_theme
colour_totheme(int c)
{
int r, g, b, brightness;
if (c == -1)
return (THEME_UNKNOWN);
if (c & COLOUR_FLAG_RGB) {
r = (c >> 16) & 0xff;
g = (c >> 8) & 0xff;
b = (c >> 0) & 0xff;
brightness = r + g + b;
if (brightness > 382)
return (THEME_LIGHT);
return (THEME_DARK);
}
if (c & COLOUR_FLAG_256)
return (colour_totheme(colour_256toRGB(c)));
switch (c) {
case 0:
return (THEME_DARK);
case 7:
return (THEME_LIGHT);
}
return (THEME_UNKNOWN);
}
/* Convert colour from string. */
int
colour_fromstring(const char *s)