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:
31
src/main.cpp
31
src/main.cpp
@@ -46,9 +46,22 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <dwmapi.h>
|
||||
#include <dbghelp.h>
|
||||
#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) {
|
||||
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<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 {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user