From 9da1101b5ba00295aee149262767f6200cc76f23 Mon Sep 17 00:00:00 2001 From: Travis Yaeger Date: Fri, 24 May 2019 11:46:12 -0700 Subject: [PATCH] Rename round_to_int to round_to_positive_int --- src/common.cc | 13 ++++++++----- src/common.h | 2 +- src/conky.cc | 14 +++++++------- src/entropy.cc | 4 ++-- src/mpd.cc | 2 +- src/specials.cc | 7 ++++--- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/common.cc b/src/common.cc index 538c5127..357a8a7a 100644 --- a/src/common.cc +++ b/src/common.cc @@ -305,7 +305,7 @@ void update_stuff() { int round_to_int_temp(float f) { return static_cast(f); } /* Don't return negative values for cpugraph, bar, gauge, percentage. * Causes unreasonable numbers to show */ -unsigned int round_to_int(float f) { +unsigned int round_to_positive_int(float f) { if (f >= 0.0) { return static_cast(f + 0.5); } return 0; } @@ -369,7 +369,7 @@ uint8_t cpu_percentage(struct text_object *obj) { CRIT_ERR(nullptr, nullptr, "attempting to use more CPUs than you have!"); } if (info.cpu_usage != nullptr) { - return round_to_int(info.cpu_usage[obj->data.i] * 100.0); + return round_to_positive_int(info.cpu_usage[obj->data.i] * 100.0); } return 0; } @@ -399,7 +399,9 @@ PRINT_HR_GENERATOR(swapmax) uint8_t mem_percentage(struct text_object *obj) { (void)obj; - return (info.memmax != 0u ? round_to_int(info.mem * 100 / info.memmax) : 0); + return (info.memmax != 0u + ? round_to_positive_int(info.mem * 100 / info.memmax) + : 0); } double mem_barval(struct text_object *obj) { @@ -419,8 +421,9 @@ double mem_with_buffers_barval(struct text_object *obj) { uint8_t swap_percentage(struct text_object *obj) { (void)obj; - return (info.swapmax != 0u ? round_to_int(info.swap * 100 / info.swapmax) - : 0); + return (info.swapmax != 0u + ? round_to_positive_int(info.swap * 100 / info.swapmax) + : 0); } double swap_barval(struct text_object *obj) { diff --git a/src/common.h b/src/common.h index a7a575b3..30ecd968 100644 --- a/src/common.h +++ b/src/common.h @@ -71,7 +71,7 @@ void format_seconds_short(char *buf, unsigned int n, long seconds); int round_to_int_temp(float); -unsigned int round_to_int(float); +unsigned int round_to_positive_int(float); extern conky::simple_config_setting no_buffers; extern conky::simple_config_setting bar_fill; diff --git a/src/conky.cc b/src/conky.cc index cc557743..8931cfbe 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1419,13 +1419,13 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) { } } /* this is mugfugly, but it works */ - XDrawLine( - display, window.drawable, window.gc, - text_offset_x + cur_x + i + 1, text_offset_y + by + h, - text_offset_x + cur_x + i + 1, - text_offset_y + round_to_int(static_cast(by) + h - - current->graph[j] * (h - 1) / - current->scale)); + XDrawLine(display, window.drawable, window.gc, + text_offset_x + cur_x + i + 1, text_offset_y + by + h, + text_offset_x + cur_x + i + 1, + text_offset_y + round_to_positive_int( + static_cast(by) + h - + current->graph[j] * (h - 1) / + current->scale)); ++j; } free_and_zero(tmpcolour); diff --git a/src/entropy.cc b/src/entropy.cc index ad4608e3..204ddd31 100644 --- a/src/entropy.cc +++ b/src/entropy.cc @@ -72,8 +72,8 @@ void print_entropy_avail(struct text_object *obj, char *p, uint8_t entropy_percentage(struct text_object *obj) { (void)obj; - return round_to_int(static_cast(entropy.avail) * 100.0 / - static_cast(entropy.poolsize)); + return round_to_positive_int(static_cast(entropy.avail) * 100.0 / + static_cast(entropy.poolsize)); } void print_entropy_poolsize(struct text_object *obj, char *p, diff --git a/src/mpd.cc b/src/mpd.cc index 6c31b86d..76e6be5d 100644 --- a/src/mpd.cc +++ b/src/mpd.cc @@ -345,7 +345,7 @@ void print_mpd_length(struct text_object *obj, char *p, uint8_t mpd_percentage(struct text_object *obj) { (void)obj; - return round_to_int(get_mpd().progress * 100.0f); + return round_to_positive_int(get_mpd().progress * 100.0f); } double mpd_barval(struct text_object *obj) { diff --git a/src/specials.cc b/src/specials.cc index f5167c5e..3e6b4efb 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -374,7 +374,8 @@ void new_gauge_in_shell(struct text_object *obj, char *p, static const char *gaugevals[] = {"_. ", "\\. ", " | ", " ./", " ._"}; auto *g = static_cast(obj->special_data); - snprintf(p, p_max_size, "%s", gaugevals[round_to_int(usage * 4 / g->scale)]); + snprintf(p, p_max_size, "%s", + gaugevals[round_to_positive_int(usage * 4 / g->scale)]); } #ifdef BUILD_X11 @@ -488,7 +489,7 @@ void new_graph_in_shell(struct special_t *s, char *buf, int buf_max_size) { char *buf_max = buf + (sizeof(char) * buf_max_size); double scale = (tickitems.size() - 1) / s->scale; for (int i = s->graph_allocated - 1; i >= 0; i--) { - const unsigned int v = round_to_int(s->graph[i] * scale); + const unsigned int v = round_to_positive_int(s->graph[i] * scale); const char *tick = tickitems[v].c_str(); size_t itemlen = tickitems[v].size(); for (unsigned int j = 0; j < itemlen; j++) { @@ -639,7 +640,7 @@ static void new_bar_in_shell(struct text_object *obj, char *buffer, if (width > buf_max_size) { width = buf_max_size; } - scaledusage = round_to_int(usage * width / b->scale); + scaledusage = round_to_positive_int(usage * width / b->scale); for (i = 0; i < scaledusage; i++) { buffer[i] = *(bar_fill.get(*state).c_str());