added functionality to randomly select images during slideshow
This commit is contained in:
parent
fa0bf7bc4d
commit
933c3b80ae
5
i3lock.c
5
i3lock.c
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue