# Adds support for the 'goto' and 'tab' commands to facilitate
# text positioning.
diff -Naurp conky-1.4.2-orig/doc/variables.xml conky-1.4.2-goto/doc/variables.xml
--- conky-1.4.2-orig/doc/variables.xml 2006-08-08 16:10:46.000000000 +0200
+++ conky-1.4.2-goto/doc/variables.xml 2006-08-08 18:55:25.000000000 +0200
@@ -448,6 +448,16 @@
+
+
+
+
+ The next letter will be printed at position 'x'.
+
+
+
+
+
@@ -1129,6 +1139,16 @@
+
+
+
+
+ Puts a tab of the specified width, starting from column 'start'.
+
+
+
+
+
diff -Naurp conky-1.4.2-orig/src/conky.c conky-1.4.2-goto/src/conky.c
--- conky-1.4.2-orig/src/conky.c 2006-08-08 16:10:46.000000000 +0200
+++ conky-1.4.2-goto/src/conky.c 2006-08-08 18:53:19.000000000 +0200
@@ -439,6 +439,8 @@ enum {
OFFSET,
VOFFSET,
FONT,
+ GOTO,
+ TAB,
};
static struct special_t {
@@ -747,6 +749,17 @@ static inline void new_alignc(char *buf,
new_special(buf, ALIGNC)->arg = c;
}
+static inline void new_goto(char *buf, long c)
+{
+ new_special(buf, GOTO)->arg = c;
+}
+
+static inline void new_tab(char *buf, int a, int b) {
+ struct special_t *s = new_special(buf, TAB);
+ s->width = a;
+ s->arg = b;
+}
+
/* quite boring functions */
static inline void for_each_line(char *b, void (*f) (char *))
@@ -850,6 +863,8 @@ enum text_object_type {
OBJ_fs_size,
OBJ_fs_used,
OBJ_fs_used_perc,
+ OBJ_goto,
+ OBJ_tab,
OBJ_hr,
OBJ_offset,
OBJ_voffset,
@@ -2220,6 +2235,28 @@ static struct text_object *construct_tex
END OBJ(hr, 0) obj->data.i = arg ? atoi(arg) : 1;
END OBJ(offset, 0) obj->data.i = arg ? atoi(arg) : 1;
END OBJ(voffset, 0) obj->data.i = arg ? atoi(arg) : 1;
+ END OBJ(goto, 0)
+
+ if (!arg) {
+ ERR("goto needs arguments");
+ obj->type = OBJ_text;
+ obj->data.s = strdup("${goto}");
+ return NULL;
+ }
+
+ obj->data.i = atoi(arg);
+
+ END OBJ(tab, 0)
+ int a = 10, b = 0;
+ if (arg) {
+ if (sscanf(arg, "%d %d", &a, &b) != 2)
+ sscanf(arg, "%d", &b);
+ }
+ if (a <= 0)
+ a = 1;
+ obj->data.pair.a = a;
+ obj->data.pair.b = b;
+
END OBJ(i2c, INFO_I2C) char buf1[64], buf2[64];
int n;
@@ -3720,6 +3757,12 @@ static void generate_text_internal(char
v[obj->data.loadavg[0] -
1]);
}
+ OBJ(goto) {
+ new_goto(p, obj->data.i);
+ }
+ OBJ(tab) {
+ new_tab(p, obj->data.pair.a, obj->data.pair.b);
+ }
OBJ(hr) {
new_hr(p, obj->data.i);
}
@@ -4673,60 +4716,7 @@ static inline int get_string_width_speci
int fontchange = 0;
-#ifdef X11
-static void text_size_updater(char *s)
-{
- int w = 0;
- char *p;
- int h = font_height();
- /* get string widths and skip specials */
- p = s;
- while (*p) {
- if (*p == SPECIAL_CHAR) {
- *p = '\0';
- w += get_string_width(s);
- *p = SPECIAL_CHAR;
-
- if (specials[special_index].type == BAR
- || specials[special_index].type == GRAPH) {
- w += specials[special_index].width;
- if (specials[special_index].height > h) {
- h = specials[special_index].height;
- h += font_ascent();
- }
- }
-
- else if (specials[special_index].type == OFFSET) {
- w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
- }
- else if (specials[special_index].type == VOFFSET) {
- h += specials[special_index].arg;
- }
- else if (specials[special_index].type == FONT) {
- fontchange = specials[special_index].font_added;
- selected_font = specials[special_index].font_added;
- h = font_height();
- }
-
-
- special_index++;
- s = p + 1;
- }
- p++;
- }
- w += get_string_width(s);
- if (w > text_width)
- text_width = w;
- if (text_width > maximum_width && maximum_width)
- text_width = maximum_width;
-
- text_height += h;
-/* if (fontchange) {
- selected_font = 0;
- }*/
-}
-#endif /* X11 */
-
+static void text_size_updater(char *s);
#ifdef X11
static void update_text_area()
@@ -4816,6 +4806,71 @@ static int cur_x, cur_y; /* current x an
static int draw_mode; /* FG, BG or OUTLINE */
static long current_color;
+#ifdef X11
+static void text_size_updater(char *s)
+{
+ int w = 0;
+ char *p;
+ int h = font_height();
+ /* get string widths and skip specials */
+ p = s;
+ while (*p) {
+ if (*p == SPECIAL_CHAR) {
+ *p = '\0';
+ w += get_string_width(s);
+ *p = SPECIAL_CHAR;
+
+ if (specials[special_index].type == BAR
+ || specials[special_index].type == GRAPH) {
+ w += specials[special_index].width;
+ if (specials[special_index].height > h) {
+ h = specials[special_index].height;
+ h += font_ascent();
+ }
+ }
+
+ else if (specials[special_index].type == OFFSET) {
+ w += specials[special_index].arg + get_string_width("a"); /* filthy, but works */
+ }
+ else if (specials[special_index].type == VOFFSET) {
+ h += specials[special_index].arg;
+ }
+ else if (specials[special_index].type == GOTO) {
+ if (specials[special_index].arg >= 0)
+ w += (int)specials[special_index].arg - cur_x;
+ }
+ else if (specials[special_index].type == TAB) {
+ int start = specials[special_index].arg;
+ int step = specials[special_index].width;
+ if (!step || step < 0)
+ step = 10;
+ w += step - (cur_x - text_start_x - start) % step;
+ }
+ else if (specials[special_index].type == FONT) {
+ fontchange = specials[special_index].font_added;
+ selected_font = specials[special_index].font_added;
+ h = font_height();
+ }
+
+
+ special_index++;
+ s = p + 1;
+ }
+ p++;
+ }
+ w += get_string_width(s);
+ if (w > text_width)
+ text_width = w;
+ if (text_width > maximum_width && maximum_width)
+ text_width = maximum_width;
+
+ text_height += h;
+/* if (fontchange) {
+ selected_font = 0;
+ }*/
+}
+#endif /* X11 */
+
static inline void set_foreground_color(long c)
{
current_color = c;
@@ -5269,14 +5324,26 @@ static void draw_line(char *s)
arg);
break;
- case OFFSET:
- {
- w += specials[special_index].arg;
- }
+ case OFFSET:
+ w += specials[special_index].arg;
+ break;
+
+ case VOFFSET:
+ cur_y += specials[special_index].arg;
+ break;
+
+ case GOTO:
+ if (specials[special_index].arg >= 0)
+ cur_x = (int)specials[special_index].arg;
break;
- case VOFFSET:
+
+ case TAB:
{
- cur_y += specials[special_index].arg;
+ int start = specials[special_index].arg;
+ int step = specials[special_index].width;
+ if (!step || step < 0)
+ step = 10;
+ w = step - (cur_x - text_start_x - start) % step;
}
break;