New key mapping: W, resize window to fit image
This commit is contained in:
parent
096c0ed935
commit
8339bb7ee7
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
all: sxiv
|
all: sxiv
|
||||||
|
|
||||||
VERSION=git-20110203
|
VERSION=git-20110204
|
||||||
|
|
||||||
CC?=gcc
|
CC?=gcc
|
||||||
PREFIX?=/usr/local
|
PREFIX?=/usr/local
|
||||||
|
|
2
image.h
2
image.h
|
@ -37,9 +37,11 @@ typedef enum pandir_e {
|
||||||
typedef struct img_s {
|
typedef struct img_s {
|
||||||
float zoom;
|
float zoom;
|
||||||
scalemode_t scalemode;
|
scalemode_t scalemode;
|
||||||
|
|
||||||
unsigned char re;
|
unsigned char re;
|
||||||
unsigned char checkpan;
|
unsigned char checkpan;
|
||||||
unsigned char aa;
|
unsigned char aa;
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int w;
|
int w;
|
||||||
|
|
4
main.c
4
main.c
|
@ -329,6 +329,10 @@ void on_keypress(XKeyEvent *kev) {
|
||||||
win_toggle_fullscreen(&win);
|
win_toggle_fullscreen(&win);
|
||||||
/* render on next configurenotify */
|
/* render on next configurenotify */
|
||||||
break;
|
break;
|
||||||
|
case XK_W:
|
||||||
|
if ((changed = win_resize(&win, img.w * img.zoom, img.h * img.zoom)))
|
||||||
|
img.checkpan = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
/* miscellaneous */
|
/* miscellaneous */
|
||||||
case XK_a:
|
case XK_a:
|
||||||
|
|
73
window.c
73
window.c
|
@ -31,10 +31,23 @@ static Cursor hand;
|
||||||
|
|
||||||
static GC bgc;
|
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) {
|
void win_open(win_t *win) {
|
||||||
win_env_t *e;
|
win_env_t *e;
|
||||||
XClassHint classhint;
|
XClassHint classhint;
|
||||||
XSizeHints sizehints;
|
|
||||||
XColor bgcol;
|
XColor bgcol;
|
||||||
int gmask;
|
int gmask;
|
||||||
|
|
||||||
|
@ -104,14 +117,8 @@ void win_open(win_t *win) {
|
||||||
classhint.res_class = "sxiv";
|
classhint.res_class = "sxiv";
|
||||||
XSetClassHint(e->dpy, win->xwin, &classhint);
|
XSetClassHint(e->dpy, win->xwin, &classhint);
|
||||||
|
|
||||||
if (options->fixed) {
|
if (options->fixed)
|
||||||
sizehints.flags = PMinSize | PMaxSize;
|
win_set_sizehints(win);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
XMapWindow(e->dpy, win->xwin);
|
XMapWindow(e->dpy, win->xwin);
|
||||||
XFlush(e->dpy);
|
XFlush(e->dpy);
|
||||||
|
@ -133,17 +140,6 @@ void win_close(win_t *win) {
|
||||||
XCloseDisplay(win->env.dpy);
|
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 win_configure(win_t *win, XConfigureEvent *c) {
|
||||||
int changed;
|
int changed;
|
||||||
|
|
||||||
|
@ -161,6 +157,32 @@ int win_configure(win_t *win, XConfigureEvent *c) {
|
||||||
return changed;
|
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) {
|
void win_toggle_fullscreen(win_t *win) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
XClientMessageEvent *cm;
|
XClientMessageEvent *cm;
|
||||||
|
@ -213,6 +235,17 @@ void win_draw(win_t *win) {
|
||||||
XClearWindow(win->env.dpy, win->xwin);
|
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) {
|
void win_set_cursor(win_t *win, win_cur_t cursor) {
|
||||||
if (!win)
|
if (!win)
|
||||||
return;
|
return;
|
||||||
|
|
5
window.h
5
window.h
|
@ -56,14 +56,15 @@ typedef struct win_s {
|
||||||
void win_open(win_t*);
|
void win_open(win_t*);
|
||||||
void win_close(win_t*);
|
void win_close(win_t*);
|
||||||
|
|
||||||
void win_set_title(win_t*, const char*);
|
|
||||||
|
|
||||||
int win_configure(win_t*, XConfigureEvent*);
|
int win_configure(win_t*, XConfigureEvent*);
|
||||||
|
int win_resize(win_t*, unsigned int, unsigned int);
|
||||||
|
|
||||||
void win_toggle_fullscreen(win_t*);
|
void win_toggle_fullscreen(win_t*);
|
||||||
|
|
||||||
void win_clear(win_t*);
|
void win_clear(win_t*);
|
||||||
void win_draw(win_t*);
|
void win_draw(win_t*);
|
||||||
|
|
||||||
|
void win_set_title(win_t*, const char*);
|
||||||
void win_set_cursor(win_t*, win_cur_t);
|
void win_set_cursor(win_t*, win_cur_t);
|
||||||
|
|
||||||
#endif /* WINDOW_H */
|
#endif /* WINDOW_H */
|
||||||
|
|
Loading…
Reference in New Issue