Libkleo

systeminfo.cpp
1/* -*- mode: c++; c-basic-offset:4 -*-
2 utils/systeminfo.cpp
3
4 This file is part of libkleopatra
5 SPDX-FileCopyrightText: 2022 g10 Code GmbH
6 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include <config-libkleo.h>
12
13#include "systeminfo.h"
14
15#include <QByteArray>
16#include <QtSystemDetection>
17
18// #include "libkleo_debug.h"
19#ifdef Q_OS_WIN
20#include "windows.h"
21// #include "gnupg-registry.h"
22#endif
23
24#ifdef Q_OS_WIN
25namespace
26{
27bool win_isHighContrastModeActive()
28{
29 HIGHCONTRAST result;
30 result.cbSize = sizeof(HIGHCONTRAST);
31 if (SystemParametersInfo(SPI_GETHIGHCONTRAST, result.cbSize, &result, 0)) {
32 return (result.dwFlags & HCF_HIGHCONTRASTON);
33 }
34 return false;
35}
36
37bool win_isDarkModeActive()
38{
39 /* This is a bit complicated. Qt does not detect this correctly
40 * for high contrast mode with white contrast. */
41
42 // First check for white background. That is set in High contrast
43 // white theme.
44 DWORD color = GetSysColor(COLOR_WINDOW);
45 if (color == 0xFFFFFF) {
46 return false;
47 }
48 // Windows 10 has only one white High Contrast mode. The other
49 // three are dark.
50 if (win_isHighContrastModeActive()) {
51 return true;
52 }
53
54#if 0
55 // This is not enabled because although Qt does check for this, the theme
56 // does not switch accordingly in tests. So we would have white icons on a
57 // bright window.
58 //
59 // The user may have customized a dark theme. Then AppsUseLightTheme is 0
60 char *val = read_w32_registry_string ("HKEY_CURRENT_USER",
61 "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
62 "AppsUseLightTheme");
63 bool ret = false;
64 if (val) {
65 ret = !((DWORD) *val);
66 free (val);
67 return ret;
68 }
69#endif
70 // Nothing set -> default to bright.
71 return false;
72}
73}
74#endif
75
76bool Kleo::SystemInfo::isHighContrastModeActive()
77{
78 static bool forceHighContrastMode = qgetenv("KLEO_HIGH_CONTRAST_MODE").toInt();
79#ifdef Q_OS_WIN
80 static bool highContrastModeActive = forceHighContrastMode || win_isHighContrastModeActive();
81 return highContrastModeActive;
82#else
83 return forceHighContrastMode;
84#endif
85}
86
87bool Kleo::SystemInfo::isDarkModeActive()
88{
89#ifdef Q_OS_WIN
90 return win_isDarkModeActive();
91#else
92 // Don't know
93 return isHighContrastModeActive();
94#endif
95}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.