add the ability to have vertical/horizontal outer padding (margin)
This commit is contained in:
parent
92cdbd68c7
commit
273fb103c9
|
@ -245,6 +245,12 @@ You may use long, descriptive arguments or the shorter arguments.
|
|||
`-txp, --text-padding padding`
|
||||
: Set text padding to padding
|
||||
|
||||
`-vem, --vertical-margin margin`
|
||||
: Set the vertical margin
|
||||
|
||||
`-hem, --horizontal-margin margin`
|
||||
: Set the horizontal margin
|
||||
|
||||
`-lp, --vertical-padding padding`
|
||||
: Set the vertical padding
|
||||
|
||||
|
|
|
@ -87,6 +87,8 @@ spmenu.menuposition: 1
|
|||
spmenu.menupaddingv: 0
|
||||
spmenu.menupaddingh: 0
|
||||
spmenu.menuwidth: 0
|
||||
spmenu.menumarginv: 0
|
||||
spmenu.menumarginh: 0
|
||||
spmenu.xpos: 0
|
||||
spmenu.ypos: 0
|
||||
spmenu.minwidth: 1000
|
||||
|
|
|
@ -10,8 +10,10 @@ spmenu =
|
|||
// General window options
|
||||
window = ( { position = 1;
|
||||
border = 0;
|
||||
paddingv = 0;
|
||||
paddingh = 0;
|
||||
margin-vertical = 0;
|
||||
margin-horizontal = 0;
|
||||
padding-vertical = 0;
|
||||
padding-horizontal = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 0;
|
||||
|
|
|
@ -214,6 +214,10 @@ readargs(int argc, char *argv[])
|
|||
menupaddingv = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-hp") || (!strcmp(argv[i], "--horizontal-padding"))) { // horizontal padding
|
||||
menupaddingh = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-vem") || (!strcmp(argv[i], "--vertical-margin"))) { // vertical margin
|
||||
menumarginv = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-hom") || (!strcmp(argv[i], "--horizontal-margin"))) { // horizontal margin
|
||||
menumarginh = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-pri") || (!strcmp(argv[i], "--priority"))) { // high priority (csv format)
|
||||
hpitems = tokenize(argv[++i], ",", &hplength);
|
||||
} else if (!strcmp(argv[i], "-ig") || (!strcmp(argv[i], "--image-gaps"))) { // gaps between image
|
||||
|
@ -477,6 +481,8 @@ usage(void)
|
|||
"spmenu -txp, --text-padding <padding> Set text padding to <padding>\n"
|
||||
"spmenu -lp, --vertical-padding <padding> Set the vertical padding\n"
|
||||
"spmenu -hp, --horizontal-padding <padding> Set the horizontal padding\n"
|
||||
"spmenu -vem, --vertical-margin <margin> Set the vertical margin\n"
|
||||
"spmenu -hem, --horizontal-margin <margin> Set the horizontal margin\n"
|
||||
"spmenu -la, --left-arrow-symbol <symbol> Set the left arrow to <symbol>\n"
|
||||
"spmenu -ra, --right-arrow-symbol <symbol> Set the right arrow to <symbol>\n"
|
||||
"spmenu -is, --image-size <size> Image size\n"
|
||||
|
|
|
@ -70,7 +70,7 @@ resizeclient(void)
|
|||
if (image) resizetoimageheight(imageheight);
|
||||
#endif
|
||||
|
||||
mh = (lines + 1) * bh;
|
||||
mh = (lines + 1) * bh + 2 * menumarginv;
|
||||
|
||||
// why have an empty line? when there's nothing to draw there anyway?
|
||||
if (hideprompt && hideinput && hidemode && hidematchcount)
|
||||
|
|
|
@ -70,8 +70,14 @@ conf_init(void)
|
|||
|
||||
// look up
|
||||
config_setting_lookup_int(conf, "position", &menuposition); // spmenu.window.menuposition
|
||||
|
||||
config_setting_lookup_int(conf, "paddingv", &menupaddingv); // spmenu.window.paddingv
|
||||
config_setting_lookup_int(conf, "paddingh", &menupaddingh); // spmenu.window.paddingh
|
||||
config_setting_lookup_int(conf, "padding-vertical", &menupaddingv); // spmenu.window.padding-vertical
|
||||
config_setting_lookup_int(conf, "padding-horizontal", &menupaddingh); // spmenu.window.padding-horizontal
|
||||
config_setting_lookup_int(conf, "margin-vertical", &menumarginv); // spmenu.window.margin-vertical
|
||||
config_setting_lookup_int(conf, "margin-horizontal", &menumarginh); // spmenu.window.margin-horizontal
|
||||
|
||||
config_setting_lookup_int(conf, "x", &xpos); // spmenu.window.x
|
||||
config_setting_lookup_int(conf, "y", &xpos); // spmenu.window.y
|
||||
config_setting_lookup_int(conf, "width", &menuwidth); // spmenu.window.width
|
||||
|
|
24
libs/draw.c
24
libs/draw.c
|
@ -204,12 +204,13 @@ drawitem(int x, int y, int w)
|
|||
if (lines > 0) {
|
||||
int i = 0;
|
||||
int rx = 0;
|
||||
int ew = 0;
|
||||
|
||||
// draw image first
|
||||
#if USEIMAGE
|
||||
if (!hideimage && longestedge != 0) {
|
||||
rx = ox;
|
||||
rx += (imagegaps * 2) + imagewidth;
|
||||
rx += (imagegaps * 2) + imagewidth + menumarginh;
|
||||
} else
|
||||
#endif
|
||||
if (!indentitems) {
|
||||
|
@ -218,12 +219,16 @@ drawitem(int x, int y, int w)
|
|||
rx = x;
|
||||
}
|
||||
|
||||
if (!hidepowerline && (powerlinemode || powerlinecount)) {
|
||||
ew = plw / 2;
|
||||
}
|
||||
|
||||
for (item = curr; item != next; item = item->right, i++) {
|
||||
x = drawitemtext(
|
||||
item,
|
||||
rx + ((i / lines) * ((mw - rx) / columns)),
|
||||
y + (((i % lines) + 1) * bh),
|
||||
(mw - rx) / columns
|
||||
(mw - rx) / columns - (menumarginh + ew / 2)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -235,9 +240,9 @@ drawitem(int x, int y, int w)
|
|||
x = drawlarrow(x, y, w);
|
||||
|
||||
for (item = curr; item != next; item = item->right) // draw items
|
||||
x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text), mw - x - rarrowWidth - numberWidth - modeWidth));
|
||||
x = drawitemtext(item, x, y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text), mw - x - rarrowWidth - numberWidth - modeWidth - menumarginh));
|
||||
|
||||
w = rarrowWidth + numberWidth + modeWidth;
|
||||
w = rarrowWidth + numberWidth + modeWidth + menumarginh;
|
||||
x = drawrarrow(mw - w, y, w);
|
||||
}
|
||||
|
||||
|
@ -294,7 +299,7 @@ drawinput(int x, int y, int w)
|
|||
|
||||
if ((curpos += lrpad / 2 - 1) < w && !hidecaret && !hideprompt) {
|
||||
drw_setscheme(drw, scheme[SchemeCaret]);
|
||||
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
|
||||
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2 + y, 2, fh - 4, 1, 0);
|
||||
}
|
||||
|
||||
return x;
|
||||
|
@ -400,6 +405,9 @@ drawmenu(void)
|
|||
numberWidth = TEXTW(numbers);
|
||||
}
|
||||
|
||||
x += menumarginh;
|
||||
y += menumarginv;
|
||||
|
||||
// why have an empty line?
|
||||
if ((hideprompt && hideinput && hidemode && hidematchcount
|
||||
#if USEIMAGE
|
||||
|
@ -408,7 +416,7 @@ drawmenu(void)
|
|||
)) {
|
||||
#endif
|
||||
y -= bh;
|
||||
mh = (lines + 1) * bh - bh;
|
||||
mh = (lines + 1) * bh - bh + 2 * menumarginv;
|
||||
|
||||
if (!win) return;
|
||||
|
||||
|
@ -438,12 +446,12 @@ drawmenu(void)
|
|||
|
||||
if (!hidematchcount) {
|
||||
w = numberWidth;
|
||||
drawnumber(mw - numberWidth - modeWidth - 2 * sp - 2 * borderwidth, y, w);
|
||||
drawnumber(mw - numberWidth - modeWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
|
||||
}
|
||||
|
||||
if (!hidemode) {
|
||||
w = modeWidth;
|
||||
drawmode(mw - modeWidth - 2 * sp - 2 * borderwidth, y, w);
|
||||
drawmode(mw - modeWidth - 2 * sp - 2 * borderwidth - menumarginh, y, w);
|
||||
}
|
||||
|
||||
drw_map(drw, win, 0, 0, mw, mh);
|
||||
|
|
18
libs/img.c
18
libs/img.c
|
@ -94,13 +94,17 @@ drawimage(void)
|
|||
int leftmargin = imagegaps;
|
||||
int wtr = 0;
|
||||
int wta = 0;
|
||||
int xta = 0;
|
||||
|
||||
if (hideprompt && hideinput && hidemode && hidematchcount) {
|
||||
wtr = bh;
|
||||
} else {
|
||||
wta = bh;
|
||||
wta = bh + menumarginv;
|
||||
}
|
||||
|
||||
// margin
|
||||
xta += menumarginh;
|
||||
|
||||
if (mh != bh + height + imagegaps * 2 - wtr) { // menu height cannot be smaller than image height
|
||||
resizetoimageheight(height);
|
||||
}
|
||||
|
@ -109,16 +113,16 @@ drawimage(void)
|
|||
if (!imageposition) { // top mode = 0
|
||||
if (height > width)
|
||||
width = height;
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, wta+imagegaps);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, wta+imagegaps);
|
||||
} else if (imageposition == 1) { // bottom mode = 1
|
||||
if (height > width)
|
||||
width = height;
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, mh-height-imagegaps);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, mh-height-imagegaps);
|
||||
} else if (imageposition == 2) { // center mode = 2
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (mh-wta-height)/2+wta);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, (mh-wta-height)/2+wta);
|
||||
} else {
|
||||
int minh = MIN(height, mh-bh-imagegaps*2);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (minh-height)/2+wta+imagegaps);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2+xta, (minh-height)/2+wta+imagegaps);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -349,10 +353,10 @@ resizetoimageheight(int imageheight)
|
|||
wtr = bh;
|
||||
}
|
||||
|
||||
mh = MAX((lines + 1) * bh, ((lines + 1) * bh) - wtr);
|
||||
mh = MAX((lines + 1) * bh + 2 * menumarginv, ((lines + 1) * bh) - wtr + 2 * menumarginv);
|
||||
|
||||
if (mh - bh < imageheight + imagegaps * 2) {
|
||||
mh = (imageheight + imagegaps * 2 + bh) - wtr;
|
||||
mh = (imageheight + imagegaps * 2 + bh) - wtr + 2 * menumarginv;
|
||||
}
|
||||
|
||||
if (!win || omh == mh) {
|
||||
|
|
|
@ -39,9 +39,10 @@ motionevent(XButtonEvent *ev)
|
|||
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
|
||||
|
||||
xy = lines > 0 ? bh : inputw + promptw + larrowWidth;
|
||||
xy += menumarginv;
|
||||
ev_xy = lines > 0 ? ev->y : ev->x;
|
||||
for (item = curr; item && item != next; item = item->right) {
|
||||
int wh = lines > 0 ? bh : textw_clamp(item->text, mw - xy - rarrowWidth);
|
||||
int wh = lines > 0 ? bh : textw_clamp(item->text, mw - xy - rarrowWidth - menumarginh);
|
||||
if (ev_xy >= xy && ev_xy < (xy + wh)) {
|
||||
sel = item;
|
||||
calcoffsets();
|
||||
|
@ -65,6 +66,8 @@ buttonpress(XEvent *e)
|
|||
x = xpad = plw;
|
||||
}
|
||||
|
||||
x += menumarginh;
|
||||
|
||||
int larrowWidth = 0;
|
||||
int rarrowWidth = 0;
|
||||
int numberWidth = 0;
|
||||
|
|
|
@ -63,6 +63,8 @@ ResourcePref resources[] = {
|
|||
{ "menuwidth", INTEGER, &menuwidth },
|
||||
{ "menupaddingv", INTEGER, &menupaddingv },
|
||||
{ "menupaddingh", INTEGER, &menupaddingh },
|
||||
{ "menumarginv", INTEGER, &menumarginv },
|
||||
{ "menumarginh", INTEGER, &menumarginh },
|
||||
{ "textpadding", INTEGER, &textpadding },
|
||||
{ "indentitems", INTEGER, &indentitems },
|
||||
{ "accuratewidth", INTEGER, &accuratewidth },
|
||||
|
|
|
@ -15,9 +15,11 @@ static int mon = -1; /* Monitor to run spmenu on */
|
|||
/* Window options */
|
||||
static int alpha = 1; /* Enable alpha */
|
||||
static int menuposition = 1; /* Position of the menu (0: Bottom, 1: Top, 2: Center */
|
||||
static int menupaddingv = 0; /* Vertical padding of bar (in pixels) */
|
||||
static int menupaddingh = 0; /* Horizontal padding of bar (in pixels) */
|
||||
static int menupaddingv = 0; /* Vertical padding inside the menu (in pixels) */
|
||||
static int menupaddingh = 0; /* Horizontal padding inside the menu (in pixels) */
|
||||
static int menuwidth = 0; /* spmenu width when setting X/Y position */
|
||||
static int menumarginv = 0; /* Vertical padding around the menu */
|
||||
static int menumarginh = 0; /* Horizontal padding around the menu */
|
||||
static int minwidth = 1000; /* Minimum width when centered */
|
||||
static int xpos = 0; /* X position to offset spmenu */
|
||||
static int ypos = 0; /* Y position to offset spmenu */
|
||||
|
|
6
spmenu.1
6
spmenu.1
|
@ -263,6 +263,12 @@ Set image gaps to gaps
|
|||
\f[V]-txp, --text-padding padding\f[R]
|
||||
Set text padding to padding
|
||||
.TP
|
||||
\f[V]-vem, --vertical-margin margin\f[R]
|
||||
Set the vertical margin
|
||||
.TP
|
||||
\f[V]-hem, --horizontal-margin margin\f[R]
|
||||
Set the horizontal margin
|
||||
.TP
|
||||
\f[V]-lp, --vertical-padding padding\f[R]
|
||||
Set the vertical padding
|
||||
.TP
|
||||
|
|
2
spmenu.c
2
spmenu.c
|
@ -533,7 +533,7 @@ setupdisplay(void)
|
|||
if (image) resizetoimageheight(imageheight);
|
||||
#endif
|
||||
|
||||
mh = (lines + 1) * bh; // lines + 1 * bh is the menu height
|
||||
mh = (lines + 1) * bh + 2 * menumarginv; // lines + 1 * bh is the menu height
|
||||
|
||||
// set prompt width based on prompt size
|
||||
promptw = (prompt && *prompt)
|
||||
|
|
Loading…
Reference in a new issue