aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-06-24 23:54:54 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-06-24 23:54:54 -0700
commitae22db5d707dd2728bbdf4d2f70d7d9285017024 (patch)
tree56f5fa0aec8e3a5d10ad582bc080658115f23a66
parent29510850182646a62d7969641edd8265a8cfc7ac (diff)
downloadmirror-meh-ae22db5d707dd2728bbdf4d2f70d7d9285017024.tar.gz
mirror-meh-ae22db5d707dd2728bbdf4d2f70d7d9285017024.tar.bz2
mirror-meh-ae22db5d707dd2728bbdf4d2f70d7d9285017024.zip
cleanup
-rw-r--r--src/main.c10
-rw-r--r--src/meh.h3
-rw-r--r--src/xlib.c66
3 files changed, 39 insertions, 40 deletions
diff --git a/src/main.c b/src/main.c
index 9a45508..c5ddd98 100644
--- a/src/main.c
+++ b/src/main.c
@@ -89,6 +89,7 @@ void run(){
const char *filename = direction();
int width = 0, height = 0;
struct image *img = NULL;
+ XImage *ximg = NULL;
int redraw = 0;
FILE *f = NULL;
@@ -106,6 +107,9 @@ void run(){
width = event.xconfigure.width;
height = event.xconfigure.height;
redraw = 1;
+ if(ximg)
+ XDestroyImage(ximg);
+ ximg = NULL;
/* Some window managers need reminding */
if(img)
@@ -138,6 +142,9 @@ void run(){
free(img->buf);
free(img);
}
+ if(ximg)
+ XDestroyImage(ximg);
+ ximg = NULL;
img = NULL;
redraw = 1;
break;
@@ -188,7 +195,8 @@ void run(){
}
continue; /* Allow for some events to be read, read is slow */
}
- drawimage(img, width, height);
+ ximg = getimage(img, width, height);
+ drawimage(ximg, width, height);
redraw = 0;
}
}
diff --git a/src/meh.h b/src/meh.h
index 46f4e0e..4190bb4 100644
--- a/src/meh.h
+++ b/src/meh.h
@@ -20,5 +20,6 @@ struct image{
XImage *ximage(struct image *img, unsigned int width, unsigned int height);
void setaspect(unsigned int w, unsigned int h);
void xinit();
-void drawimage(struct image *img, unsigned int width, unsigned int height);
+void drawimage(XImage *ximg, unsigned int width, unsigned int height);
+XImage *getimage(struct image *img, int width, int height);
diff --git a/src/xlib.c b/src/xlib.c
index 57a7581..5023cbd 100644
--- a/src/xlib.c
+++ b/src/xlib.c
@@ -86,53 +86,43 @@ XImage *ximage(struct image *img, unsigned int width, unsigned int height) {
}
-void drawimage(struct image *img, unsigned int width, unsigned int height){
- static struct image *lastimg = NULL;
- static int lastwidth = 0, lastheight = 0;
- static XImage *ximg = NULL;
- if(0 && img == lastimg && width == lastwidth && height == lastheight){
+XImage *getimage(struct image *img, int width, int height){
+ if(width * img->height > height * img->width){
+ return ximage(img, img->width * height / img->height, height);
}else{
- if(ximg)
- XDestroyImage(ximg);
- lastwidth = width;
- lastheight = height;
- lastimg = img;
- if(width * img->height > height * img->width){
- ximg = ximage(img, img->width * height / img->height, height);
- }else{
- ximg = ximage(img, width, img->height * width / img->width);
- }
+ return ximage(img, width, img->height * width / img->width);
}
- assert(ximg);
- {
- XRectangle rects[2];
- int yoffset, xoffset;
- xoffset = (width - ximg->width) / 2;
- yoffset = (height - ximg->height) / 2;
- if(xoffset || yoffset){
- rects[0].x = rects[0].y = 0;
- if(xoffset){
- rects[0].width = rects[1].width = xoffset;
- rects[0].height = rects[1].height = height;
- rects[1].x = width-xoffset;
- rects[1].y = 0;
- }else if(yoffset){
- rects[0].width = rects[1].width = width;
- rects[0].height = rects[1].height = yoffset;
- rects[1].x = 0;
- rects[1].y = height - yoffset;
- }
- XFillRectangles(display, window, gc, rects, 2);
+}
+
+void drawimage(XImage *ximg, unsigned int width, unsigned int height){
+ XRectangle rects[2];
+ int yoffset, xoffset;
+ xoffset = (width - ximg->width) / 2;
+ yoffset = (height - ximg->height) / 2;
+ if(xoffset || yoffset){
+ rects[0].x = rects[0].y = 0;
+ if(xoffset){
+ rects[0].width = rects[1].width = xoffset;
+ rects[0].height = rects[1].height = height;
+ rects[1].x = width-xoffset;
+ rects[1].y = 0;
+ }else if(yoffset){
+ rects[0].width = rects[1].width = width;
+ rects[0].height = rects[1].height = yoffset;
+ rects[1].x = 0;
+ rects[1].y = height - yoffset;
}
- XPutImage(display, window, gc, ximg, 0, 0, xoffset, yoffset, ximg->width, ximg->height);
- XFlush(display);
+ XFillRectangles(display, window, gc, rects, 2);
}
+ XPutImage(display, window, gc, ximg, 0, 0, xoffset, yoffset, ximg->width, ximg->height);
+ XFlush(display);
}
void setaspect(unsigned int w, unsigned int h){
XSizeHints *hints = XAllocSizeHints();
- hints->flags = PAspect;
+ //hints->flags = PAspect;
+ hints->flags = 0;
hints->min_aspect.x = hints->max_aspect.x = w;
hints->min_aspect.y = hints->max_aspect.y = h;
XSetWMNormalHints(display, window, hints);