diff options
Diffstat (limited to 'src/comet.c')
| -rw-r--r-- | src/comet.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/comet.c b/src/comet.c index b6c40fd..fd50aeb 100644 --- a/src/comet.c +++ b/src/comet.c @@ -199,18 +199,18 @@ static void menu_action(Button *btn) ButtonGroup *group; char *strings[2]; GList *toggled; + bool closed; } *menu_ctx = CAST(btn, ButtonSimple)->data; - bool to_open = menu_ctx->group->children->next == NULL; - - if (to_open) + if (menu_ctx->closed) { + g_list_free(menu_ctx->group->children); menu_ctx->group->children = g_list_copy(menu_ctx->toggled); + } - log_debug("%s menu", to_open ? "Opened" : "Closed"); - - button_simple_set_text(btn, g_strdup(menu_ctx->strings[to_open]), CAST(btn, ButtonSimple)->text_color); + char *text = g_strdup(menu_ctx->strings[menu_ctx->closed]); + button_simple_set_text(btn, text, CAST(btn, ButtonSimple)->text_color); - Animation *anim = to_open + Animation *anim = menu_ctx->closed ? animation_group_grow_create(MILLIS(600)) : animation_group_shrink_create(MILLIS(600)); @@ -218,6 +218,9 @@ static void menu_action(Button *btn) state_request_animation(menu_ctx->state); else animation_destroy(anim); + + log_debug("%s menu", menu_ctx->closed ? "Opened" : "Closed"); + menu_ctx->closed = !menu_ctx->closed; } static void register_buttons(State *state, Color color, Color text_color, Color line_color, int line_w) @@ -371,7 +374,8 @@ int main(int argc, char **argv) ButtonGroup *group; char *strings[2]; GList *toggled; - } menu_ctx = { state, (gpointer)group, {"", ""}, NULL }; + bool closed; + } menu_ctx = { state, (gpointer)group, {"", ""}, NULL, true }; Button *menu = button_simple_create(PANGO_ALIGN_LEFT, color); button_simple_set_text(menu, g_strdup(menu_ctx.strings[0]), text_color); @@ -407,9 +411,13 @@ int main(int argc, char **argv) g_source_remove(source_int); // NOTE: Skip the first element (the open/close button) - //g_list_free_full(menu_ctx.toggled->next, (GDestroyNotify)button_destroy); - //g_free(menu_ctx.toggled); + if (menu_ctx.closed) + g_list_free_full(g_list_delete_link(menu_ctx.toggled, menu_ctx.toggled), (GDestroyNotify)button_destroy); + else + g_list_free(menu_ctx.toggled); + timer_delete(date_ctx.timer); + g_object_unref(context); // NOTE: Buttons are freed by state_destroy dwm_destroy(dwm); |
