Unverified Commit 91a87b6d authored by Andre Heinecke's avatar Andre Heinecke
Browse files

Add SystemInfo::isDarkModeActive

At least on Windows HighContrastMode does not automatically
mean dark mode. The problem is that the Dark Mode detection
in Qt does not seem to work properly so that we only handle
Dark Modes in High Contrast mode and not if the User enabled
a Dark Theme through AppsUseLightTheme registry value.

GnuPG-Bug-Id: T6076
parent b5c7bfee
Pipeline #221576 passed with stage
in 1 minute and 53 seconds
# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: none
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
set(PIM_VERSION "5.21.46")
set(PIM_VERSION "5.21.47")
project(libkleo VERSION ${PIM_VERSION})
......
......@@ -14,9 +14,12 @@
#include <QByteArray>
#include <QtGlobal>
#include <QOperatingSystemVersion>
// #include "libkleo_debug.h"
#ifdef Q_OS_WIN
#include "windows.h"
// #include "gnupg-registry.h"
#endif
#ifdef Q_OS_WIN
......@@ -31,6 +34,43 @@ bool win_isHighContrastModeActive()
}
return false;
}
bool win_isDarkModeActive()
{
/* This is a bit complicated. Qt does not detect this correctly
* for high contrast mode with white contrast. */
// First check for white background. That is set in High contrast
// white theme.
DWORD color = GetSysColor(COLOR_WINDOW);
if (color == 0xFFFFFF) {
return false;
}
// Windows 10 has only one white High Contrast mode. The other
// three are dark.
if (win_isHighContrastModeActive()) {
return true;
}
#if 0
// This is not enabled because although Qt does check for this, the theme
// does not switch accordingly in tests. So we would have white icons on a
// bright window.
//
// The user may have customized a dark theme. Then AppsUseLightTheme is 0
char *val = read_w32_registry_string ("HKEY_CURRENT_USER",
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
"AppsUseLightTheme");
bool ret = false;
if (val) {
ret = !((DWORD) *val);
free (val);
return ret;
}
#endif
// Nothing set -> default to bright.
return false;
}
}
#endif
......@@ -44,3 +84,13 @@ bool Kleo::SystemInfo::isHighContrastModeActive()
return forceHighContrastMode;
#endif
}
bool Kleo::SystemInfo::isDarkModeActive()
{
#ifdef Q_OS_WIN
return win_isDarkModeActive();
#else
// Don't know
return isHighContrastModeActive();
#endif
}
......@@ -16,5 +16,6 @@ namespace Kleo::SystemInfo
{
KLEO_EXPORT bool isHighContrastModeActive();
KLEO_EXPORT bool isDarkModeActive();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment