diff --git a/docs/docs.md b/docs/docs.md index 1cbc7b4..9f16786 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -773,8 +773,8 @@ These are the default keybinds. You can generate these yourself from a | 0 | 0 | t | toggleimg | 0 | | 0 | 0 | f | togglefullimg | 0 | | 0 | 0 | p | paste | 2 | -| 0 | Shift | h | flipimg | 1 | -| 0 | Shift | v | flipimg | 0 | +| 0 | 0 | q | flipimg | 1 | +| 0 | 0 | w | flipimg | 0 | | 0 | 0 | k | moveup | 0 | | 0 | 0 | j | movedown | 0 | | 0 | 0 | h | moveleft | 0 | diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 394d146..ebe9174 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -313,8 +313,8 @@ spmenu = { { mode = 0; modifier = "Shift"; key = "@"; function = "setimggaps"; argument = "+100"; }, // Shift+2: Increase image gaps by 100 { mode = 0; modifier = "None"; key = "t"; function = "toggleimg"; argument = "0"; }, // t: Toggle image { mode = 0; modifier = "None"; key = "f"; function = "togglefullimg"; argument = "0"; }, // f: Toggle image full screen mode - { mode = 0; modifier = "Shift"; key = "h"; function = "flipimg"; argument = "1"; }, // Shift+h: Flip image horizontally - { mode = 0; modifier = "Shift"; key = "v"; function = "flipimg"; argument = "0"; }, // Shift+v: Flip image vertically + { mode = 0; modifier = "None"; key = "q"; function = "flipimg"; argument = "1"; }, // q: Flip image horizontally + { mode = 0; modifier = "None"; key = "w"; function = "flipimg"; argument = "0"; }, // w: Flip image vertically { mode = 0; modifier = "None"; key = "k"; function = "moveup"; argument = "0"; }, // k: Move up 1 item { mode = 0; modifier = "None"; key = "j"; function = "movedown"; argument = "0"; }, // j: Move down 1 item { mode = 0; modifier = "None"; key = "h"; function = "moveleft"; argument = "0"; }, // h: Move left 1 item diff --git a/libs/arg.c b/libs/arg.c index a95987e..3fa35af 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -368,7 +368,7 @@ out: void setimgsize(Arg *arg) { #if USEIMAGE - setimagesize(imagewidth + arg->i, imageheight + arg->i); + setimagesize(img.imagewidth + arg->i, img.imageheight + arg->i); drawmenu(); #endif } @@ -401,16 +401,16 @@ void setimgpos(Arg *arg) { void setimggaps(Arg *arg) { #if USEIMAGE - imagegaps += arg->i; + img.imagegaps += arg->i; if (!image || hideimage) return; - if (imagegaps < 0) - imagegaps = 0; + if (img.imagegaps < 0) + img.imagegaps = 0; // limitation to make sure we have a reasonable gap size - if (imagegaps > imagewidth / 2) - imagegaps -= arg->i; + if (img.imagegaps > img.imagewidth / 2) + img.imagegaps -= arg->i; drawmenu(); #endif @@ -431,14 +431,14 @@ void togglefullimg(Arg *arg) { fullscreen = image ? !fullscreen : 0; if (fullscreen) { - img.ow = imagewidth; - img.oh = imageheight; + img.ow = img.imagewidth; + img.oh = img.imageheight; - imagewidth = sp.mw; - imageheight = sp.mh; + img.imagewidth = sp.mw; + img.imageheight = sp.mh; } else { - imagewidth = img.ow; - imageheight = img.oh; + img.imagewidth = img.ow; + img.imageheight = img.oh; } drawmenu(); @@ -450,11 +450,9 @@ void defaultimg(Arg *arg) { if (hideimage || !image) return; - if (img.imagew) { - imagewidth = img.imagew; - imageheight = img.imageh; - imagegaps = img.imageg; - } + img.imagewidth = imagewidth; + img.imageheight = imageheight; + img.imagegaps = imagegaps; drawmenu(); #endif diff --git a/libs/draw.c b/libs/draw.c index a8c8dd1..e884960 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -306,7 +306,7 @@ int drawitem(int x, int y, int w) { #if USEIMAGE if (!hideimage && img.longestedge != 0) { rx = ox; - rx += MAX((imagegaps * 2) + imagewidth + menumarginh, indentitems ? x : 0); + rx += MAX((imagegaps * 2) + img.imagewidth + menumarginh, indentitems ? x : 0); } else #endif if (!indentitems) { diff --git a/libs/img.c b/libs/img.c index 16361c2..d59c6aa 100644 --- a/libs/img.c +++ b/libs/img.c @@ -6,8 +6,8 @@ void setimagesize(int width, int height) { return; } - imageheight = height; - imagewidth = width; + img.imageheight = height; + img.imagewidth = width; } void flipimage(void) { @@ -69,14 +69,14 @@ void drawimage(void) { wta += menumarginv; if (sp.mh != sp.bh + height + leftmargin * 2 - wtr && imageresize) { // menu height cannot be smaller than image height - resizetoimageheight(width, imlib_image_get_height() - (fullscreen ? 2 * menumarginv : 0)); + resizetoimageheight(imlib_image_get_height() - (fullscreen ? 2 * menumarginv : 0)); } draw_set_img(draw, imlib_image_get_data(), width, height); if (fullscreen) { xta = wta = leftmargin = 0; - draw_img(draw, (imagewidth - width) / 2, 0); + draw_img(draw, (img.imagewidth - width) / 2, 0); if (sel) { limg = sel->image; @@ -92,17 +92,17 @@ void drawimage(void) { if (height > width) width = height; - draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, wta + leftmargin); + draw_img(draw, leftmargin + (img.imagewidth - width) / 2 + xta, wta + leftmargin); } else if (imageposition == 1 && image) { // bottom mode = 1 if (height > width) width = height; - draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, sp.mh - height - leftmargin); + draw_img(draw, leftmargin + (img.imagewidth - width) / 2 + xta, sp.mh - height - leftmargin); } else if (imageposition == 2 && image) { // center mode = 2 - draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, (sp.mh - wta - height) / 2 + wta); + draw_img(draw, leftmargin + (img.imagewidth - width) / 2 + xta, (sp.mh - wta - height) / 2 + wta); } else if (image) { // top center int minh = MIN(height, sp.mh - sp.bh - leftmargin * 2); - draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, (minh - height) / 2 + wta + leftmargin); + draw_img(draw, leftmargin + (img.imagewidth - width) / 2 + xta, (minh - height) / 2 + wta + leftmargin); } } @@ -169,10 +169,10 @@ void scaleimage(int *width, int *height) { float aspect = 1.0f; // depending on what size, we determine aspect ratio - if (imagewidth > *width) { - aspect = (float)(*width)/imagewidth; + if (img.imagewidth > *width) { + aspect = (float)(*width)/img.imagewidth; } else { - aspect = (float)imagewidth/(*width); + aspect = (float)img.imagewidth/(*width); } new_width = *width * aspect; @@ -277,10 +277,10 @@ void loadimagecache(const char *file, int *width, int *height) { loadimage(buf, width, height); - if (image && *width < imagewidth && *height < imageheight) { + if (image && *width < img.imagewidth && *height < img.imageheight) { imlib_free_image(); image = NULL; - } else if(image && (*width > imagewidth || *height > imageheight)) { + } else if(image && (*width > img.imagewidth || *height > img.imageheight)) { scaleimage(width, height); } @@ -320,19 +320,17 @@ void jumptoindex(unsigned int index) { } } -void resizetoimageheight(int imagewidth, int imageheight) { - int ih = imageheight; - +void resizetoimageheight(int imageheight) { #if USEX if (!protocol) { - resizetoimageheight_x11(ih); + resizetoimageheight_x11(imageheight); } else { #if USEWAYLAND - resizetoimageheight_wl(ih); + resizetoimageheight_wl(imageheight); #endif } #elif USEWAYLAND - resizetoimageheight_wl(ih); + resizetoimageheight_wl(imageheight); #endif } @@ -501,12 +499,10 @@ void resizetoimageheight_wl(int imageheight) { #endif void store_image_vars(void) { - img.longestedge = MAX(imagewidth, imageheight); + img.imagewidth = imagewidth; + img.imageheight = imageheight; + img.imagegaps = imagegaps; - if (!img.imagew || !img.imageh || !img.imageg) { - img.imagew = imagewidth; - img.imageh = imageheight; - img.imageg = imagegaps; - } + img.longestedge = MAX(img.imagewidth, img.imageheight); } #endif diff --git a/libs/img.h b/libs/img.h index 1d2326f..d1f89eb 100644 --- a/libs/img.h +++ b/libs/img.h @@ -13,7 +13,7 @@ static void drawimage(void); static void flipimage(void); static void loadimage(const char *file, int *width, int *height); static void loadimagecache(const char *file, int *width, int *height); -static void resizetoimageheight(int imagewidth, int imageheight); +static void resizetoimageheight(int imageheight); #if USEWAYLAND static void resizetoimageheight_wl(int imageheight); #endif diff --git a/libs/keybinds.h b/libs/keybinds.h index 075d820..3fcaa35 100644 --- a/libs/keybinds.h +++ b/libs/keybinds.h @@ -51,8 +51,8 @@ static Key keys[] = { { 0, 0, XK_t, toggleimg, {0} }, { 0, 0, XK_f, togglefullimg, {0} }, { 0, 0, XK_p, paste, {.i = 2 } }, - { 0, Shift, XK_h, flipimg, {.i = 1 } }, - { 0, Shift, XK_v, flipimg, {.i = 0 } }, + { 0, 0, XK_q, flipimg, {.i = 1 } }, + { 0, 0, XK_w, flipimg, {.i = 0 } }, { 0, 0, XK_k, moveup, {0} }, { 0, 0, XK_j, movedown, {0} }, { 0, 0, XK_h, moveleft, {0} }, @@ -60,7 +60,7 @@ static Key keys[] = { { 0, Ctrl, XK_u, moveup, {.i = 5 } }, { 0, Ctrl, XK_d, movedown, {.i = 5 } }, { 0, 0, XK_u, togglehighlight, {0} }, - { 0, Ctrl, XK_h, viewhist, {0} }, + { 0, Shift, XK_h, viewhist, {0} }, { 0, 0, XK_d, clear, {0} }, { 0, Shift, XK_d, clearins, {0} }, { 0, 0, XK_Escape, quit, {0} }, @@ -127,8 +127,8 @@ static WlKey wl_keys[] = { { 0, WL_None, XKB_KEY_t, toggleimg, {0} }, { 0, WL_None, XKB_KEY_f, togglefullimg, {0} }, { 0, WL_None, XKB_KEY_p, paste, {.i = 2 } }, - { 0, WL_Shift, XKB_KEY_h, flipimg, {.i = 1 } }, - { 0, WL_Shift, XKB_KEY_v, flipimg, {.i = 0 } }, + { 0, WL_None, XKB_KEY_q, flipimg, {.i = 1 } }, + { 0, WL_None, XKB_KEY_w, flipimg, {.i = 0 } }, { 0, WL_None, XKB_KEY_k, moveup, {0} }, { 0, WL_None, XKB_KEY_j, movedown, {0} }, { 0, WL_None, XKB_KEY_h, moveleft, {0} }, @@ -136,7 +136,7 @@ static WlKey wl_keys[] = { { 0, WL_Ctrl, XKB_KEY_u, moveup, {.i = 5 } }, { 0, WL_Ctrl, XKB_KEY_d, movedown, {.i = 5 } }, { 0, WL_None, XKB_KEY_u, togglehighlight, {0} }, - { 0, WL_Ctrl, XKB_KEY_h, viewhist, {0} }, + { 0, WL_Shift, XKB_KEY_h, viewhist, {0} }, { 0, WL_None, XKB_KEY_d, clear, {0} }, { 0, WL_Shift, XKB_KEY_d, clearins, {0} }, { 0, WL_None, XKB_KEY_Escape, quit, {0} }, diff --git a/libs/stream.c b/libs/stream.c index e448682..5d52ae5 100644 --- a/libs/stream.c +++ b/libs/stream.c @@ -48,7 +48,7 @@ void readstdin(void) { } #if USEIMAGE - if (!o) img.longestedge = imagegaps = 0; + if (!o) img.longestedge = img.imagegaps = 0; #endif // clean @@ -129,7 +129,7 @@ void readfile(void) { lines = columns == 1 ? i : MIN(i, lines); // i = number of items #if USEIMAGE - if (!o) img.longestedge = imagegaps = 0; + if (!o) img.longestedge = img.imagegaps = 0; #endif if (i == listcount) { diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index 01fad0a..822dee1 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -275,7 +275,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { #if USEIMAGE if (!hideimage && img.longestedge != 0) { - x += MAX((imagegaps * 2) + imagewidth, indentitems ? sp.promptw : 0); + x += MAX((imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0); } #endif diff --git a/libs/x11/client.c b/libs/x11/client.c index 9c9636b..61d5bf9 100644 --- a/libs/x11/client.c +++ b/libs/x11/client.c @@ -93,7 +93,7 @@ void resizeclient_x11(void) { img.setlines = lines; // resize client to image height - if (image) resizetoimageheight(imagewidth, imageheight); + if (image) resizetoimageheight(img.imageheight); #endif get_mh(); diff --git a/libs/x11/init.c b/libs/x11/init.c index 8d15188..ffe393a 100644 --- a/libs/x11/init.c +++ b/libs/x11/init.c @@ -10,7 +10,7 @@ void setupdisplay_x11(void) { // resize client to image height if deemed necessary #if USEIMAGE - if (image) resizetoimageheight(imagewidth, imageheight); + if (image) resizetoimageheight(img.imageheight); #endif // set prompt width based on prompt size diff --git a/libs/x11/mouse.c b/libs/x11/mouse.c index f3d1dbf..05583ef 100644 --- a/libs/x11/mouse.c +++ b/libs/x11/mouse.c @@ -59,7 +59,7 @@ void buttonpress_x11(XEvent *e) { #if USEIMAGE if (!hideimage && img.longestedge != 0) { - x += MAX((imagegaps * 2) + imagewidth, indentitems ? sp.promptw : 0); + x += MAX((img.imagegaps * 2) + img.imagewidth, indentitems ? sp.promptw : 0); } #endif diff --git a/spmenu.c b/spmenu.c index 94ace3f..dd93f76 100644 --- a/spmenu.c +++ b/spmenu.c @@ -130,7 +130,7 @@ struct sp { int itemnumber; // item number - size_t cursor; + size_t cursor; // cursor width int ignoreconfkeys; // can be set globally if you don't want to override keybinds with config file keys int ignoreglobalkeys; // should be set in the config file, if 1, the Keys keys array is ignored @@ -140,14 +140,14 @@ struct sp { #if USEIMAGE struct img { - int setlines; - int flip; - int longestedge; - int imagew; - int imageh; - int imageg; - int ow; - int oh; + int setlines; // actual lines + int flip; // %= + int longestedge; // MAX(imagewidth, imagheight) + int imagewidth; // current image width + int imageheight; // current image height + int imagegaps; // current image gaps + int ow; // original sp.mw + int oh; // original sp.mh }; #endif