Finalize dynamic dark mode switching
Make QMenuBar items spaced identically
This commit is contained in:
@@ -362,7 +362,8 @@ QMenuBar:focus {
|
|||||||
|
|
||||||
QMenuBar::item {
|
QMenuBar::item {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 4px;
|
padding-left: 7px;
|
||||||
|
padding-right: 7px;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenuBar::item:selected {
|
QMenuBar::item:selected {
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ private:
|
|||||||
friend class ProgSettings;
|
friend class ProgSettings;
|
||||||
friend class RendererCommon;
|
friend class RendererCommon;
|
||||||
friend class RendererStack; // For UI variable access by non-primary renderer windows.
|
friend class RendererStack; // For UI variable access by non-primary renderer windows.
|
||||||
|
friend class WindowsRawInputFilter; // Needed to reload renderers on style sheet changes.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QT_MAINWINDOW_HPP
|
#endif // QT_MAINWINDOW_HPP
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ StyleOverride::polish(QWidget *widget)
|
|||||||
}
|
}
|
||||||
widget->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
widget->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
BOOL DarkMode = TRUE;
|
extern bool windows_is_light_theme();
|
||||||
|
BOOL DarkMode = !windows_is_light_theme();
|
||||||
DwmSetWindowAttribute((HWND)widget->winId(), DWMWA_USE_IMMERSIVE_DARK_MODE, (LPCVOID)&DarkMode, sizeof(DarkMode));
|
DwmSetWindowAttribute((HWND)widget->winId(), DWMWA_USE_IMMERSIVE_DARK_MODE, (LPCVOID)&DarkMode, sizeof(DarkMode));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
@@ -50,11 +51,13 @@
|
|||||||
#include <86box/mouse.h>
|
#include <86box/mouse.h>
|
||||||
#include <86box/plat.h>
|
#include <86box/plat.h>
|
||||||
#include <86box/86box.h>
|
#include <86box/86box.h>
|
||||||
|
#include <86box/video.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "qt_rendererstack.hpp"
|
#include "qt_rendererstack.hpp"
|
||||||
|
#include "ui_qt_mainwindow.h"
|
||||||
|
|
||||||
bool windows_is_light_theme() {
|
bool windows_is_light_theme() {
|
||||||
// based on https://stackoverflow.com/questions/51334674/how-to-detect-windows-10-light-dark-mode-in-win32-application
|
// based on https://stackoverflow.com/questions/51334674/how-to-detect-windows-10-light-dark-mode-in-win32-application
|
||||||
@@ -170,13 +173,31 @@ WindowsRawInputFilter::nativeEventFilter(const QByteArray &eventType, void *mess
|
|||||||
QTextStream ts(&f);
|
QTextStream ts(&f);
|
||||||
qApp->setStyleSheet(ts.readAll());
|
qApp->setStyleSheet(ts.readAll());
|
||||||
}
|
}
|
||||||
// From Dolphin emulator code:
|
QTimer::singleShot(1000, [this] () {
|
||||||
// TODO: When switching from light to dark, the window decorations remain light. Qt seems very
|
BOOL DarkMode = TRUE;
|
||||||
// convinced that it needs to change these in response to this message, so even if we set them
|
DwmSetWindowAttribute((HWND)window->winId(), DWMWA_USE_IMMERSIVE_DARK_MODE, (LPCVOID)&DarkMode, sizeof(DarkMode));
|
||||||
// to dark here, Qt sets them back to light afterwards.
|
window->ui->stackedWidget->switchRenderer((RendererStack::Renderer) vid_api);
|
||||||
|
for (int i = 1; i < MONITORS_NUM; i++) {
|
||||||
|
if (window->renderers[i] && !window->renderers[i]->isHidden())
|
||||||
|
window->renderers[i]->switchRenderer((RendererStack::Renderer) vid_api);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
qApp->setStyleSheet("");
|
qApp->setStyleSheet("");
|
||||||
|
QTimer::singleShot(1000, [this] () {
|
||||||
|
BOOL DarkMode = FALSE;
|
||||||
|
DwmSetWindowAttribute((HWND)window->winId(), DWMWA_USE_IMMERSIVE_DARK_MODE, (LPCVOID)&DarkMode, sizeof(DarkMode));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTimer::singleShot(1000, [this] () {
|
||||||
|
window->resizeContents(monitors[0].mon_scrnsz_x, monitors[0].mon_scrnsz_y);
|
||||||
|
for (int i = 1; i < MONITORS_NUM; i++) {
|
||||||
|
if (window->renderers[i] && !window->renderers[i]->isHidden()) {
|
||||||
|
window->resizeContentsMonitor(monitors[i].mon_scrnsz_x, monitors[i].mon_scrnsz_y, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop processing of Alt-F4 */
|
/* Stop processing of Alt-F4 */
|
||||||
|
|||||||
Reference in New Issue
Block a user