diff options
| author | Federico Angelilli <code@fedang.net> | 2024-03-16 15:34:14 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-03-16 15:34:14 +0100 |
| commit | 40ca9598d269c9b6f162e80b5293f83ec37bb75d (patch) | |
| tree | 8e7e9627ca94fa87382d95fb83ee0f14385ff286 | |
| parent | 15baf349fa6985262da39b70f2d496af104c478d (diff) | |
Refactor and fix a couple leaks
| -rw-r--r-- | src/button.c | 2 | ||||
| -rw-r--r-- | src/button.h | 3 | ||||
| -rw-r--r-- | src/comet.c | 17 | ||||
| -rw-r--r-- | src/connect.c | 1 | ||||
| -rw-r--r-- | src/draw.c | 9 | ||||
| -rw-r--r-- | src/dwm.c | 2 |
6 files changed, 16 insertions, 18 deletions
diff --git a/src/button.c b/src/button.c index 05a77ef..bf3c575 100644 --- a/src/button.c +++ b/src/button.c @@ -32,7 +32,7 @@ void button_simple_set_action(Button *btn, ButtonAction action, gpointer data) { g_assert(btn->simple); CAST(btn, ButtonSimple)->action = action; - CAST(btn, ButtonSimple)->action_data = data; + CAST(btn, ButtonSimple)->data = data; } ButtonAction button_simple_get_action(Button *btn) diff --git a/src/button.h b/src/button.h index 423e29a..d1516fc 100644 --- a/src/button.h +++ b/src/button.h @@ -31,8 +31,7 @@ typedef struct { Color text_color; char *text; ButtonAction action; - // TODO: Add a GDestroyNotify - gpointer action_data; + gpointer data; } ButtonSimple; typedef struct { diff --git a/src/comet.c b/src/comet.c index 34c9b2a..9e7f46c 100644 --- a/src/comet.c +++ b/src/comet.c @@ -53,7 +53,7 @@ static gboolean disk_update(gpointer data) size_t len2 = g_utf8_strlen(btn->text, -1); log_debug("Updated disk percentage"); - state_request_redraw(btn->action_data, len1 != len2); + state_request_redraw(btn->data, len1 != len2); return G_SOURCE_CONTINUE; } @@ -76,7 +76,7 @@ static gboolean temp_update(gpointer data) size_t len2 = g_utf8_strlen(btn->text, -1); log_debug("Updated temperature"); - state_request_redraw(btn->action_data, len1 != len2); + state_request_redraw(btn->data, len1 != len2); return G_SOURCE_CONTINUE; } @@ -119,7 +119,7 @@ static gboolean cpu_update(gpointer data) button_simple_set_text((gpointer)btn, perc, btn->text_color); size_t len2 = g_utf8_strlen(btn->text, -1); - state_request_redraw(btn->action_data, len1 != len2); + state_request_redraw(btn->data, len1 != len2); } log_debug("%s cpu percentage", perc != NULL ? "Updated" : "Unchanged"); @@ -150,7 +150,7 @@ static gboolean ram_update(gpointer data) size_t len2 = g_utf8_strlen(btn->text, -1); log_debug("Updated ram percentage"); - state_request_redraw(btn->action_data, len1 != len2); + state_request_redraw(btn->data, len1 != len2); return G_SOURCE_CONTINUE; } @@ -170,7 +170,7 @@ static gboolean date_update(gpointer data) struct { State *state; timer_t timer; - } *date_ctx = btn->action_data; + } *date_ctx = btn->data; log_debug("Updated date and time"); state_request_redraw(date_ctx->state, len1 != len2); @@ -194,7 +194,7 @@ static void show_action(Button *btn) static void quit_action(Button *btn) { log_info("Quit button pressed"); - g_main_loop_quit(CAST(btn, ButtonSimple)->action_data); + g_main_loop_quit(CAST(btn, ButtonSimple)->data); } static void menu_action(Button *btn) @@ -205,7 +205,7 @@ static void menu_action(Button *btn) char *strings[2]; GList *toggled; State *state; - } *menu_ctx = sbtn->action_data; + } *menu_ctx = sbtn->data; // NOTE: To close the menu the toggle button must be inside @@ -389,8 +389,9 @@ int main(int argc, char **argv) g_source_remove(source_term); 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); timer_delete(date_ctx.timer); - g_list_free(menu_ctx.toggled); // Buttons are freed by state_destroy dwm_destroy(dwm); diff --git a/src/connect.c b/src/connect.c index 054153d..9e709af 100644 --- a/src/connect.c +++ b/src/connect.c @@ -253,6 +253,7 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer extension ? extension : "none"); } } + g_free(xsource->event); } while ((xsource->event = xcb_poll_for_event(xsource->con->connection)) != NULL); return G_SOURCE_CONTINUE; @@ -202,7 +202,7 @@ static GList *compute_group_layout(Drawer *draw, Window *win, GList *btns, int b layout->x = bx; layout->y = 0; - // TODO: Allow nested groups +retry: if (!btn->simple) { ButtonGroup *group = CAST(btn, ButtonGroup); g_assert_nonnull(group->children); @@ -211,6 +211,7 @@ static GList *compute_group_layout(Drawer *draw, Window *win, GList *btns, int b if (group->children->next == NULL) { layout->btn = btn = group->children->data; g_assert_true(btn->simple); + goto retry; } else { layout->children = compute_group_layout(draw, win, group->children, bx, false); g_assert_nonnull(layout->children); @@ -231,11 +232,7 @@ static GList *compute_group_layout(Drawer *draw, Window *win, GList *btns, int b if (fix_right) layout->width -= 1; } - } - - // NOTE: This check is only apparently redundant because it handles the case where there - // there is only a single children in a group - if (btn->simple) { + } else { layout->pl = pango_cairo_create_layout(window_get_context(win)); layout_set_text(layout, draw->desc, draw->height); } @@ -386,7 +386,7 @@ DwmIpc *dwm_create(State *state, const char *socket) static void change_tag_action(Button *btn) { ButtonSimple *sbtn = CAST(btn, ButtonSimple); - DwmIpc *dwm = sbtn->action_data; + DwmIpc *dwm = sbtn->data; int n = sbtn->text[0] - '0'; g_assert(n >= 1 && n <= 9); |
