mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 12:27:52 +00:00
scroll: add 'wait' and 'interval' parameters. (#297)
This commit is contained in:
parent
e2bd14e7b7
commit
b14f459740
@ -3672,19 +3672,22 @@
|
||||
<command>
|
||||
<option>scroll</option>
|
||||
</command>
|
||||
<option>(direction) length (step) text</option>
|
||||
<option>(direction) length (step) (interval) text</option>
|
||||
</term>
|
||||
<listitem>Scroll 'text' by 'step' characters to the left
|
||||
or right (set 'direction' to 'left' or 'right') showing
|
||||
'length' number of characters at the same time. The text
|
||||
may also contain variables. 'step' is optional and defaults
|
||||
to 1 if not set. 'direction' is optional and defaults to left
|
||||
if not set. If a var creates output on multiple lines
|
||||
then the lines are placed behind each other separated with
|
||||
a '|'-sign. If you change the textcolor inside $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.
|
||||
or right (set 'direction' to 'left' or 'right' or 'wait')
|
||||
showing 'length' number of characters at the same time. The
|
||||
text may also contain variables. 'step' is optional and
|
||||
defaults to 1 if not set. 'direction' is optional and defaults
|
||||
to left if not set. When direction is 'wait' then text will
|
||||
scroll left and wait for 'interval' itertations at the
|
||||
beginning and end of the text. If a var creates output on
|
||||
multiple lines then the lines are placed behind each other
|
||||
separated with a '|'-sign. If you change the textcolor inside
|
||||
$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>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
|
@ -35,16 +35,19 @@
|
||||
#include "x11.h"
|
||||
#include <vector>
|
||||
|
||||
#define SCROLL_LEFT true
|
||||
#define SCROLL_RIGHT false
|
||||
#define SCROLL_LEFT 1
|
||||
#define SCROLL_RIGHT 2
|
||||
#define SCROLL_WAIT 3
|
||||
|
||||
struct scroll_data {
|
||||
char *text;
|
||||
unsigned int show;
|
||||
unsigned int step;
|
||||
int wait;
|
||||
unsigned int wait_arg;
|
||||
signed int start;
|
||||
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)
|
||||
@ -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 (strcasecmp(dirarg, "right") == 0 || strcasecmp(dirarg, "r") == 0)
|
||||
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)
|
||||
n1 = 0;
|
||||
}
|
||||
@ -73,7 +78,7 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
|
||||
free(obj->next);
|
||||
#endif
|
||||
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;
|
||||
|
||||
@ -82,9 +87,17 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
|
||||
} else {
|
||||
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);
|
||||
|
||||
if (strlen(arg) > sd->show) {
|
||||
if (strlen(arg) > sd->show && sd->direction != SCROLL_WAIT) {
|
||||
for(n2 = 0; (unsigned int) n2 < sd->show; 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;
|
||||
|
||||
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));
|
||||
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]))) {
|
||||
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 {
|
||||
if(sd->start < 1) {
|
||||
sd->start = strlen(&(buf[0]));
|
||||
|
Loading…
Reference in New Issue
Block a user