diff options
| author | Federico Angelilli <code@fedang.net> | 2023-11-26 20:18:08 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2023-11-26 20:18:08 +0100 |
| commit | 00bd74159e2f7d209a10d11e8cbecb894c3d0ef0 (patch) | |
| tree | 01ea73f9635c282ec8b0fcb4c5e775448dda9502 /src/comet.c | |
| parent | f9ec9bb88ae2b1423d30da21c76a7e131cb383cc (diff) | |
Generalize button struct
Diffstat (limited to 'src/comet.c')
| -rw-r--r-- | src/comet.c | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/src/comet.c b/src/comet.c index 4b28a71..7664ade 100644 --- a/src/comet.c +++ b/src/comet.c @@ -39,7 +39,7 @@ static gboolean mainloop_quit(gpointer data) static gboolean disk_update(gpointer data) { - Button *btn = data; + ButtonSimple *btn = data; struct statvfs buffer; g_assert(statvfs("/", &buffer) == 0); @@ -59,7 +59,7 @@ static gboolean disk_update(gpointer data) static gboolean temp_update(gpointer data) { - Button *btn = data; + ButtonSimple *btn = data; FILE *temp = fopen("/sys/class/thermal/thermal_zone2/temp", "rb"); g_assert_nonnull(temp); @@ -110,7 +110,7 @@ char *cpu_percentage(void) static gboolean cpu_update(gpointer data) { - Button *btn = data; + ButtonSimple *btn = data; char *perc = cpu_percentage(); // Don't update on error @@ -130,7 +130,7 @@ static gboolean cpu_update(gpointer data) static gboolean ram_update(gpointer data) { - Button *btn = data; + ButtonSimple *btn = data; FILE *meminfo = fopen("/proc/meminfo", "rb"); g_assert_nonnull(meminfo); @@ -159,7 +159,7 @@ static gboolean ram_update(gpointer data) static gboolean date_update(gpointer data) { - Button *btn = data; + ButtonSimple *btn = data; size_t len1 = g_utf8_strlen(btn->text, -1); g_free(btn->text); @@ -191,13 +191,13 @@ static gboolean date_update(gpointer data) static void show_action(Button *btn) { - log_info("Called action: %s", btn->text); + log_info("Called action: %s", button_simple_get_text(btn)); } static void quit_action(Button *btn) { log_info("Quit button pressed"); - g_main_loop_quit(btn->action_data); + g_main_loop_quit(CAST(btn, ButtonSimple)->action_data); } int main(int argc, char **argv) @@ -226,45 +226,45 @@ int main(int argc, char **argv) State *state = state_create(win, draw); - Color background = { 0.4, 0.4, 0.4, 1 }; - Color foreground = { 0.8, 0.8, 0.8, 1 }; - Color stroke = { 0.8, 0.8, 0.8, 1 }; + Color color = { 0.4, 0.4, 0.4, 1 }; + Color line_color = { 0.8, 0.8, 0.8, 1 }; + Color text_color = { 0.8, 0.8, 0.8, 1 }; for (int i = 0; i < 9; ++i) { char text[] = { '1' + i, '\0' }; - Button *btn = button_create(text, PANGO_ALIGN_LEFT); - button_set_colors(btn, background, foreground, stroke); - button_set_action(btn, show_action, NULL); + Button *btn = button_simple_create(PANGO_ALIGN_LEFT, color, line_color); + button_simple_set_text(btn, text, text_color); + button_simple_set_action(btn, show_action, NULL); state_add_button(state, btn); } - Button *cpu_btn = button_create("cpu", PANGO_ALIGN_RIGHT); - button_set_colors(cpu_btn, background, foreground, stroke); - button_set_action(cpu_btn, show_action, state); + Button *cpu_btn = button_simple_create(PANGO_ALIGN_RIGHT, color, line_color); + button_simple_set_text(cpu_btn, "cpu", text_color); + button_simple_set_action(cpu_btn, show_action, state); state_add_button(state, cpu_btn); cpu_update(cpu_btn); g_timeout_add(1000, cpu_update, cpu_btn); - Button *temp_btn = button_create("temp", PANGO_ALIGN_RIGHT); - button_set_colors(temp_btn, background, foreground, stroke); - button_set_action(temp_btn, show_action, state); + Button *temp_btn = button_simple_create(PANGO_ALIGN_RIGHT, color, line_color); + button_simple_set_text(temp_btn, "temp", text_color); + button_simple_set_action(temp_btn, show_action, state); state_add_button(state, temp_btn); temp_update(temp_btn); g_timeout_add(20 * 1000, temp_update, temp_btn); - Button *ram_btn = button_create("ram", PANGO_ALIGN_RIGHT); - button_set_colors(ram_btn, background, foreground, stroke); - button_set_action(ram_btn, show_action, state); + Button *ram_btn = button_simple_create(PANGO_ALIGN_RIGHT, color, line_color); + button_simple_set_text(ram_btn, "ram", text_color); + button_simple_set_action(ram_btn, show_action, state); state_add_button(state, ram_btn); ram_update(ram_btn); g_timeout_add(10 * 1000, ram_update, ram_btn); - Button *disk_btn = button_create("disk", PANGO_ALIGN_RIGHT); - button_set_colors(disk_btn, background, foreground, stroke); - button_set_action(disk_btn, show_action, state); + Button *disk_btn = button_simple_create(PANGO_ALIGN_RIGHT, color, line_color); + button_simple_set_text(disk_btn, "disk", text_color); + button_simple_set_action(disk_btn, show_action, state); state_add_button(state, disk_btn); disk_update(disk_btn); @@ -275,9 +275,9 @@ int main(int argc, char **argv) timer_t timer; } date_ctx = { state, 0 }; - Button *date_btn = button_create("date", PANGO_ALIGN_CENTER); - button_set_colors(date_btn, background, foreground, stroke); - button_set_action(date_btn, show_action, &date_ctx); + Button *date_btn = button_simple_create(PANGO_ALIGN_CENTER, color, line_color); + button_simple_set_text(date_btn, "date", text_color); + button_simple_set_action(date_btn, show_action, &date_ctx); state_add_button(state, date_btn); struct sigevent sev = { 0 }; @@ -287,11 +287,10 @@ int main(int argc, char **argv) g_assert(timer_create(CLOCK_REALTIME, &sev, &date_ctx.timer) == 0); date_update(date_btn); - // purple - Color background2 = { 0.502, 0.168, 0.886, 1 }; - Button *q_btn = button_create("", PANGO_ALIGN_RIGHT); - button_set_colors(q_btn, background2, foreground, stroke); - button_set_action(q_btn, quit_action, mainloop); + 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, "", text_color); + button_simple_set_action(q_btn, quit_action, mainloop); state_add_button(state, q_btn); connect_attach_state(con, state); |
