mirror of
https://github.com/NohamR/Reclass.git
synced 2026-05-10 19:59:21 +00:00
Add dark title bar support for Qt5
This commit is contained in:
@@ -74,7 +74,7 @@ target_link_libraries(ReclassX PRIVATE
|
|||||||
${_QT_WINEXTRAS}
|
${_QT_WINEXTRAS}
|
||||||
)
|
)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(ReclassX PRIVATE dbghelp psapi)
|
target_link_libraries(ReclassX PRIVATE dbghelp dwmapi psapi)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(rcx-mcp-stdio tools/rcx-mcp-stdio.cpp)
|
add_executable(rcx-mcp-stdio tools/rcx-mcp-stdio.cpp)
|
||||||
|
|||||||
31
src/main.cpp
31
src/main.cpp
@@ -46,9 +46,22 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <dwmapi.h>
|
||||||
#include <dbghelp.h>
|
#include <dbghelp.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
static void setDarkTitleBar(QWidget* widget) {
|
||||||
|
// Requires Windows 10 1809+ (build 17763)
|
||||||
|
auto hwnd = reinterpret_cast<HWND>(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) {
|
static LONG WINAPI crashHandler(EXCEPTION_POINTERS* ep) {
|
||||||
fprintf(stderr, "\n=== UNHANDLED EXCEPTION ===\n");
|
fprintf(stderr, "\n=== UNHANDLED EXCEPTION ===\n");
|
||||||
fprintf(stderr, "Code : 0x%08lX\n", ep->ExceptionRecord->ExceptionCode);
|
fprintf(stderr, "Code : 0x%08lX\n", ep->ExceptionRecord->ExceptionCode);
|
||||||
@@ -118,6 +131,22 @@ static LONG WINAPI crashHandler(EXCEPTION_POINTERS* ep) {
|
|||||||
}
|
}
|
||||||
#endif
|
#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<QWidget*>(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 {
|
class MenuBarStyle : public QProxyStyle {
|
||||||
public:
|
public:
|
||||||
using QProxyStyle::QProxyStyle;
|
using QProxyStyle::QProxyStyle;
|
||||||
@@ -1359,7 +1388,7 @@ int main(int argc, char* argv[]) {
|
|||||||
SetUnhandledExceptionFilter(crashHandler);
|
SetUnhandledExceptionFilter(crashHandler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
DarkApp app(argc, argv);
|
||||||
app.setApplicationName("ReclassX");
|
app.setApplicationName("ReclassX");
|
||||||
app.setOrganizationName("ReclassX");
|
app.setOrganizationName("ReclassX");
|
||||||
app.setStyle("Fusion"); // Fusion style respects dark palette well
|
app.setStyle("Fusion"); // Fusion style respects dark palette well
|
||||||
|
|||||||
Reference in New Issue
Block a user