diff --git a/event_loop.cpp b/event_loop.cpp index cf33097..cb4e2da 100644 --- a/event_loop.cpp +++ b/event_loop.cpp @@ -34,7 +34,7 @@ static inline void check_for_logcat_items(LogcatThread& logcat_thread, const Con } -void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread, bool* run_event_loop) { +void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread) { static Config inactive_config; static bool show_settings_window = false; static bool show_filters_window = false; @@ -73,5 +73,5 @@ void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& log main_window(log_entries_read == log_entries.size(), monospace_font, logcat_thread, logcat_entries, filtered_logcat_entry_offsets, active_config, inactive_config, - &show_settings_window, &show_filters_window, &show_exclusions_window, &show_logs_window, run_event_loop); + &show_settings_window, &show_filters_window, &show_exclusions_window, &show_logs_window); } diff --git a/event_loop.h b/event_loop.h index 683a7f3..68b3e08 100644 --- a/event_loop.h +++ b/event_loop.h @@ -5,4 +5,4 @@ #include "config.h" #include "logcat_thread.h" -void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread, bool* run_event_loop); +void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread); diff --git a/main.cpp b/main.cpp index d31b687..aecfa2c 100644 --- a/main.cpp +++ b/main.cpp @@ -162,7 +162,7 @@ int main(int, char**) { ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - event_loop(monospace_font, config, logcat_thread, &run_event_loop); + event_loop(monospace_font, config, logcat_thread); // Rendering ImGui::Render(); diff --git a/misc.cpp b/misc.cpp index 38caae5..5d980e2 100644 --- a/misc.cpp +++ b/misc.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "misc.h" @@ -60,3 +61,12 @@ bool ImGui::Button(const char* label, bool enabled) { } return res; } + +bool ImGui::BeginWithCloseShortcut(const char* label, bool* p_open, ImGuiWindowFlags flags) { + bool res = ImGui::Begin(label, p_open, flags); + + if (p_open && ImGui::Shortcut(ImGuiMod_Shortcut | ImGuiKey_W, 0, ImGuiInputFlags_Repeat)) { + *p_open = false; + } + return res; +} diff --git a/misc.h b/misc.h index a6e3d08..5aed951 100644 --- a/misc.h +++ b/misc.h @@ -12,4 +12,5 @@ namespace ImGui { void TextUnformatted(const std::string& str); bool RedButton(const char* label); bool Button(const char* label, bool enabled); + bool BeginWithCloseShortcut(const char* label, bool* p_open, ImGuiWindowFlags flags = 0); }; // namespace ImGui diff --git a/windows/exclusions.cpp b/windows/exclusions.cpp index 3bd8b35..338da6f 100644 --- a/windows/exclusions.cpp +++ b/windows/exclusions.cpp @@ -1,5 +1,6 @@ #include +#include "../misc.h" #include "../fragments/filters.h" #include "../filters.h" #include "../config.h" @@ -8,7 +9,7 @@ void exclusions_window(Config& active_config, Config& inactive_config, const std::vector& logcat_entries, std::vector& filtered_logcat_entry_offsets, bool* p_open) { - if (!ImGui::Begin("Exclusions", p_open)) { + if (!ImGui::BeginWithCloseShortcut("Exclusions", p_open)) { ImGui::End(); return; } diff --git a/windows/filters.cpp b/windows/filters.cpp index 84b47ee..3b9ced7 100644 --- a/windows/filters.cpp +++ b/windows/filters.cpp @@ -1,5 +1,6 @@ #include +#include "../misc.h" #include "../fragments/filters.h" #include "../filters.h" #include "../config.h" @@ -8,7 +9,7 @@ void filters_window(Config& active_config, Config& inactive_config, const std::vector& logcat_entries, std::vector& filtered_logcat_entry_offsets, bool* p_open) { - if (!ImGui::Begin("Filters", p_open)) { + if (!ImGui::BeginWithCloseShortcut("Filters", p_open)) { ImGui::End(); return; } diff --git a/windows/logs.cpp b/windows/logs.cpp index e1f0fc9..d743962 100644 --- a/windows/logs.cpp +++ b/windows/logs.cpp @@ -44,7 +44,7 @@ static inline void render_table(ImFont* monospace_font, bool* autoscrolling) { } void logs_window(ImFont* monospace_font, bool* autoscrolling, bool* p_open) { - if (!ImGui::Begin("LogMeow Logs", p_open)) { + if (!ImGui::BeginWithCloseShortcut("LogMeow Logs", p_open)) { ImGui::End(); return; } diff --git a/windows/main.cpp b/windows/main.cpp index 664707a..15d6154 100644 --- a/windows/main.cpp +++ b/windows/main.cpp @@ -57,11 +57,11 @@ static inline void render_table(ImFont* monospace_font, std::vector void main_window(bool latest_log_entries_read, ImFont* monospace_font, LogcatThread& logcat_thread, std::vector& logcat_entries, std::vector& filtered_logcat_entry_offsets, const Config& active_config, Config& inactive_config, - bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window, bool* run_event_loop) { + bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window) { ImGui::SetNextWindowPos(ImGui::GetMainViewport()->WorkPos); ImGui::SetNextWindowSize(ImGui::GetMainViewport()->WorkSize); - if (!ImGui::Begin("LogMeow", run_event_loop, + if (!ImGui::BeginWithCloseShortcut("LogMeow", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus)) { ImGui::End(); return; diff --git a/windows/main.h b/windows/main.h index 9f4d7bf..25b0dc9 100644 --- a/windows/main.h +++ b/windows/main.h @@ -10,4 +10,4 @@ void main_window(bool latest_log_entries_read, ImFont* monospace_font, LogcatThread& logcat_thread, std::vector& logcat_entries, std::vector& filtered_logcat_entry_offsets, const Config& active_config, Config& inactive_config, - bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window, bool* run_event_loop); + bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window); diff --git a/windows/settings.cpp b/windows/settings.cpp index 4ade920..c99b752 100644 --- a/windows/settings.cpp +++ b/windows/settings.cpp @@ -1,6 +1,7 @@ #include #include +#include "../misc.h" #include "../config.h" #include "settings.h" @@ -13,7 +14,7 @@ static void try_write_config(const Config& config) { } void settings_window(Config& active_config, Config& inactive_config, bool* p_open) { - if (!ImGui::Begin("Settings", p_open)) { + if (!ImGui::BeginWithCloseShortcut("Settings", p_open)) { ImGui::End(); return; }