Skip to content

Commit

Permalink
Windows: Dark mode with non-native theme now uses dark titlebar.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Oct 6, 2023
1 parent 5f6dc8c commit 3deef33
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qView.pro
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ win32 {

# To build without win32: qmake CONFIG+=NO_WIN32
!CONFIG(NO_WIN32) {
LIBS += -lshell32 -luser32 -lole32 -lshlwapi -lgdi32
LIBS += -lshell32 -luser32 -lole32 -lshlwapi -lgdi32 -ldwmapi
DEFINES += WIN32_LOADED
message("Linked to win32 api")
}
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ void MainWindow::showEvent(QShowEvent *event)
QTimer::singleShot(0, this, [this]() {
QVCocoaFunctions::setFullSizeContentView(windowHandle(), true);
});
#elif defined WIN32_LOADED
if (qvApp->getSettingsManager().getBoolean("nonnativetheme"))
QVWin32Functions::setDarkTitlebarOptIn(windowHandle(), true);
#endif

if (!menuBar()->sizeHint().isEmpty())
Expand Down
9 changes: 9 additions & 0 deletions src/qvwin32functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Objbase.h"
#include "appmodel.h"
#include "Shlwapi.h"
#include "dwmapi.h"

#include <QFileInfo>
#include <QFile>
Expand Down Expand Up @@ -173,6 +174,14 @@ QString QVWin32Functions::getShortPath(const QString &path)
return getLongOrShortPath(path, GetShortPathNameW);
}

void QVWin32Functions::setDarkTitlebarOptIn(const QWindow *window, const bool enable)
{
const HWND hWnd = reinterpret_cast<HWND>(window->winId());
const DWORD useImmersiveDarkModeAttribute = 20;
const BOOL attributeValue = static_cast<BOOL>(enable);
DwmSetWindowAttribute(hWnd, useImmersiveDarkModeAttribute, &attributeValue, sizeof(attributeValue));
}

QByteArray QVWin32Functions::getIccProfileForWindow(const QWindow *window)
{
QByteArray result;
Expand Down
2 changes: 2 additions & 0 deletions src/qvwin32functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class QVWin32Functions

static QString getShortPath(const QString &path);

static void setDarkTitlebarOptIn(const QWindow *window, const bool enable);

static QByteArray getIccProfileForWindow(const QWindow *window);
};

Expand Down

0 comments on commit 3deef33

Please sign in to comment.