No more expose handling

This commit is contained in:
Bert 2011-01-20 21:44:34 +01:00
parent 08018427c6
commit 029e1208b9
5 changed files with 47 additions and 43 deletions

41
image.c
View File

@ -31,7 +31,6 @@ void imlib_init(win_t *win) {
imlib_context_set_display(win->env.dpy);
imlib_context_set_visual(win->env.vis);
imlib_context_set_colormap(win->env.cmap);
imlib_context_set_drawable(win->xwin);
}
void imlib_destroy() {
@ -86,43 +85,43 @@ void img_display(img_t *img, win_t *win) {
img->x = (win->w - img->w * img->zoom) / 2;
img->y = (win->h - img->h * img->zoom) / 2;
win_clear(win);
img_render(img, win, 0, 0, win->w, win->h);
img_render(img, win);
}
void img_render(img_t *img, win_t *win, int x, int y, int w, int h) {
void img_render(img_t *img, win_t *win) {
int sx, sy, sw, sh;
int dx, dy, dw, dh;
if (!img || !win || !imlib_context_get_image())
return;
if (img->x < x) {
sx = (x - img->x) / img->zoom;
sw = MIN(w / img->zoom, img->w - sx);
dx = x;
dw = sw * img->zoom;
if (img->x < 0) {
sx = -img->x / img->zoom;
sw = win->w / img->zoom;
dx = 0;
dw = win->w;
} else {
sx = 0;
sw = MIN((w - img->x + x) / img->zoom, img->w);
sw = img->w;
dx = img->x;
dw = sw * img->zoom;
dw = img->w * img->zoom;
}
if (img->y < y) {
sy = (y - img->y) / img->zoom;
sh = MIN(h / img->zoom, img->h - sy);
dy = y;
dh = sh * img->zoom;
if (img->y < 0) {
sy = -img->y / img->zoom;
sh = win->h / img->zoom;
dy = 0;
dh = win->h;
} else {
sy = 0;
sh = MIN((h - img->y + y) / img->zoom, img->h);
sh = img->h;
dy = img->y;
dh = sh * img->zoom;
dh = img->h * img->zoom;
}
if (sw < 0 || sh < 0)
return;
win_clear(win);
imlib_context_set_drawable(win->pm);
imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
win_draw(win);
}

View File

@ -41,6 +41,6 @@ void imlib_destroy();
int img_load(img_t*, const char*);
void img_display(img_t*, win_t*);
void img_render(img_t*, win_t*, int, int, int, int);
void img_render(img_t*, win_t*);
#endif /* IMAGE_H */

14
main.c
View File

@ -29,14 +29,12 @@
void on_keypress(XEvent*);
void on_configurenotify(XEvent*);
void on_expose(XEvent*);
void update_title();
static void (*handler[LASTEvent])(XEvent*) = {
[Expose] = on_expose,
[ConfigureNotify] = on_configurenotify,
[KeyPress] = on_keypress
[KeyPress] = on_keypress,
[ConfigureNotify] = on_configurenotify
};
img_t img;
@ -154,14 +152,6 @@ void on_configurenotify(XEvent *ev) {
win_configure(&win, &ev->xconfigure);
}
void on_expose(XEvent *ev) {
if (!ev)
return;
img_render(&img, &win, ev->xexpose.x, ev->xexpose.y,
ev->xexpose.width, ev->xexpose.height);
}
void update_title() {
int n;

View File

@ -28,8 +28,7 @@ void win_open(win_t *win) {
win_env_t *e;
XClassHint *classhint;
XColor bgcol;
XSetWindowAttributes attr;
unsigned long mask;
XGCValues gcval;
if (!win)
return;
@ -58,19 +57,19 @@ void win_open(win_t *win) {
win->x = (e->scrw - win->w) / 2;
win->y = (e->scrh - win->h) / 2;
attr.backing_store = NotUseful;
attr.background_pixel = bgcol.pixel;
attr.save_under = False;
mask = CWBackingStore | CWBackPixel | CWSaveUnder;
win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
win->x, win->y, win->w, win->h, 0,
e->depth, InputOutput, e->vis, mask, &attr);
e->depth, InputOutput, e->vis, 0, None);
if (win->xwin == None)
DIE("could not create window");
XSelectInput(e->dpy, win->xwin,
StructureNotifyMask | ExposureMask | KeyPressMask);
StructureNotifyMask | KeyPressMask);
win->pm = 0;
gcval.foreground = bgcol.pixel;
win->bgc = XCreateGC(e->dpy, win->xwin, GCForeground, &gcval);
win_set_title(win, "sxiv");
@ -124,5 +123,17 @@ void win_clear(win_t *win) {
if (!win)
return;
if (win->pm)
XFreePixmap(win->env.dpy, win->pm);
win->pm = XCreatePixmap(win->env.dpy, win->xwin, win->w, win->h,
win->env.depth);
XFillRectangle(win->env.dpy, win->pm, win->bgc, 0, 0, win->w, win->h);
}
void win_draw(win_t *win) {
if (!win)
return;
XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm);
XClearWindow(win->env.dpy, win->xwin);
}

View File

@ -33,6 +33,8 @@ typedef struct win_env_s {
typedef struct win_s {
Window xwin;
win_env_t env;
Pixmap pm;
GC bgc;
int w;
int h;
@ -49,6 +51,8 @@ void win_close(win_t*);
void win_set_title(win_t*, const char*);
int win_configure(win_t*, XConfigureEvent*);
void win_clear(win_t*);
void win_draw(win_t*);
#endif /* WINDOW_H */