diff --git a/include/widget.h b/include/widget.h index 1fc3772..a379674 100644 --- a/include/widget.h +++ b/include/widget.h @@ -28,6 +28,6 @@ #pragma once #include -void on_windows_activation (GtkApplication *app); -void widget_get_main_window (GtkWindow *main_window, GtkApplication *app); - +void on_app_activation (GtkApplication *app); +void widget_design_main_window (GtkWindow *main_window, GtkApplication *app); +gboolean on_window_close_request (GtkWindow *main_window, gpointer user_data); diff --git a/src/main.c b/src/main.c index 078977c..93aca3a 100644 --- a/src/main.c +++ b/src/main.c @@ -74,7 +74,7 @@ int main (int argc, char **argv) "| 👉️ windows creation requested"); // g_signal_connect (app, "startup", G_CALLBACK (on_windows_startup), NULL); - g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL); + g_signal_connect (app, "activate", G_CALLBACK (on_app_activation), NULL); status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); diff --git a/src/widget/main_window/design.c b/src/widget/main_window/design.c index 7cfda4f..20bb98f 100644 --- a/src/widget/main_window/design.c +++ b/src/widget/main_window/design.c @@ -39,16 +39,16 @@ * @param *main_window * @param *app */ -void widget_get_main_window (GtkWindow *main_window, GtkApplication *app) +void widget_design_main_window (GtkWindow *main_window, GtkApplication *app) { fsm_add_log (INFO, TOPBAR, "widget/main_window/design", "main window", "start of design"); - GtkWidget *topbar = GTK_WIDGET (gtk_header_bar_new ()); + /* GtkWidget *topbar = GTK_WIDGET (gtk_header_bar_new ()); */ - char *title = "E coli (with permission from David S. Goodsell, 2009)"; - gtk_header_bar_set_title_widget (GTK_HEADER_BAR (topbar), - gtk_label_new (title)); + /* char *title = "E coli (with permission from David S. Goodsell, 2009)"; */ + /* gtk_header_bar_set_title_widget (GTK_HEADER_BAR (topbar), */ + /* gtk_label_new (title)); */ GtkWidget *e_coli = GTK_WIDGET (gtk_picture_new_for_filename ("./docs/showcase/E coli (Goodsell).png")); @@ -60,4 +60,3 @@ void widget_get_main_window (GtkWindow *main_window, GtkApplication *app) fsm_add_log (INFO, TOPBAR, "widget/main_window/design", "main window", "ready for presentation"); } - diff --git a/src/widget/manager.c b/src/widget/manager.c index 9f93bcb..95ae579 100644 --- a/src/widget/manager.c +++ b/src/widget/manager.c @@ -35,20 +35,18 @@ #include -static GtkWindow *main_window; +static GtkWindow *window; /** * @brief 1) creates a new main window 2) presents this window * - * NB > on_windows_activation() is in: widget/manager NOT in: src/signal + * NB > on_app_activation() is in: widget/manager NOT in: src/signal * * @since 2024-06 * * @callgraph * @see widget_design_main_window() - * @see widget_design_dialog_window() - * @see widget_design_text_window() * @see util_trigger_test() * @see fsm_add_log() * @@ -57,9 +55,9 @@ static GtkWindow *main_window; * * @param *app */ -void on_windows_activation (GtkApplication *app) +void on_app_activation (GtkApplication *app) { - fsm_add_log (INFO, WIDGETS, "widget/manager", "windows activation()", "has began"); + fsm_add_log (INFO, WIDGETS, "widget/manager", "app activation()", "has began"); // on_windows_activation() is in: widget/manager NOT in: src/signal // g_application_activate (G_APPLICATION (app)); < how ? > in main is @@ -76,12 +74,14 @@ void on_windows_activation (GtkApplication *app) //gtk_widget_destroy(widget); - main_window = GTK_WINDOW (gtk_application_window_new (app)); + window = GTK_WINDOW (gtk_application_window_new (app)); - int window_int_id = gtk_application_window_get_id (GTK_APPLICATION_WINDOW (main_window)); + int window_int_id = gtk_application_window_get_id (GTK_APPLICATION_WINDOW (window)); char window_char_id[40]; sprintf(window_char_id, "%d", window_int_id); + g_signal_connect(window, "close-request", G_CALLBACK (on_window_close_request), (void *)(long long)window_int_id); + //printf ("gtk_application_window_id = %s = %d\n", window_char_id, window_int_id); fsm_add_log (INFO, WIDGETS, "widget/manager", "gtk_application_window_get_id", @@ -90,9 +90,9 @@ void on_windows_activation (GtkApplication *app) //printf ("gtk_application_window_get_id (main_window) = %d\n", //gtk_application_window_get_id (GTK_APPLICATION_WINDOW (main_window))); - widget_get_main_window (main_window, app); + widget_design_main_window (window, app); - gtk_window_present (GTK_WINDOW (main_window)); + gtk_window_present (GTK_WINDOW (window)); // g_object_unref (main_window); TODO get the closing signal of the main window @@ -117,7 +117,21 @@ void on_windows_activation (GtkApplication *app) g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_b)); g_signal_connect (act_b, "activate", G_CALLBACK (action_b), app2);*/ - fsm_add_log (INFO, WIDGETS, "widget/manager", "windows activation()", + fsm_add_log (INFO, WIDGETS, "widget/manager", "app activation()", "has ended 🧐️ | 👉️ a new session starts"); } +gboolean on_window_close_request (GtkWindow *window, gpointer user_data) +{ + + fsm_add_log (INFO, WIDGETS, "widget/manager", "window close request()", + "freeing all ressources !"); + + // free the only child + gtk_window_set_child (window, NULL); // deleting the child from window + + // drop window's reference + gtk_window_destroy (window); + + return false; // the default handler takes care of g_object_unref for window +}