Skip to content

Commit

Permalink
Add some magic to make title bar on Windows dark
Browse files Browse the repository at this point in the history
Fix #5199
  • Loading branch information
uglide committed Feb 17, 2022
1 parent 6bfc0f3 commit dd5a5b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
#include "modules/value-editor/valueviewmodel.h"
#include "qmlutils.h"

#ifdef Q_OS_WINDOWS
#include <dwmapi.h>
#endif

Application::Application(int& argc, char** argv)
: QApplication(argc, argv),
m_engine(this),
Expand Down Expand Up @@ -405,6 +409,26 @@ void Application::updatePalette()
return;
}

m_engine.rootObjects().at(0)->setProperty(
"palette", QGuiApplication::palette());
auto rootObject = m_engine.rootObjects().at(0);

rootObject->setProperty("palette", QGuiApplication::palette());

#ifdef Q_OS_WINDOWS
if (!isDarkThemeEnabled()) return;

auto window = qobject_cast<QWindow*>(rootObject);

if (window) {
auto winHwnd = reinterpret_cast<HWND>(window->winId());
BOOL USE_DARK_MODE = true;
BOOL SET_IMMERSIVE_DARK_MODE_SUCCESS = SUCCEEDED(DwmSetWindowAttribute(
winHwnd, 20, &USE_DARK_MODE, sizeof(USE_DARK_MODE)));

if (SET_IMMERSIVE_DARK_MODE_SUCCESS) {
// Dirty hack to re-draw window and apply darkmode color
rootObject->setProperty("visible", false);
rootObject->setProperty("visible", true);
}
}
#endif
}
2 changes: 2 additions & 0 deletions src/resp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ win32 {

release: DESTDIR = ./../bin/windows/release
debug: DESTDIR = ./../bin/windows/debug

LIBS += -ldwmapi
}

unix:macx { # OSX
Expand Down

0 comments on commit dd5a5b8

Please sign in to comment.