Bus, Ui, main: the system's appearance, dark or light and its accent
The desktop portal's org.freedesktop.appearance settings on the session bus say whether the system prefers dark (color-scheme 1) and which accent colour it uses, and a flatpak may read them. Bus:Appearance subscribes to SettingChanged and reads the namespace in one ReadAll call, which every portal version has, so a start waits for one answer at most, 2 s; a portal that gave no colour scheme by then — still starting, or not on the bus yet — is asked again when its name has an owner, without waiting, and its answer comes as a change. The canvas gained a dark palette and takes the accent for the avatars, badges, buttons and outgoing bubbles, with the text on it dark or light by the accent's brightness. The app applies the theme to the window at once and keeps it for the next one; --theme dark|light or IMSD_MESSAGES_THEME (the same two values: another is refused on the command line and ignored in the environment) overrides the portal's colour scheme, for benches and desktops without a portal.
This commit is contained in:
parent
4342c84d8f
commit
9332094333
7 changed files with 222 additions and 7 deletions
|
|
@ -34,6 +34,32 @@ export namespace ImsdMessages::Ui {
|
|||
Color divider = { 0.88f, 0.88f, 0.89f, 1.0f };
|
||||
Color danger = { 0.80f, 0.16f, 0.16f, 1.0f };
|
||||
Color scrim = { 0.0f, 0.0f, 0.0f, 0.35f };
|
||||
|
||||
static Theme Light() { return Theme{}; }
|
||||
|
||||
static Theme Dark() {
|
||||
Theme t;
|
||||
t.bg = { 0.07f, 0.07f, 0.08f, 1.0f };
|
||||
t.surface = { 0.12f, 0.12f, 0.13f, 1.0f };
|
||||
t.text = { 0.93f, 0.93f, 0.94f, 1.0f };
|
||||
t.muted = { 0.62f, 0.62f, 0.65f, 1.0f };
|
||||
t.bubbleIn = { 0.18f, 0.18f, 0.20f, 1.0f };
|
||||
t.banner = { 0.30f, 0.26f, 0.10f, 1.0f };
|
||||
t.bannerText = { 0.98f, 0.88f, 0.55f, 1.0f };
|
||||
t.divider = { 0.20f, 0.20f, 0.22f, 1.0f };
|
||||
t.danger = { 0.90f, 0.30f, 0.30f, 1.0f };
|
||||
t.scrim = { 0.0f, 0.0f, 0.0f, 0.55f };
|
||||
return t;
|
||||
}
|
||||
|
||||
// The system's accent colour, with text on it dark or light as its
|
||||
// brightness asks.
|
||||
void Accent(std::array<float, 3> rgb) {
|
||||
accent = { rgb[0], rgb[1], rgb[2], 1.0f };
|
||||
bubbleOut = accent;
|
||||
const float luminance = 0.2126f * rgb[0] + 0.7152f * rgb[1] + 0.0722f * rgb[2];
|
||||
onAccent = luminance > 0.6f ? Color{ 0.08f, 0.08f, 0.09f, 1.0f } : Color{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
}
|
||||
};
|
||||
|
||||
// One compositing layer: its own item buffers, one fused dispatch.
|
||||
|
|
|
|||
Loading…
Reference in a new issue