Krolyxon
Commit 029e120

Branches

Refs →

nsxiv029e120

No more expose handling

Author
Bert
Date
2011-01-20 21:44 +0100
Parent
0801842
Commit
029e1208b91250f4bd91ecc2015d051294fb9d3f

+47 −43

5 files changed

  1. M image.c +20 −21
  2. M image.h +1 −1
  3. M main.c +2 −12
  4. M window.c +20 −9
  5. M window.h +4 −0
M image.c View
@@ -31,7 +31,6 @@ void imlib_init(win_t *win) {
3131 imlib_context_set_display(win->env.dpy);
3232 imlib_context_set_visual(win->env.vis);
3333 imlib_context_set_colormap(win->env.cmap);
34− imlib_context_set_drawable(win->xwin);
3534 }
3635
3736 void imlib_destroy() {
@@ -86,43 +85,43 @@ void img_display(img_t *img, win_t *win) {
8685 img->x = (win->w - img->w * img->zoom) / 2;
8786 img->y = (win->h - img->h * img->zoom) / 2;
8887
89− win_clear(win);
90−
91− img_render(img, win, 0, 0, win->w, win->h);
88+ img_render(img, win);
9289 }
9390
94−void img_render(img_t *img, win_t *win, int x, int y, int w, int h) {
91+void img_render(img_t *img, win_t *win) {
9592 int sx, sy, sw, sh;
9693 int dx, dy, dw, dh;
9794
9895 if (!img || !win || !imlib_context_get_image())
9996 return;
10097
101− if (img->x < x) {
102− sx = (x - img->x) / img->zoom;
103− sw = MIN(w / img->zoom, img->w - sx);
104− dx = x;
105− dw = sw * img->zoom;
98+ if (img->x < 0) {
99+ sx = -img->x / img->zoom;
100+ sw = win->w / img->zoom;
101+ dx = 0;
102+ dw = win->w;
106103 } else {
107104 sx = 0;
108− sw = MIN((w - img->x + x) / img->zoom, img->w);
105+ sw = img->w;
109106 dx = img->x;
110− dw = sw * img->zoom;
107+ dw = img->w * img->zoom;
111108 }
112− if (img->y < y) {
113− sy = (y - img->y) / img->zoom;
114− sh = MIN(h / img->zoom, img->h - sy);
115− dy = y;
116− dh = sh * img->zoom;
109+ if (img->y < 0) {
110+ sy = -img->y / img->zoom;
111+ sh = win->h / img->zoom;
112+ dy = 0;
113+ dh = win->h;
117114 } else {
118115 sy = 0;
119− sh = MIN((h - img->y + y) / img->zoom, img->h);
116+ sh = img->h;
120117 dy = img->y;
121− dh = sh * img->zoom;
118+ dh = img->h * img->zoom;
122119 }
123120
124− if (sw < 0 || sh < 0)
125− return;
121+ win_clear(win);
126122
123+ imlib_context_set_drawable(win->pm);
127124 imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh);
125+
126+ win_draw(win);
128127 }
M image.h View
@@ -41,6 +41,6 @@ void imlib_destroy();
4141
4242 int img_load(img_t*, const char*);
4343 void img_display(img_t*, win_t*);
44−void img_render(img_t*, win_t*, int, int, int, int);
44+void img_render(img_t*, win_t*);
4545
4646 #endif /* IMAGE_H */
M main.c View
@@ -29,14 +29,12 @@
2929
3030 void on_keypress(XEvent*);
3131 void on_configurenotify(XEvent*);
32−void on_expose(XEvent*);
3332
3433 void update_title();
3534
3635 static void (*handler[LASTEvent])(XEvent*) = {
37− [Expose] = on_expose,
38− [ConfigureNotify] = on_configurenotify,
39− [KeyPress] = on_keypress
36+ [KeyPress] = on_keypress,
37+ [ConfigureNotify] = on_configurenotify
4038 };
4139
4240 img_t img;
@@ -154,14 +152,6 @@ void on_configurenotify(XEvent *ev) {
154152 win_configure(&win, &ev->xconfigure);
155153 }
156154
157−void on_expose(XEvent *ev) {
158− if (!ev)
159− return;
160−
161− img_render(&img, &win, ev->xexpose.x, ev->xexpose.y,
162− ev->xexpose.width, ev->xexpose.height);
163−}
164−
165155 void update_title() {
166156 int n;
167157
M window.c View
@@ -28,8 +28,7 @@ void win_open(win_t *win) {
2828 win_env_t *e;
2929 XClassHint *classhint;
3030 XColor bgcol;
31− XSetWindowAttributes attr;
32− unsigned long mask;
31+ XGCValues gcval;
3332
3433 if (!win)
3534 return;
@@ -58,19 +57,19 @@ void win_open(win_t *win) {
5857 win->x = (e->scrw - win->w) / 2;
5958 win->y = (e->scrh - win->h) / 2;
6059
61− attr.backing_store = NotUseful;
62− attr.background_pixel = bgcol.pixel;
63− attr.save_under = False;
64− mask = CWBackingStore | CWBackPixel | CWSaveUnder;
65−
6660 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
6761 win->x, win->y, win->w, win->h, 0,
68− e->depth, InputOutput, e->vis, mask, &attr);
62+ e->depth, InputOutput, e->vis, 0, None);
6963 if (win->xwin == None)
7064 DIE("could not create window");
7165
7266 XSelectInput(e->dpy, win->xwin,
73− StructureNotifyMask | ExposureMask | KeyPressMask);
67+ StructureNotifyMask | KeyPressMask);
68+
69+ win->pm = 0;
70+
71+ gcval.foreground = bgcol.pixel;
72+ win->bgc = XCreateGC(e->dpy, win->xwin, GCForeground, &gcval);
7473
7574 win_set_title(win, "sxiv");
7675
@@ -124,5 +123,17 @@ void win_clear(win_t *win) {
124123 if (!win)
125124 return;
126125
126+ if (win->pm)
127+ XFreePixmap(win->env.dpy, win->pm);
128+ win->pm = XCreatePixmap(win->env.dpy, win->xwin, win->w, win->h,
129+ win->env.depth);
130+ XFillRectangle(win->env.dpy, win->pm, win->bgc, 0, 0, win->w, win->h);
131+}
132+
133+void win_draw(win_t *win) {
134+ if (!win)
135+ return;
136+
137+ XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm);
127138 XClearWindow(win->env.dpy, win->xwin);
128139 }
M window.h View
@@ -33,6 +33,8 @@ typedef struct win_env_s {
3333 typedef struct win_s {
3434 Window xwin;
3535 win_env_t env;
36+ Pixmap pm;
37+ GC bgc;
3638
3739 int w;
3840 int h;
@@ -49,6 +51,8 @@ void win_close(win_t*);
4951 void win_set_title(win_t*, const char*);
5052
5153 int win_configure(win_t*, XConfigureEvent*);
54+
5255 void win_clear(win_t*);
56+void win_draw(win_t*);
5357
5458 #endif /* WINDOW_H */