src/widget/*, src/main.c: catching window::close-request signal, and a few renames
We create a window in the app activation and it needs to be closed properly, freeing all ressources in the meantime. For now, there is only the picture (E. coli) to free. From now on, freeing window ressources will be done in src/widget/manager.c:on_window_close_request(). Signed-off-by: Jean Sirmai <jean@a-lec.org>
This commit is contained in:
parent
bb89a2f03c
commit
4df832f342
|
@ -28,6 +28,6 @@
|
|||
#pragma once
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -35,20 +35,18 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue