diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/connect.c | 30 | ||||
| -rw-r--r-- | src/connect.h | 2 | ||||
| -rw-r--r-- | src/draw.c | 15 |
3 files changed, 11 insertions, 36 deletions
diff --git a/src/connect.c b/src/connect.c index 0ef12f9..9272a5c 100644 --- a/src/connect.c +++ b/src/connect.c @@ -70,20 +70,6 @@ static gboolean source_check(GSource *source) return xsource->event != NULL; } -static void redraw_window(Connection *con, xcb_window_t id) -{ - for (int i = 0; i < con->states->len; ++i) { - State *state = con->states->pdata[i]; - - // Redraw matching window - if (state->win->window == id) { - log_debug("Redrawing window [id=%d]", id); - draw_paint(state->draw, state->win); - break; - } - } -} - static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer data) { EventSource *xsource = (EventSource *)source; @@ -113,7 +99,9 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer case XCB_EXPOSE: { xcb_expose_event_t *expose = (xcb_expose_event_t *)xsource->event; log_debug("Processing event 'Expose' [type=%d]", XCB_EXPOSE); - redraw_window(xsource->con, expose->window); + + // Redraw + draw_paint(xsource->con->state->draw, xsource->con->state->win); break; } @@ -140,7 +128,9 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer if (property->atom == XCB_ATOM_RESOURCE_MANAGER) { update_xrm(xsource->con); update_scale(xsource->con); - redraw_window(xsource->con, property->window); + + // Redraw + draw_paint(xsource->con->state->draw, xsource->con->state->win); } break; } @@ -259,16 +249,12 @@ Connection *connect_create() xcb_flush(con->connection); log_debug("Xcb set up"); - con->states = g_ptr_array_new(); - g_assert_nonnull(con->states); - return con; } void connect_attach_source(Connection *con) { g_assert_null(con->source); - attach_source(con); log_debug("Xcb event loop attached"); } @@ -276,14 +262,12 @@ void connect_attach_source(Connection *con) void connect_attach_state(Connection *con, State *state) { g_assert_nonnull(state); - g_ptr_array_add(con->states, state); + con->state = state; log_debug("Attached state to event loop"); } void connect_destroy(Connection *con) { - g_ptr_array_free(con->states, true); - g_source_destroy(con->source); g_source_unref(con->source); diff --git a/src/connect.h b/src/connect.h index e348bcf..35ed3d3 100644 --- a/src/connect.h +++ b/src/connect.h @@ -25,7 +25,7 @@ struct Connection { xcb_errors_context_t *errors; xcb_ewmh_connection_t ewmh; GSource *source; - GPtrArray *states; + State *state; }; Connection *connect_create(); @@ -80,18 +80,9 @@ void draw_paint(Drawable *draw, Window *win) PangoLayout *layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, draw->desc); - int bwidth, bheight = height; - char *btn_text = btn->text; - char tmp[2] = { 0 }; - - if (btn->fixed_size) { - bwidth = height; - // Get only the first char - tmp[0] = btn->text[0]; - btn_text = tmp; - } + int bwidth = height, bheight = height; - pango_layout_set_text(layout, btn_text, -1); + pango_layout_set_text(layout, btn->text, -1); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); int text_w, text_h; @@ -100,7 +91,7 @@ void draw_paint(Drawable *draw, Window *win) text_h = ceil(text_h / scale); if (!btn->fixed_size) { - bwidth = text_w + 2*radius; + bwidth = text_w + 2 * radius; } int text_x = bx + (bwidth / 2) - (text_w / 2); |
