tAdd proper clean up functions - ltkx - GUI toolkit for X11 (WIP)
HTML git clone git://lumidify.org/ltkx.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 696ff69d34503c5cba0e98287997c089ecd36b18
DIR parent bfc883141ea28d04d8da91fa69dcd0dfeb01b6a0
HTML Author: lumidify <nobody@lumidify.org>
Date: Mon, 2 Jan 2017 17:13:20 +0100
Add proper clean up functions
Diffstat:
M ltk.c | 21 +++++++++++++++++----
M window.c | 6 ++----
2 files changed, 19 insertions(+), 8 deletions(-)
---
DIR diff --git a/ltk.c b/ltk.c
t@@ -34,16 +34,29 @@ void ltk_init(const char *theme_path)
ltk->window_hash = NULL;
}
+void ltk_clean_up(void)
+{
+ LtkWindow *window;
+ for (window = ltk_global->window_hash; window != NULL; window = window->hh.next)
+ {
+ ltk_destroy_window(window);
+ }
+ XCloseDisplay(ltk_global->display);
+ ltk_destroy_theme(ltk_global->theme);
+ free(ltk_global);
+}
+
void ltk_quit(void)
{
- printf("CLEAN UP!\n");
- exit(1);
+ ltk_clean_up();
+ exit(0);
}
void ltk_fatal(const char *msg)
{
- printf(msg);
- ltk_quit();
+ fprintf(stderr, msg);
+ ltk_clean_up();
+ exit(1);
};
XColor ltk_create_xcolor(const char *hex)
DIR diff --git a/window.c b/window.c
t@@ -84,10 +84,8 @@ LtkWindow *ltk_create_window(const char *title, int x, int y, unsigned int w, un
void ltk_destroy_window(LtkWindow *window)
{
LtkWidget *ptr = window->root_widget;
- if (ptr)
- {
- ptr->destroy(ptr);
- }
+ if (ptr) ptr->destroy(ptr);
+ XDestroyWindow(ltk_global->display, window->xwindow);
free(window);
}