diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-05-22 12:00:22 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-05-22 12:00:22 -0700 |
commit | c6bfd9c44048aa9a437db919bdef61509501f22a (patch) | |
tree | 2d1d283b501e6bb8bfdfa24759a7d5a6e52a2d76 | |
parent | 72573e45e04541413fa50336a56ae8a88f8f0cb8 (diff) | |
download | mirror-meh-c6bfd9c44048aa9a437db919bdef61509501f22a.tar.gz mirror-meh-c6bfd9c44048aa9a437db919bdef61509501f22a.tar.bz2 mirror-meh-c6bfd9c44048aa9a437db919bdef61509501f22a.zip |
basic error handling
-rw-r--r-- | src/main.c | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -152,6 +152,7 @@ void init(){ void run(char *images[], int length){ int i = 0; + int direction = 0; int bufwidth = 0, bufheight = 0; int xoffset = 0, yoffset = 0; int imagewidth = 0, imageheight = 0; @@ -189,17 +190,9 @@ void run(char *images[], int length){ exit(0); break; case XK_t: - i = (i + 1) % length; - if(img) - free(img); - if(buf) - free(buf); - img = NULL; - buf = NULL; - redraw = 1; - break; case XK_n: - i = i ? i - 1 : length - 1; + direction = (XLookupKeysym(&event.xkey, 0) == XK_t) ? 1 : -1; + i += direction; if(img) free(img); if(buf) @@ -213,9 +206,15 @@ void run(char *images[], int length){ } } if(redraw){ - if(!buf){ + while(!buf){ + if(i > length) + i -= length; + if(i < 0) + i += length; buf = loadbuf(images[i], &bufwidth, &bufheight); - assert(buf); + if(!buf){ + i += direction; + } } if(!img){ if(width * bufheight > height * bufwidth){ |