From 2eed6ed0b8a2992b43dfed15f4132ba162a5fb5c Mon Sep 17 00:00:00 2001 From: bert Date: Sun, 13 Mar 2016 16:37:54 +0100 Subject: [PATCH] Added central infrastructure for un-init'ing GUI hids. Signed-off-by: bert --- src/hid.h | 11 +++++++++++ src/hid/common/hidinit.c | 6 ++++++ src/hid/lesstif/main.c | 18 ++++++++++++++++++ src/hid/lesstif/menu.c | 5 +++++ src/main.c | 20 ++++++++++++++++++++ src/misc.c | 16 +++++++++------- 6 files changed, 69 insertions(+), 7 deletions(-) diff --git a/src/hid.h b/src/hid.h index 69e454169d..ed45ffc8db 100644 --- a/src/hid.h +++ b/src/hid.h @@ -430,6 +430,12 @@ typedef enum * main window, print, export, etc). */ + void (*uninit) (HID *hid); + /*!< uninit a GUI hid. */ + + void (*do_exit) (HID *hid); + /*!< uninit a GUI hid. */ + void (*parse_arguments) (int *argc_, char ***argv_); /*!< Parse the command line. * @@ -763,6 +769,11 @@ typedef enum void hid_init (void); /*! + * \brief Call this at exit. + */ + void hid_uninit (void); + + /*! * \brief When PCB runs in interactive mode, this is called to * instantiate one GUI HID which happens to be the GUI. * diff --git a/src/hid/common/hidinit.c b/src/hid/common/hidinit.c index 9f058008f2..bd6e1b4339 100644 --- a/src/hid/common/hidinit.c +++ b/src/hid/common/hidinit.c @@ -148,6 +148,12 @@ hid_init () } void +hid_uninit (void) +{ + +} + +void hid_register_hid (HID * hid) { int i; diff --git a/src/hid/lesstif/main.c b/src/hid/lesstif/main.c index 2cb3393fe3..e5bd52cea1 100644 --- a/src/hid/lesstif/main.c +++ b/src/hid/lesstif/main.c @@ -1963,6 +1963,22 @@ lesstif_do_export (HID_Attr_Val * options) XtAppMainLoop (app_context); } +static void +lesstif_do_exit (HID *hid) +{ + XtAppSetExitFlag (app_context); +} + +void +lesstif_uninit_menu (void); + +static void +lesstif_uninit (HID *hid) +{ + lesstif_uninit_menu (); +} + + #if 0 XrmOptionDescRec lesstif_options[] = { }; @@ -4071,6 +4087,8 @@ hid_lesstif_init () lesstif_hid.get_export_options = lesstif_get_export_options; lesstif_hid.do_export = lesstif_do_export; + lesstif_hid.do_exit = lesstif_do_exit; + lesstif_hid.uninit = lesstif_uninit; lesstif_hid.parse_arguments = lesstif_parse_arguments; lesstif_hid.invalidate_lr = lesstif_invalidate_lr; lesstif_hid.invalidate_all = lesstif_invalidate_all; diff --git a/src/hid/lesstif/menu.c b/src/hid/lesstif/menu.c index dab8baad49..32ea98c904 100644 --- a/src/hid/lesstif/menu.c +++ b/src/hid/lesstif/menu.c @@ -1515,3 +1515,8 @@ lesstif_menu (Widget parent, char *name, Arg * margs, int mn) return mb; } + +void lesstif_uninit_menu (void) +{ +/*! \todo XtDestroyWidget (...); */ +} diff --git a/src/main.c b/src/main.c index eeaf5d2d16..3920c8df1a 100644 --- a/src/main.c +++ b/src/main.c @@ -1868,6 +1868,24 @@ char *program_directory = 0; #include "dolists.h" /*! + * \brief Free up memory allocated to the PCB. + * + * Why bother when we're about to exit ?\n + * Because it removes some false positives from heap bug detectors such + * as lib dmalloc. + */ +void +pcb_main_uninit (void) +{ + FreePCBMemory (PCB); + + if (gui->uninit != NULL) + gui->uninit (gui); + + hid_uninit (); +} + +/*! * \brief Main program. * * Init application: @@ -2089,6 +2107,8 @@ main (int argc, char *argv[]) pcb_dbus_finish(); #endif + pcb_main_uninit (); + return (0); } diff --git a/src/misc.c b/src/misc.c index 0ad2ff305f..8c84ab0e53 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1248,6 +1248,8 @@ AssignDefaultLayerTypes() END_LOOP; } +extern void pcb_main_uninit(void); + /*! * \brief Quits application. */ @@ -1264,13 +1266,13 @@ QuitApplication (void) else DisableEmergencySave (); - /* Free up memory allocated to the PCB. Why bother when we're about to exit ? - * Because it removes some false positives from heap bug detectors such as - * lib dmalloc. - */ - FreePCBMemory(PCB); - - exit (0); + if (gui->do_exit == NULL) + { + pcb_main_uninit (); + exit (0); + } + else + gui->do_exit (gui); } /*! -- 2.11.4.GIT