From 531eb79446860230aec4cdbcad550c14a38ea4df Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 6 May 2014 18:57:34 +1000 Subject: GuiLua's self delete when their first window gets deleted. --- src/GuiLua/GuiLua.c | 41 +++++++++++++++++++++++++++++++++++++---- src/GuiLua/GuiLua.h | 3 +++ src/extantz/extantz.c | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 5c76e15..643a9d5 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -229,6 +229,15 @@ static int colour(lua_State *L) Light user data an actual pointer. */ +static void _on_us_del(void *data, Evas_Object *obj, void *event_info) +{ + winFang *win = data; + GuiLua *gl = win->data; + + gl->inDel = 1; + GuiLuaDel(gl); +} + static int window(lua_State *L) { winFang *win = NULL; @@ -247,8 +256,21 @@ static int window(lua_State *L) win = winFangAdd(parent, 25, 25, w, h, title, name); // If there's no parent, we become the parent. - if (gl && !parent) - gl->parent = win; + if (gl) + { + // If there's no parent, we become the parent. + if (!parent) + gl->parent = win; + // If there's no us, we must be the first, so we are us. + if (!gl->us) + { + gl->us = win; + // TODO - If this invocation of GuiLuaDo never opens a window, then this GuiLua will never get deleted. + // Also, who ever opened this window might have other plans for on_del or data. + win->data = gl; + win->on_del = _on_us_del; + } + } lua_pushlightuserdata(L, win); return 1; @@ -399,8 +421,8 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent) // This does nothing if no module opened a window. if (0 != luaL_dostring(L, "skang.loopWindow()")) PE("Error running - skang.loopWindow()"); - lua_pop(L, closeWindow(L)); - lua_close(L); + GuiLuaDel(result); + result = NULL; if (logDom >= 0) { eina_log_domain_unregister(logDom); @@ -416,3 +438,14 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent) return result; } + +void GuiLuaDel(GuiLua *gl) +{ + if (gl) + { + gl->us->on_del = NULL; + if (!gl->inDel) winFangDel(gl->us); + if (gl->L) lua_close(gl->L); + free(gl); + } +} diff --git a/src/GuiLua/GuiLua.h b/src/GuiLua/GuiLua.h index 4fd1617..2a4a3f0 100644 --- a/src/GuiLua/GuiLua.h +++ b/src/GuiLua/GuiLua.h @@ -18,7 +18,9 @@ typedef struct _GuiLua { lua_State *L; + winFang *us; // Our window, if it exists. winFang *parent; // Our parent window, if it exists. + int inDel; Eina_Clist node; void *data; @@ -26,5 +28,6 @@ typedef struct _GuiLua } GuiLua; GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent); +void GuiLuaDel(GuiLua *gl); #endif diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index aceebe7..9f8eaef 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -474,7 +474,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) chat_add(&ourGlobals); ourGlobals.files = filesAdd(&ourGlobals, (char *) elm_app_data_dir_get(), EINA_TRUE, EINA_FALSE); char *args[] = {"extantz", "-l", "test", "-foo", "COMBINED!", NULL}; - GuiLua *test = GuiLuaDo(5, args, ourGlobals.mainWindow); + GuiLuaDo(5, args, ourGlobals.mainWindow); // Gotta do this after adding the windows, otherwise the menu renders under the window. // This sucks, gotta redefine this menu each time we create a new window? -- cgit v1.1