aboutsummaryrefslogtreecommitdiff
path: root/src/comet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/comet.c')
-rw-r--r--src/comet.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/comet.c b/src/comet.c
index b8cce7d..9c552f5 100644
--- a/src/comet.c
+++ b/src/comet.c
@@ -194,26 +194,32 @@ static void quit_action(Button *btn)
static void menu_action(Button *btn)
{
- ButtonSimple *sbtn = CAST(btn, ButtonSimple);
struct {
+ State *state;
ButtonGroup *group;
char *strings[2];
GList *toggled;
- State *state;
- } *menu_ctx = sbtn->data;
+ } *menu_ctx = CAST(btn, ButtonSimple)->data;
- // NOTE: To close the menu the toggle button must be inside
+ bool to_open = menu_ctx->group->children->next == NULL;
- GList *temp = menu_ctx->group->children;
- menu_ctx->group->children = menu_ctx->toggled;
- menu_ctx->toggled = temp;
+ if (to_open)
+ menu_ctx->group->children = g_list_copy(menu_ctx->toggled);
- bool closed = menu_ctx->group->children->next == NULL;
+ log_debug("%s menu", to_open ? "Opened" : "Closed");
- button_simple_set_text(btn, g_strdup(menu_ctx->strings[!closed]), sbtn->text_color);
+ button_simple_set_text(btn, g_strdup(menu_ctx->strings[to_open]), CAST(btn, ButtonSimple)->text_color);
- log_debug("%s menu", closed ? "Closed" : "Opened");
- state_request_redraw(menu_ctx->state, true);
+ if (!to_open) {
+ Animation *shrink = animation_group_shrink_create(600 * G_TIME_SPAN_MILLISECOND);
+
+ if (button_set_animation((gpointer)menu_ctx->group, shrink))
+ state_request_animation(menu_ctx->state);
+ else
+ animation_destroy(shrink);
+ } else {
+ state_request_redraw(menu_ctx->state, true);
+ }
}
static void register_buttons(State *state, Color color, Color text_color, Color line_color, int line_w)
@@ -358,11 +364,11 @@ int main(int argc, char **argv)
button_simple_set_action(child3, show_action, NULL);
struct {
+ State *state;
ButtonGroup *group;
char *strings[2];
GList *toggled;
- State *state;
- } menu_ctx = { (gpointer)group, {"", ""}, NULL, state };
+ } menu_ctx = { state, (gpointer)group, {"", ""}, NULL };
Button *menu = button_simple_create(PANGO_ALIGN_LEFT, color);
button_simple_set_text(menu, g_strdup(menu_ctx.strings[0]), text_color);
@@ -398,8 +404,8 @@ 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);
+ //g_list_free_full(menu_ctx.toggled->next, (GDestroyNotify)button_destroy);
+ //g_free(menu_ctx.toggled);
timer_delete(date_ctx.timer);
// NOTE: Buttons are freed by state_destroy