2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <linux/input.h>
22 #include <cutils/klog.h>
23 #include "minui/minui.h"
25 #define NEXT_TIMEOUT_MS 5000
26 #define LAST_TIMEOUT_S 30
28 #define LOGE(x...) do { KLOG_ERROR("slideshow", x); } while (0)
30 static int input_cb(int fd, unsigned int epevents, void *data)
32 struct input_event ev;
33 int *key_code = (int *)data;
37 if (ev_get_input(fd, epevents, &ev)) {
41 if (ev.type == EV_KEY) {
55 static void draw(const char *resname)
60 if (res_create_display_surface(resname, &surface) < 0) {
61 LOGE("failed to create surface for %s\n", resname);
65 w = gr_get_width(surface);
66 h = gr_get_height(surface);
67 x = (gr_fb_width() - w) / 2;
68 y = (gr_fb_height() - h) / 2;
70 gr_blit(surface, 0, 0, w, h, x, y);
73 res_free_surface(surface);
78 LOGE("usage: slideshow [-t timeout] image.png [image2.png ...] last.png\n");
82 int main(int argc, char **argv)
87 long int timeout = NEXT_TIMEOUT_MS;
90 while ((opt = getopt(argc, argv, "t")) != -1) {
93 timeout = strtol(optarg, NULL, 0);
95 if (timeout < 0 || timeout >= LONG_MAX) {
96 timeout = NEXT_TIMEOUT_MS;
97 LOGE("invalid timeout %s, defaulting to %ld\n", optarg,
106 if (optind >= argc) {
110 if (gr_init() == -1 || ev_init(input_cb, &key_code) == -1) {
111 LOGE("failed to initialize minui\n");
115 /* display all images except the last one, switch to next image after
116 * timeout or user input */
118 while (optind < argc - 1) {
119 draw(argv[optind++]);
121 if (ev_wait(timeout) == 0) {
124 if (key_code != -1) {
130 /* if there was user input while showing the images, display the last
131 * image and wait until the power button is pressed or LAST_TIMEOUT_S
139 if (ev_wait(timeout) == 0) {
143 if (time(NULL) - start >= LAST_TIMEOUT_S) {
146 } while (key_code != KEY_POWER);