don't allow scaling too far up/down, also add wip default image size keybind
This commit is contained in:
parent
6f8e1c5683
commit
3d4fc5247a
1
TODO
1
TODO
|
@ -4,5 +4,4 @@
|
|||
- Remove padding added for background colors
|
||||
- Add configuration file using (probably) libconfig
|
||||
- Fix highlighting for last character in a match
|
||||
- Don't allow image scaling too far up/down
|
||||
- Add rotate and flip keybinds for the image
|
||||
|
|
|
@ -51,6 +51,7 @@ static Key normkeys[] = {
|
|||
{ 0, XK_minus, setimgsize, {.i = -10 } },
|
||||
{ SHIFT, XK_equal, setimgsize, {.i = +100 } },
|
||||
{ SHIFT, XK_minus, setimgsize, {.i = -100 } },
|
||||
{ 0, XK_d, defaultimg, {0} },
|
||||
{ 0, XK_t, toggleimg, {0} },
|
||||
{ 0, XK_k, move, {.i = 1 } },
|
||||
{ 0, XK_j, move, {.i = 2 } },
|
||||
|
|
28
libs/img.c
28
libs/img.c
|
@ -1,5 +1,5 @@
|
|||
void
|
||||
cleanupimg(void)
|
||||
cleanupimage(void)
|
||||
{
|
||||
if (image) {
|
||||
imlib_free_image();
|
||||
|
@ -9,6 +9,24 @@ cleanupimg(void)
|
|||
return;
|
||||
}
|
||||
|
||||
void
|
||||
prepareimage(void)
|
||||
{
|
||||
/* values which can be restored later */
|
||||
if (!imagew || !imageh || !imageg) {
|
||||
imagew = imagewidth;
|
||||
imageh = imageheight;
|
||||
imageg = imagegaps;
|
||||
}
|
||||
|
||||
/* restore values if necessary */
|
||||
if (!imageheight || !imagewidth || !longestedge) {
|
||||
imageheight = imageh;
|
||||
imagewidth = imagew;
|
||||
imagegaps = imageg;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
drawimage(void)
|
||||
{
|
||||
|
@ -22,11 +40,6 @@ drawimage(void)
|
|||
if (!lines) return;
|
||||
if (hideimage) return;
|
||||
|
||||
if (!imagewidth || !imageheight) {
|
||||
imagewidth = imageheight = longestedge = imagegaps = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (sel && sel->image && strcmp(sel->image, limg ? limg : "")) {
|
||||
if (longestedge)
|
||||
loadimagecache(sel->image, &width, &height);
|
||||
|
@ -34,6 +47,9 @@ drawimage(void)
|
|||
imlib_free_image();
|
||||
image = NULL;
|
||||
} if (image && longestedge) {
|
||||
|
||||
prepareimage();
|
||||
|
||||
int leftmargin = imagegaps;
|
||||
|
||||
if(mh != bh + height + imagegaps * 2) {
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
#include <openssl/md5.h>
|
||||
|
||||
static void setimageopts(void);
|
||||
static void cleanupimg(void);
|
||||
static void cleanupimage(void);
|
||||
static void drawimage(void);
|
||||
static void prepareimage(void);
|
||||
static void loadimagecache(const char *file, int *width, int *height);
|
||||
static void resizetoimageheight(int imageheight);
|
||||
|
||||
|
|
36
spmenu.c
36
spmenu.c
|
@ -127,6 +127,10 @@ static struct item *prev, *curr, *next, *sel;
|
|||
static int mon = -1, screen;
|
||||
static int managed = 0;
|
||||
|
||||
static int imagew = 0;
|
||||
static int imageh = 0;
|
||||
static int imageg = 0;
|
||||
|
||||
#if USERTL
|
||||
static int isrtl = 1;
|
||||
#else
|
||||
|
@ -173,6 +177,7 @@ static void complete(const Arg *arg);
|
|||
static void savehistory(char *input);
|
||||
static void setimgsize(const Arg *arg);
|
||||
static void toggleimg(const Arg *arg);
|
||||
static void defaultimg(const Arg *arg);
|
||||
|
||||
static void drawmenu(void);
|
||||
static void calcoffsets(void);
|
||||
|
@ -220,16 +225,14 @@ setimgsize(const Arg *arg)
|
|||
return;
|
||||
#endif
|
||||
|
||||
cleanupimg();
|
||||
/* this makes sure we cannot scale down the image too much */
|
||||
if (!image && imageheight + arg->i < imageheight || hideimage) return;
|
||||
|
||||
cleanupimage();
|
||||
|
||||
imageheight += arg->i;
|
||||
imagewidth += arg->i;
|
||||
|
||||
if (!imageheight || !imagewidth || !longestedge) {
|
||||
imageheight = imagewidth = longestedge = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
drawmenu();
|
||||
drawimage();
|
||||
}
|
||||
|
@ -241,7 +244,7 @@ toggleimg(const Arg *arg)
|
|||
return;
|
||||
#endif
|
||||
|
||||
cleanupimg();
|
||||
cleanupimage();
|
||||
|
||||
hideimage = !hideimage;
|
||||
|
||||
|
@ -249,6 +252,23 @@ toggleimg(const Arg *arg)
|
|||
drawimage();
|
||||
}
|
||||
|
||||
void
|
||||
defaultimg(const Arg *arg)
|
||||
{
|
||||
#if !USEIMAGE
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (hideimage || !image) return;
|
||||
|
||||
/* this will cause values to be reset */
|
||||
imagewidth = 0;
|
||||
prepareimage();
|
||||
|
||||
drawmenu();
|
||||
drawimage();
|
||||
}
|
||||
|
||||
void
|
||||
appenditem(struct item *item, struct item **list, struct item **last)
|
||||
{
|
||||
|
@ -321,7 +341,7 @@ cleanup(void)
|
|||
size_t i;
|
||||
|
||||
#if USEIMAGE
|
||||
cleanupimg();
|
||||
cleanupimage();
|
||||
#endif
|
||||
|
||||
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||||
|
|
Loading…
Reference in a new issue