Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vgoto #1559

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(current->arg); }
} else if (current->type == VGOTO) {
if (current->arg > cur_y) {
last_font_height = static_cast<int>(current->arg);
}
} else if (current->type == TAB) {
int start = current->arg;
int step = current->width;
Expand Down Expand Up @@ -1510,14 +1514,28 @@ 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<int>(current->arg);
cur_x = static_cast<int>(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<int>(current->arg);
cur_x = static_cast<int>(current->arg) + text_start_x;
for (auto output : display_outputs()) output->gotox(cur_x);
}
break;

case VGOTO:
if (current->arg >= 0) {
#ifdef BUILD_GUI
cur_y =
static_cast<int>(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<int>(current->arg) + text_start_y + font_ascent();
for (auto output : display_outputs()) output->gotoy(cur_y);
}
break;
}

#ifdef BUILD_GUI
Expand Down
3 changes: 3 additions & 0 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/nvidia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const char *translate_nvidia_special_type[] = {
"", // SAVE_COORDINATES
"", // FONT
"", // GOTO
"", // VGOTO
"" // TAB
};

Expand Down
5 changes: 5 additions & 0 deletions src/specials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/specials.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum special_types {
SAVE_COORDINATES,
FONT,
GOTO,
VGOTO,
TAB
};

Expand Down Expand Up @@ -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();
Expand Down