nsxiv603e664
Nicer fit window to image
+18 −11
4 files changed
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | all: sxiv | |
| 2 | 2 | ||
| 3 | − | VERSION=git-20110204 | |
| 3 | + | VERSION=git-20110206 | |
| 4 | 4 | ||
| 5 | 5 | CC?=gcc | |
| 6 | 6 | PREFIX?=/usr/local | |
| @@ -222,6 +222,8 @@ unsigned char timeout; | |||
| 222 | 222 | int mox, moy; | |
| 223 | 223 | ||
| 224 | 224 | void on_keypress(XKeyEvent *kev) { | |
| 225 | + | int x, y; | |
| 226 | + | unsigned int w, h; | |
| 225 | 227 | char key; | |
| 226 | 228 | KeySym ksym; | |
| 227 | 229 | int changed; | |
| @@ -330,8 +332,14 @@ void on_keypress(XKeyEvent *kev) { | |||
| 330 | 332 | /* render on next configurenotify */ | |
| 331 | 333 | break; | |
| 332 | 334 | case XK_W: | |
| 333 | − | if ((changed = win_resize(&win, img.w * img.zoom, img.h * img.zoom))) | |
| 334 | − | img.checkpan = 1; | |
| 335 | + | x = win.x + img.x; | |
| 336 | + | y = win.y + img.y; | |
| 337 | + | w = img.w * img.zoom; | |
| 338 | + | h = img.h * img.zoom; | |
| 339 | + | if ((changed = win_moveresize(&win, x, y, w, h))) { | |
| 340 | + | img.x = x - win.x; | |
| 341 | + | img.y = y - win.y; | |
| 342 | + | } | |
| 335 | 343 | break; | |
| 336 | 344 | ||
| 337 | 345 | /* miscellaneous */ | |
| @@ -157,24 +157,23 @@ int win_configure(win_t *win, XConfigureEvent *c) { | |||
| 157 | 157 | return changed; | |
| 158 | 158 | } | |
| 159 | 159 | ||
| 160 | − | int win_resize(win_t *win, unsigned int w, unsigned int h) { | |
| 160 | + | int win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) { | |
| 161 | 161 | if (!win) | |
| 162 | 162 | return 0; | |
| 163 | 163 | ||
| 164 | + | x = MAX(0, x); | |
| 165 | + | y = MAX(0, y); | |
| 164 | 166 | w = MIN(w, win->env.scrw - 2 * win->bw); | |
| 165 | 167 | h = MIN(h, win->env.scrh - 2 * win->bw); | |
| 166 | 168 | ||
| 167 | − | if (win->w == w && win->h == h) | |
| 169 | + | if (win->x == x && win->y == y && win->w == w && win->h == h) | |
| 168 | 170 | return 0; | |
| 169 | 171 | ||
| 172 | + | win->x = x; | |
| 173 | + | win->y = y; | |
| 170 | 174 | win->w = w; | |
| 171 | 175 | win->h = h; | |
| 172 | 176 | ||
| 173 | − | if (win->x + w + 2 * win->bw > win->env.scrw) | |
| 174 | − | win->x = win->env.scrw - w - 2 * win->bw; | |
| 175 | − | if (win->y + h + 2 * win->bw > win->env.scrh) | |
| 176 | − | win->y = win->env.scrh - h - 2 * win->bw; | |
| 177 | − | ||
| 178 | 177 | if (options->fixed) | |
| 179 | 178 | win_set_sizehints(win); | |
| 180 | 179 | ||
| @@ -57,7 +57,7 @@ void win_open(win_t*); | |||
| 57 | 57 | void win_close(win_t*); | |
| 58 | 58 | ||
| 59 | 59 | int win_configure(win_t*, XConfigureEvent*); | |
| 60 | − | int win_resize(win_t*, unsigned int, unsigned int); | |
| 60 | + | int win_moveresize(win_t*, int, int, unsigned int, unsigned int); | |
| 61 | 61 | ||
| 62 | 62 | void win_toggle_fullscreen(win_t*); | |
| 63 | 63 | ||