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
|
|
@ -123,6 +123,15 @@ export namespace ImsdMessages::Ui {
|
|||
|
||||
bool Visible() const noexcept { return canvas.has_value(); }
|
||||
|
||||
// The system's appearance: dark or light, and its accent colour.
|
||||
// Applied to the window at once and kept for the next one.
|
||||
void SetTheme(bool dark, std::optional<std::array<float, 3>> accent) {
|
||||
theme = dark ? Theme::Dark() : Theme::Light();
|
||||
if (accent) theme.Accent(*accent);
|
||||
if (canvas) canvas->theme = theme;
|
||||
Dirty();
|
||||
}
|
||||
|
||||
// Cancels a close's deferred Hide: a Show or an Open before it runs
|
||||
// keeps the window. True when there was one.
|
||||
bool KeepWindow() {
|
||||
|
|
@ -157,6 +166,7 @@ export namespace ImsdMessages::Ui {
|
|||
Log(std::format("no window: {}", e.what()));
|
||||
return;
|
||||
}
|
||||
canvas->theme = theme;
|
||||
if (!source) {
|
||||
source.emplace(Crafter::Device::display);
|
||||
source->onLost = [this] {
|
||||
|
|
@ -936,6 +946,7 @@ export namespace ImsdMessages::Ui {
|
|||
std::filesystem::path assetDir;
|
||||
std::filesystem::path cacheDir;
|
||||
AppStatus status;
|
||||
Theme theme;
|
||||
std::vector<Conversation> convs;
|
||||
std::optional<Canvas> canvas;
|
||||
std::vector<std::string> hitKeys; // the conversation each row region named, as drawn
|
||||
|
|
|
|||
Loading…
Reference in a new issue