aboutsummaryrefslogtreecommitdiff
path: root/src/state.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.c')
-rw-r--r--src/state.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/state.c b/src/state.c
index c5dc759..2051652 100644
--- a/src/state.c
+++ b/src/state.c
@@ -2,7 +2,7 @@
#include "state.h"
-State *state_create(Window *win, Drawable *draw)
+State *state_create(Window *win, Drawer *draw)
{
State *state = g_malloc(sizeof(State));
g_assert_nonnull(state);
@@ -17,7 +17,6 @@ State *state_create(Window *win, Drawable *draw)
void state_add_button(State *state, Button *btn)
{
- // insert sorted
state->btns = g_list_append(state->btns, btn);
}
@@ -26,33 +25,33 @@ void state_remove_button(State *state, Button *btn)
state->btns = g_list_remove(state->btns, btn);
}
-static gboolean redraw_and_layout(gpointer data)
+static gboolean redraw_handler(gpointer data)
{
State *state = data;
- draw_compute_layout(state->draw, state->win, state->btns);
- draw_paint(state->draw, state->win);
- state->id = 0;
- return G_SOURCE_REMOVE;
-}
-static gboolean redraw(gpointer data)
-{
- State *state = data;
+ if (state->relayout) {
+ draw_compute_layout(state->draw, state->win, state->btns);
+ state->relayout = false;
+ }
+
draw_paint(state->draw, state->win);
+
state->id = 0;
return G_SOURCE_REMOVE;
}
-// Sometimes we schedule multiple redraws in a row without actually checking if there are
-// others already scheduled...
-// This could probably be fixed by implementing a redraw source...
void state_redraw(State *state, bool changed_layout)
{
- // XXX: Override old redraw
- if (state->id != 0)
+ if (state->id != 0) {
+ if (!changed_layout || state->relayout)
+ return;
+
+ // If we should relayout override old redraw
g_source_remove(state->id);
+ }
- state->id = g_idle_add_full(G_PRIORITY_HIGH_IDLE, changed_layout ? redraw_and_layout : redraw, state, NULL);
+ state->relayout = changed_layout;
+ state->id = g_idle_add_full(G_PRIORITY_HIGH_IDLE, redraw_handler, state, NULL);
}
static gint align_compare(gconstpointer a, gconstpointer b)