diff --git a/TODO b/TODO index 902c85a..0e5d5c7 100644 --- a/TODO +++ b/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 diff --git a/keybinds.h b/keybinds.h index ddd2d9e..7f4b976 100644 --- a/keybinds.h +++ b/keybinds.h @@ -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 } }, diff --git a/libs/img.c b/libs/img.c index 2301d31..9fa9daa 100644 --- a/libs/img.c +++ b/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; diff --git a/libs/img.h b/libs/img.h index e6f6ad8..a371330 100644 --- a/libs/img.h +++ b/libs/img.h @@ -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); diff --git a/spmenu.c b/spmenu.c index 6fcdda7..453a45a 100644 --- a/spmenu.c +++ b/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) {