From e9bbe8178ab45cb9880c9b6b0324e9b4467f26d5 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Sat, 25 Nov 2023 18:42:33 +0100 Subject: Recalculate layouts only when needed --- src/state.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/state.c') diff --git a/src/state.c b/src/state.c index 64c479b..11ecd77 100644 --- a/src/state.c +++ b/src/state.c @@ -19,7 +19,7 @@ void state_add_button(State *state, Button *btn) state->btns = g_list_append(state->btns, btn); } -static gboolean redraw(gpointer data) +static gboolean redraw_and_layout(gpointer data) { State *state = data; draw_compute_layout(state->draw, state->win, state->btns); @@ -27,9 +27,16 @@ static gboolean redraw(gpointer data) return G_SOURCE_REMOVE; } -void state_redraw(State *state) +static gboolean redraw(gpointer data) +{ + State *state = data; + draw_paint(state->draw, state->win); + return G_SOURCE_REMOVE; +} + +void state_redraw(State *state, bool changed_layout) { - g_idle_add_full(G_PRIORITY_HIGH_IDLE, redraw, state, NULL); + g_idle_add_full(G_PRIORITY_HIGH_IDLE, changed_layout ? redraw_and_layout : redraw, state, NULL); } void state_destroy(State *state) -- cgit v1.2.3