diff --git a/mpanel/launcher/module.c b/mpanel/launcher/module.c index fcf1470..c21ac4c 100644 --- a/mpanel/launcher/module.c +++ b/mpanel/launcher/module.c @@ -33,7 +33,13 @@ void module_reload(MwWidget box, MwWidget user, xl_node_t* node) { children = MwGetChildren(user); if(children != NULL) { int i; - for(i = 0; children[i] != NULL; i++) MwDestroyWidget(children[i]); + for(i = 0; children[i] != NULL; i++) { + MwLLPixmap px = MwGetVoid(children[i], MwNpixmap); + + if(px != NULL) MwLLDestroyPixmap(px); + + MwDestroyWidget(children[i]); + } free(children); } @@ -95,3 +101,22 @@ MwWidget module(MwWidget box, xl_node_t* node) { return f; } + +void module_destroy(MwWidget box, MwWidget user) { + MwWidget* children; + + children = MwGetChildren(user); + if(children != NULL) { + int i; + for(i = 0; children[i] != NULL; i++) { + MwLLPixmap px = MwGetVoid(children[i], MwNpixmap); + + if(px != NULL) MwLLDestroyPixmap(px); + + MwDestroyWidget(children[i]); + } + free(children); + } + + MwDestroyWidget(user); +} diff --git a/mpanel/module.c b/mpanel/module.c index 993238c..6215918 100644 --- a/mpanel/module.c +++ b/mpanel/module.c @@ -6,6 +6,8 @@ typedef struct module { char* key; void* value; MwWidget user; + int is_there; + int count; } module_t; module_t* modules = NULL; @@ -22,7 +24,7 @@ static void read_config(xemil_t** cfg, const char* path) { } } -static void init_module(xl_node_t* node) { +static void init_module(xl_node_t* node, int count) { char* p = MDEStringConcatenate("lib", node->name); char* p2 = MDEStringConcatenate(p, "Module.so"); char* s = MwDirectoryJoin(LIBDIR "/mpanel", p2); @@ -52,8 +54,10 @@ static void init_module(xl_node_t* node) { shput(modules, id, lib); - ind = shgeti(modules, id); - modules[ind].user = ret; + ind = shgeti(modules, id); + modules[ind].user = ret; + modules[ind].is_there = 1; + modules[ind].count = count; } } else { void (*module)(MwWidget box, MwWidget user, xl_node_t* node); @@ -67,6 +71,9 @@ static void init_module(xl_node_t* node) { if(module != NULL) { module(box, modules[ind].user, node); } + + modules[ind].is_there = 1; + modules[ind].count = count; } } @@ -76,11 +83,12 @@ static void init_module(xl_node_t* node) { } static void module_scan(xl_node_t* node) { - xl_node_t* n = node->first_child; + xl_node_t* n = node->first_child; + int count = 0; while(n != NULL) { if(n->type == XL_NODE_NODE) { - init_module(n); + init_module(n, count++); } n = n->next; @@ -127,11 +135,23 @@ void load_modules(void) { } } +int sort_num(const void* a, const void* b) { + return ((module_t*)a)->count - ((module_t*)b)->count; +} + void reload_modules(void) { xemil_t* cfg = NULL; + int i; + int old; prepare_config(&cfg); + for(i = 0; i < shlen(modules); i++) { + modules[i].is_there = 0; + } + + old = shlen(modules); + if(cfg != NULL && cfg->root != NULL) { xl_node_t* n = cfg->root->first_child; if(strcmp(cfg->root->name, "Panel") != 0) { @@ -149,4 +169,34 @@ void reload_modules(void) { xl_close(cfg); } + + for(i = 0; i < shlen(modules); i++) { + if(!modules[i].is_there) { + void (*module)(MwWidget box, MwWidget user) = dlsym(modules[i].value, "module_destroy"); + + if(module != NULL) { + module(box, modules[i].user); + } + + dlclose(modules[i].value); + + shdel(modules, modules[i].key); + + i = -1; + } + } + + if(old != shlen(modules)) { + module_t* mods = NULL; + + for(i = 0; i < shlen(modules); i++) arrput(mods, modules[i]); + + qsort(mods, arrlen(mods), sizeof(*mods), sort_num); + + for(i = 0; i < arrlen(mods); i++) { + MwReparent(mods[i].user, box); + } + + arrfree(mods); + } } diff --git a/mpanel/mpanelrc.in b/mpanel/mpanelrc.in index 02b406b..d2e998b 100644 --- a/mpanel/mpanelrc.in +++ b/mpanel/mpanelrc.in @@ -2,6 +2,7 @@ + @CMAKE_INSTALL_FULL_DATAROOTDIR@/mpanel/mde-stripe.png diff --git a/mpanel/separator/module.c b/mpanel/separator/module.c index f0d14eb..2a49165 100644 --- a/mpanel/separator/module.c +++ b/mpanel/separator/module.c @@ -7,3 +7,7 @@ MwWidget module(MwWidget box, xl_node_t* node) { MwNorientation, MwVERTICAL, NULL); } + +void module_destroy(MwWidget box, MwWidget user) { + MwDestroyWidget(user); +} diff --git a/mpanel/startbutton/module.c b/mpanel/startbutton/module.c index a509032..a07b31f 100644 --- a/mpanel/startbutton/module.c +++ b/mpanel/startbutton/module.c @@ -513,3 +513,19 @@ MwWidget module(MwWidget box, xl_node_t* node) { return btn; } + +void module_destroy(MwWidget box, MwWidget user) { + opaque_t* opaque = user->opaque; + + MwLLDestroyPixmap(opaque->closed); + MwLLDestroyPixmap(opaque->opened); + + if(opaque->stripe != NULL) MwLLDestroyPixmap(opaque->stripe); + if(opaque->stripe_color != NULL) free(opaque->stripe_color); + + recursive_free(opaque->menu); + + free(opaque); + + MwDestroyWidget(user); +} diff --git a/mpanel/taskbar/module.c b/mpanel/taskbar/module.c index d24443b..b0fdcc4 100644 --- a/mpanel/taskbar/module.c +++ b/mpanel/taskbar/module.c @@ -6,3 +6,7 @@ MwWidget module(MwWidget box, xl_node_t* node) { return b; } + +void module_destroy(MwWidget box, MwWidget user) { + MwDestroyWidget(user); +} diff --git a/mpanel/time/module.c b/mpanel/time/module.c index 65ed1ac..675f5b8 100644 --- a/mpanel/time/module.c +++ b/mpanel/time/module.c @@ -83,3 +83,7 @@ MwWidget module(MwWidget box, xl_node_t* node) { return b; } + +void module_destroy(MwWidget box, MwWidget user) { + MwDestroyWidget(user); +}