Krolyxon
Commit 6a0fa25

Branches

Refs →

nsxivmain.c

821 lines · 17.3 KB · C

1/* Copyright 2011-2013 Bert Muennich
2 *
3 * This file is part of sxiv.
4 *
5 * sxiv is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License,
8 * or (at your option) any later version.
9 *
10 * sxiv is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#define _POSIX_C_SOURCE 200112L
20#define _MAPPINGS_CONFIG
21
22#include <stdlib.h>
23#include <stdio.h>
24#include <string.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include <errno.h>
28#include <signal.h>
29#include <sys/select.h>
30#include <sys/stat.h>
31#include <sys/time.h>
32#include <sys/wait.h>
33#include <X11/keysym.h>
34
35#include "types.h"
36#include "commands.h"
37#include "image.h"
38#include "options.h"
39#include "thumbs.h"
40#include "util.h"
41#include "window.h"
42#include "config.h"
43
44enum {
45 FILENAME_CNT = 1024,
46 TITLE_LEN = 256
47};
48
49#define EXEC_REL_DIR ".sxiv/exec"
50
51enum {
52 EXEC_INFO,
53 EXEC_KEY
54};
55
56typedef struct {
57 const char *name;
58 char *cmd;
59} exec_t;
60
61typedef struct {
62 struct timeval when;
63 bool active;
64 timeout_f handler;
65} timeout_t;
66
67/* timeout handler functions: */
68void redraw(void);
69void reset_cursor(void);
70void animate(void);
71void slideshow(void);
72void clear_resize(void);
73
74appmode_t mode;
75img_t img;
76tns_t tns;
77win_t win;
78
79fileinfo_t *files;
80int filecnt, fileidx;
81int alternate;
82
83int prefix;
84
85bool resized = false;
86
87exec_t exec[] = {
88 { "image-info", NULL },
89 { "key-handler", NULL }
90};
91
92struct {
93 char *cmd;
94 int fd;
95 unsigned int i, lastsep;
96 bool open;
97} info;
98
99timeout_t timeouts[] = {
100 { { 0, 0 }, false, redraw },
101 { { 0, 0 }, false, reset_cursor },
102 { { 0, 0 }, false, animate },
103 { { 0, 0 }, false, slideshow },
104 { { 0, 0 }, false, clear_resize },
105};
106
107void cleanup(void)
108{
109 static bool in = false;
110
111 if (!in) {
112 in = true;
113 img_close(&img, false);
114 tns_free(&tns);
115 win_close(&win);
116 }
117}
118
119void check_add_file(char *filename)
120{
121 const char *bn;
122
123 if (filename == NULL || *filename == '\0')
124 return;
125
126 if (access(filename, R_OK) < 0) {
127 warn("could not open file: %s", filename);
128 return;
129 }
130
131 if (fileidx == filecnt) {
132 filecnt *= 2;
133 files = (fileinfo_t*) s_realloc(files, filecnt * sizeof(fileinfo_t));
134 }
135 if (*filename != '/') {
136 files[fileidx].path = absolute_path(filename);
137 if (files[fileidx].path == NULL) {
138 warn("could not get absolute path of file: %s\n", filename);
139 return;
140 }
141 }
142 files[fileidx].loaded = false;
143 files[fileidx].name = s_strdup(filename);
144 if (*filename == '/')
145 files[fileidx].path = files[fileidx].name;
146 if ((bn = strrchr(files[fileidx].name , '/')) != NULL && bn[1] != '\0')
147 files[fileidx].base = ++bn;
148 else
149 files[fileidx].base = files[fileidx].name;
150 fileidx++;
151}
152
153void remove_file(int n, bool manual)
154{
155 if (n < 0 || n >= filecnt)
156 return;
157
158 if (filecnt == 1) {
159 if (!manual)
160 fprintf(stderr, "sxiv: no more files to display, aborting\n");
161 cleanup();
162 exit(manual ? EXIT_SUCCESS : EXIT_FAILURE);
163 }
164
165 if (files[n].path != files[n].name)
166 free((void*) files[n].path);
167 free((void*) files[n].name);
168
169 if (n + 1 < filecnt)
170 memmove(files + n, files + n + 1, (filecnt - n - 1) * sizeof(fileinfo_t));
171 if (n + 1 < tns.cnt) {
172 memmove(tns.thumbs + n, tns.thumbs + n + 1, (tns.cnt - n - 1) *
173 sizeof(thumb_t));
174 memset(tns.thumbs + tns.cnt - 1, 0, sizeof(thumb_t));
175 }
176
177 filecnt--;
178 if (n < tns.cnt)
179 tns.cnt--;
180 if (n < alternate)
181 alternate--;
182}
183
184void set_timeout(timeout_f handler, int time, bool overwrite)
185{
186 int i;
187
188 for (i = 0; i < ARRLEN(timeouts); i++) {
189 if (timeouts[i].handler == handler) {
190 if (!timeouts[i].active || overwrite) {
191 gettimeofday(&timeouts[i].when, 0);
192 TV_ADD_MSEC(&timeouts[i].when, time);
193 timeouts[i].active = true;
194 }
195 return;
196 }
197 }
198}
199
200void reset_timeout(timeout_f handler)
201{
202 int i;
203
204 for (i = 0; i < ARRLEN(timeouts); i++) {
205 if (timeouts[i].handler == handler) {
206 timeouts[i].active = false;
207 return;
208 }
209 }
210}
211
212bool check_timeouts(struct timeval *t)
213{
214 int i = 0, tdiff, tmin = -1;
215 struct timeval now;
216
217 while (i < ARRLEN(timeouts)) {
218 if (timeouts[i].active) {
219 gettimeofday(&now, 0);
220 tdiff = TV_DIFF(&timeouts[i].when, &now);
221 if (tdiff <= 0) {
222 timeouts[i].active = false;
223 if (timeouts[i].handler != NULL)
224 timeouts[i].handler();
225 i = tmin = -1;
226 } else if (tmin < 0 || tdiff < tmin) {
227 tmin = tdiff;
228 }
229 }
230 i++;
231 }
232 if (tmin > 0 && t != NULL)
233 TV_SET_MSEC(t, tmin);
234 return tmin > 0;
235}
236
237void open_info(void)
238{
239 static pid_t pid;
240 int pfd[2];
241
242 if (info.cmd == NULL || info.open || win.bar.h == 0)
243 return;
244 if (info.fd != -1) {
245 close(info.fd);
246 kill(pid, SIGTERM);
247 info.fd = -1;
248 }
249 win.bar.l[0] = '\0';
250
251 if (pipe(pfd) < 0)
252 return;
253 pid = fork();
254 if (pid > 0) {
255 close(pfd[1]);
256 fcntl(pfd[0], F_SETFL, O_NONBLOCK);
257 info.fd = pfd[0];
258 info.i = info.lastsep = 0;
259 info.open = true;
260 } else if (pid == 0) {
261 close(pfd[0]);
262 dup2(pfd[1], 1);
263 execl(info.cmd, info.cmd, files[fileidx].name, NULL);
264 warn("could not exec: %s", info.cmd);
265 exit(EXIT_FAILURE);
266 }
267}
268
269void read_info(void)
270{
271 ssize_t i, n;
272 char buf[BAR_L_LEN];
273
274 while (true) {
275 n = read(info.fd, buf, sizeof(buf));
276 if (n < 0 && errno == EAGAIN)
277 return;
278 else if (n == 0)
279 goto end;
280 for (i = 0; i < n; i++) {
281 if (buf[i] == '\n') {
282 if (info.lastsep == 0) {
283 win.bar.l[info.i++] = ' ';
284 info.lastsep = 1;
285 }
286 } else {
287 win.bar.l[info.i++] = buf[i];
288 info.lastsep = 0;
289 }
290 if (info.i + 1 == sizeof(win.bar.l))
291 goto end;
292 }
293 }
294end:
295 info.i -= info.lastsep;
296 win.bar.l[info.i] = '\0';
297 win_update_bar(&win);
298 close(info.fd);
299 info.fd = -1;
300 while (waitpid(-1, NULL, WNOHANG) > 0);
301}
302
303void load_image(int new)
304{
305 if (new < 0 || new >= filecnt)
306 return;
307
308 win_set_cursor(&win, CURSOR_WATCH);
309 reset_timeout(slideshow);
310
311 if (new != fileidx)
312 alternate = fileidx;
313
314 img_close(&img, false);
315 while (!img_load(&img, &files[new])) {
316 remove_file(new, false);
317 if (new >= filecnt)
318 new = filecnt - 1;
319 else if (new > 0 && new < fileidx)
320 new--;
321 }
322 files[new].loaded = true;
323 fileidx = new;
324
325 info.open = false;
326 open_info();
327
328 if (img.multi.cnt > 0 && img.multi.animate)
329 set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
330 else
331 reset_timeout(animate);
332}
333
334void update_info(void)
335{
336 int sel;
337 unsigned int i, fn, fw, n;
338 unsigned int llen = sizeof(win.bar.l), rlen = sizeof(win.bar.r);
339 char *lt = win.bar.l, *rt = win.bar.r, title[TITLE_LEN];
340 const char * mark;
341 bool ow_info;
342
343 for (fw = 0, i = filecnt; i > 0; fw++, i /= 10);
344 sel = mode == MODE_IMAGE ? fileidx : tns.sel;
345
346 /* update window title */
347 if (mode == MODE_THUMB) {
348 win_set_title(&win, "sxiv");
349 } else {
350 snprintf(title, sizeof(title), "sxiv - %s", files[sel].name);
351 win_set_title(&win, title);
352 }
353
354 /* update bar contents */
355 if (win.bar.h == 0)
356 return;
357 mark = files[sel].marked ? "* " : "";
358 if (mode == MODE_THUMB) {
359 if (tns.cnt == filecnt) {
360 n = snprintf(rt, rlen, "%s%0*d/%d", mark, fw, sel + 1, filecnt);
361 ow_info = true;
362 } else {
363 snprintf(lt, llen, "Loading... %0*d/%d", fw, tns.cnt, filecnt);
364 rt[0] = '\0';
365 ow_info = false;
366 }
367 } else {
368 n = snprintf(rt, rlen, "%s", mark);
369 if (img.ss.on)
370 n += snprintf(rt + n, rlen - n, "%ds | ", img.ss.delay);
371 if (img.gamma != 0)
372 n += snprintf(rt + n, rlen - n, "G%+d | ", img.gamma);
373 n += snprintf(rt + n, rlen - n, "%3d%% | ", (int) (img.zoom * 100.0));
374 if (img.multi.cnt > 0) {
375 for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10);
376 n += snprintf(rt + n, rlen - n, "%0*d/%d | ",
377 fn, img.multi.sel + 1, img.multi.cnt);
378 }
379 n += snprintf(rt + n, rlen - n, "%0*d/%d", fw, sel + 1, filecnt);
380 ow_info = info.cmd == NULL;
381 }
382 if (ow_info) {
383 fn = strlen(files[sel].name);
384 if (fn < llen &&
385 win_textwidth(files[sel].name, fn, true) +
386 win_textwidth(rt, n, true) < win.w)
387 {
388 strncpy(lt, files[sel].name, llen);
389 } else {
390 strncpy(lt, files[sel].base, llen);
391 }
392 }
393}
394
395void redraw(void)
396{
397 int t;
398
399 if (mode == MODE_IMAGE) {
400 img_render(&img);
401 if (img.ss.on) {
402 t = img.ss.delay * 1000;
403 t = img.multi.animate ? MAX(t, img.multi.length) : t;
404 set_timeout(slideshow, t, false);
405 }
406 } else {
407 tns_render(&tns);
408 }
409 update_info();
410 win_draw(&win);
411 reset_timeout(redraw);
412 reset_cursor();
413}
414
415void reset_cursor(void)
416{
417 int i;
418 cursor_t cursor = CURSOR_NONE;
419
420 if (mode == MODE_IMAGE) {
421 for (i = 0; i < ARRLEN(timeouts); i++) {
422 if (timeouts[i].handler == reset_cursor) {
423 if (timeouts[i].active)
424 cursor = CURSOR_ARROW;
425 break;
426 }
427 }
428 } else {
429 if (tns.cnt != filecnt)
430 cursor = CURSOR_WATCH;
431 else
432 cursor = CURSOR_ARROW;
433 }
434 win_set_cursor(&win, cursor);
435}
436
437void animate(void)
438{
439 if (img_frame_animate(&img, false)) {
440 redraw();
441 set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
442 }
443}
444
445void slideshow(void)
446{
447 load_image(fileidx + 1 < filecnt ? fileidx + 1 : 0);
448 redraw();
449}
450
451void clear_resize(void)
452{
453 resized = false;
454}
455
456void key_handler(const char *key, unsigned int mask)
457{
458 pid_t pid;
459 int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
460 char *cmd = exec[EXEC_KEY].cmd, kstr[32];
461
462 if (cmd == NULL || key == NULL)
463 return;
464
465 snprintf(kstr, sizeof(kstr), "%s%s%s%s",
466 mask & ControlMask ? "C-" : "",
467 mask & Mod1Mask ? "M-" : "",
468 mask & ShiftMask ? "S-" : "", key);
469
470 if ((pid = fork()) == 0) {
471 execl(cmd, cmd, kstr, files[n].path, NULL);
472 warn("could not exec key handler");
473 exit(EXIT_FAILURE);
474 } else if (pid < 0) {
475 warn("could not fork key handler");
476 return;
477 }
478 win_set_cursor(&win, CURSOR_WATCH);
479
480 waitpid(pid, &status, 0);
481 retval = WEXITSTATUS(status);
482 if (WIFEXITED(status) == 0 || retval != 0)
483 warn("key handler exited with non-zero return value: %d", retval);
484 if (mode == MODE_IMAGE) {
485 img_close(&img, true);
486 load_image(fileidx);
487 }
488 if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) &&
489 mode == MODE_THUMB)
490 {
491 remove_file(tns.sel, false);
492 tns.dirty = true;
493 if (tns.sel >= tns.cnt)
494 tns.sel = tns.cnt - 1;
495 }
496 redraw();
497}
498
499#define MODMASK(mask) ((mask) & (ShiftMask|ControlMask|Mod1Mask))
500
501void on_keypress(XKeyEvent *kev)
502{
503 int i;
504 unsigned int sh;
505 KeySym ksym, shksym;
506 char key;
507
508 if (kev == NULL)
509 return;
510
511 if (kev->state & ShiftMask) {
512 kev->state &= ~ShiftMask;
513 XLookupString(kev, &key, 1, &shksym, NULL);
514 kev->state |= ShiftMask;
515 }
516 XLookupString(kev, &key, 1, &ksym, NULL);
517 sh = (kev->state & ShiftMask) && ksym != shksym ? ShiftMask : 0;
518
519 if (IsModifierKey(ksym))
520 return;
521
522 if ((ksym == XK_Escape && MODMASK(kev->state) == 0) ||
523 (key >= '0' && key <= '9'))
524 {
525 /* number prefix for commands */
526 prefix = ksym == XK_Escape ? 0 : prefix * 10 + (int) (key - '0');
527 return;
528 }
529
530 for (i = 0; i < ARRLEN(keys); i++) {
531 if (keys[i].ksym == ksym &&
532 MODMASK(keys[i].mask | sh) == MODMASK(kev->state))
533 {
534 if (keys[i].cmd != NULL && keys[i].cmd(keys[i].arg))
535 redraw();
536 prefix = 0;
537 return;
538 }
539 }
540 key_handler(XKeysymToString(ksym), kev->state & ~sh);
541}
542
543void on_buttonpress(XButtonEvent *bev)
544{
545 int i, sel;
546
547 if (bev == NULL)
548 return;
549
550 if (mode == MODE_IMAGE) {
551 win_set_cursor(&win, CURSOR_ARROW);
552 set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
553
554 for (i = 0; i < ARRLEN(buttons); i++) {
555 if (buttons[i].button == bev->button &&
556 MODMASK(buttons[i].mask) == MODMASK(bev->state))
557 {
558 if (buttons[i].cmd != NULL && buttons[i].cmd(buttons[i].arg))
559 redraw();
560 return;
561 }
562 }
563 } else {
564 /* thumbnail mode (hard-coded) */
565 switch (bev->button) {
566 case Button1:
567 if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
568 if (sel == tns.sel) {
569 mode = MODE_IMAGE;
570 set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
571 load_image(tns.sel);
572 } else {
573 tns_highlight(&tns, tns.sel, false);
574 tns_highlight(&tns, sel, true);
575 tns.sel = sel;
576 }
577 redraw();
578 break;
579 }
580 break;
581 case Button3:
582 if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
583 files[sel].marked = !files[sel].marked;
584 tns_mark(&tns, sel, files[sel].marked);
585 redraw();
586 }
587 break;
588 case Button4:
589 case Button5:
590 if (tns_scroll(&tns, bev->button == Button4 ? DIR_UP : DIR_DOWN,
591 (bev->state & ControlMask) != 0))
592 redraw();
593 break;
594 }
595 }
596}
597
598void run(void)
599{
600 int xfd;
601 fd_set fds;
602 struct timeval timeout;
603 bool discard, to_set;
604 XEvent ev, nextev;
605
606 redraw();
607
608 while (true) {
609 while (mode == MODE_THUMB && tns.cnt < filecnt &&
610 XPending(win.env.dpy) == 0)
611 {
612 /* load thumbnails */
613 set_timeout(redraw, TO_REDRAW_THUMBS, false);
614 if (tns_load(&tns, tns.cnt, &files[tns.cnt], false, false)) {
615 tns.cnt++;
616 } else {
617 remove_file(tns.cnt, false);
618 if (tns.sel > 0 && tns.sel >= tns.cnt)
619 tns.sel--;
620 }
621 if (tns.cnt == filecnt)
622 redraw();
623 else
624 check_timeouts(NULL);
625 }
626
627 while (XPending(win.env.dpy) == 0
628 && ((to_set = check_timeouts(&timeout)) || info.fd != -1))
629 {
630 /* check for timeouts & input */
631 xfd = ConnectionNumber(win.env.dpy);
632 FD_ZERO(&fds);
633 FD_SET(xfd, &fds);
634 if (info.fd != -1) {
635 FD_SET(info.fd, &fds);
636 xfd = MAX(xfd, info.fd);
637 }
638 select(xfd + 1, &fds, 0, 0, to_set ? &timeout : NULL);
639 if (info.fd != -1 && FD_ISSET(info.fd, &fds))
640 read_info();
641 }
642
643 do {
644 XNextEvent(win.env.dpy, &ev);
645 discard = false;
646 if (XEventsQueued(win.env.dpy, QueuedAlready) > 0) {
647 XPeekEvent(win.env.dpy, &nextev);
648 switch (ev.type) {
649 case ConfigureNotify:
650 discard = ev.type == nextev.type;
651 break;
652 case KeyPress:
653 discard = (nextev.type == KeyPress || nextev.type == KeyRelease)
654 && ev.xkey.keycode == nextev.xkey.keycode;
655 break;
656 }
657 }
658 } while (discard);
659
660 switch (ev.type) {
661 /* handle events */
662 case ButtonPress:
663 on_buttonpress(&ev.xbutton);
664 break;
665 case ClientMessage:
666 if ((Atom) ev.xclient.data.l[0] == wm_delete_win)
667 return;
668 break;
669 case ConfigureNotify:
670 if (win_configure(&win, &ev.xconfigure)) {
671 if (mode == MODE_IMAGE) {
672 img.dirty = true;
673 img.checkpan = true;
674 } else {
675 tns.dirty = true;
676 }
677 if (!resized || win.fullscreen) {
678 redraw();
679 set_timeout(clear_resize, TO_REDRAW_RESIZE, false);
680 resized = true;
681 } else {
682 set_timeout(redraw, TO_REDRAW_RESIZE, false);
683 }
684 }
685 break;
686 case Expose:
687 win_expose(&win, &ev.xexpose);
688 break;
689 case KeyPress:
690 on_keypress(&ev.xkey);
691 break;
692 case MotionNotify:
693 if (mode == MODE_IMAGE) {
694 win_set_cursor(&win, CURSOR_ARROW);
695 set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
696 }
697 break;
698 }
699 }
700}
701
702int fncmp(const void *a, const void *b)
703{
704 return strcoll(((fileinfo_t*) a)->name, ((fileinfo_t*) b)->name);
705}
706
707int main(int argc, char **argv)
708{
709 int i, start;
710 size_t n;
711 ssize_t len;
712 char *filename;
713 const char *homedir;
714 struct stat fstats;
715 r_dir_t dir;
716
717 parse_options(argc, argv);
718
719 if (options->clean_cache) {
720 tns_init(&tns, 0, NULL);
721 tns_clean_cache(&tns);
722 exit(EXIT_SUCCESS);
723 }
724
725 if (options->filecnt == 0 && !options->from_stdin) {
726 print_usage();
727 exit(EXIT_FAILURE);
728 }
729
730 if (options->recursive || options->from_stdin)
731 filecnt = FILENAME_CNT;
732 else
733 filecnt = options->filecnt;
734
735 files = (fileinfo_t*) s_malloc(filecnt * sizeof(fileinfo_t));
736 fileidx = 0;
737
738 if (options->from_stdin) {
739 filename = NULL;
740 while ((len = get_line(&filename, &n, stdin)) > 0) {
741 if (filename[len-1] == '\n')
742 filename[len-1] = '\0';
743 check_add_file(filename);
744 }
745 if (filename != NULL)
746 free(filename);
747 }
748
749 for (i = 0; i < options->filecnt; i++) {
750 filename = options->filenames[i];
751
752 if (stat(filename, &fstats) < 0) {
753 warn("could not stat file: %s", filename);
754 continue;
755 }
756 if (!S_ISDIR(fstats.st_mode)) {
757 check_add_file(filename);
758 } else {
759 if (!options->recursive) {
760 warn("ignoring directory: %s", filename);
761 continue;
762 }
763 if (r_opendir(&dir, filename) < 0) {
764 warn("could not open directory: %s", filename);
765 continue;
766 }
767 start = fileidx;
768 while ((filename = r_readdir(&dir)) != NULL) {
769 check_add_file(filename);
770 free((void*) filename);
771 }
772 r_closedir(&dir);
773 if (fileidx - start > 1)
774 qsort(files + start, fileidx - start, sizeof(fileinfo_t), fncmp);
775 }
776 }
777
778 if (fileidx == 0) {
779 fprintf(stderr, "sxiv: no valid image file given, aborting\n");
780 exit(EXIT_FAILURE);
781 }
782
783 filecnt = fileidx;
784 fileidx = options->startnum < filecnt ? options->startnum : 0;
785
786 win_init(&win);
787 img_init(&img, &win);
788
789 if ((homedir = getenv("HOME")) == NULL) {
790 warn("could not locate home directory");
791 } else for (i = 0; i < ARRLEN(exec); i++) {
792 len = strlen(homedir) + strlen(EXEC_REL_DIR) + strlen(exec[i].name) + 3;
793 exec[i].cmd = (char*) s_malloc(len);
794 snprintf(exec[i].cmd, len, "%s/%s/%s", homedir, EXEC_REL_DIR, exec[i].name);
795 if (access(exec[i].cmd, X_OK) != 0) {
796 free(exec[i].cmd);
797 exec[i].cmd = NULL;
798 }
799 }
800 info.fd = -1;
801 info.cmd = exec[EXEC_INFO].cmd;
802
803 if (options->thumb_mode) {
804 mode = MODE_THUMB;
805 tns_init(&tns, filecnt, &win);
806 while (!tns_load(&tns, 0, &files[0], false, false))
807 remove_file(0, false);
808 tns.cnt = 1;
809 } else {
810 mode = MODE_IMAGE;
811 tns.thumbs = NULL;
812 load_image(fileidx);
813 }
814
815 win_open(&win);
816
817 run();
818 cleanup();
819
820 return 0;
821}