diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index e2efeb7b0..9d3618770 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -9,13 +9,20 @@ #include #include +#include -#define EVENT_DEF(event_name, ...) \ +#include + +#define EVENT_DEF_IMPL(event_name, should_log, ...) \ struct event_name final : public hex::impl::Event<__VA_ARGS__> { \ - constexpr static auto id = [] { return hex::impl::EventId(); }(); \ + constexpr static auto Id = [] { return hex::impl::EventId(); }(); \ + constexpr static auto ShouldLog = (should_log); \ explicit event_name(Callback func) noexcept : Event(std::move(func)) { } \ } +#define EVENT_DEF(event_name, ...) EVENT_DEF_IMPL(event_name, true, __VA_ARGS__) +#define EVENT_DEF_NO_LOG(event_name, ...) EVENT_DEF_IMPL(event_name, false, __VA_ARGS__) + struct GLFWwindow; namespace hex { @@ -75,7 +82,7 @@ namespace hex { */ template static EventList::iterator subscribe(typename E::Callback function) { - return s_events.insert(s_events.end(), std::make_pair(E::id, new E(function))); + return s_events.insert(s_events.end(), std::make_pair(E::Id, new E(function))); } /** @@ -105,7 +112,7 @@ namespace hex { template static void unsubscribe(void *token) noexcept { auto iter = std::find_if(s_tokenStore.begin(), s_tokenStore.end(), [&](auto &item) { - return item.first == token && item.second->first == E::id; + return item.first == token && item.second->first == E::Id; }); if (iter != s_tokenStore.end()) { @@ -123,9 +130,15 @@ namespace hex { template static void post(auto &&...args) noexcept { for (const auto &[id, event] : s_events) { - if (id == E::id) + if (id == E::Id) { (*static_cast(event))(std::forward(args)...); + } } + + #if defined (DEBUG) + if (E::ShouldLog) + log::debug("Event posted: '{}'", wolv::type::getTypeName()); + #endif } /** @@ -157,10 +170,7 @@ namespace hex { EVENT_DEF(EventProviderClosed, prv::Provider *); EVENT_DEF(EventProviderDeleted, prv::Provider *); EVENT_DEF(EventProviderSaved, prv::Provider *); - EVENT_DEF(EventFrameBegin); - EVENT_DEF(EventFrameEnd); EVENT_DEF(EventWindowInitialized); - EVENT_DEF(EventSetTaskBarIconState, u32, u32, u32); EVENT_DEF(EventBookmarkCreated, ImHexApi::Bookmarks::Entry&); EVENT_DEF(EventPatchCreated, u64, u8, u8); EVENT_DEF(EventPatternExecuted, const std::string&); @@ -169,6 +179,10 @@ namespace hex { EVENT_DEF(EventStoreContentRemoved, const std::fs::path&); EVENT_DEF(EventImHexClosing); + EVENT_DEF_NO_LOG(EventFrameBegin); + EVENT_DEF_NO_LOG(EventFrameEnd); + EVENT_DEF_NO_LOG(EventSetTaskBarIconState, u32, u32, u32); + EVENT_DEF(RequestOpenWindow, std::string); EVENT_DEF(RequestSelectionChange, Region); EVENT_DEF(RequestAddBookmark, Region, std::string, std::string, color_t); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 1f28766bf..dfdafcfe4 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -401,7 +401,7 @@ namespace hex { } // Render main menu - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0F); if (ImGui::BeginMainMenuBar()) { if (ImHexApi::System::isBorderlessWindowModeEnabled()) { diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index bfce656de..90e7fb620 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -51,6 +51,8 @@ namespace hex::plugin::builtin { #endif ContentRegistry::Interface::addFooterItem([] { + static bool shouldResetProgress = false; + auto taskCount = TaskManager::getRunningTaskCount(); if (taskCount > 0) { const auto &tasks = TaskManager::getRunningTasks(); @@ -103,8 +105,13 @@ namespace hex::plugin::builtin { if (ImGui::ToolBarButton(ICON_VS_DEBUG_STOP, ImGui::GetStyleColorVec4(ImGuiCol_Text))) frontTask->interrupt(); ImGui::PopStyleVar(); + + shouldResetProgress = true; } else { - ImHexApi::System::setTaskBarProgress(ImHexApi::System::TaskProgressState::Reset, ImHexApi::System::TaskProgressType::Normal, 0); + if (shouldResetProgress) { + ImHexApi::System::setTaskBarProgress(ImHexApi::System::TaskProgressState::Reset, ImHexApi::System::TaskProgressType::Normal, 0); + shouldResetProgress = false; + } } }); }