diff --git a/CMakeLists.txt b/CMakeLists.txt index 45bc31d..726c54e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ target_link_libraries(ReclassX PRIVATE ${_QT_WINEXTRAS} ) if(WIN32) - target_link_libraries(ReclassX PRIVATE dbghelp psapi) + target_link_libraries(ReclassX PRIVATE dbghelp dwmapi psapi) endif() add_executable(rcx-mcp-stdio tools/rcx-mcp-stdio.cpp) diff --git a/src/main.cpp b/src/main.cpp index 37c3ecb..02144e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,9 +46,22 @@ #ifdef _WIN32 #include +#include #include #include +static void setDarkTitleBar(QWidget* widget) { + // Requires Windows 10 1809+ (build 17763) + auto hwnd = reinterpret_cast(widget->winId()); + BOOL dark = TRUE; + // Attribute 20 = DWMWA_USE_IMMERSIVE_DARK_MODE (build 18985+), 19 for older + DWORD attr = 20; + if (FAILED(DwmSetWindowAttribute(hwnd, attr, &dark, sizeof(dark)))) { + attr = 19; + DwmSetWindowAttribute(hwnd, attr, &dark, sizeof(dark)); + } +} + static LONG WINAPI crashHandler(EXCEPTION_POINTERS* ep) { fprintf(stderr, "\n=== UNHANDLED EXCEPTION ===\n"); fprintf(stderr, "Code : 0x%08lX\n", ep->ExceptionRecord->ExceptionCode); @@ -118,6 +131,22 @@ static LONG WINAPI crashHandler(EXCEPTION_POINTERS* ep) { } #endif +class DarkApp : public QApplication { +public: + using QApplication::QApplication; + bool notify(QObject* receiver, QEvent* event) override { + if (event->type() == QEvent::WindowActivate && receiver->isWidgetType()) { + auto* w = static_cast(receiver); + if ((w->windowFlags() & Qt::Window) == Qt::Window + && !w->property("DarkTitleBar").toBool()) { + w->setProperty("DarkTitleBar", true); + setDarkTitleBar(w); + } + } + return QApplication::notify(receiver, event); + } +}; + class MenuBarStyle : public QProxyStyle { public: using QProxyStyle::QProxyStyle; @@ -1359,7 +1388,7 @@ int main(int argc, char* argv[]) { SetUnhandledExceptionFilter(crashHandler); #endif - QApplication app(argc, argv); + DarkApp app(argc, argv); app.setApplicationName("ReclassX"); app.setOrganizationName("ReclassX"); app.setStyle("Fusion"); // Fusion style respects dark palette well