forked from speedie/spmenu
resize window to fit image if necessary
This commit is contained in:
parent
8599d73be9
commit
4a0df5c1d5
45
libs/img.c
45
libs/img.c
|
@ -168,3 +168,48 @@ loadimagecache(const char *file, int *width, int *height)
|
||||||
imlib_save_image(buf);
|
imlib_save_image(buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
jumptoindex(unsigned int index) {
|
||||||
|
unsigned int i;
|
||||||
|
sel = curr = matches;
|
||||||
|
calcoffsets();
|
||||||
|
for(i = 1; i < index; ++i) {
|
||||||
|
if(sel && sel->right && (sel = sel->right) == next) {
|
||||||
|
curr = next;
|
||||||
|
calcoffsets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
resizetoimageheight(int imageheight)
|
||||||
|
{
|
||||||
|
int omh = mh, olines = lines;
|
||||||
|
lines = reallines;
|
||||||
|
|
||||||
|
if(lines * bh < imageheight + imagegaps * 2)
|
||||||
|
lines = (imageheight+imagegaps*2)/bh;
|
||||||
|
|
||||||
|
mh = (lines + 1) * bh;
|
||||||
|
|
||||||
|
if(mh - bh < imageheight + imagegaps * 2)
|
||||||
|
mh = imageheight+imagegaps*2+bh;
|
||||||
|
|
||||||
|
if(!win || omh == mh)
|
||||||
|
return;
|
||||||
|
|
||||||
|
XResizeWindow(dpy, win, mw, mh);
|
||||||
|
drw_resize(drw, mw, mh);
|
||||||
|
|
||||||
|
if (olines != lines) {
|
||||||
|
struct item *item;
|
||||||
|
unsigned int i = 1;
|
||||||
|
for (item = matches; item && item != sel; item = item->right)
|
||||||
|
++i;
|
||||||
|
|
||||||
|
jumptoindex(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
|
11
spmenu.c
11
spmenu.c
|
@ -103,6 +103,7 @@ static char numbers[NUMBERSBUFSIZE] = "";
|
||||||
static char *embed;
|
static char *embed;
|
||||||
static int numlockmask = 0;
|
static int numlockmask = 0;
|
||||||
static int bh, mw, mh;
|
static int bh, mw, mh;
|
||||||
|
static int reallines = 0;
|
||||||
static int reqlineheight; /* required menu height */
|
static int reqlineheight; /* required menu height */
|
||||||
static int clineheight; /* menu height added through argument */
|
static int clineheight; /* menu height added through argument */
|
||||||
static int dmx = 0; /* put spmenu at this x offset */
|
static int dmx = 0; /* put spmenu at this x offset */
|
||||||
|
@ -159,6 +160,7 @@ static void complete(const Arg *arg);
|
||||||
static void savehistory(char *input);
|
static void savehistory(char *input);
|
||||||
|
|
||||||
static void drawmenu(void);
|
static void drawmenu(void);
|
||||||
|
static void calcoffsets(void);
|
||||||
|
|
||||||
#include "libs/xrdb.h"
|
#include "libs/xrdb.h"
|
||||||
|
|
||||||
|
@ -1504,6 +1506,10 @@ run(void)
|
||||||
} if (image && longestedge) {
|
} if (image && longestedge) {
|
||||||
int leftmargin = imagegaps;
|
int leftmargin = imagegaps;
|
||||||
|
|
||||||
|
if(mh != bh + height + imagegaps * 2) {
|
||||||
|
resizetoimageheight(height);
|
||||||
|
}
|
||||||
|
|
||||||
if (!imageposition) { /* top mode = 0 */
|
if (!imageposition) { /* top mode = 0 */
|
||||||
if (height > width)
|
if (height > width)
|
||||||
width = height;
|
width = height;
|
||||||
|
@ -1612,6 +1618,11 @@ setup(void)
|
||||||
/* calculate menu geometry */
|
/* calculate menu geometry */
|
||||||
bh = drw->font->h + 2 + reqlineheight;
|
bh = drw->font->h + 2 + reqlineheight;
|
||||||
lines = MAX(lines, 0);
|
lines = MAX(lines, 0);
|
||||||
|
reallines = lines;
|
||||||
|
#if USEIMAGE
|
||||||
|
if (image)
|
||||||
|
resizetoimageheight(imageheight);
|
||||||
|
#endif
|
||||||
mh = (lines + 1) * bh;
|
mh = (lines + 1) * bh;
|
||||||
promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0;
|
promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue