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 795729b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
41 changes: 29 additions & 12 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,26 @@ 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)
base::Platform::XDP::SettingWatcher _darkModeWatcher;
#endif // Qt < 6.5.0
};

LinuxIntegration::LinuxIntegration()
: _application(MakeApplication())
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
, _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
{
"org.freedesktop.appearance",
"color-scheme",
[](GLib::Variant value) {
#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(
value.get_uint32() == 1);
});
}) {
LOG(("Icon theme: %1").arg(QIcon::themeName()));
LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName()));

Expand All @@ -230,6 +233,20 @@ void LinuxIntegration::init() {

initInhibit();
}));

Core::App().settings().systemDarkModeChanges(
) | rpl::filter(
!rpl::mappers::_1
) | rpl::start_with_next([] {
const auto value = base::Platform::XDP::ReadSetting(
"org.freedesktop.appearance",
"color-scheme");

if (value.has_value()) {
Core::App().settings().setSystemDarkMode(
value->get_uint32() == 1);
}
});
}

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 795729b

Please sign in to comment.