diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d2351939..3eb0c814f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,150 +1,150 @@ # 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}) set(KF5_MIN_VERSION "5.97.0") if (WIN32) set(KF5_WANT_VERSION "5.70.0") else () set(KF5_WANT_VERSION ${KF5_MIN_VERSION}) endif () find_package(ECM ${KF5_WANT_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(GenerateExportHeader) include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(FeatureSummary) include(ECMQtDeclareLoggingCategory) include(ECMDeprecationSettings) include(ECMAddQch) include(KDEClangFormat) include(KDEGitCommitHooks) option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") set(LIBKLEO_LIB_VERSION ${PIM_VERSION}) set(QT_REQUIRED_VERSION "5.15.2") set(KDEPIMTEXTEDIT_VERSION "5.21.40") set(GPGME_REQUIRED_VERSION "1.15.0") find_package(Qt${QT_MAJOR_VERSION} ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets) if (QT_MAJOR_VERSION STREQUAL "6") find_package(Qt6Core5Compat) endif() find_package(KF5I18n ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5Config ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5WidgetsAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5ConfigWidgets ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5Completion ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5CoreAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5Codecs ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5ItemModels ${KF5_WANT_VERSION} CONFIG REQUIRED) find_package(KF5PimTextEdit ${KDEPIMTEXTEDIT_VERSION} CONFIG) find_package(Gpgmepp ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) set_package_properties(Gpgmepp PROPERTIES DESCRIPTION "GpgME++ Library" URL "https://www.gnupg.org" TYPE REQUIRED PURPOSE "GpgME++ is required for OpenPGP support") if (QT_MAJOR_VERSION STREQUAL "6") find_package(QGpgmeQt6 ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) else() find_package(QGpgme ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) endif() message(STATUS "GpgME++ Version ${Gpgmepp_VERSION}") if (Gpgmepp_VERSION VERSION_GREATER_EQUAL "1.16.0") set(GPGMEPP_SUPPORTS_TRUST_SIGNATURES 1) endif() find_package(Boost 1.34.0) set_package_properties(Boost PROPERTIES DESCRIPTION "Boost C++ Libraries" URL "https://www.boost.org" TYPE REQUIRED PURPOSE "Boost is required for building most KDEPIM applications") set_package_properties(KF5PimTextEdit PROPERTIES DESCRIPTION "A textedit with PIM-specific features." URL "https://commits.kde.org/kpimtextedit" TYPE OPTIONAL PURPOSE "Improved audit log viewer.") ecm_setup_version(PROJECT VARIABLE_PREFIX LIBKLEO VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/libkleo_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkleoConfigVersion.cmake" SOVERSION 5 ) ########### Targets ########### ecm_set_disabled_deprecation_versions(QT 5.15.2 KF 5.97.0) remove_definitions(-DQT_NO_FOREACH) add_definitions(-DQT_NO_EMIT) ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Libkleo") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5LibkleoConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkleoConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkleoConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5LibkleoConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5LibkleoTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5LibkleoTargets.cmake NAMESPACE KF5::) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libkleo_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/Libkleo COMPONENT Devel ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-libkleo.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-libkleo.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) option(USE_UNITY_CMAKE_SUPPORT "Use UNITY cmake support (speedup compile time)" OFF) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT OFF) if (USE_UNITY_CMAKE_SUPPORT) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT ON) endif() add_subdirectory(src) if (BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ecm_qt_install_logging_categories( EXPORT LIBKLEO FILE libkleo.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} ) ki18n_install(po) if (BUILD_QCH) ecm_install_qch_export( TARGETS KF5Libkleo_QCH FILE KF5LibkleoQchTargets.cmake DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) set(PACKAGE_INCLUDE_QCHTARGETS "include(\"\${CMAKE_CURRENT_LIST_DIR}/KF5LibkleoQchTargets.cmake\")") endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT) diff --git a/src/utils/systeminfo.cpp b/src/utils/systeminfo.cpp index 52fdcfe20..6540ead75 100644 --- a/src/utils/systeminfo.cpp +++ b/src/utils/systeminfo.cpp @@ -1,46 +1,96 @@ /* -*- mode: c++; c-basic-offset:4 -*- utils/systeminfo.cpp This file is part of libkleopatra SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "systeminfo.h" #include #include +#include +// #include "libkleo_debug.h" #ifdef Q_OS_WIN #include "windows.h" +// #include "gnupg-registry.h" #endif #ifdef Q_OS_WIN namespace { bool win_isHighContrastModeActive() { HIGHCONTRAST result; result.cbSize = sizeof(HIGHCONTRAST); if (SystemParametersInfo(SPI_GETHIGHCONTRAST, result.cbSize, &result, 0)) { return (result.dwFlags & HCF_HIGHCONTRASTON); } 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 bool Kleo::SystemInfo::isHighContrastModeActive() { static bool forceHighContrastMode = qgetenv("KLEO_HIGH_CONTRAST_MODE").toInt(); #ifdef Q_OS_WIN static bool highContrastModeActive = forceHighContrastMode || win_isHighContrastModeActive(); return highContrastModeActive; #else return forceHighContrastMode; #endif } + +bool Kleo::SystemInfo::isDarkModeActive() +{ +#ifdef Q_OS_WIN + return win_isDarkModeActive(); +#else + // Don't know + return isHighContrastModeActive(); +#endif +} diff --git a/src/utils/systeminfo.h b/src/utils/systeminfo.h index 2546fa2a2..3f2248c2f 100644 --- a/src/utils/systeminfo.h +++ b/src/utils/systeminfo.h @@ -1,20 +1,21 @@ /* -*- mode: c++; c-basic-offset:4 -*- utils/systeminfo.h This file is part of libkleopatra SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include "kleo_export.h" namespace Kleo::SystemInfo { KLEO_EXPORT bool isHighContrastModeActive(); +KLEO_EXPORT bool isDarkModeActive(); }