diff options
| author | Federico Angelilli <code@fedang.net> | 2024-02-08 12:40:56 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-02-08 12:40:56 +0100 |
| commit | a81b8b36afad38e93ab2051e26d21d6125a46eca (patch) | |
| tree | cfa3ff11138783f7a85c6658a3f3284269e9a366 /src | |
| parent | 09505cb480274bdc154c1b4ae3dd6988e56b4368 (diff) | |
Add dwm tags
Diffstat (limited to 'src')
| -rw-r--r-- | src/comet.c | 22 | ||||
| -rw-r--r-- | src/draw.c | 4 | ||||
| -rw-r--r-- | src/dwm.c | 17 | ||||
| -rw-r--r-- | src/dwm.h | 2 |
4 files changed, 30 insertions, 15 deletions
diff --git a/src/comet.c b/src/comet.c index 825cb25..586245f 100644 --- a/src/comet.c +++ b/src/comet.c @@ -222,16 +222,6 @@ static void menu_action(Button *btn) static void register_buttons(State *state, Color color, Color line_color, Color text_color) { - // Tags button - // TODO: They don't do anything now... - for (int i = 0; i < 9; ++i) { - char text[] = { '1' + i, '\0' }; - Button *btn = button_simple_create(PANGO_ALIGN_LEFT, color, line_color); - button_simple_set_text(btn, g_strdup(text), text_color); - button_simple_set_action(btn, show_action, NULL); - state_add_button(state, btn); - } - // Cpu usage button Button *cpu_btn = button_simple_create(PANGO_ALIGN_RIGHT, color, line_color); button_simple_set_text(cpu_btn, g_strdup(" 0%"), text_color); @@ -296,8 +286,17 @@ int main(int argc, char **argv) State *state = state_create(win, draw); Color color = { 0.4, 0.4, 0.4, 1 }; + Color purple = { 0.502, 0.168, 0.886, 1 }; Color line_color = { 0.8, 0.8, 0.8, 1 }; Color text_color = { 0.9, 0.9, 0.9, 1 }; + + // Dwm tags + DwmIpc *dwm = dwm_create(state, "/tmp/dwm.sock"); + + // FIXME: BUG! Explodes if the buttons are not loaded with the left first!!! + // And I have no clue as to why!!!!! + dwm_register_tags(dwm, color, purple, text_color, line_color); + register_buttons(state, color, line_color, text_color); // Buttons with special handling @@ -321,7 +320,6 @@ int main(int argc, char **argv) date_update(date_btn); // Quit button - Color purple = { 0.502, 0.168, 0.886, 1 }; Button *q_btn = button_simple_create(PANGO_ALIGN_RIGHT, purple, line_color); button_simple_set_text(q_btn, g_strdup(""), text_color); button_simple_set_action(q_btn, quit_action, mainloop); @@ -365,8 +363,6 @@ int main(int argc, char **argv) button_group_append(group, menu); state_add_button(state, group); - DwmIpc *dwm = dwm_create(state, "/tmp/dwm.sock"); - connect_attach_state(con, state); connect_attach_source(con); @@ -260,6 +260,8 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) draw->layouts = g_list_reverse(draw->layouts); + // FIXME: BUG! Explodes if the buttons are not loaded with the left first!!! + int layout_width[3] = { layout_end[PANGO_ALIGN_LEFT], layout_end[PANGO_ALIGN_CENTER] - layout_end[PANGO_ALIGN_LEFT], @@ -274,7 +276,7 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) int center_off = center - round(layout_width[PANGO_ALIGN_CENTER] / 2) - layout_end[PANGO_ALIGN_LEFT]; log_debug("Aligning center layout [center=%d, off=%d]", center, center_off); - for (GList *it = layout_start[PANGO_ALIGN_CENTER]; it != layout_start[PANGO_ALIGN_RIGHT]; it = it->next) { + for (GList *it = layout_start[PANGO_ALIGN_CENTER]; it != NULL && it != layout_start[PANGO_ALIGN_RIGHT]; it = it->next) { Layout *layout = it->data; layout->x += center_off; } @@ -277,12 +277,27 @@ static void change_tag_action(Button *btn) { ButtonSimple *sbtn = CAST(btn, ButtonSimple); - g_assert(sbtn->text[0] >= 1 && sbtn->text[0] <= 9); int n = sbtn->text[0] - '0'; + g_assert(n >= 1 && n <= 9); log_debug("Toggled tag %d",n ); } +void dwm_register_tags(DwmIpc *dwm, Color color, Color selected, Color text_color, Color line_color) +{ + dwm->color = color; + dwm->selected = selected; + + // Tags button + for (int i = 0; i < 9; ++i) { + char text[] = { '1' + i, '\0' }; + dwm->tags[i] = button_simple_create(PANGO_ALIGN_LEFT, color, line_color); + button_simple_set_text(dwm->tags[i], g_strdup(text), text_color); + button_simple_set_action(dwm->tags[i], change_tag_action, dwm->state); + state_add_button(dwm->state, dwm->tags[i]); + } +} + void dwm_destroy(DwmIpc *dwm) { g_source_destroy((GSource *)dwm); @@ -7,6 +7,8 @@ typedef struct DwmIpc DwmIpc; DwmIpc *dwm_create(State *state, const char *socket); +void dwm_register_tags(DwmIpc *dwm, Color color, Color selected, Color text_color, Color line_color); + void dwm_destroy(DwmIpc *dwm); #endif |
