add reload
This commit is contained in:
parent
ef89c2dac9
commit
9aaf59b94f
7 changed files with 110 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<!-- This file should be copied to .config/mpanel/mpanelrc -->
|
||||
<Panel>
|
||||
<Module>
|
||||
<!-- !!! We keep track of modules using ID - so do not remove ID !!! -->
|
||||
<StartButton ID="0">
|
||||
<Stripe Color="#000000">
|
||||
@CMAKE_INSTALL_FULL_DATAROOTDIR@/mpanel/mde-stripe.png
|
||||
|
|
|
|||
|
|
@ -7,3 +7,7 @@ MwWidget module(MwWidget box, xl_node_t* node) {
|
|||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void module_destroy(MwWidget box, MwWidget user) {
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,3 +6,7 @@ MwWidget module(MwWidget box, xl_node_t* node) {
|
|||
|
||||
return b;
|
||||
}
|
||||
|
||||
void module_destroy(MwWidget box, MwWidget user) {
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,3 +83,7 @@ MwWidget module(MwWidget box, xl_node_t* node) {
|
|||
|
||||
return b;
|
||||
}
|
||||
|
||||
void module_destroy(MwWidget box, MwWidget user) {
|
||||
MwDestroyWidget(user);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue