1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

Rename round_to_int to round_to_positive_int

This commit is contained in:
Travis Yaeger 2019-05-24 11:46:12 -07:00 committed by Brenden Matthews
parent e6bb3d666a
commit 9da1101b5b
6 changed files with 23 additions and 19 deletions

View File

@ -305,7 +305,7 @@ void update_stuff() {
int round_to_int_temp(float f) { return static_cast<int>(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<int>(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) {

View File

@ -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<bool> no_buffers;
extern conky::simple_config_setting<std::string> bar_fill;

View File

@ -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<double>(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<double>(by) + h -
current->graph[j] * (h - 1) /
current->scale));
++j;
}
free_and_zero(tmpcolour);

View File

@ -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<double>(entropy.avail) * 100.0 /
static_cast<double>(entropy.poolsize));
return round_to_positive_int(static_cast<double>(entropy.avail) * 100.0 /
static_cast<double>(entropy.poolsize));
}
void print_entropy_poolsize(struct text_object *obj, char *p,

View File

@ -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) {

View File

@ -374,7 +374,8 @@ void new_gauge_in_shell(struct text_object *obj, char *p,
static const char *gaugevals[] = {"_. ", "\\. ", " | ", " ./", " ._"};
auto *g = static_cast<struct gauge *>(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());