nsxiv029e120
No more expose handling
+47 −43
5 files changed
| @@ -31,7 +31,6 @@ void imlib_init(win_t *win) { | |||
| 31 | 31 | imlib_context_set_display(win->env.dpy); | |
| 32 | 32 | imlib_context_set_visual(win->env.vis); | |
| 33 | 33 | imlib_context_set_colormap(win->env.cmap); | |
| 34 | − | imlib_context_set_drawable(win->xwin); | |
| 35 | 34 | } | |
| 36 | 35 | ||
| 37 | 36 | void imlib_destroy() { | |
| @@ -86,43 +85,43 @@ void img_display(img_t *img, win_t *win) { | |||
| 86 | 85 | img->x = (win->w - img->w * img->zoom) / 2; | |
| 87 | 86 | img->y = (win->h - img->h * img->zoom) / 2; | |
| 88 | 87 | ||
| 89 | − | win_clear(win); | |
| 90 | − | ||
| 91 | − | img_render(img, win, 0, 0, win->w, win->h); | |
| 88 | + | img_render(img, win); | |
| 92 | 89 | } | |
| 93 | 90 | ||
| 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) { | |
| 95 | 92 | int sx, sy, sw, sh; | |
| 96 | 93 | int dx, dy, dw, dh; | |
| 97 | 94 | ||
| 98 | 95 | if (!img || !win || !imlib_context_get_image()) | |
| 99 | 96 | return; | |
| 100 | 97 | ||
| 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; | |
| 106 | 103 | } else { | |
| 107 | 104 | sx = 0; | |
| 108 | − | sw = MIN((w - img->x + x) / img->zoom, img->w); | |
| 105 | + | sw = img->w; | |
| 109 | 106 | dx = img->x; | |
| 110 | − | dw = sw * img->zoom; | |
| 107 | + | dw = img->w * img->zoom; | |
| 111 | 108 | } | |
| 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; | |
| 117 | 114 | } else { | |
| 118 | 115 | sy = 0; | |
| 119 | − | sh = MIN((h - img->y + y) / img->zoom, img->h); | |
| 116 | + | sh = img->h; | |
| 120 | 117 | dy = img->y; | |
| 121 | − | dh = sh * img->zoom; | |
| 118 | + | dh = img->h * img->zoom; | |
| 122 | 119 | } | |
| 123 | 120 | ||
| 124 | − | if (sw < 0 || sh < 0) | |
| 125 | − | return; | |
| 121 | + | win_clear(win); | |
| 126 | 122 | ||
| 123 | + | imlib_context_set_drawable(win->pm); | |
| 127 | 124 | imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw, dh); | |
| 125 | + | ||
| 126 | + | win_draw(win); | |
| 128 | 127 | } | |
| @@ -41,6 +41,6 @@ void imlib_destroy(); | |||
| 41 | 41 | ||
| 42 | 42 | int img_load(img_t*, const char*); | |
| 43 | 43 | 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*); | |
| 45 | 45 | ||
| 46 | 46 | #endif /* IMAGE_H */ | |
| @@ -29,14 +29,12 @@ | |||
| 29 | 29 | ||
| 30 | 30 | void on_keypress(XEvent*); | |
| 31 | 31 | void on_configurenotify(XEvent*); | |
| 32 | − | void on_expose(XEvent*); | |
| 33 | 32 | ||
| 34 | 33 | void update_title(); | |
| 35 | 34 | ||
| 36 | 35 | 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 | |
| 40 | 38 | }; | |
| 41 | 39 | ||
| 42 | 40 | img_t img; | |
| @@ -154,14 +152,6 @@ void on_configurenotify(XEvent *ev) { | |||
| 154 | 152 | win_configure(&win, &ev->xconfigure); | |
| 155 | 153 | } | |
| 156 | 154 | ||
| 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 | − | ||
| 165 | 155 | void update_title() { | |
| 166 | 156 | int n; | |
| 167 | 157 | ||
| @@ -28,8 +28,7 @@ void win_open(win_t *win) { | |||
| 28 | 28 | win_env_t *e; | |
| 29 | 29 | XClassHint *classhint; | |
| 30 | 30 | XColor bgcol; | |
| 31 | − | XSetWindowAttributes attr; | |
| 32 | − | unsigned long mask; | |
| 31 | + | XGCValues gcval; | |
| 33 | 32 | ||
| 34 | 33 | if (!win) | |
| 35 | 34 | return; | |
| @@ -58,19 +57,19 @@ void win_open(win_t *win) { | |||
| 58 | 57 | win->x = (e->scrw - win->w) / 2; | |
| 59 | 58 | win->y = (e->scrh - win->h) / 2; | |
| 60 | 59 | ||
| 61 | − | attr.backing_store = NotUseful; | |
| 62 | − | attr.background_pixel = bgcol.pixel; | |
| 63 | − | attr.save_under = False; | |
| 64 | − | mask = CWBackingStore | CWBackPixel | CWSaveUnder; | |
| 65 | − | ||
| 66 | 60 | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), | |
| 67 | 61 | 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); | |
| 69 | 63 | if (win->xwin == None) | |
| 70 | 64 | DIE("could not create window"); | |
| 71 | 65 | ||
| 72 | 66 | 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); | |
| 74 | 73 | ||
| 75 | 74 | win_set_title(win, "sxiv"); | |
| 76 | 75 | ||
| @@ -124,5 +123,17 @@ void win_clear(win_t *win) { | |||
| 124 | 123 | if (!win) | |
| 125 | 124 | return; | |
| 126 | 125 | ||
| 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); | |
| 127 | 138 | XClearWindow(win->env.dpy, win->xwin); | |
| 128 | 139 | } | |
| @@ -33,6 +33,8 @@ typedef struct win_env_s { | |||
| 33 | 33 | typedef struct win_s { | |
| 34 | 34 | Window xwin; | |
| 35 | 35 | win_env_t env; | |
| 36 | + | Pixmap pm; | |
| 37 | + | GC bgc; | |
| 36 | 38 | ||
| 37 | 39 | int w; | |
| 38 | 40 | int h; | |
| @@ -49,6 +51,8 @@ void win_close(win_t*); | |||
| 49 | 51 | void win_set_title(win_t*, const char*); | |
| 50 | 52 | ||
| 51 | 53 | int win_configure(win_t*, XConfigureEvent*); | |
| 54 | + | ||
| 52 | 55 | void win_clear(win_t*); | |
| 56 | + | void win_draw(win_t*); | |
| 53 | 57 | ||
| 54 | 58 | #endif /* WINDOW_H */ | |