lel

Fork of Hiltjo's Farbfeld image viewer. (It was just for fun, not much use)
Log | Files | Refs | README | LICENSE

commit 8091d61acc1f5c39a01ad33d2a5ed08033231c67
parent cf9336060f7ba63be42921e98556135bb3adde82
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Sun, 18 Apr 2021 20:12:28 -0700

Cleanup keypress event handler and add another view

Sort similar keypress cases sorted near each other and all various
cases added and removed.

Add the full image view which always fits the whole image in the
window with the proper aspect ratio.

Diffstat:
Mlel.c | 72+++++++++++++++++++++++++++++++-----------------------------------------
1 file changed, 31 insertions(+), 41 deletions(-)

diff --git a/lel.c b/lel.c @@ -24,7 +24,7 @@ enum { NONE = 0, LOADED = 1, SCALED = 2, DRAWN = 4 }; /* View mode. */ -enum { ASPECT, FULL_ASPECT, FULL_STRETCH, FULL_WIDTH, FULL_HEIGHT }; +enum { ASPECT, FULL_ASPECT, FULL_STRETCH, FULL_WIDTH, FULL_HEIGHT, FULL_IMAGE }; struct img { int index; @@ -329,7 +329,11 @@ scaleview(void) goto width; else goto height; - break; + case FULL_IMAGE: + if (winwidth * img.height > winheight * img.width) + goto height; + else + goto width; case FULL_WIDTH: width: w = winwidth; @@ -453,10 +457,6 @@ keypress(XEvent *ev) key = XLookupKeysym(&ev->xkey, 0); switch(key) { - case XK_Escape: - case XK_q: - done = 1; - break; case XK_Left: case XK_h: panperc(paninc, 0); @@ -473,40 +473,20 @@ keypress(XEvent *ev) case XK_l: panperc(-paninc, 0); break; - case XK_a: - setview(FULL_ASPECT); - break; - case XK_o: - setview(ASPECT); - break; - case XK_Return: - printname(); - break; - case XK_f: - setview(FULL_STRETCH); - break; case XK_KP_Add: case XK_equal: case XK_plus: + case XK_i: inczoom(zoominc); break; case XK_KP_Subtract: case XK_underscore: case XK_minus: + case XK_o: inczoom(-zoominc); break; - case XK_3: - zoom(4.0); - break; - case XK_2: - zoom(2.0); - break; - case XK_1: - zoom(1.0); - break; case XK_0: - zoom(1.0); - setview(ASPECT); /* fallthrough */ + zoom(1.0); /* fallthrough */ case XK_r: img.view.panxoffset = 0; img.view.panyoffset = 0; @@ -520,12 +500,31 @@ keypress(XEvent *ev) previmg(); img.state &= ~(DRAWN | SCALED); break; + case XK_a: + setview(FULL_ASPECT); + break; + case XK_s: + setview(FULL_STRETCH); + break; + case XK_d: + setview(ASPECT); + break; + case XK_f: + setview(FULL_IMAGE); + break; case XK_w: setview(FULL_WIDTH); break; case XK_e: setview(FULL_HEIGHT); break; + case XK_Escape: + case XK_q: + done = 1; + break; + case XK_Return: + printname(); + break; } update(); } @@ -604,22 +603,13 @@ main(int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "aefw")) != -1) { + while ((c = getopt(argc, argv, "f")) != -1) { switch (c) { - case 'a': - viewmode = FULL_ASPECT; - break; - case 'e': - viewmode = FULL_HEIGHT; - break; case 'f': - viewmode = FULL_STRETCH; - break; - case 'w': - viewmode = FULL_WIDTH; + viewmode = FULL_IMAGE; break; default: - fprintf(stderr, "usage: %s [-afv] [file...]\n", + fprintf(stderr, "usage: %s [-f] [file...]\n", getprogname()); exit(1); }