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>
This commit is contained in:
Morten Johan Sørvig
2018-08-16 14:01:17 +02:00
parent 389fb7f060
commit c79f436e2a
11 changed files with 111 additions and 1 deletions

View File

@@ -244,6 +244,7 @@ FlatProjectsMode=true
FlatMenuBar=true
ToolBarIconShadow=true
WindowColorAsBase=false
DarkUserInteface=true
[Gradients]
DetailsWidgetHeaderGradient\1\color=00000000

View File

@@ -216,6 +216,7 @@ FlatProjectsMode=false
FlatMenuBar=false
ToolBarIconShadow=true
WindowColorAsBase=false
DarkUserInteface=false
[Gradients]
DetailsWidgetHeaderGradient\1\color=ffffffff

View File

@@ -248,6 +248,7 @@ FlatProjectsMode=true
FlatMenuBar=true
ToolBarIconShadow=true
WindowColorAsBase=false
DarkUserInteface=true
[Gradients]
DetailsWidgetHeaderGradient\1\color=00000000

View File

@@ -225,6 +225,7 @@ FlatProjectsMode=false
FlatMenuBar=false
ToolBarIconShadow=false
WindowColorAsBase=false
DarkUserInteface=false
[Gradients]
DetailsWidgetHeaderGradient\1\color=00000000

View File

@@ -223,6 +223,7 @@ FlatProjectsMode=false
FlatMenuBar=false
ToolBarIconShadow=true
WindowColorAsBase=false
DarkUserInteface=false
[Gradients]
DetailsWidgetHeaderGradient\1\color=00000000

View File

@@ -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();
}

View File

@@ -337,7 +337,8 @@ public:
FlatProjectsMode,
FlatMenuBar,
ToolBarIconShadow,
WindowColorAsBase
WindowColorAsBase,
DarkUserInteface
};
Q_INVOKABLE bool flag(Flag f) const;

View File

@@ -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

View File

@@ -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

View File

@@ -270,8 +270,10 @@ RESOURCES += $$PWD/utils.qrc
osx {
HEADERS += \
$$PWD/theme/theme_mac.h \
$$PWD/fileutils_mac.h
OBJECTIVE_SOURCES += \
$$PWD/theme/theme_mac.mm \
$$PWD/fileutils_mac.mm \
$$PWD/processhandle_mac.mm
LIBS += -framework Foundation -framework AppKit

View File

@@ -314,6 +314,15 @@ Project {
]
}
Group {
name: "Theme_macos"
condition: qbs.targetOS.contains("macos")
prefix: "theme/"
files: [
"theme_mac.h", "theme_mac.mm",
]
}
Group {
name: "ProcessHandle_macos"
condition: qbs.targetOS.contains("macos")