aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--thumbs.c37
-rw-r--r--thumbs.h4
-rw-r--r--window.c29
-rw-r--r--window.h6
5 files changed, 32 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index 0afa901..8ad92c1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
all: sxiv
-VERSION=git-20110310
+VERSION=git-20110315
CC?=gcc
PREFIX?=/usr/local
diff --git a/thumbs.c b/thumbs.c
index 4669967..7af1753 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -19,8 +19,6 @@
#include <stdlib.h>
#include <string.h>
-#include <Imlib2.h>
-
#include "config.h"
#include "thumbs.h"
#include "util.h"
@@ -45,8 +43,12 @@ void tns_free(tns_t *tns, win_t *win) {
if (!tns || !tns->thumbs)
return;
- for (i = 0; i < tns->cnt; ++i)
- win_free_pixmap(win, tns->thumbs[i].pm);
+ for (i = 0; i < tns->cnt; ++i) {
+ if (tns->thumbs[i].im) {
+ imlib_context_set_image(tns->thumbs[i].im);
+ imlib_free_image();
+ }
+ }
free(tns->thumbs);
tns->thumbs = NULL;
@@ -66,6 +68,13 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
else if (n >= tns->cnt)
tns->cnt = n + 1;
+ t = &tns->thumbs[n];
+
+ if (t->im) {
+ imlib_context_set_image(t->im);
+ imlib_free_image();
+ }
+
if ((im = imlib_load_image(filename)))
imlib_context_set_image(im);
else
@@ -79,23 +88,16 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
if (!im && z > 1.0)
z = 1.0;
- t = &tns->thumbs[n];
t->w = z * w;
t->h = z * h;
- if (t->pm)
- win_free_pixmap(win, t->pm);
- t->pm = win_create_pixmap(win, t->w, t->h);
- imlib_context_set_drawable(t->pm);
imlib_context_set_anti_alias(1);
- if (imlib_image_has_alpha())
- win_draw_rect(win, t->pm, 0, 0, t->w, t->h, True, 0, win->white);
- imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
- 0, 0, t->w, t->h);
- tns->dirty = 1;
-
+ if (!(t->im = imlib_create_cropped_scaled_image(0, 0, w, h, t->w, t->h)))
+ die("could not allocate memory");
if (im)
imlib_free_image_and_decache();
+
+ tns->dirty = 1;
}
void tns_check_view(tns_t *tns, Bool scrolled) {
@@ -133,6 +135,7 @@ void tns_render(tns_t *tns, win_t *win) {
return;
win_clear(win);
+ imlib_context_set_drawable(win->pm);
tns->cols = MAX(1, win->w / thumb_dim);
tns->rows = MAX(1, win->h / thumb_dim);
@@ -157,7 +160,9 @@ void tns_render(tns_t *tns, win_t *win) {
t = &tns->thumbs[tns->first + i];
t->x = x + (THUMB_SIZE - t->w) / 2;
t->y = y + (THUMB_SIZE - t->h) / 2;
- win_draw_pixmap(win, t->pm, t->x, t->y, t->w, t->h);
+ imlib_context_set_image(t->im);
+ imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
+ t->x, t->y, t->w, t->h);
if ((i + 1) % tns->cols == 0) {
x = tns->x;
y += thumb_dim;
diff --git a/thumbs.h b/thumbs.h
index af9c239..4b428d7 100644
--- a/thumbs.h
+++ b/thumbs.h
@@ -19,6 +19,8 @@
#ifndef THUMBS_H
#define THUMBS_H
+#include <Imlib2.h>
+
#include "window.h"
typedef enum {
@@ -29,7 +31,7 @@ typedef enum {
} tnsdir_t;
typedef struct {
- Pixmap pm;
+ Imlib_Image *im;
int x;
int y;
int w;
diff --git a/window.c b/window.c
index 75eac60..7e29176 100644
--- a/window.c
+++ b/window.c
@@ -232,18 +232,6 @@ void win_toggle_fullscreen(win_t *win) {
SubstructureNotifyMask, &ev);
}
-Pixmap win_create_pixmap(win_t *win, int w, int h) {
- if (!win)
- return 0;
-
- return XCreatePixmap(win->env.dpy, win->xwin, w, h, win->env.depth);
-}
-
-void win_free_pixmap(win_t *win, Pixmap pm) {
- if (win && pm)
- XFreePixmap(win->env.dpy, pm);
-}
-
void win_clear(win_t *win) {
win_env_t *e;
XGCValues gcval;
@@ -262,9 +250,12 @@ void win_clear(win_t *win) {
XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh);
}
-void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
- if (win)
- XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y);
+void win_draw(win_t *win) {
+ if (!win)
+ return;
+
+ XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm);
+ XClearWindow(win->env.dpy, win->xwin);
}
void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
@@ -284,14 +275,6 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h);
}
-void win_draw(win_t *win) {
- if (!win)
- return;
-
- XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm);
- XClearWindow(win->env.dpy, win->xwin);
-}
-
void win_set_title(win_t *win, const char *title) {
if (!win)
return;
diff --git a/window.h b/window.h
index 4848395..b4b23c3 100644
--- a/window.h
+++ b/window.h
@@ -68,14 +68,10 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
void win_toggle_fullscreen(win_t*);
-Pixmap win_create_pixmap(win_t*, int, int);
-void win_free_pixmap(win_t*, Pixmap);
-
void win_clear(win_t*);
-void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
+void win_draw(win_t*);
void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int,
unsigned long);
-void win_draw(win_t*);
void win_set_title(win_t*, const char*);
void win_set_cursor(win_t*, win_cur_t);