add the ability to full screen an image + code cleanup

images are drawn quite slowly, something needs to be done about that
soon
This commit is contained in:
speedie 2023-05-14 00:10:24 +02:00
parent b730dd6fa9
commit 15141c230d
8 changed files with 54 additions and 12 deletions

View file

@ -500,6 +500,13 @@ spmenu = {
function = "toggleimg";
argument = "0";
},
// f: Toggle image full screen mode
{ mode = 0;
modifier = "None";
key = "f";
function = "togglefullimg";
argument = "0";
},
// h: Flip image horizontally
{ mode = 0;
modifier = "None";

View file

@ -41,6 +41,7 @@ static Key keys[] = {
{ 0, Shift, XK_1, setimggaps, {.i = -100 } },
{ 0, Shift, XK_2, setimggaps, {.i = +100 } },
{ 0, 0, XK_t, toggleimg, {0} },
{ 0, 0, XK_f, togglefullimg, {0} },
{ 0, 0, XK_p, paste, {.i = 2 } },
{ 0, 0, XK_h, flipimg, {.i = 1 } },
{ 0, 0, XK_v, flipimg, {.i = 0 } },

View file

@ -403,6 +403,25 @@ void toggleimg(Arg *arg) {
#endif
}
void togglefullimg(Arg *arg) {
#if USEIMAGE
fullscreen = image ? !fullscreen : 0;
if (fullscreen) {
ow = imagewidth;
oh = imageheight;
imagewidth = mw;
imageheight = mh;
} else {
imagewidth = ow;
imageheight = oh;
}
drawmenu();
#endif
}
void defaultimg(Arg *arg) {
#if USEIMAGE
@ -419,6 +438,7 @@ void defaultimg(Arg *arg) {
}
void setlines(Arg *arg) {
if (fullscreen) return;
lines += arg->i;
if (lines < 0) lines = 0;
@ -428,6 +448,7 @@ void setlines(Arg *arg) {
}
void setcolumns(Arg *arg) {
if (fullscreen) return;
columns += arg->i;
if (columns < 1) columns = 1;

View file

@ -30,6 +30,7 @@ static void quit(Arg *arg);
static void complete(Arg *arg);
static void setimgsize(Arg *arg);
static void toggleimg(Arg *arg);
static void togglefullimg(Arg *arg);
static void defaultimg(Arg *arg);
static void rotateimg(Arg *arg);
static void flipimg(Arg *arg);

View file

@ -356,6 +356,7 @@ static FuncList fl[] = {
{ "setimgsize", setimgsize },
{ "setimgsize", setimgsize },
{ "toggleimg", toggleimg },
{ "togglefullimg", togglefullimg },
{ "defaultimg", defaultimg },
{ "rotateimg", rotateimg },
{ "flipimg", flipimg },

View file

@ -488,31 +488,32 @@ void drawmenu(void) {
}
#endif
if (!hideprompt) {
if (!hideprompt && !fullscreen) {
w = promptw;
x = drawprompt(x, y, w);
}
if (!hideinput) {
if (!hideinput && !fullscreen) {
w = (lines > 0 || !matches) ? mw - x : inputw;
x = drawinput(x, y, w);
}
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
if (!hidemode && !fullscreen) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
// draw the items, this function also calls drawrarrow() and drawlarrow()
if (!hideitem) drawitem(x, y, w);
if (!hidematchcount) {
if (!hidematchcount && !fullscreen) {
w = numberWidth;
drawnumber(mw - numberWidth - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
}
if (!hidemode) {
if (!hidemode && !fullscreen) {
w = modeWidth;
drawmode(mw - modeWidth - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
}
if (!hidecaps) {
if (!hidecaps && !fullscreen) {
w = capsWidth;
drawcaps(mw - capsWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
}

View file

@ -4,7 +4,7 @@ void setimagesize(int width, int height) {
int oiw = 0;
// this makes sure we cannot scale the image up or down too much
if ((!image && height < imageheight) || (!image && width < imagewidth) || (width < 0) || width > mw || hideimage) return;
if ((!image && height < imageheight) || (!image && width < imagewidth) || (width < 0) || width > mw || hideimage || fullscreen) return;
// original width/height
oih = imageheight;
@ -94,24 +94,31 @@ void drawimage(void) {
xta += menumarginh;
wta += menumarginv;
if (mh != bh + height + imagegaps * 2 - wtr) { // menu height cannot be smaller than image height
if (mh != bh + height + leftmargin * 2 - wtr && !fullscreen) { // menu height cannot be smaller than image height
resizetoimageheight(height);
} else if (mh != bh + height + leftmargin * 2 - wtr && fullscreen) {
resizetoimageheight(height-bh);
}
// we're covering all the area
if (fullscreen) {
xta = wta = wtr = leftmargin = 0;
}
// render image
if (!imageposition && image) { // top mode = 0
if (height > width)
width = height;
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, wta+imagegaps);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, wta+leftmargin);
} else if (imageposition == 1 && image) { // bottom mode = 1
if (height > width)
width = height;
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, mh-height-imagegaps);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, mh-height-leftmargin);
} else if (imageposition == 2 && image) { // center mode = 2
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, (mh-wta-height)/2+wta);
} else if (image) { // top center
int minh = MIN(height, mh-bh-imagegaps*2);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, (minh-height)/2+wta+imagegaps);
int minh = MIN(height, mh-bh-leftmargin*2);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, (minh-height)/2+wta+leftmargin);
}
}

View file

@ -183,7 +183,10 @@ static int longestedge = 0;
static int imagew = 0;
static int imageh = 0;
static int imageg = 0;
static int ow = 0;
static int oh = 0;
#endif
static int fullscreen = 0;
// config file
#if USECONFIG