diff --git a/src/conky.cc b/src/conky.cc index 509940c7..a4df7318 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1009,15 +1009,17 @@ static inline void draw_graph_bars(special_node *current, std::unique_ptrinverty ? by : by + h; + int offsety2 = current->inverty ? by + current->graph[j] * (h - 1) / current->scale + : round_to_positive_int(static_cast(by) + h - + current->graph[j] * (h - 1) / + current->scale); /* this is mugfugly, but it works */ if (display_output()) { display_output()->draw_line( - 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)); + text_offset.x() + cur_x + i + 1, text_offset.y() + offsety1, + text_offset.x() + cur_x + i + 1, text_offset.y() + offsety2); } ++j; } @@ -1321,7 +1323,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) { } colour_idx = 0; if(current->invertx){ - for (i = 0; i <= w- 2; i++) { + for (i = 0; i <= w - 2; i++) { draw_graph_bars(current, tmpcolour, text_offset, i, j, w, colour_idx, cur_x, by, h); } diff --git a/src/specials.cc b/src/specials.cc index 84bb1242..0a80cb37 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -85,6 +85,7 @@ conky::simple_config_setting console_graph_ticks( /* special flag for inverting axis */ #define SF_INVERTX (1 << 0) +#define SF_INVERTY (1 << 1) /* * Special data typedefs @@ -250,6 +251,7 @@ std::pair scan_command(const char *s) { * -l will set the showlog flag, enabling logarithmic graph scales * -t will set the tempgrad member to true, enabling temperature gradient colors * -x will set the invertx flag to true, inverting the x axis + * -y will set the invertx flag to true, inverting the y axis * * @param[out] obj struct in which to save width, height and other options * @param[in] args argument string to parse @@ -298,6 +300,12 @@ bool scan_graph(struct text_object *obj, const char *argstr, double defscale, ch strncmp(argstr, INVERTX, strlen(INVERTX)) == 0) { g->invertflag |= SF_INVERTX; } + /* set inverty to true if '-y' specified. + * It doesn't matter where the argument is exactly. */ + if ((strstr(argstr, " " INVERTY) != nullptr) || + strncmp(argstr, INVERTY, strlen(INVERTY)) == 0) { + g->invertflag |= SF_INVERTY; + } /* all the following functions try to interpret the beginning of a * a string with different format strings. If successful, they return from @@ -322,9 +330,7 @@ bool scan_graph(struct text_object *obj, const char *argstr, double defscale, ch * therfore we ensure last_colour_name is not TEMPGRAD or LOGGRAPH */ if (sscanf(argstr, "%d,%d %s %s", &g->height, &g->width, first_colour_name, last_colour_name) == 4 && - strcmp(last_colour_name, TEMPGRAD) != 0 && - strcmp(last_colour_name, LOGGRAPH) != 0 && - strcmp(last_colour_name, INVERTX) != 0) { + strchr(last_colour_name,'-') == NULL) { apply_graph_colours(g, first_colour_name, last_colour_name); return true; } @@ -365,9 +371,7 @@ bool scan_graph(struct text_object *obj, const char *argstr, double defscale, ch * This could match as [scale] [-l | -t], * therfore we ensure last_colour_name is not TEMPGRAD or LOGGRAPH */ if (sscanf(argstr, "%s %s", first_colour_name, last_colour_name) == 2 && - strcmp(last_colour_name, TEMPGRAD) != 0 && - strcmp(last_colour_name, LOGGRAPH) != 0 && - strcmp(last_colour_name, INVERTX) != 0) { + strchr(last_colour_name,'-') == NULL) { apply_graph_colours(g, first_colour_name, last_colour_name); return true; } @@ -647,6 +651,9 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size, if ((g->invertflag & SF_INVERTX) != 0){ s->invertx = 1; } + if ((g->invertflag & SF_INVERTY) != 0){ + s->inverty = 1; + } if (g->speedgraph) { s->speedgraph = TRUE; } diff --git a/src/specials.h b/src/specials.h index 03015f67..a54c3f2c 100644 --- a/src/specials.h +++ b/src/specials.h @@ -40,6 +40,7 @@ #define LOGGRAPH "-l" #define TEMPGRAD "-t" #define INVERTX "-x" +#define INVERTY "-y" enum class text_node_t : uint32_t { NONSPECIAL = 0, @@ -83,6 +84,7 @@ struct special_node { char tempgrad; char speedgraph; char invertx; + char inverty; struct special_node *next; };