mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 01:57:09 +00:00
convert meter type object values from uint8_t to double
This commit is contained in:
parent
1e25633fc1
commit
e5d32f4ad0
@ -1288,8 +1288,8 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
|||||||
|
|
||||||
case BAR:
|
case BAR:
|
||||||
{
|
{
|
||||||
int h, bar_usage, by;
|
int h, by;
|
||||||
float scale;
|
double bar_usage, scale;
|
||||||
if (cur_x - text_start_x > maximum_width
|
if (cur_x - text_start_x > maximum_width
|
||||||
&& maximum_width > 0) {
|
&& maximum_width > 0) {
|
||||||
break;
|
break;
|
||||||
@ -1330,8 +1330,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
|||||||
unsigned long last_colour = current_color;
|
unsigned long last_colour = current_color;
|
||||||
#ifdef MATH
|
#ifdef MATH
|
||||||
float angle, px, py;
|
float angle, px, py;
|
||||||
int usage;
|
double usage, scale;
|
||||||
float scale;
|
|
||||||
#endif /* MATH */
|
#endif /* MATH */
|
||||||
|
|
||||||
if (cur_x - text_start_x > maximum_width
|
if (cur_x - text_start_x > maximum_width
|
||||||
@ -1362,7 +1361,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
|||||||
#ifdef MATH
|
#ifdef MATH
|
||||||
usage = specials[special_index].arg;
|
usage = specials[special_index].arg;
|
||||||
scale = specials[special_index].scale;
|
scale = specials[special_index].scale;
|
||||||
angle = (M_PI)*(float)(usage)/scale;
|
angle = M_PI * usage / scale;
|
||||||
px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
|
px = (float)(cur_x+(w/2.))-(float)(w/2.)*cos(angle);
|
||||||
py = (float)(by+(h))-(float)(h)*sin(angle);
|
py = (float)(by+(h))-(float)(h)*sin(angle);
|
||||||
|
|
||||||
|
@ -62,20 +62,20 @@ int default_gauge_width = 40, default_gauge_height = 25;
|
|||||||
struct bar {
|
struct bar {
|
||||||
char flags;
|
char flags;
|
||||||
int width, height;
|
int width, height;
|
||||||
unsigned int scale;
|
double scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gauge {
|
struct gauge {
|
||||||
char flags;
|
char flags;
|
||||||
int width, height;
|
int width, height;
|
||||||
unsigned int scale;
|
double scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct graph {
|
struct graph {
|
||||||
char flags;
|
char flags;
|
||||||
int width, height;
|
int width, height;
|
||||||
unsigned int first_colour, last_colour;
|
unsigned int first_colour, last_colour;
|
||||||
unsigned int scale;
|
double scale;
|
||||||
char tempgrad;
|
char tempgrad;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ struct tab {
|
|||||||
* Scanning arguments to various special text objects
|
* Scanning arguments to various special text objects
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char *scan_gauge(struct text_object *obj, const char *args, unsigned int scale)
|
const char *scan_gauge(struct text_object *obj, const char *args, double scale)
|
||||||
{
|
{
|
||||||
struct gauge *g;
|
struct gauge *g;
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ const char *scan_gauge(struct text_object *obj, const char *args, unsigned int s
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *scan_bar(struct text_object *obj, const char *args, unsigned int scale)
|
const char *scan_bar(struct text_object *obj, const char *args, double scale)
|
||||||
{
|
{
|
||||||
struct bar *b;
|
struct bar *b;
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ void scan_font(struct text_object *obj, const char *args)
|
|||||||
obj->data.s = strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
|
obj->data.s = strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *scan_graph(struct text_object *obj, const char *args, int defscale)
|
char *scan_graph(struct text_object *obj, const char *args, double defscale)
|
||||||
{
|
{
|
||||||
struct graph *g;
|
struct graph *g;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
@ -184,14 +184,14 @@ char *scan_graph(struct text_object *obj, const char *args, int defscale)
|
|||||||
if (strstr(args, " "LOGGRAPH) || strncmp(args, LOGGRAPH, strlen(LOGGRAPH)) == 0) {
|
if (strstr(args, " "LOGGRAPH) || strncmp(args, LOGGRAPH, strlen(LOGGRAPH)) == 0) {
|
||||||
g->flags |= SF_SHOWLOG;
|
g->flags |= SF_SHOWLOG;
|
||||||
}
|
}
|
||||||
if (sscanf(args, "%d,%d %x %x %u", &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 5) {
|
if (sscanf(args, "%d,%d %x %x %lf", &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 5) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
g->scale = defscale;
|
g->scale = defscale;
|
||||||
if (sscanf(args, "%d,%d %x %x", &g->height, &g->width, &g->first_colour, &g->last_colour) == 4) {
|
if (sscanf(args, "%d,%d %x %x", &g->height, &g->width, &g->first_colour, &g->last_colour) == 4) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sscanf(args, "%1023s %d,%d %x %x %u", buf, &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 6) {
|
if (sscanf(args, "%1023s %d,%d %x %x %lf", buf, &g->height, &g->width, &g->first_colour, &g->last_colour, &g->scale) == 6) {
|
||||||
return strndup(buf, text_buffer_size);
|
return strndup(buf, text_buffer_size);
|
||||||
}
|
}
|
||||||
g->scale = defscale;
|
g->scale = defscale;
|
||||||
@ -201,14 +201,14 @@ char *scan_graph(struct text_object *obj, const char *args, int defscale)
|
|||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
g->height = 25;
|
g->height = 25;
|
||||||
g->width = 0;
|
g->width = 0;
|
||||||
if (sscanf(args, "%x %x %u", &g->first_colour, &g->last_colour, &g->scale) == 3) {
|
if (sscanf(args, "%x %x %lf", &g->first_colour, &g->last_colour, &g->scale) == 3) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
g->scale = defscale;
|
g->scale = defscale;
|
||||||
if (sscanf(args, "%x %x", &g->first_colour, &g->last_colour) == 2) {
|
if (sscanf(args, "%x %x", &g->first_colour, &g->last_colour) == 2) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sscanf(args, "%1023s %x %x %u", buf, &g->first_colour, &g->last_colour, &g->scale) == 4) {
|
if (sscanf(args, "%1023s %x %x %lf", buf, &g->first_colour, &g->last_colour, &g->scale) == 4) {
|
||||||
return strndup(buf, text_buffer_size);
|
return strndup(buf, text_buffer_size);
|
||||||
}
|
}
|
||||||
g->scale = defscale;
|
g->scale = defscale;
|
||||||
@ -218,14 +218,14 @@ char *scan_graph(struct text_object *obj, const char *args, int defscale)
|
|||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
g->first_colour = 0;
|
g->first_colour = 0;
|
||||||
g->last_colour = 0;
|
g->last_colour = 0;
|
||||||
if (sscanf(args, "%d,%d %u", &g->height, &g->width, &g->scale) == 3) {
|
if (sscanf(args, "%d,%d %lf", &g->height, &g->width, &g->scale) == 3) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
g->scale = defscale;
|
g->scale = defscale;
|
||||||
if (sscanf(args, "%d,%d", &g->height, &g->width) == 2) {
|
if (sscanf(args, "%d,%d", &g->height, &g->width) == 2) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sscanf(args, "%1023s %d,%d %u", buf, &g->height, &g->width, &g->scale) < 4) {
|
if (sscanf(args, "%1023s %d,%d %lf", buf, &g->height, &g->width, &g->scale) < 4) {
|
||||||
g->scale = defscale;
|
g->scale = defscale;
|
||||||
//TODO: check the return value and throw an error?
|
//TODO: check the return value and throw an error?
|
||||||
sscanf(args, "%1023s %d,%d", buf, &g->height, &g->width);
|
sscanf(args, "%1023s %d,%d", buf, &g->height, &g->width);
|
||||||
@ -259,16 +259,16 @@ static struct special_t *new_special(char *buf, enum special_types t)
|
|||||||
return &specials[special_count++];
|
return &specials[special_count++];
|
||||||
}
|
}
|
||||||
|
|
||||||
void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, int usage)
|
void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, double usage)
|
||||||
{
|
{
|
||||||
static const char *gaugevals[] = { "_. ", "\\. ", " | ", " ./", " ._" };
|
static const char *gaugevals[] = { "_. ", "\\. ", " | ", " ./", " ._" };
|
||||||
struct gauge *g = obj->special_data;
|
struct gauge *g = obj->special_data;
|
||||||
|
|
||||||
snprintf(p, p_max_size, "%s", gaugevals[round_to_int((double)usage * 4 / g->scale)]);
|
snprintf(p, p_max_size, "%s", gaugevals[round_to_int(usage * 4 / g->scale)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
void new_gauge_in_x11(struct text_object *obj, char *buf, int usage)
|
void new_gauge_in_x11(struct text_object *obj, char *buf, double usage)
|
||||||
{
|
{
|
||||||
struct special_t *s = 0;
|
struct special_t *s = 0;
|
||||||
struct gauge *g = obj->special_data;
|
struct gauge *g = obj->special_data;
|
||||||
@ -288,7 +288,7 @@ void new_gauge_in_x11(struct text_object *obj, char *buf, int usage)
|
|||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
|
|
||||||
void new_gauge(struct text_object *obj, char *p, int p_max_size, int usage)
|
void new_gauge(struct text_object *obj, char *p, int p_max_size, double usage)
|
||||||
{
|
{
|
||||||
struct gauge *g = obj->special_data;
|
struct gauge *g = obj->special_data;
|
||||||
|
|
||||||
@ -296,9 +296,9 @@ void new_gauge(struct text_object *obj, char *p, int p_max_size, int usage)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (g->flags & SF_SCALED)
|
if (g->flags & SF_SCALED)
|
||||||
g->scale = MAX(g->scale, (unsigned int)usage);
|
g->scale = MAX(g->scale, usage);
|
||||||
else
|
else
|
||||||
usage = MIN(g->scale, (unsigned int)usage);
|
usage = MIN(g->scale, usage);
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
if (output_methods & TO_X)
|
if (output_methods & TO_X)
|
||||||
@ -516,7 +516,7 @@ static void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
static void new_bar_in_x11(struct text_object *obj, char *buf, int usage)
|
static void new_bar_in_x11(struct text_object *obj, char *buf, double usage)
|
||||||
{
|
{
|
||||||
struct special_t *s = 0;
|
struct special_t *s = 0;
|
||||||
struct bar *b = obj->special_data;
|
struct bar *b = obj->special_data;
|
||||||
@ -537,7 +537,7 @@ static void new_bar_in_x11(struct text_object *obj, char *buf, int usage)
|
|||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
|
|
||||||
/* usage is in range [0,255] */
|
/* usage is in range [0,255] */
|
||||||
void new_bar(struct text_object *obj, char *p, int p_max_size, int usage)
|
void new_bar(struct text_object *obj, char *p, int p_max_size, double usage)
|
||||||
{
|
{
|
||||||
struct bar *b = obj->special_data;
|
struct bar *b = obj->special_data;
|
||||||
|
|
||||||
@ -545,9 +545,9 @@ void new_bar(struct text_object *obj, char *p, int p_max_size, int usage)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (b->flags & SF_SCALED)
|
if (b->flags & SF_SCALED)
|
||||||
b->scale = MAX(b->scale, (unsigned int)usage);
|
b->scale = MAX(b->scale, usage);
|
||||||
else
|
else
|
||||||
usage = MIN(b->scale, (unsigned int)usage);
|
usage = MIN(b->scale, usage);
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
if ((output_methods & TO_X))
|
if ((output_methods & TO_X))
|
||||||
|
@ -62,7 +62,7 @@ struct special_t {
|
|||||||
int type;
|
int type;
|
||||||
short height;
|
short height;
|
||||||
short width;
|
short width;
|
||||||
long arg;
|
double arg;
|
||||||
double *graph;
|
double *graph;
|
||||||
double scale; /* maximum value */
|
double scale; /* maximum value */
|
||||||
short show_scale;
|
short show_scale;
|
||||||
@ -94,11 +94,11 @@ struct text_object;
|
|||||||
extern int max_specials;
|
extern int max_specials;
|
||||||
|
|
||||||
/* scanning special arguments */
|
/* scanning special arguments */
|
||||||
const char *scan_bar(struct text_object *, const char *, unsigned int);
|
const char *scan_bar(struct text_object *, const char *, double);
|
||||||
const char *scan_gauge(struct text_object *, const char *, unsigned int);
|
const char *scan_gauge(struct text_object *, const char *, double);
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
void scan_font(struct text_object *, const char *);
|
void scan_font(struct text_object *, const char *);
|
||||||
char *scan_graph(struct text_object *, const char *, int);
|
char *scan_graph(struct text_object *, const char *, double);
|
||||||
void scan_tab(struct text_object *, const char *);
|
void scan_tab(struct text_object *, const char *);
|
||||||
void scan_stippled_hr(struct text_object *, const char*);
|
void scan_stippled_hr(struct text_object *, const char*);
|
||||||
|
|
||||||
@ -108,8 +108,8 @@ void new_graph(struct text_object *, char *, int, double);
|
|||||||
void new_hr(struct text_object *, char *, int);
|
void new_hr(struct text_object *, char *, int);
|
||||||
void new_stippled_hr(struct text_object *, char *, int);
|
void new_stippled_hr(struct text_object *, char *, int);
|
||||||
#endif
|
#endif
|
||||||
void new_gauge(struct text_object *, char *, int, int);
|
void new_gauge(struct text_object *, char *, int, double);
|
||||||
void new_bar(struct text_object *, char *, int, int);
|
void new_bar(struct text_object *, char *, int, double);
|
||||||
void new_fg(struct text_object *, char *, int);
|
void new_fg(struct text_object *, char *, int);
|
||||||
void new_bg(struct text_object *, char *, int);
|
void new_bg(struct text_object *, char *, int);
|
||||||
void new_outline(struct text_object *, char *, int);
|
void new_outline(struct text_object *, char *, int);
|
||||||
|
@ -475,16 +475,23 @@ enum text_object_type {
|
|||||||
struct obj_cb {
|
struct obj_cb {
|
||||||
/* text object: print obj's output to p */
|
/* text object: print obj's output to p */
|
||||||
void (*print)(struct text_object *obj, char *p, int p_max_size);
|
void (*print)(struct text_object *obj, char *p, int p_max_size);
|
||||||
|
|
||||||
/* ifblock object: return zero to trigger jumping */
|
/* ifblock object: return zero to trigger jumping */
|
||||||
int (*iftest)(struct text_object *obj);
|
int (*iftest)(struct text_object *obj);
|
||||||
/* bar object: return bar value in range [0,255] */
|
|
||||||
uint8_t (*barval)(struct text_object *obj);
|
/* meter objects:
|
||||||
/* gauge object: return gauge value in range [0,255] */
|
* The following functions return the current meter-type value
|
||||||
uint8_t (*gaugeval)(struct text_object *obj);
|
* in a range between 0 and the value passed to the appropriate
|
||||||
/* graph object: return graph value in range [0,255] */
|
* scan_* function. Or, if named function has been called with
|
||||||
uint8_t (*graphval)(struct text_object *obj);
|
* a value of 0, make use of auto-scaling (i.e., scaling to the
|
||||||
/* percentage object: return percentage in range [0,100] */
|
* maximum value seen so far). */
|
||||||
|
double (*barval)(struct text_object *obj);
|
||||||
|
double (*gaugeval)(struct text_object *obj);
|
||||||
|
double (*graphval)(struct text_object *obj);
|
||||||
|
|
||||||
|
/* percentage object: return value in range [0, 100] */
|
||||||
uint8_t (*percentage)(struct text_object *obj);
|
uint8_t (*percentage)(struct text_object *obj);
|
||||||
|
|
||||||
/* free obj's data */
|
/* free obj's data */
|
||||||
void (*free)(struct text_object *obj);
|
void (*free)(struct text_object *obj);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user