add support for flipping and rotating images
This commit is contained in:
parent
f61ad4f61a
commit
cc231b8df8
1
TODO
1
TODO
|
@ -4,4 +4,3 @@
|
|||
- Remove SGR sequences from width when item text is drawn, currently the width of the item before SGR sequences are used, resulting in some ugly behavior for the selected item
|
||||
- Add configuration file using (probably) libconfig
|
||||
- Fix highlighting for last character in a match
|
||||
- Add rotate and flip keybinds for the image
|
||||
|
|
|
@ -52,7 +52,10 @@ static Key normkeys[] = {
|
|||
{ SHIFT, XK_equal, setimgsize, {.i = +100 } },
|
||||
{ SHIFT, XK_minus, setimgsize, {.i = -100 } },
|
||||
{ 0, XK_d, defaultimg, {0} },
|
||||
{ 0, XK_r, rotateimg, {0} },
|
||||
{ 0, XK_t, toggleimg, {0} },
|
||||
{ 0, XK_h, flipimagehoriz, {0} },
|
||||
{ 0, XK_v, flipimagevert, {0} },
|
||||
{ 0, XK_k, move, {.i = 1 } },
|
||||
{ 0, XK_j, move, {.i = 2 } },
|
||||
{ 0, XK_h, move, {.i = 3 } },
|
||||
|
|
40
libs/img.c
40
libs/img.c
|
@ -1,3 +1,41 @@
|
|||
void
|
||||
flipimage(void)
|
||||
{
|
||||
if (!flip) return;
|
||||
if (flip == 1) { /* horizontal */
|
||||
imlib_image_flip_horizontal();
|
||||
} else if (flip == 2) {
|
||||
imlib_image_flip_vertical();
|
||||
} else if (flip == 3) {
|
||||
imlib_image_flip_diagonal();
|
||||
} else {
|
||||
flip = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rotateimage(void)
|
||||
{
|
||||
if (!rotation) return;
|
||||
if (rotation == 1) {
|
||||
imlib_image_orientate(1);
|
||||
} else if (rotation == 2) {
|
||||
imlib_image_orientate(1);
|
||||
imlib_image_orientate(1);
|
||||
} else if (rotation == 3) {
|
||||
imlib_image_orientate(1);
|
||||
imlib_image_orientate(1);
|
||||
imlib_image_orientate(1);
|
||||
} else if (rotation == 4) {
|
||||
imlib_image_orientate(1);
|
||||
imlib_image_orientate(1);
|
||||
imlib_image_orientate(1);
|
||||
imlib_image_orientate(1);
|
||||
} else {
|
||||
rotation = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cleanupimage(void)
|
||||
{
|
||||
|
@ -49,6 +87,8 @@ drawimage(void)
|
|||
} if (image && longestedge) {
|
||||
|
||||
prepareimage();
|
||||
rotateimage();
|
||||
flipimage();
|
||||
|
||||
int leftmargin = imagegaps;
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ static void setimageopts(void);
|
|||
static void cleanupimage(void);
|
||||
static void drawimage(void);
|
||||
static void prepareimage(void);
|
||||
static void rotateimage(void);
|
||||
static void flipimage(void);
|
||||
static void loadimagecache(const char *file, int *width, int *height);
|
||||
static void resizetoimageheight(int imageheight);
|
||||
|
||||
|
|
59
spmenu.c
59
spmenu.c
|
@ -127,6 +127,8 @@ static struct item *prev, *curr, *next, *sel;
|
|||
static int mon = -1, screen;
|
||||
static int managed = 0;
|
||||
|
||||
static int flip = 0;
|
||||
static int rotation = 0;
|
||||
static int imagew = 0;
|
||||
static int imageh = 0;
|
||||
static int imageg = 0;
|
||||
|
@ -178,6 +180,9 @@ 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 rotateimg(const Arg *arg);
|
||||
static void flipimagevert(const Arg *arg);
|
||||
static void flipimagehoriz(const Arg *arg);
|
||||
|
||||
static void drawmenu(void);
|
||||
static void calcoffsets(void);
|
||||
|
@ -244,6 +249,60 @@ setimgsize(const Arg *arg)
|
|||
drawmenu();
|
||||
}
|
||||
|
||||
void
|
||||
flipimagevert(const Arg *arg)
|
||||
{
|
||||
#if !USEIMAGE
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!image) return;
|
||||
|
||||
if (flip)
|
||||
flip = 0;
|
||||
else
|
||||
flip = 2;
|
||||
|
||||
cleanupimage();
|
||||
drawimage();
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
void
|
||||
flipimagehoriz(const Arg *arg)
|
||||
{
|
||||
#if !USEIMAGE
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!image) return;
|
||||
|
||||
if (flip)
|
||||
flip = 0;
|
||||
else
|
||||
flip = 1;
|
||||
|
||||
cleanupimage();
|
||||
drawimage();
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
void
|
||||
rotateimg(const Arg *arg)
|
||||
{
|
||||
#if !USEIMAGE
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!image) return;
|
||||
|
||||
rotation++;
|
||||
|
||||
cleanupimage();
|
||||
drawimage();
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
void
|
||||
toggleimg(const Arg *arg)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue