зеркало из https://github.com/nextcloud/desktop.git
on Windows 10 follow color scheme changes and apply them
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Родитель
1399a32edc
Коммит
1a9ba18661
|
@ -126,21 +126,6 @@ namespace {
|
|||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
class WindowsNativeEventFilter : public QAbstractNativeEventFilter {
|
||||
public:
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override {
|
||||
const auto msg = static_cast<MSG *>(message);
|
||||
if(msg->message == WM_SYSCOLORCHANGE || msg->message == WM_SETTINGCHANGE) {
|
||||
if (const auto ptr = qobject_cast<QGuiApplication *>(QGuiApplication::instance())) {
|
||||
emit ptr->paletteChanged(ptr->palette());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
bool Application::configVersionMigration()
|
||||
{
|
||||
QStringList deleteKeys, ignoreKeys;
|
||||
|
@ -237,9 +222,6 @@ Application::Application(int &argc, char **argv)
|
|||
// Ensure OpenSSL config file is only loaded from app directory
|
||||
QString opensslConf = QCoreApplication::applicationDirPath() + QString("/openssl.cnf");
|
||||
qputenv("OPENSSL_CONF", opensslConf.toLocal8Bit());
|
||||
|
||||
// Set up event listener for Windows theme changing
|
||||
installNativeEventFilter(new WindowsNativeEventFilter());
|
||||
#endif
|
||||
|
||||
// TODO: Can't set this without breaking current config paths
|
||||
|
@ -384,6 +366,8 @@ Application::Application(int &argc, char **argv)
|
|||
|
||||
_theme->setSystrayUseMonoIcons(ConfigFile().monoIcons());
|
||||
connect(_theme, &Theme::systrayUseMonoIconsChanged, this, &Application::slotUseMonoIconsChanged);
|
||||
connect(this, &Application::systemPaletteChanged,
|
||||
_theme, &Theme::systemPaletteHasChanged);
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
_shellExtensionsServer.reset(new ShellExtensionsServer);
|
||||
|
@ -1127,6 +1111,9 @@ bool Application::event(QEvent *event)
|
|||
qCInfo(lcApplication) << errorParsingLocalFileEditingUrl;
|
||||
showHint(errorParsingLocalFileEditingUrl.toStdString());
|
||||
}
|
||||
} else if (event->type() == QEvent::ApplicationPaletteChange) {
|
||||
qCInfo(lcApplication) << "application palette changed";
|
||||
emit systemPaletteChanged();
|
||||
}
|
||||
return SharedTools::QtSingleApplication::event(event);
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ signals:
|
|||
void folderRemoved();
|
||||
void folderStateChanged(OCC::Folder *);
|
||||
void isShowingSettingsDialog();
|
||||
void systemPaletteChanged();
|
||||
|
||||
protected slots:
|
||||
void slotParseMessage(const QString &, QObject *);
|
||||
|
|
|
@ -969,16 +969,8 @@ QColor Theme::defaultColor()
|
|||
void Theme::connectToPaletteSignal()
|
||||
{
|
||||
if (!_paletteSignalsConnected) {
|
||||
if (const auto ptr = qobject_cast<QGuiApplication *>(QGuiApplication::instance())) {
|
||||
#ifdef Q_OS_WIN
|
||||
// Windows 10 does not have proper dark mode support via Qt 6 so hack detection
|
||||
if (!isWindows11OrGreater()) {
|
||||
connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged);
|
||||
}
|
||||
if (const auto ptr = qobject_cast<QGuiApplication*>(qApp)) {
|
||||
connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged);
|
||||
_paletteSignalsConnected = true;
|
||||
}
|
||||
}
|
||||
|
@ -1088,4 +1080,14 @@ void Theme::setStartLoginFlowAutomatically(bool startLoginFlowAuto)
|
|||
}
|
||||
}
|
||||
|
||||
void Theme::systemPaletteHasChanged()
|
||||
{
|
||||
qCInfo(lcTheme()) << "system palette changed";
|
||||
#ifdef Q_OS_WIN
|
||||
if (darkMode() && !isWindows11OrGreater()) {
|
||||
qApp->setPalette(reserveDarkPalette);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // end namespace client
|
||||
|
|
|
@ -609,6 +609,7 @@ public slots:
|
|||
void setForceOverrideServerUrl(bool forceOverride);
|
||||
void setVfsEnabled(bool enabled);
|
||||
void setStartLoginFlowAutomatically(bool startLoginFlowAuto);
|
||||
void systemPaletteHasChanged();
|
||||
|
||||
protected:
|
||||
#ifndef TOKEN_AUTH_ONLY
|
||||
|
|
Загрузка…
Ссылка в новой задаче