mirror of https://github.com/i3/i3lock.git
Read PNG from stdin when no argument is given
Change -i to optional_argument When image_path is the empty string assume stdinpull/76/head
parent
9a7604bb35
commit
de70369f91
18
i3lock.c
18
i3lock.c
|
@ -743,6 +743,13 @@ static void raise_loop(xcb_window_t window) {
|
|||
}
|
||||
}
|
||||
|
||||
cairo_status_t img_read(void *closure, unsigned char *data,
|
||||
unsigned int length) {
|
||||
return fread(data, 1, length, stdin) == length ? CAIRO_STATUS_SUCCESS
|
||||
: CAIRO_STATUS_READ_ERROR;
|
||||
(void)closure;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct passwd *pw;
|
||||
char *username;
|
||||
|
@ -762,7 +769,7 @@ int main(int argc, char *argv[]) {
|
|||
{"debug", no_argument, NULL, 0},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"no-unlock-indicator", no_argument, NULL, 'u'},
|
||||
{"image", required_argument, NULL, 'i'},
|
||||
{"image", optional_argument, NULL, 'i'},
|
||||
{"tiling", no_argument, NULL, 't'},
|
||||
{"ignore-empty-password", no_argument, NULL, 'e'},
|
||||
{"inactivity-timeout", required_argument, NULL, 'I'},
|
||||
|
@ -774,7 +781,7 @@ int main(int argc, char *argv[]) {
|
|||
if ((username = pw->pw_name) == NULL)
|
||||
errx(EXIT_FAILURE, "pw->pw_name is NULL.\n");
|
||||
|
||||
char *optstring = "hvnbdc:p:ui:teI:f";
|
||||
char *optstring = "hvnbdc:p:ui::teI:f";
|
||||
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
|
||||
switch (o) {
|
||||
case 'v':
|
||||
|
@ -811,6 +818,9 @@ int main(int argc, char *argv[]) {
|
|||
unlock_indicator = false;
|
||||
break;
|
||||
case 'i':
|
||||
if (optarg == NULL)
|
||||
image_path = "";
|
||||
else
|
||||
image_path = strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
|
@ -933,7 +943,11 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
if (image_path) {
|
||||
/* Create a pixmap to render on, fill it with the background color */
|
||||
if (strlen(image_path) == 0)
|
||||
img = cairo_image_surface_create_from_png_stream(img_read, NULL);
|
||||
else
|
||||
img = cairo_image_surface_create_from_png(image_path);
|
||||
|
||||
/* In case loading failed, we just pretend no -i was specified. */
|
||||
if (cairo_surface_status(img) != CAIRO_STATUS_SUCCESS) {
|
||||
fprintf(stderr, "Could not load image \"%s\": %s\n",
|
||||
|
|
Loading…
Reference in New Issue