aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-05-22 12:00:22 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-05-22 12:00:22 -0700
commitc6bfd9c44048aa9a437db919bdef61509501f22a (patch)
tree2d1d283b501e6bb8bfdfa24759a7d5a6e52a2d76
parent72573e45e04541413fa50336a56ae8a88f8f0cb8 (diff)
downloadmirror-meh-c6bfd9c44048aa9a437db919bdef61509501f22a.tar.gz
mirror-meh-c6bfd9c44048aa9a437db919bdef61509501f22a.tar.bz2
mirror-meh-c6bfd9c44048aa9a437db919bdef61509501f22a.zip
basic error handling
-rw-r--r--src/main.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 8ee8367..d2bc5cb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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){