mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-25 12:10:03 +00:00
Patch by Kim Holviala sf.net id #2484548.
* change the height of execbar and execibar to be the same as other bars have by default (6 pixels) * treat mixer values as percentages as they're usually 0-100 (switch to spaced_print() with pad_percents) * change temp_print() from snprintf() to spaced_print() * remove decimals from temp_print() as none of the current sources can supply values smaller than 1 degree (C or F, doesn't matter) * add a space between number and the unit in human_readable() * fix number printing in human_readable() * network $upspeed and $downspeed now use human_readable()
This commit is contained in:
parent
b516e19440
commit
27bb931e41
12
ChangeLog
12
ChangeLog
@ -1,5 +1,17 @@
|
||||
2009-02-17
|
||||
* Added $battery_short patch, sf.net id #2300911 (thanks Swoog)
|
||||
* Patch by Kim Holviala sf.net id #2484548:
|
||||
* change the height of execbar and execibar to be the same as other
|
||||
bars have by default (6 pixels)
|
||||
* treat mixer values as percentages as they're usually 0-100 (switch
|
||||
to spaced_print() with pad_percents)
|
||||
* change temp_print() from snprintf() to spaced_print()
|
||||
* remove decimals from temp_print() as none of the current sources can
|
||||
supply values smaller than 1 degree (C or F, doesn't matter)
|
||||
* add a space between number and the unit in human_readable()
|
||||
* fix number printing in human_readable()
|
||||
* network $upspeed and $downspeed now use human_readable()
|
||||
|
||||
|
||||
2009-02-15
|
||||
* Added out_to_x
|
||||
|
54
src/conky.c
54
src/conky.c
@ -1097,10 +1097,8 @@ static void convert_escapes(char *buf)
|
||||
/* Prints anything normally printed with snprintf according to the current value
|
||||
* of use_spacer. Actually slightly more flexible than snprintf, as you can
|
||||
* safely specify the destination buffer as one of your inputs. */
|
||||
static int spaced_print(char *, int, const char *, int, ...)
|
||||
__attribute__((format(printf, 3, 5)));
|
||||
|
||||
static int spaced_print(char *buf, int size, const char *format, int width, ...) {
|
||||
int spaced_print(char *buf, int size, const char *format, int width, ...)
|
||||
{
|
||||
int len = 0;
|
||||
va_list argp;
|
||||
char *tempbuf;
|
||||
@ -1130,24 +1128,23 @@ static int spaced_print(char *buf, int size, const char *format, int width, ...)
|
||||
return len;
|
||||
}
|
||||
|
||||
/* converts from bytes to human readable format (k, M, G, T) */
|
||||
/* converts from bytes to human readable format (K, M, G, T) */
|
||||
static void human_readable(long long num, char *buf, int size)
|
||||
{
|
||||
const char **suffix = suffixes;
|
||||
float fnum;
|
||||
int precision, len;
|
||||
static const int WIDTH = 10, SHORT_WIDTH = 8;
|
||||
int width;
|
||||
const char *format, *format2;
|
||||
|
||||
if (short_units) {
|
||||
width = SHORT_WIDTH;
|
||||
format = "%lld%1s";
|
||||
format2 = "%.*f%1s";
|
||||
width = 7;
|
||||
format = "%lld %.1s";
|
||||
format2 = "%.*f %.1s";
|
||||
} else {
|
||||
width = WIDTH;
|
||||
format = "%lld%s";
|
||||
format2 = "%.*f%s";
|
||||
width = 9;
|
||||
format = "%lld %s";
|
||||
format2 = "%.*f %s";
|
||||
}
|
||||
|
||||
if (llabs(num) < 1024LL) {
|
||||
@ -1163,15 +1160,11 @@ static void human_readable(long long num, char *buf, int size)
|
||||
suffix++;
|
||||
fnum = num / 1024.0;
|
||||
|
||||
precision = 3;
|
||||
do {
|
||||
precision--;
|
||||
if (precision < 0) {
|
||||
break;
|
||||
}
|
||||
len = spaced_print(buf, size, format2, width,
|
||||
precision, fnum, *suffix);
|
||||
} while (len >= MAX(width, size));
|
||||
if (fnum < 10) precision = 1;
|
||||
else precision = 0;
|
||||
|
||||
len = spaced_print(buf, size, format2, width,
|
||||
precision, fnum, *suffix);
|
||||
}
|
||||
|
||||
/* global object list root element */
|
||||
@ -4091,8 +4084,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
obj->data.diskio->current_write, obj->e, 1, obj->showaslog);
|
||||
}
|
||||
OBJ(downspeed) {
|
||||
spaced_print(p, p_max_size, "%d", 6,
|
||||
round_to_int(obj->data.net->recv_speed / 1024));
|
||||
human_readable(obj->data.net->recv_speed, p, 255);
|
||||
}
|
||||
OBJ(downspeedf) {
|
||||
spaced_print(p, p_max_size, "%.1f", 8,
|
||||
@ -4199,7 +4191,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
|
||||
if (barnum >= 0.0) {
|
||||
barnum /= 100;
|
||||
new_bar(p, 0, 4, round_to_int(barnum * 255.0));
|
||||
new_bar(p, 0, 6, round_to_int(barnum * 255.0));
|
||||
}
|
||||
}
|
||||
OBJ(execgraph) {
|
||||
@ -4234,7 +4226,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
}
|
||||
obj->data.execi.last_update = current_update_time;
|
||||
}
|
||||
new_bar(p, 0, 4, round_to_int(obj->f));
|
||||
new_bar(p, 0, 6, round_to_int(obj->f));
|
||||
}
|
||||
OBJ(execigraph) {
|
||||
if (current_update_time - obj->data.execi.last_update
|
||||
@ -4696,13 +4688,16 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
|
||||
/* mixer stuff */
|
||||
OBJ(mixer) {
|
||||
snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
|
||||
spaced_print(p, p_max_size, "%*d", 4,
|
||||
pad_percents, mixer_get_avg(obj->data.l));
|
||||
}
|
||||
OBJ(mixerl) {
|
||||
snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
|
||||
spaced_print(p, p_max_size, "%*d", 4,
|
||||
pad_percents, mixer_get_left(obj->data.l));
|
||||
}
|
||||
OBJ(mixerr) {
|
||||
snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
|
||||
spaced_print(p, p_max_size, "%*d", 4,
|
||||
pad_percents, mixer_get_right(obj->data.l));
|
||||
}
|
||||
OBJ(mixerbar) {
|
||||
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
|
||||
@ -4828,8 +4823,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
snprintf(p, p_max_size, "%d", total_updates);
|
||||
}
|
||||
OBJ(upspeed) {
|
||||
spaced_print(p, p_max_size, "%d", 6,
|
||||
round_to_int(obj->data.net->trans_speed / 1024));
|
||||
human_readable(obj->data.net->trans_speed, p, 255);
|
||||
}
|
||||
OBJ(upspeedf) {
|
||||
spaced_print(p, p_max_size, "%.1f", 8,
|
||||
|
@ -294,4 +294,8 @@ void update_users(void);
|
||||
/* defined in conky.c */
|
||||
extern double current_update_time, last_update_time;
|
||||
|
||||
/* defined in conky.c */
|
||||
int spaced_print(char *, int, const char *, int, ...)
|
||||
__attribute__((format(printf, 3, 5)));
|
||||
|
||||
#endif
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include "temphelper.h"
|
||||
#include "conky.h"
|
||||
|
||||
/* default to output in celsius */
|
||||
static enum TEMP_UNIT output_unit = TEMP_CELSIUS;
|
||||
@ -86,11 +87,7 @@ int temp_print(char *p, size_t p_max_size, double n, enum TEMP_UNIT input_unit)
|
||||
double out, plen;
|
||||
|
||||
out = convert_temp_output(n, input_unit);
|
||||
plen = spaced_print(p, p_max_size, "%.lf", 5, out);
|
||||
|
||||
/* Skip decimal for big values but keep padding sane
|
||||
* (i.e. use 4 chars for them)
|
||||
*/
|
||||
plen = snprintf(p, p_max_size, ((out > 100.0) ?
|
||||
"%4.0lf" : "%2.1lf") , out);
|
||||
return !(plen >= p_max_size);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user