Skip to content

Commit

Permalink
Attempt to provide fallback for Linux platform themes not implementin…
Browse files Browse the repository at this point in the history
…g QStyleHints::colorScheme
  • Loading branch information
ilya-fedin committed Oct 12, 2024
1 parent 88703ba commit 1ee66f9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
45 changes: 35 additions & 10 deletions Telegram/SourceFiles/platform/linux/integration_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For license and copyright information please follow this link:
#include "base/random.h"

#include <QtCore/QAbstractEventDispatcher>
#include <QtGui/QStyleHints>

#include <gio/gio.hpp>
#include <xdpinhibit/xdpinhibit.hpp>
Expand Down Expand Up @@ -189,24 +190,28 @@ class LinuxIntegration final : public Integration, public base::has_weak_ptr {

const gi::ref_ptr<Application> _application;
XdpInhibit::InhibitProxy _inhibitProxy;
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
rpl::variable<std::optional<bool>> _darkMode;
base::Platform::XDP::SettingWatcher _darkModeWatcher;
#endif // Qt < 6.5.0
rpl::lifetime _lifetime;
};

LinuxIntegration::LinuxIntegration()
: _application(MakeApplication())
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
, _darkMode([]() -> std::optional<bool> {
if (auto value = base::Platform::XDP::ReadSetting(
"org.freedesktop.appearance",
"color-scheme")) {
return value->get_uint32() == 1;
}
return std::nullopt;
})
, _darkModeWatcher(
"org.freedesktop.appearance",
"color-scheme",
[](GLib::Variant value) {
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
Core::App().settings().setSystemDarkMode(value.get_uint32() == 1);
});
})
#endif // Qt < 6.5.0
{
[=](GLib::Variant value) {
_darkMode = value.get_uint32() == 1;
}
) {
LOG(("Icon theme: %1").arg(QIcon::themeName()));
LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName()));

Expand All @@ -230,6 +235,26 @@ void LinuxIntegration::init() {

initInhibit();
}));

_darkMode.value(
) | rpl::start_with_next([=] {
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
if (QGuiApplication::styleHints()->colorScheme()
!= Qt::ColorScheme::Unknown) {
return;
}
#endif // Qt >= 6.5.0
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
Core::App().settings().setSystemDarkMode(_darkMode.current());
});
}, _lifetime);

Core::App().settings().systemDarkModeValue(
) | rpl::filter(
!rpl::mappers::_1
) | rpl::start_with_next([=] {
Core::App().settings().setSystemDarkMode(_darkMode.current());
}, _lifetime);
}

void LinuxIntegration::initInhibit() {
Expand Down
8 changes: 1 addition & 7 deletions Telegram/SourceFiles/platform/linux/specific_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,7 @@ QString SingleInstanceLocalServerName(const QString &hash) {

#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
std::optional<bool> IsDarkMode() {
auto result = base::Platform::XDP::ReadSetting(
"org.freedesktop.appearance",
"color-scheme");

return result.has_value()
? std::make_optional(result->get_uint32() == 1)
: std::nullopt;
return std::nullopt;
}
#endif // Qt < 6.5.0

Expand Down

0 comments on commit 1ee66f9

Please sign in to comment.