mirror of
https://github.com/Raymo111/i3lock-color.git
synced 2025-02-24 16:06:26 -05:00
added slideshow functionality
This commit is contained in:
parent
4fca1ff1b1
commit
bbd2196326
2 changed files with 106 additions and 18 deletions
104
i3lock.c
104
i3lock.c
|
@ -17,6 +17,7 @@
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -91,6 +92,7 @@ int screen_number = 0;
|
||||||
int internal_line_source = 0;
|
int internal_line_source = 0;
|
||||||
/* bool for showing the clock; why am I commenting this? */
|
/* bool for showing the clock; why am I commenting this? */
|
||||||
bool show_clock = false;
|
bool show_clock = false;
|
||||||
|
bool slideshow_enabled = false;
|
||||||
bool always_show_clock = false;
|
bool always_show_clock = false;
|
||||||
bool show_indicator = false;
|
bool show_indicator = false;
|
||||||
float refresh_rate = 1.0;
|
float refresh_rate = 1.0;
|
||||||
|
@ -200,6 +202,10 @@ static int randr_base = -1;
|
||||||
|
|
||||||
cairo_surface_t *img = NULL;
|
cairo_surface_t *img = NULL;
|
||||||
cairo_surface_t *blur_img = NULL;
|
cairo_surface_t *blur_img = NULL;
|
||||||
|
cairo_surface_t *img_slideshow[256];
|
||||||
|
int slideshow_image_count = 0;
|
||||||
|
int slideshow_interval = 10;
|
||||||
|
|
||||||
bool tile = false;
|
bool tile = false;
|
||||||
bool ignore_empty_password = false;
|
bool ignore_empty_password = false;
|
||||||
bool skip_repeated_empty_password = false;
|
bool skip_repeated_empty_password = false;
|
||||||
|
@ -234,6 +240,15 @@ bool bar_reversed = false;
|
||||||
/* isutf, u8_dec © 2005 Jeff Bezanson, public domain */
|
/* isutf, u8_dec © 2005 Jeff Bezanson, public domain */
|
||||||
#define isutf(c) (((c)&0xC0) != 0x80)
|
#define isutf(c) (((c)&0xC0) != 0x80)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks if the given path leads to an actual file or something else, e.g. a directory
|
||||||
|
*/
|
||||||
|
int is_regular_file(const char *path) {
|
||||||
|
struct stat path_stat;
|
||||||
|
stat(path, &path_stat);
|
||||||
|
return S_ISREG(path_stat.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decrements i to point to the previous unicode glyph
|
* Decrements i to point to the previous unicode glyph
|
||||||
*
|
*
|
||||||
|
@ -1046,6 +1061,44 @@ static void raise_loop(xcb_window_t window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loads the images from the provided directory and stores them in the pointer array
|
||||||
|
* img_slideshow
|
||||||
|
*/
|
||||||
|
void load_slideshow_images(const char *path) {
|
||||||
|
slideshow_enabled = true;
|
||||||
|
DIR *d;
|
||||||
|
struct dirent *dir;
|
||||||
|
int file_count = 0;
|
||||||
|
|
||||||
|
d = opendir(path);
|
||||||
|
if (d == NULL) {
|
||||||
|
printf("Could not open directory: %s\n", path);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((dir = readdir(d)) != NULL) {
|
||||||
|
if (file_count >= 256) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
char path_to_image[256];
|
||||||
|
strcpy(path_to_image, path);
|
||||||
|
strcat(path_to_image, "/");
|
||||||
|
strcat(path_to_image, dir->d_name);
|
||||||
|
|
||||||
|
if (verify_png_image(path_to_image)) {
|
||||||
|
img_slideshow[file_count] = cairo_image_surface_create_from_png(path_to_image);
|
||||||
|
++file_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
slideshow_image_count = file_count;
|
||||||
|
|
||||||
|
closedir(d);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
char *username;
|
char *username;
|
||||||
|
@ -1166,6 +1219,9 @@ int main(int argc, char *argv[]) {
|
||||||
{"refresh-rate", required_argument, NULL, 901},
|
{"refresh-rate", required_argument, NULL, 901},
|
||||||
{"composite", no_argument, NULL, 902},
|
{"composite", no_argument, NULL, 902},
|
||||||
|
|
||||||
|
/* slideshow options */
|
||||||
|
{"slideshow-interval", required_argument, NULL, 1000},
|
||||||
|
|
||||||
{NULL, no_argument, NULL, 0}};
|
{NULL, no_argument, NULL, 0}};
|
||||||
|
|
||||||
if ((pw = getpwuid(getuid())) == NULL)
|
if ((pw = getpwuid(getuid())) == NULL)
|
||||||
|
@ -1619,6 +1675,13 @@ int main(int argc, char *argv[]) {
|
||||||
case 999:
|
case 999:
|
||||||
debug_mode = true;
|
debug_mode = true;
|
||||||
break;
|
break;
|
||||||
|
case 1000:
|
||||||
|
slideshow_interval = atoi(optarg);
|
||||||
|
|
||||||
|
if (slideshow_interval < 0) {
|
||||||
|
slideshow_interval = 10;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
|
errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
|
||||||
" [-i image.png] [-t] [-e] [-f]\n"
|
" [-i image.png] [-t] [-e] [-f]\n"
|
||||||
|
@ -1743,23 +1806,28 @@ int main(int argc, char *argv[]) {
|
||||||
(uint32_t[]){XCB_EVENT_MASK_STRUCTURE_NOTIFY});
|
(uint32_t[]){XCB_EVENT_MASK_STRUCTURE_NOTIFY});
|
||||||
|
|
||||||
init_colors_once();
|
init_colors_once();
|
||||||
if (verify_png_image(image_path)) {
|
if (is_regular_file(image_path)) {
|
||||||
/* Create a pixmap to render on, fill it with the background color */
|
if (verify_png_image(image_path)) {
|
||||||
img = cairo_image_surface_create_from_png(image_path);
|
/* Create a pixmap to render on, fill it with the background color */
|
||||||
} else if (file_is_jpg(image_path)) {
|
img = cairo_image_surface_create_from_png(image_path);
|
||||||
DEBUG("Image looks like a jpeg, decoding\n");
|
} else if (file_is_jpg(image_path)) {
|
||||||
unsigned char* jpg_data = read_JPEG_file(image_path, &jpg_info);
|
DEBUG("Image looks like a jpeg, decoding\n");
|
||||||
if (jpg_data != NULL) {
|
unsigned char* jpg_data = read_JPEG_file(image_path, &jpg_info);
|
||||||
img = cairo_image_surface_create_for_data(jpg_data,
|
if (jpg_data != NULL) {
|
||||||
CAIRO_FORMAT_ARGB32, jpg_info.width, jpg_info.height,
|
img = cairo_image_surface_create_for_data(jpg_data,
|
||||||
jpg_info.stride);
|
CAIRO_FORMAT_ARGB32, jpg_info.width, jpg_info.height,
|
||||||
}
|
jpg_info.stride);
|
||||||
}
|
}
|
||||||
/* In case loading failed, we just pretend no -i was specified. */
|
}
|
||||||
if (img && cairo_surface_status(img) != CAIRO_STATUS_SUCCESS) {
|
/* In case loading failed, we just pretend no -i was specified. */
|
||||||
fprintf(stderr, "Could not load image \"%s\": %s\n",
|
if (img && cairo_surface_status(img) != CAIRO_STATUS_SUCCESS) {
|
||||||
image_path, cairo_status_to_string(cairo_surface_status(img)));
|
fprintf(stderr, "Could not load image \"%s\": %s\n",
|
||||||
img = NULL;
|
image_path, cairo_status_to_string(cairo_surface_status(img)));
|
||||||
|
img = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Path to a directory is provided -> use slideshow mode */
|
||||||
|
load_slideshow_images(image_path);
|
||||||
}
|
}
|
||||||
free(image_path);
|
free(image_path);
|
||||||
|
|
||||||
|
@ -1881,7 +1949,7 @@ int main(int argc, char *argv[]) {
|
||||||
* file descriptor becomes readable). */
|
* file descriptor becomes readable). */
|
||||||
ev_invoke(main_loop, xcb_check, 0);
|
ev_invoke(main_loop, xcb_check, 0);
|
||||||
|
|
||||||
if (show_clock || bar_enabled) {
|
if (show_clock || bar_enabled || slideshow_enabled) {
|
||||||
if (redraw_thread) {
|
if (redraw_thread) {
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
double s;
|
double s;
|
||||||
|
|
|
@ -59,6 +59,11 @@ extern char *modifier_string;
|
||||||
/* A Cairo surface containing the specified image (-i), if any. */
|
/* A Cairo surface containing the specified image (-i), if any. */
|
||||||
extern cairo_surface_t *img;
|
extern cairo_surface_t *img;
|
||||||
extern cairo_surface_t *blur_img;
|
extern cairo_surface_t *blur_img;
|
||||||
|
extern cairo_surface_t *img_slideshow[256];
|
||||||
|
extern int slideshow_image_count;
|
||||||
|
extern int slideshow_interval;
|
||||||
|
|
||||||
|
unsigned long lastCheck = -1;
|
||||||
|
|
||||||
/* Whether the image should be tiled. */
|
/* Whether the image should be tiled. */
|
||||||
extern bool tile;
|
extern bool tile;
|
||||||
|
@ -144,6 +149,8 @@ static struct ev_periodic *time_redraw_tick;
|
||||||
/* Cache the screen’s visual, necessary for creating a Cairo context. */
|
/* Cache the screen’s visual, necessary for creating a Cairo context. */
|
||||||
static xcb_visualtype_t *vistype;
|
static xcb_visualtype_t *vistype;
|
||||||
|
|
||||||
|
int current_slideshow_index = 0;
|
||||||
|
|
||||||
/* Maintain the current unlock/PAM state to draw the appropriate unlock
|
/* Maintain the current unlock/PAM state to draw the appropriate unlock
|
||||||
* indicator. */
|
* indicator. */
|
||||||
unlock_state_t unlock_state;
|
unlock_state_t unlock_state;
|
||||||
|
@ -678,6 +685,19 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
|
||||||
cairo_surface_t *xcb_output = cairo_xcb_surface_create(conn, bg_pixmap, vistype, resolution[0], resolution[1]);
|
cairo_surface_t *xcb_output = cairo_xcb_surface_create(conn, bg_pixmap, vistype, resolution[0], resolution[1]);
|
||||||
cairo_t *xcb_ctx = cairo_create(xcb_output);
|
cairo_t *xcb_ctx = cairo_create(xcb_output);
|
||||||
|
|
||||||
|
/*update image according to the slideshow_interval*/
|
||||||
|
if (slideshow_image_count > 0) {
|
||||||
|
unsigned long now = (unsigned long)time(NULL);
|
||||||
|
if (-1 == lastCheck || now - lastCheck >= slideshow_interval) {
|
||||||
|
img = img_slideshow[current_slideshow_index++];
|
||||||
|
|
||||||
|
if (current_slideshow_index >= slideshow_image_count) {
|
||||||
|
current_slideshow_index = 0;
|
||||||
|
}
|
||||||
|
lastCheck = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (blur_img || img) {
|
if (blur_img || img) {
|
||||||
if (blur_img) {
|
if (blur_img) {
|
||||||
cairo_set_source_surface(xcb_ctx, blur_img, 0, 0);
|
cairo_set_source_surface(xcb_ctx, blur_img, 0, 0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue