diff --git a/doc/spacebar.asciidoc b/doc/spacebar.asciidoc index 7882de9..6ea8112 100644 --- a/doc/spacebar.asciidoc +++ b/doc/spacebar.asciidoc @@ -87,6 +87,9 @@ Settings *status_bar_clock_icon* ['']:: Specify a symbol to represent the current time. +*status_bar_clock_format* ['']:: + Specify a format for the current time, according to the strftime function. + Exit Codes ---------- diff --git a/examples/spacebarrc b/examples/spacebarrc index 5909496..b037144 100755 --- a/examples/spacebarrc +++ b/examples/spacebarrc @@ -8,5 +8,6 @@ spacebar -m config status_bar_space_icon_strip I II III IV V VI VII VIII IX X spacebar -m config status_bar_power_icon_strip   spacebar -m config status_bar_space_icon  spacebar -m config status_bar_clock_icon  +spacebar -m config status_bar_clock_format "%d/%m/%y %R" echo "spacebar configuration loaded.." diff --git a/src/bar.c b/src/bar.c index 573c9be..4f502d4 100644 --- a/src/bar.c +++ b/src/bar.c @@ -272,7 +272,8 @@ void bar_refresh(struct bar *bar) struct tm *timeinfo = localtime(&rawtime); if (timeinfo) { char time[255]; - snprintf(time, sizeof(time), "%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min); + strftime(time, sizeof(time), g_bar_manager._clock_format, timeinfo); + //snprintf(time, sizeof(time), "%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min); struct bar_line time_line = bar_prepare_line(g_bar_manager.t_font, time, g_bar_manager.foreground_color); CGPoint t_pos = bar_align_line(bar, time_line, ALIGN_RIGHT, ALIGN_CENTER); bar_draw_line(bar, time_line, t_pos.x, t_pos.y); diff --git a/src/bar_manager.c b/src/bar_manager.c index d72aeda..4aebb52 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -45,7 +45,23 @@ void bar_manager_set_text_font(struct bar_manager *bar_manager, char *font_strin bar_manager->t_font = bar_create_font(bar_manager->t_font_prop); bar_manager->space_underline = bar_prepare_line(bar_manager->t_font, "______", rgba_color_from_hex(0xffd4d232)); bar_manager->power_underline = bar_prepare_line(bar_manager->t_font, "__________", rgba_color_from_hex(0xffd75f5f)); - bar_manager->clock_underline = bar_prepare_line(bar_manager->t_font, "__________", rgba_color_from_hex(0xff458588)); + + time_t rawtime; + time(&rawtime); + struct tm *timeinfo = localtime(&rawtime); + if (timeinfo) { + char time[255]; + strftime(time, sizeof(time), g_bar_manager._clock_format, timeinfo); + char underline[255] = {0}; + + for (int i = 0; i < strlen(time) + 4; ++i) + underline[i] = '_'; + + bar_manager->clock_underline = bar_prepare_line(bar_manager->t_font, underline, rgba_color_from_hex(0xff458588)); + } + else + bar_manager->clock_underline = bar_prepare_line(bar_manager->t_font, "__________", rgba_color_from_hex(0xff458588)); + bar_manager_refresh(bar_manager); } @@ -146,6 +162,12 @@ void bar_manager_set_clock_icon(struct bar_manager *bar_manager, char *icon) bar_manager_refresh(bar_manager); } +void bar_manager_set_clock_format(struct bar_manager *bar_manager, char *format) +{ + bar_manager->_clock_format = format; + bar_manager_set_text_font(bar_manager, bar_manager->t_font_prop); +} + void bar_manager_set_space_icon(struct bar_manager *bar_manager, char *icon) { if (bar_manager->space_icon.line) { @@ -194,6 +216,7 @@ void bar_manager_init(struct bar_manager *bar_manager) bar_manager_set_background_color(bar_manager, 0xff202020); bar_manager_set_foreground_color(bar_manager, 0xffa8a8a8); bar_manager_set_clock_icon(bar_manager, string_copy(" ")); + bar_manager_set_clock_format(bar_manager, string_copy("%R")); bar_manager_set_space_icon(bar_manager, string_copy("*")); bar_manager_set_power_strip(bar_manager, NULL); } diff --git a/src/bar_manager.h b/src/bar_manager.h index 9e7a523..b8a6163 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -12,6 +12,7 @@ struct bar_manager char **_space_icon_strip; char **_power_icon_strip; char *_clock_icon; + char *_clock_format; char *_space_icon; struct rgba_color foreground_color; struct rgba_color background_color; @@ -33,6 +34,7 @@ void bar_manager_set_icon_font(struct bar_manager *bar_manager, char *font_strin void bar_manager_set_space_strip(struct bar_manager *bar_manager, char **icon_strip); void bar_manager_set_power_strip(struct bar_manager *bar_manager, char **icon_strip); void bar_manager_set_clock_icon(struct bar_manager *bar_manager, char *icon); +void bar_manager_set_clock_format(struct bar_manager *bar_manager, char *format); void bar_manager_set_space_icon(struct bar_manager *bar_manager, char *icon); void bar_manager_display_changed(struct bar_manager *bar_manager); diff --git a/src/message.c b/src/message.c index 5e1a56f..1616ff6 100644 --- a/src/message.c +++ b/src/message.c @@ -20,6 +20,7 @@ extern bool g_verbose; #define COMMAND_CONFIG_BAR_POWER_STRIP "status_bar_power_icon_strip" #define COMMAND_CONFIG_BAR_SPACE_ICON "status_bar_space_icon" #define COMMAND_CONFIG_BAR_CLOCK_ICON "status_bar_clock_icon" +#define COMMAND_CONFIG_BAR_CLOCK_FORMAT "status_bar_clock_format" /* --------------------------------COMMON ARGUMENTS----------------------------- */ #define ARGUMENT_COMMON_VAL_ON "on" @@ -187,7 +188,15 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message) } else { bar_manager_set_clock_icon(&g_bar_manager, token_to_string(token)); } - } else { + } else if (token_equals(command, COMMAND_CONFIG_BAR_CLOCK_FORMAT)) { + struct token token = get_token(&message); + if (!token_is_valid(token)) { + fprintf(rsp, "%s\n", g_bar_manager._clock_icon ? g_bar_manager._clock_icon : ""); + } else { + bar_manager_set_clock_format(&g_bar_manager, token_to_string(token)); + } + } + else { daemon_fail(rsp, "unknown command '%.*s' for domain '%.*s'\n", command.length, command.text, domain.length, domain.text); } } diff --git a/src/spacebar.c b/src/spacebar.c index 7c49137..d996276 100644 --- a/src/spacebar.c +++ b/src/spacebar.c @@ -12,7 +12,7 @@ #define CONFIG_OPT_SHRT "-c" #define MAJOR 0 -#define MINOR 3 +#define MINOR 4 #define PATCH 0 extern int SLSMainConnectionID(void);