added functionality to randomly select images during slideshow

This commit is contained in:
Thomas Osterland 2018-03-22 21:02:26 +01:00
parent fa0bf7bc4d
commit 933c3b80ae
2 changed files with 13 additions and 3 deletions

View File

@ -205,6 +205,7 @@ cairo_surface_t *blur_img = NULL;
cairo_surface_t *img_slideshow[256];
int slideshow_image_count = 0;
int slideshow_interval = 10;
bool slideshow_random_selection = false;
bool tile = false;
bool ignore_empty_password = false;
@ -1221,6 +1222,7 @@ int main(int argc, char *argv[]) {
/* slideshow options */
{"slideshow-interval", required_argument, NULL, 903},
{"slideshow-random-selection", no_argument, NULL, 904},
{NULL, no_argument, NULL, 0}};
@ -1679,6 +1681,9 @@ int main(int argc, char *argv[]) {
slideshow_interval = 10;
}
break;
case 904:
slideshow_random_selection = true;
break;
case 999:
debug_mode = true;
break;

View File

@ -62,6 +62,7 @@ extern cairo_surface_t *blur_img;
extern cairo_surface_t *img_slideshow[256];
extern int slideshow_image_count;
extern int slideshow_interval;
extern bool slideshow_random_selection;
unsigned long lastCheck;
@ -693,10 +694,14 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
if (slideshow_image_count > 0) {
unsigned long now = (unsigned long)time(NULL);
if (img == NULL || now - lastCheck >= slideshow_interval) {
img = img_slideshow[current_slideshow_index++];
if (slideshow_random_selection) {
img = img_slideshow[rand() % slideshow_image_count];
} else {
img = img_slideshow[current_slideshow_index++];
if (current_slideshow_index >= slideshow_image_count) {
current_slideshow_index = 0;
if (current_slideshow_index >= slideshow_image_count) {
current_slideshow_index = 0;
}
}
lastCheck = now;
}