mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 18:45:10 +00:00
scroll: add 'wait' and 'interval' parameters. (#297)
This commit is contained in:
parent
e2bd14e7b7
commit
b14f459740
@ -3672,19 +3672,22 @@
|
|||||||
<command>
|
<command>
|
||||||
<option>scroll</option>
|
<option>scroll</option>
|
||||||
</command>
|
</command>
|
||||||
<option>(direction) length (step) text</option>
|
<option>(direction) length (step) (interval) text</option>
|
||||||
</term>
|
</term>
|
||||||
<listitem>Scroll 'text' by 'step' characters to the left
|
<listitem>Scroll 'text' by 'step' characters to the left
|
||||||
or right (set 'direction' to 'left' or 'right') showing
|
or right (set 'direction' to 'left' or 'right' or 'wait')
|
||||||
'length' number of characters at the same time. The text
|
showing 'length' number of characters at the same time. The
|
||||||
may also contain variables. 'step' is optional and defaults
|
text may also contain variables. 'step' is optional and
|
||||||
to 1 if not set. 'direction' is optional and defaults to left
|
defaults to 1 if not set. 'direction' is optional and defaults
|
||||||
if not set. If a var creates output on multiple lines
|
to left if not set. When direction is 'wait' then text will
|
||||||
then the lines are placed behind each other separated with
|
scroll left and wait for 'interval' itertations at the
|
||||||
a '|'-sign. If you change the textcolor inside $scroll it
|
beginning and end of the text. If a var creates output on
|
||||||
will automatically have it's old value back at the end of
|
multiple lines then the lines are placed behind each other
|
||||||
$scroll. The end and the start of text will be separated by
|
separated with a '|'-sign. If you change the textcolor inside
|
||||||
'length' number of spaces.
|
$scroll it will automatically have it's old value back at the
|
||||||
|
end of $scroll. The end and the start of text will be
|
||||||
|
separated by 'length' number of spaces unless direction is
|
||||||
|
'wait'.
|
||||||
<para /></listitem>
|
<para /></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
@ -35,16 +35,19 @@
|
|||||||
#include "x11.h"
|
#include "x11.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define SCROLL_LEFT true
|
#define SCROLL_LEFT 1
|
||||||
#define SCROLL_RIGHT false
|
#define SCROLL_RIGHT 2
|
||||||
|
#define SCROLL_WAIT 3
|
||||||
|
|
||||||
struct scroll_data {
|
struct scroll_data {
|
||||||
char *text;
|
char *text;
|
||||||
unsigned int show;
|
unsigned int show;
|
||||||
unsigned int step;
|
unsigned int step;
|
||||||
|
int wait;
|
||||||
|
unsigned int wait_arg;
|
||||||
signed int start;
|
signed int start;
|
||||||
long resetcolor;
|
long resetcolor;
|
||||||
bool direction;
|
int direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash, char *free_at_crash2)
|
void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash, char *free_at_crash2)
|
||||||
@ -63,6 +66,8 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
|
|||||||
if (arg && sscanf(arg, "%5s %n", dirarg, &n1) == 1) {
|
if (arg && sscanf(arg, "%5s %n", dirarg, &n1) == 1) {
|
||||||
if (strcasecmp(dirarg, "right") == 0 || strcasecmp(dirarg, "r") == 0)
|
if (strcasecmp(dirarg, "right") == 0 || strcasecmp(dirarg, "r") == 0)
|
||||||
sd->direction = SCROLL_RIGHT;
|
sd->direction = SCROLL_RIGHT;
|
||||||
|
else if ( strcasecmp(dirarg, "wait") == 0 || strcasecmp(dirarg, "w") == 0)
|
||||||
|
sd->direction = SCROLL_WAIT;
|
||||||
else if ( strcasecmp(dirarg, "left") != 0 && strcasecmp(dirarg, "l") != 0)
|
else if ( strcasecmp(dirarg, "left") != 0 && strcasecmp(dirarg, "l") != 0)
|
||||||
n1 = 0;
|
n1 = 0;
|
||||||
}
|
}
|
||||||
@ -73,7 +78,7 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
|
|||||||
free(obj->next);
|
free(obj->next);
|
||||||
#endif
|
#endif
|
||||||
free(free_at_crash2);
|
free(free_at_crash2);
|
||||||
CRIT_ERR(obj, free_at_crash, "scroll needs arguments: [left|right] <length> [<step>] <text>");
|
CRIT_ERR(obj, free_at_crash, "scroll needs arguments: [left|right|wait] <length> [<step>] [interval] <text>");
|
||||||
}
|
}
|
||||||
n1 += n2;
|
n1 += n2;
|
||||||
|
|
||||||
@ -82,9 +87,17 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
|
|||||||
} else {
|
} else {
|
||||||
sd->step = 1;
|
sd->step = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sscanf(arg + n1, "%u %n", &sd->wait_arg, &n2) == 1) {
|
||||||
|
n1 += n2;
|
||||||
|
sd->wait = sd->wait_arg;
|
||||||
|
} else {
|
||||||
|
sd->wait_arg = sd->wait = 0;
|
||||||
|
}
|
||||||
|
|
||||||
sd->text = (char*)malloc(strlen(arg + n1) + sd->show + 1);
|
sd->text = (char*)malloc(strlen(arg + n1) + sd->show + 1);
|
||||||
|
|
||||||
if (strlen(arg) > sd->show) {
|
if (strlen(arg) > sd->show && sd->direction != SCROLL_WAIT) {
|
||||||
for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {
|
for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {
|
||||||
sd->text[n2] = ' ';
|
sd->text[n2] = ' ';
|
||||||
}
|
}
|
||||||
@ -94,7 +107,7 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
|
|||||||
sd->text[0] = 0;
|
sd->text[0] = 0;
|
||||||
|
|
||||||
strcat(sd->text, arg + n1);
|
strcat(sd->text, arg + n1);
|
||||||
sd->start = 0;
|
sd->start = sd->direction == SCROLL_WAIT ? strlen(sd->text) : 0;
|
||||||
obj->sub = (struct text_object *)malloc(sizeof(struct text_object));
|
obj->sub = (struct text_object *)malloc(sizeof(struct text_object));
|
||||||
extract_variable_text_internal(obj->sub, sd->text);
|
extract_variable_text_internal(obj->sub, sd->text);
|
||||||
|
|
||||||
@ -173,6 +186,25 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size)
|
|||||||
if(buf[sd->start] == 0 || (unsigned) sd->start > strlen(&(buf[0]))) {
|
if(buf[sd->start] == 0 || (unsigned) sd->start > strlen(&(buf[0]))) {
|
||||||
sd->start = 0;
|
sd->start = 0;
|
||||||
}
|
}
|
||||||
|
} else if(sd->direction == SCROLL_WAIT) {
|
||||||
|
size_t len = strlen(&buf[0]);
|
||||||
|
|
||||||
|
if(sd->start >= len || sd->show + sd->start >= len) {
|
||||||
|
if (sd->wait_arg && (--sd->wait <= 0 && sd->wait_arg != 1)) {
|
||||||
|
sd->wait = sd->wait_arg;
|
||||||
|
} else {
|
||||||
|
sd->start = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(!sd->wait_arg || sd->wait_arg == 1 ||
|
||||||
|
(sd->wait_arg && sd->wait-- <= 0)) {
|
||||||
|
sd->wait = 0;
|
||||||
|
sd->start += sd->step;
|
||||||
|
|
||||||
|
if (sd->start + sd->show >= len)
|
||||||
|
sd->start = len - sd->show;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if(sd->start < 1) {
|
if(sd->start < 1) {
|
||||||
sd->start = strlen(&(buf[0]));
|
sd->start = strlen(&(buf[0]));
|
||||||
|
Loading…
Reference in New Issue
Block a user