summaryrefslogtreecommitdiff
path: root/src/libs/utils/theme
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2018-08-16 14:01:17 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2018-08-24 07:50:25 +0000
commitc79f436e2acb0f7652cad536fc73c4488ee99398 (patch)
treebd55cda519013664d05ead57fd2d07778b5cc5f8 /src/libs/utils/theme
parent389fb7f0605b97b47f1a54661f83f802f8416185 (diff)
downloadqt-creator-c79f436e2acb0f7652cad536fc73c4488ee99398.tar.gz
Improve macOS dark mode support
The current theme support in Creator works well, also in macOS dark mode. This change makes sure that the native macOS appearance setting (for the Creator process) and the creator theme setting are in sync. This is required to avoid light/dark palette issues for the light Creator themes when the desktop is configured for dark appearance. Add a “DarkUserInterface” flag to the creatortheme files. This flag indicates if the theme is overall dark, with light text on dark background. Make setCreatorTheme() force the standard light aqua appearance for light Creator themes. Change-Id: I1a5c183230ab0e66641fd834df19d7e0ad1b6a53 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/libs/utils/theme')
-rw-r--r--src/libs/utils/theme/theme.cpp11
-rw-r--r--src/libs/utils/theme/theme.h3
-rw-r--r--src/libs/utils/theme/theme_mac.h34
-rw-r--r--src/libs/utils/theme/theme_mac.mm48
4 files changed, 95 insertions, 1 deletions
diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp
index fc3018fc1d..4d9aeae356 100644
--- a/src/libs/utils/theme/theme.cpp
+++ b/src/libs/utils/theme/theme.cpp
@@ -27,6 +27,9 @@
#include "theme_p.h"
#include "../algorithm.h"
#include "../qtcassert.h"
+#ifdef Q_OS_MACOS
+#import "theme_mac.h"
+#endif
#include <QApplication>
#include <QFileInfo>
@@ -69,6 +72,14 @@ void setCreatorTheme(Theme *theme)
return;
delete m_creatorTheme;
m_creatorTheme = theme;
+
+#ifdef Q_OS_MACOS
+ // Match the native UI theme and palette with the creator
+ // theme by forcing light aqua for light creator themes.
+ if (!theme->flag(Theme::DarkUserInteface))
+ Internal::forceMacOSLightAquaApperance();
+#endif
+
setThemeApplicationPalette();
}
diff --git a/src/libs/utils/theme/theme.h b/src/libs/utils/theme/theme.h
index 49c7c881ad..7bca48b9ea 100644
--- a/src/libs/utils/theme/theme.h
+++ b/src/libs/utils/theme/theme.h
@@ -337,7 +337,8 @@ public:
FlatProjectsMode,
FlatMenuBar,
ToolBarIconShadow,
- WindowColorAsBase
+ WindowColorAsBase,
+ DarkUserInteface
};
Q_INVOKABLE bool flag(Flag f) const;
diff --git a/src/libs/utils/theme/theme_mac.h b/src/libs/utils/theme/theme_mac.h
new file mode 100644
index 0000000000..55e6d12bc0
--- /dev/null
+++ b/src/libs/utils/theme/theme_mac.h
@@ -0,0 +1,34 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+namespace Utils {
+namespace Internal {
+
+void forceMacOSLightAquaApperance();
+
+} // Internal
+} // Utils
diff --git a/src/libs/utils/theme/theme_mac.mm b/src/libs/utils/theme/theme_mac.mm
new file mode 100644
index 0000000000..6a940240f1
--- /dev/null
+++ b/src/libs/utils/theme/theme_mac.mm
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "theme_mac.h"
+
+#include <qglobal.h>
+
+#include <AppKit/AppKit.h>
+
+#if !QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
+@interface NSApplication (MojaveForwardDeclarations)
+@property (strong) NSAppearance *appearance NS_AVAILABLE_MAC(10_14);
+@end
+#endif
+
+namespace Utils {
+namespace Internal {
+
+void forceMacOSLightAquaApperance()
+{
+ if (__builtin_available(macOS 10.14, *))
+ NSApp.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
+}
+
+} // Internal
+} // Utils