1
0
mirror of synced 2024-11-12 10:10:53 +01:00

sys: Move Windows theme detection to Windows plugin

This commit is contained in:
WerWolv 2022-02-15 22:50:04 +01:00
parent 4357d68462
commit f72e9700ab
4 changed files with 31 additions and 20 deletions

View File

@ -116,6 +116,7 @@ namespace hex {
EVENT_DEF(EventProviderChanged, prv::Provider *, prv::Provider *); EVENT_DEF(EventProviderChanged, prv::Provider *, prv::Provider *);
EVENT_DEF(EventFrameBegin); EVENT_DEF(EventFrameBegin);
EVENT_DEF(EventFrameEnd); EVENT_DEF(EventFrameEnd);
EVENT_DEF(EventWindowInitialized);
EVENT_DEF(RequestOpenWindow, std::string); EVENT_DEF(RequestOpenWindow, std::string);
EVENT_DEF(RequestSelectionChange, Region); EVENT_DEF(RequestSelectionChange, Region);

View File

@ -253,26 +253,6 @@ namespace hex {
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE); ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE);
::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW); ::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
} }
// Setup system theme change detector
bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color") == 0;
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem] {
if (!themeFollowSystem) return;
HKEY hkey;
if (RegOpenKey(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", &hkey) == ERROR_SUCCESS) {
DWORD value = 0;
DWORD size = sizeof(DWORD);
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
if (error == ERROR_SUCCESS) {
EventManager::post<RequestChangeTheme>(value == 0 ? 1 : 2);
}
}
});
if (themeFollowSystem)
EventManager::post<EventOSThemeChanged>();
} }
void Window::beginNativeWindowFrame() { void Window::beginNativeWindowFrame() {

View File

@ -159,6 +159,7 @@ namespace hex {
ContentRegistry::Settings::store(); ContentRegistry::Settings::store();
EventManager::post<EventSettingsChanged>(); EventManager::post<EventSettingsChanged>();
EventManager::post<EventWindowInitialized>();
} }
Window::~Window() { Window::~Window() {

View File

@ -2,8 +2,12 @@
#include <hex/api/content_registry.hpp> #include <hex/api/content_registry.hpp>
#include <nlohmann/json.hpp>
#include "views/view_tty_console.hpp" #include "views/view_tty_console.hpp"
using namespace hex;
namespace hex::plugin::windows { namespace hex::plugin::windows {
void registerLanguageEnUS(); void registerLanguageEnUS();
@ -15,6 +19,29 @@ namespace hex::plugin::windows {
void registerSettings(); void registerSettings();
} }
static void detectSystemTheme() {
// Setup system theme change detector
bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color") == 0;
EventManager::subscribe<EventOSThemeChanged>([themeFollowSystem] {
if (!themeFollowSystem) return;
HKEY hkey;
if (RegOpenKey(HKEY_CURRENT_USER, R"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)", &hkey) == ERROR_SUCCESS) {
DWORD value = 0;
DWORD size = sizeof(DWORD);
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
if (error == ERROR_SUCCESS) {
EventManager::post<RequestChangeTheme>(value == 0 ? 1 : 2);
}
}
});
EventManager::subscribe<EventWindowInitialized>([=] {
if (themeFollowSystem)
EventManager::post<EventOSThemeChanged>();
});
}
IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") { IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") {
using namespace hex::plugin::windows; using namespace hex::plugin::windows;
@ -28,4 +55,6 @@ IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") {
addFooterItems(); addFooterItems();
addTitleBarButtons(); addTitleBarButtons();
registerSettings(); registerSettings();
detectSystemTheme();
} }