From eb9864ab9abc7253321eb461fc9c49a39f8354b3 Mon Sep 17 00:00:00 2001 From: bi4k8 Date: Tue, 30 May 2023 14:08:20 +0000 Subject: [PATCH 1/3] core: use text_start_x as base for ${goto} otherwise, one must explicitly goto a "magic" offset to match the position of the first text conky renders --- src/conky.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index b316b18f0..a8e5f2c16 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1510,11 +1510,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) { case GOTO: if (current->arg >= 0) { #ifdef BUILD_GUI - cur_x = static_cast(current->arg); + cur_x = static_cast(current->arg) + text_start_x; // make sure shades are 1 pixel to the right of the text if (draw_mode == BG) { cur_x++; } #endif /* BUILD_GUI */ - cur_x = static_cast(current->arg); + cur_x = static_cast(current->arg) + text_start_x; for (auto output : display_outputs()) output->gotox(cur_x); } break; From 0f2c8d9107e95d132f9c91d1bae5829df86d6ef3 Mon Sep 17 00:00:00 2001 From: bi4k8 Date: Tue, 30 May 2023 14:10:05 +0000 Subject: [PATCH 2/3] add ${vgoto} for vertical placement Co-authored-by: easysid --- src/conky.cc | 18 ++++++++++++++++++ src/core.cc | 3 +++ src/nvidia.cc | 1 + src/specials.cc | 5 +++++ src/specials.h | 2 ++ 5 files changed, 29 insertions(+) diff --git a/src/conky.cc b/src/conky.cc index a8e5f2c16..f218ff3f6 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -982,6 +982,10 @@ static int text_size_updater(char *s, int special_index) { last_font_height += current->arg; } else if (current->type == GOTO) { if (current->arg > cur_x) { w = static_cast(current->arg); } + } else if (current->type == VGOTO) { + if (current->arg > cur_y) { + last_font_height = static_cast(current->arg); + } } else if (current->type == TAB) { int start = current->arg; int step = current->width; @@ -1518,6 +1522,20 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) { for (auto output : display_outputs()) output->gotox(cur_x); } break; + + case VGOTO: + if (current->arg >= 0) { +#ifdef BUILD_GUI + cur_y = + static_cast(current->arg) + text_start_y + font_ascent(); + // make sure shades are 1 pixel to the bottom of the text + if (draw_mode == BG) cur_y++; +#endif /* BUILD_GUI */ + cur_y = + static_cast(current->arg) + text_start_y + font_ascent(); + for (auto output : display_outputs()) output->gotoy(cur_y); + } + break; } #ifdef BUILD_GUI diff --git a/src/core.cc b/src/core.cc index 99bbffb25..4027b0053 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1034,6 +1034,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, END OBJ_ARG(goto, nullptr, "goto needs arguments") obj->data.l = strtol(arg, nullptr, 10); obj->callbacks.print = &new_goto; + END OBJ_ARG(vgoto, nullptr, "vgoto needs arguments") obj->data.l = + strtol(arg, nullptr, 10); + obj->callbacks.print = &new_vgoto; #ifdef BUILD_GUI END OBJ(tab, nullptr) scan_tab(obj, arg); obj->callbacks.print = &new_tab; diff --git a/src/nvidia.cc b/src/nvidia.cc index 48c5083ed..3c4b83f5f 100644 --- a/src/nvidia.cc +++ b/src/nvidia.cc @@ -315,6 +315,7 @@ const char *translate_nvidia_special_type[] = { "", // SAVE_COORDINATES "", // FONT "", // GOTO + "", // VGOTO "" // TAB }; diff --git a/src/specials.cc b/src/specials.cc index 133193cac..fb46e208d 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -794,6 +794,11 @@ void new_goto(struct text_object *obj, char *p, unsigned int p_max_size) { new_special(p, GOTO)->arg = dpi_scale(obj->data.l); } +void new_vgoto(struct text_object *obj, char *p, unsigned int p_max_size) { + if (p_max_size == 0) { return; } + new_special(p, VGOTO)->arg = dpi_scale(obj->data.l); +} + void scan_tab(struct text_object *obj, const char *arg) { struct tab *t; diff --git a/src/specials.h b/src/specials.h index 513b43f7a..cac55ff58 100644 --- a/src/specials.h +++ b/src/specials.h @@ -57,6 +57,7 @@ enum special_types { SAVE_COORDINATES, FONT, GOTO, + VGOTO, TAB }; @@ -115,6 +116,7 @@ void new_save_coordinates(struct text_object *, char *, unsigned int); void new_alignr(struct text_object *, char *, unsigned int); void new_alignc(struct text_object *, char *, unsigned int); void new_goto(struct text_object *, char *, unsigned int); +void new_vgoto(struct text_object *, char *, unsigned int); void new_tab(struct text_object *, char *, unsigned int); void clear_stored_graphs(); From d13320e11343f563f55a2cc055dcf75c151356fc Mon Sep 17 00:00:00 2001 From: bi4k8 Date: Tue, 30 May 2023 14:13:56 +0000 Subject: [PATCH 3/3] docs: document ${vgoto} --- doc/variables.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/variables.yaml b/doc/variables.yaml index 9625792dd..d5a6c48a8 100644 --- a/doc/variables.yaml +++ b/doc/variables.yaml @@ -2359,6 +2359,11 @@ values: - (interface) - name: version desc: Git version number. DragonFly only. + - name: vgoto + desc: The next element will be printed at vertical position 'y'. See + also $goto. + args: + - y - name: voffset desc: |- Change vertical offset by N pixels. Negative values will