From 46ddac37f551f5fe601e00f6960f428a3961b441 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Tue, 29 Oct 2024 18:00:04 +0100 Subject: [PATCH] Program quits correctly --- app_win_2_back.cpp | 13 +++++++++++-- app_win_2_back.hpp | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app_win_2_back.cpp b/app_win_2_back.cpp index 640c650..bd005a2 100644 --- a/app_win_2_back.cpp +++ b/app_win_2_back.cpp @@ -1,6 +1,7 @@ #include "app_win_2_back.hpp" #include "hello_world.hpp" #include +#include namespace gui_to_app { AppWin2Back::AppWin2Back() : Gtk::Application("org.billy_adventures.character_sheet", Flags::HANDLES_OPEN) { @@ -22,7 +23,7 @@ namespace gui_to_app { std::cerr << "Error occured while loading menu bar's.\n"; } else { set_menubar(menu_bar); - add_action("quit", sigc::mem_fun(*this, &AppWin2Back::quit)); + add_action("quit", sigc::mem_fun(*this, &AppWin2Back::on_quit)); set_accel_for_action("app.quit", "q"); } } @@ -54,8 +55,16 @@ namespace gui_to_app { main_window->set_show_menubar(true); main_window->set_visible(true); } else { - quit(); + on_quit(); } } + void AppWin2Back::on_quit() { + auto windows = get_windows(); + for (auto *window: windows) { + window->set_visible(false); + } + quit(); + } + } // gui_to_app \ No newline at end of file diff --git a/app_win_2_back.hpp b/app_win_2_back.hpp index bd743c5..fbc2d67 100644 --- a/app_win_2_back.hpp +++ b/app_win_2_back.hpp @@ -1,7 +1,8 @@ #ifndef LEARNGTK4_APP_WIN_2_BACK_HPP #define LEARNGTK4_APP_WIN_2_BACK_HPP -#include +#include +#include namespace learn_gtkmm4 { class HelloWorld; @@ -23,6 +24,8 @@ namespace gui_to_app { void on_activate() final; private: + void on_quit(); + learn_gtkmm4::HelloWorld *main_window{ nullptr }; };