Fix keybind conflict, replace imageg, imagew and imageh in favor of

using the img struct
This commit is contained in:
speedie 2023-06-24 04:20:51 +02:00
parent aba3541d37
commit 0a59088313
13 changed files with 63 additions and 69 deletions

View file

@ -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 |

View file

@ -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

View file

@ -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

View file

@ -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) {

View file

@ -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

View file

@ -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

View file

@ -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} },

View file

@ -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) {

View file

@ -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

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -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