diff options
| -rw-r--r-- | src/comet.c | 38 | ||||
| -rw-r--r-- | src/connect.c | 37 | ||||
| -rw-r--r-- | src/connect.h | 4 | ||||
| -rw-r--r-- | src/state.c | 13 | ||||
| -rw-r--r-- | src/state.h | 5 | ||||
| -rw-r--r-- | src/window.c | 1 |
6 files changed, 75 insertions, 23 deletions
diff --git a/src/comet.c b/src/comet.c index 54bb851..86023fc 100644 --- a/src/comet.c +++ b/src/comet.c @@ -300,7 +300,21 @@ int main(int argc, char **argv) draw_set_context(draw, context); draw_set_size(draw, height, x_padding, x_padding, y_padding); - State *state = state_create(win, draw); + State *state = state_create("$1", win, draw); + + Window *win2 = window_create(con); + int y_padding2 = EVEN(round(screen_height * 0.204)); + + PangoContext *context2 = pango_cairo_create_context(window_get_context(win2)); + + Drawer *draw2 = draw_create(); + draw_set_background(draw2, background_all); + draw_set_separator(draw2, 10); + draw_set_font(draw2, "Hack 13 Bold"); + draw_set_context(draw2, context); + draw_set_size(draw2, height, x_padding, x_padding, y_padding2); + + State *state2 = state_create("$2", win2, draw2); Color color = { 0.4, 0.4, 0.4, 1 }; Color purple = { 0.502, 0.168, 0.886, 1 }; @@ -386,7 +400,19 @@ int main(int argc, char **argv) state_order_button(state); - connect_attach_state(con, state); + Button *btn2 = button_simple_create(PANGO_ALIGN_LEFT, color); + button_set_padding(btn2, 1, 1); + button_simple_set_text(btn2, g_strdup("YAY"), text_color); + button_simple_set_action(btn2, show_action, NULL); + + state_add_button(state2, btn2); + state_order_button(state2); + + // TODO: Mirroring + //state2->btns = state->btns; + + connect_add_state(con, state); + connect_add_state(con, state2); connect_attach_source(con); guint source_alrm = g_unix_signal_add(SIGUSR1, G_SOURCE_FUNC(date_update), date_btn); @@ -416,9 +442,17 @@ int main(int argc, char **argv) // NOTE: Buttons are freed by state_destroy dwm_destroy(dwm); + + g_list_free_full(state->btns, (GDestroyNotify)button_destroy); + state_destroy(state); draw_destroy(draw); window_destroy(win); + + state_destroy(state2); + draw_destroy(draw2); + window_destroy(win2); + connect_destroy(con); return 0; diff --git a/src/connect.c b/src/connect.c index 79fd2b1..aaced77 100644 --- a/src/connect.c +++ b/src/connect.c @@ -192,7 +192,13 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer xcb_expose_event_t *expose = (xcb_expose_event_t *)xsource->event; log_debug("Processing event 'Expose' [type=%d]", XCB_EXPOSE); - state_request_redraw(xsource->con->state, true); + for (GList *it = xsource->con->states; it != NULL; it = it->next) { + State *state = it->data; + if (state->win->window == expose->window) { + state_request_redraw(state, true); + break; + } + } break; } @@ -214,7 +220,13 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer case XCB_BUTTON_INDEX_2: // left click case XCB_BUTTON_INDEX_1: // right click case XCB_BUTTON_INDEX_3: // middle click - button_action(xsource->con->state, "button release", button->event_x, button->event_y); + for (GList *it = xsource->con->states; it != NULL; it = it->next) { + State *state = it->data; + if (state->win->window == button->event) { + button_action(state, "button release", button->event_x, button->event_y); + break; + } + } break; default: @@ -225,12 +237,12 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer } // TODO: Implement correctly hovering - case XCB_MOTION_NOTIFY: { - xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xsource->event; - log_debug("Processing event 'MotionNotify' [type=%d]", XCB_MOTION_NOTIFY); - button_action(xsource->con->state, "motion notify", motion->event_x, motion->event_y); - break; - } + //case XCB_MOTION_NOTIFY: { + // xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xsource->event; + // log_debug("Processing event 'MotionNotify' [type=%d]", XCB_MOTION_NOTIFY); + // button_action(xsource->con->state, "motion notify", motion->event_x, motion->event_y); + // break; + //} case XCB_PROPERTY_NOTIFY: { xcb_property_notify_event_t *property = (xcb_property_notify_event_t *)xsource->event; @@ -239,7 +251,8 @@ static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer if (property->atom == XCB_ATOM_RESOURCE_MANAGER) { update_xrm(xsource->con); update_scale(xsource->con); - state_request_redraw(xsource->con->state, true); + for (GList *it = xsource->con->states; it != NULL; it = it->next) + state_request_redraw(it->data, true); } break; } @@ -371,11 +384,11 @@ void connect_attach_source(Connection *con) log_debug("Xcb event loop attached"); } -void connect_attach_state(Connection *con, State *state) +void connect_add_state(Connection *con, State *state) { g_assert_nonnull(state); - con->state = state; - log_debug("Attached state to event loop"); + con->states = g_list_append(con->states, state); + log_debug("Add state to event loop [state=%p, state=\"%s\"]", state, state->label); } void connect_destroy(Connection *con) diff --git a/src/connect.h b/src/connect.h index 2428819..dbb650c 100644 --- a/src/connect.h +++ b/src/connect.h @@ -26,14 +26,14 @@ struct Connection { xcb_errors_context_t *errors; xcb_ewmh_connection_t ewmh; GSource *source; - State *state; + GList *states; }; Connection *connect_create(); void connect_attach_source(Connection *con); -void connect_attach_state(Connection *con, State *state); +void connect_add_state(Connection *con, State *state); void connect_destroy(Connection *con); diff --git a/src/state.c b/src/state.c index 7748e58..c8fe0df 100644 --- a/src/state.c +++ b/src/state.c @@ -3,10 +3,11 @@ #include "state.h" #include "log.h" -State *state_create(Window *win, Drawer *draw) +State *state_create(const char *label, Window *win, Drawer *draw) { State *state = g_malloc0(sizeof(State)); g_assert_nonnull(state); + state->label = label ? label : "comet"; state->win = win; state->draw = draw; return state; @@ -39,7 +40,7 @@ void state_order_button(State *state) static gboolean redraw_handler(State *state) { - log_debug("Redrawing once [relayout=%d]", state->relayout); + log_debug("Redrawing once [relayout=%d, state=\"%s\"]", state->relayout, state->label); if (state->relayout) { draw_compute_layout(state->draw, state->win, state->btns); @@ -78,8 +79,8 @@ static bool anim_check_more(State *state, GList *btns) // Remove animation if all functions finished if (!layout && !before && !after) { - log_debug("Removing animation [type=%d, end=%ld, button=%p]", - btn->anim->type, btn->anim->start + btn->anim->duration, btn); + log_debug("Removing animation [type=%d, end=%ld, button=%p, state=\"%s\"]", + btn->anim->type, btn->anim->start + btn->anim->duration, btn, state->label); g_clear_pointer(&btn->anim, animation_destroy); } else { @@ -97,7 +98,8 @@ static bool anim_check_more(State *state, GList *btns) static gboolean anim_handler(State *state) { bool more = anim_check_more(state, state->btns); - log_debug("Redrawing animation [relayout=%d, more=%d]", state->relayout, more); + log_debug("Redrawing animation [relayout=%d, more=%d, state=\"%s\"]", + state->relayout, more, state->label); if (state->relayout) { draw_compute_layout(state->draw, state->win, state->btns); @@ -129,7 +131,6 @@ void state_request_animation(State *state) void state_destroy(State *state) { - g_list_free_full(state->btns, (GDestroyNotify)button_destroy); g_free(state); } diff --git a/src/state.h b/src/state.h index ef621f4..32d3ada 100644 --- a/src/state.h +++ b/src/state.h @@ -10,6 +10,7 @@ typedef struct State State; struct State { + const char *label; Window *win; Drawer *draw; GList *btns; @@ -18,7 +19,9 @@ struct State { bool relayout; }; -State *state_create(Window *win, Drawer *draw); +State *state_create(const char *label, Window *win, Drawer *draw); + +State *state_create_copy(const char *label, State *target); void state_add_button(State *state, Button *btn); diff --git a/src/window.c b/src/window.c index 30d492f..b3577c3 100644 --- a/src/window.c +++ b/src/window.c @@ -117,6 +117,7 @@ Window *window_create(Connection *con) uint32_t event_mask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS; + // TODO: Implement hovering //| XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_POINTER_MOTION_HINT; xcb_colormap_t colormap = xcb_generate_id(con->connection); |
