New key mapping: W, resize window to fit image

master
Bert 2011-02-04 00:25:57 +01:00
parent 096c0ed935
commit 8339bb7ee7
5 changed files with 63 additions and 23 deletions

View File

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

View File

@ -37,9 +37,11 @@ typedef enum pandir_e {
typedef struct img_s {
float zoom;
scalemode_t scalemode;
unsigned char re;
unsigned char checkpan;
unsigned char aa;
int x;
int y;
int w;

4
main.c
View File

@ -329,6 +329,10 @@ void on_keypress(XKeyEvent *kev) {
win_toggle_fullscreen(&win);
/* render on next configurenotify */
break;
case XK_W:
if ((changed = win_resize(&win, img.w * img.zoom, img.h * img.zoom)))
img.checkpan = 1;
break;
/* miscellaneous */
case XK_a:

View File

@ -31,10 +31,23 @@ static Cursor hand;
static GC bgc;
void win_set_sizehints(win_t *win) {
XSizeHints sizehints;
if (!win)
return;
sizehints.flags = PMinSize | PMaxSize;
sizehints.min_width = win->w;
sizehints.max_width = win->w;
sizehints.min_height = win->h;
sizehints.max_height = win->h;
XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints);
}
void win_open(win_t *win) {
win_env_t *e;
XClassHint classhint;
XSizeHints sizehints;
XColor bgcol;
int gmask;
@ -104,14 +117,8 @@ void win_open(win_t *win) {
classhint.res_class = "sxiv";
XSetClassHint(e->dpy, win->xwin, &classhint);
if (options->fixed) {
sizehints.flags = PMinSize | PMaxSize;
sizehints.min_width = win->w;
sizehints.max_width = win->w;
sizehints.min_height = win->h;
sizehints.max_height = win->h;
XSetWMNormalHints(e->dpy, win->xwin, &sizehints);
}
if (options->fixed)
win_set_sizehints(win);
XMapWindow(e->dpy, win->xwin);
XFlush(e->dpy);
@ -133,17 +140,6 @@ void win_close(win_t *win) {
XCloseDisplay(win->env.dpy);
}
void win_set_title(win_t *win, const char *title) {
if (!win)
return;
if (!title)
title = "sxiv";
XStoreName(win->env.dpy, win->xwin, title);
XSetIconName(win->env.dpy, win->xwin, title);
}
int win_configure(win_t *win, XConfigureEvent *c) {
int changed;
@ -161,6 +157,32 @@ int win_configure(win_t *win, XConfigureEvent *c) {
return changed;
}
int win_resize(win_t *win, unsigned int w, unsigned int h) {
if (!win)
return 0;
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)
return 0;
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);
XMoveResizeWindow(win->env.dpy, win->xwin, win->x, win->y, win->w, win->h);
return 1;
}
void win_toggle_fullscreen(win_t *win) {
XEvent ev;
XClientMessageEvent *cm;
@ -213,6 +235,17 @@ void win_draw(win_t *win) {
XClearWindow(win->env.dpy, win->xwin);
}
void win_set_title(win_t *win, const char *title) {
if (!win)
return;
if (!title)
title = "sxiv";
XStoreName(win->env.dpy, win->xwin, title);
XSetIconName(win->env.dpy, win->xwin, title);
}
void win_set_cursor(win_t *win, win_cur_t cursor) {
if (!win)
return;

View File

@ -56,14 +56,15 @@ typedef struct win_s {
void win_open(win_t*);
void win_close(win_t*);
void win_set_title(win_t*, const char*);
int win_configure(win_t*, XConfigureEvent*);
int win_resize(win_t*, unsigned int, unsigned int);
void win_toggle_fullscreen(win_t*);
void win_clear(win_t*);
void win_draw(win_t*);
void win_set_title(win_t*, const char*);
void win_set_cursor(win_t*, win_cur_t);
#endif /* WINDOW_H */