Nicer fit window to image

This commit is contained in:
Bert 2011-02-06 17:40:48 +01:00
parent cbf6aae721
commit 603e664f7c
4 changed files with 18 additions and 11 deletions

View file

@ -1,6 +1,6 @@
all: sxiv
VERSION=git-20110204
VERSION=git-20110206
CC?=gcc
PREFIX?=/usr/local

12
main.c
View file

@ -222,6 +222,8 @@ unsigned char timeout;
int mox, moy;
void on_keypress(XKeyEvent *kev) {
int x, y;
unsigned int w, h;
char key;
KeySym ksym;
int changed;
@ -330,8 +332,14 @@ void on_keypress(XKeyEvent *kev) {
/* render on next configurenotify */
break;
case XK_W:
if ((changed = win_resize(&win, img.w * img.zoom, img.h * img.zoom)))
img.checkpan = 1;
x = win.x + img.x;
y = win.y + img.y;
w = img.w * img.zoom;
h = img.h * img.zoom;
if ((changed = win_moveresize(&win, x, y, w, h))) {
img.x = x - win.x;
img.y = y - win.y;
}
break;
/* miscellaneous */

View file

@ -157,24 +157,23 @@ int win_configure(win_t *win, XConfigureEvent *c) {
return changed;
}
int win_resize(win_t *win, unsigned int w, unsigned int h) {
int win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
if (!win)
return 0;
x = MAX(0, x);
y = MAX(0, y);
w = MIN(w, win->env.scrw - 2 * win->bw);
h = MIN(h, win->env.scrh - 2 * win->bw);
if (win->w == w && win->h == h)
if (win->x == x && win->y == y && win->w == w && win->h == h)
return 0;
win->x = x;
win->y = y;
win->w = w;
win->h = h;
if (win->x + w + 2 * win->bw > win->env.scrw)
win->x = win->env.scrw - w - 2 * win->bw;
if (win->y + h + 2 * win->bw > win->env.scrh)
win->y = win->env.scrh - h - 2 * win->bw;
if (options->fixed)
win_set_sizehints(win);

View file

@ -57,7 +57,7 @@ void win_open(win_t*);
void win_close(win_t*);
int win_configure(win_t*, XConfigureEvent*);
int win_resize(win_t*, unsigned int, unsigned int);
int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
void win_toggle_fullscreen(win_t*);