mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Implement org.freedesktop.appearance.color-scheme
This commit is contained in:
parent
ddeac15859
commit
17fcc729a2
1 changed files with 13 additions and 117 deletions
|
@ -32,11 +32,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
||||||
#include "base/platform/linux/base_linux_xsettings.h"
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
#include <QtWidgets/QStyle>
|
|
||||||
#include <QtCore/QStandardPaths>
|
#include <QtCore/QStandardPaths>
|
||||||
#include <QtCore/QProcess>
|
#include <QtCore/QProcess>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
|
@ -68,7 +66,6 @@ namespace {
|
||||||
|
|
||||||
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
|
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
|
||||||
constexpr auto kIconName = "telegram"_cs;
|
constexpr auto kIconName = "telegram"_cs;
|
||||||
constexpr auto kDarkColorLimit = 192;
|
|
||||||
|
|
||||||
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
|
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
|
||||||
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
|
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
|
||||||
|
@ -400,6 +397,7 @@ QString GetIconName() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<bool> IsDarkMode() {
|
std::optional<bool> IsDarkMode() {
|
||||||
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
[[maybe_unused]] static const auto Inited = [] {
|
[[maybe_unused]] static const auto Inited = [] {
|
||||||
static const auto Setter = [] {
|
static const auto Setter = [] {
|
||||||
crl::on_main([] {
|
crl::on_main([] {
|
||||||
|
@ -407,140 +405,38 @@ std::optional<bool> IsDarkMode() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
qGuiApp,
|
|
||||||
&QGuiApplication::paletteChanged,
|
|
||||||
Setter);
|
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
||||||
using base::Platform::XCB::XSettings;
|
|
||||||
if (const auto xSettings = XSettings::Instance()) {
|
|
||||||
xSettings->registerCallbackForProperty("Net/ThemeName", [](
|
|
||||||
xcb_connection_t *,
|
|
||||||
const QByteArray &,
|
|
||||||
const QVariant &,
|
|
||||||
void *) {
|
|
||||||
Setter();
|
|
||||||
}, nullptr);
|
|
||||||
}
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
using XDPSettingWatcher = base::Platform::XDP::SettingWatcher;
|
using XDPSettingWatcher = base::Platform::XDP::SettingWatcher;
|
||||||
static const XDPSettingWatcher GtkThemeWatcher(
|
static const XDPSettingWatcher Watcher(
|
||||||
[=](
|
[=](
|
||||||
const Glib::ustring &group,
|
const Glib::ustring &group,
|
||||||
const Glib::ustring &key,
|
const Glib::ustring &key,
|
||||||
const Glib::VariantBase &value) {
|
const Glib::VariantBase &value) {
|
||||||
if (group == "org.gnome.desktop.interface"
|
if (group == "org.freedesktop.appearance"
|
||||||
&& key == "gtk-theme") {
|
&& key == "color-scheme") {
|
||||||
Setter();
|
Setter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
static const XDPSettingWatcher KdeColorSchemeWatcher(
|
|
||||||
[=](
|
|
||||||
const Glib::ustring &group,
|
|
||||||
const Glib::ustring &key,
|
|
||||||
const Glib::VariantBase &value) {
|
|
||||||
if (group == "org.kde.kdeglobals.General"
|
|
||||||
&& key == "ColorScheme") {
|
|
||||||
Setter();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
std::optional<bool> result;
|
|
||||||
|
|
||||||
const auto styleName = QApplication::style()->metaObject()->className();
|
|
||||||
if (styleName != qstr("QFusionStyle")
|
|
||||||
&& styleName != qstr("QWindowsStyle")) {
|
|
||||||
result = false;
|
|
||||||
|
|
||||||
const auto paletteBackgroundGray = qGray(
|
|
||||||
QPalette().color(QPalette::Window).rgb());
|
|
||||||
|
|
||||||
if (paletteBackgroundGray < kDarkColorLimit) {
|
|
||||||
result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
||||||
using base::Platform::XCB::XSettings;
|
|
||||||
if (const auto xSettings = XSettings::Instance()) {
|
|
||||||
const auto gtkThemeX = xSettings->setting("Net/ThemeName");
|
|
||||||
if (gtkThemeX.isValid()) {
|
|
||||||
result = false;
|
|
||||||
if (gtkThemeX.toString().contains(
|
|
||||||
qsl("-dark"),
|
|
||||||
Qt::CaseInsensitive)) {
|
|
||||||
result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
try {
|
try {
|
||||||
using namespace base::Platform::XDP;
|
const auto result = base::Platform::XDP::ReadSetting(
|
||||||
|
"org.freedesktop.appearance",
|
||||||
|
"color-scheme");
|
||||||
|
|
||||||
const auto gtkThemePortal = ReadSetting(
|
if (result.has_value()) {
|
||||||
"org.gnome.desktop.interface",
|
const auto value = base::Platform::GlibVariantCast<uint>(*result);
|
||||||
"gtk-theme");
|
if (value == 1) {
|
||||||
|
return true;
|
||||||
if (gtkThemePortal.has_value()) {
|
|
||||||
const auto gtkThemePortalString = QString::fromStdString(
|
|
||||||
base::Platform::GlibVariantCast<Glib::ustring>(
|
|
||||||
*gtkThemePortal));
|
|
||||||
|
|
||||||
result = false;
|
|
||||||
|
|
||||||
if (gtkThemePortalString.contains(
|
|
||||||
qsl("-dark"),
|
|
||||||
Qt::CaseInsensitive)) {
|
|
||||||
result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
using namespace base::Platform::XDP;
|
|
||||||
|
|
||||||
const auto kdeBackgroundColorOptional = ReadSetting(
|
|
||||||
"org.kde.kdeglobals.Colors:Window",
|
|
||||||
"BackgroundNormal");
|
|
||||||
|
|
||||||
if (kdeBackgroundColorOptional.has_value()) {
|
|
||||||
const auto kdeBackgroundColorList = QString::fromStdString(
|
|
||||||
base::Platform::GlibVariantCast<Glib::ustring>(
|
|
||||||
*kdeBackgroundColorOptional)).split(',');
|
|
||||||
|
|
||||||
if (kdeBackgroundColorList.size() >= 3) {
|
|
||||||
result = false;
|
|
||||||
|
|
||||||
const auto kdeBackgroundGray = qGray(
|
|
||||||
kdeBackgroundColorList[0].toInt(),
|
|
||||||
kdeBackgroundColorList[1].toInt(),
|
|
||||||
kdeBackgroundColorList[2].toInt());
|
|
||||||
|
|
||||||
if (kdeBackgroundGray < kDarkColorLimit) {
|
|
||||||
result = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
}
|
}
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
return result;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AutostartSupported() {
|
bool AutostartSupported() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue