#include #include "state.h" State *state_create(Window *win, Drawable *draw) { State *state = g_malloc(sizeof(State)); g_assert_nonnull(state); state->win = win; state->draw = draw; state->btns = NULL; state->id = 0; return state; } void state_add_button(State *state, Button *btn) { // insert sorted state->btns = g_list_append(state->btns, btn); } static gboolean redraw_and_layout(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; 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) g_source_remove(state->id); state->id = g_idle_add_full(G_PRIORITY_HIGH_IDLE, changed_layout ? redraw_and_layout : redraw, state, NULL); } void state_destroy(State *state) { g_list_free_full(state->btns, (void *)button_destroy); g_free(state); } // vim: ts=4 sw=4 et