diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index b3b1c0755..b0fcd56a5 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -116,6 +116,7 @@ namespace hex { EVENT_DEF(EventProviderChanged, prv::Provider *, prv::Provider *); EVENT_DEF(EventFrameBegin); EVENT_DEF(EventFrameEnd); + EVENT_DEF(EventWindowInitialized); EVENT_DEF(RequestOpenWindow, std::string); EVENT_DEF(RequestSelectionChange, Region); diff --git a/main/source/window/win_window.cpp b/main/source/window/win_window.cpp index 639068c10..144c78844 100644 --- a/main/source/window/win_window.cpp +++ b/main/source/window/win_window.cpp @@ -253,26 +253,6 @@ namespace hex { ::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); } - - // Setup system theme change detector - bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color") == 0; - EventManager::subscribe(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(&value), &size); - if (error == ERROR_SUCCESS) { - EventManager::post(value == 0 ? 1 : 2); - } - } - }); - - if (themeFollowSystem) - EventManager::post(); } void Window::beginNativeWindowFrame() { diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 629aef8bd..e36346957 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -159,6 +159,7 @@ namespace hex { ContentRegistry::Settings::store(); EventManager::post(); + EventManager::post(); } Window::~Window() { diff --git a/plugins/windows/source/plugin_windows.cpp b/plugins/windows/source/plugin_windows.cpp index d3e8410ec..2ddc5349d 100644 --- a/plugins/windows/source/plugin_windows.cpp +++ b/plugins/windows/source/plugin_windows.cpp @@ -2,8 +2,12 @@ #include +#include + #include "views/view_tty_console.hpp" +using namespace hex; + namespace hex::plugin::windows { void registerLanguageEnUS(); @@ -15,6 +19,29 @@ namespace hex::plugin::windows { 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([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(&value), &size); + if (error == ERROR_SUCCESS) { + EventManager::post(value == 0 ? 1 : 2); + } + } + }); + + EventManager::subscribe([=] { + if (themeFollowSystem) + EventManager::post(); + }); +} IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") { using namespace hex::plugin::windows; @@ -28,4 +55,6 @@ IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") { addFooterItems(); addTitleBarButtons(); registerSettings(); + + detectSystemTheme(); }