mirror of
https://github.com/86Box/86Box.git
synced 2026-02-23 18:08:20 -07:00
Manager: Fix style not reacting to Windows light/dark mode change
Add a native event filter for dark mode update, move the function that queries the current theme to qt_util.cpp and make widgets with custom stylesheets update their style on update
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "qt_util.hpp"
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
# include <windows.h>
|
||||
# include <dwmapi.h>
|
||||
# ifndef DWMWA_WINDOW_CORNER_PREFERENCE
|
||||
# define DWMWA_WINDOW_CORNER_PREFERENCE 33
|
||||
@@ -62,6 +63,36 @@ screenOfWidget(QWidget *widget)
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
||||
bool
|
||||
isWindowsLightTheme(void) {
|
||||
// based on https://stackoverflow.com/questions/51334674/how-to-detect-windows-10-light-dark-mode-in-win32-application
|
||||
|
||||
// The value is expected to be a REG_DWORD, which is a signed 32-bit little-endian
|
||||
auto buffer = std::vector<char>(4);
|
||||
auto cbData = static_cast<DWORD>(buffer.size() * sizeof(char));
|
||||
auto res = RegGetValueW(
|
||||
HKEY_CURRENT_USER,
|
||||
L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
|
||||
L"AppsUseLightTheme",
|
||||
RRF_RT_REG_DWORD, // expected value type
|
||||
nullptr,
|
||||
buffer.data(),
|
||||
&cbData);
|
||||
|
||||
if (res != ERROR_SUCCESS) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// convert bytes written to our buffer to an int, assuming little-endian
|
||||
auto i = int(buffer[3] << 24 |
|
||||
buffer[2] << 16 |
|
||||
buffer[1] << 8 |
|
||||
buffer[0]);
|
||||
|
||||
return i == 1;
|
||||
}
|
||||
|
||||
void
|
||||
setWin11RoundedCorners(WId hwnd, bool enable)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user