Bugfix: Menu get out of the screen view area. Feature: New menu option 'align'.

This commit is contained in:
OldMan 2010-04-10 16:43:03 +06:00
parent a0258c13d0
commit 590acffb62
4 changed files with 39 additions and 6 deletions

View File

@ -533,6 +533,15 @@ conf_menu_section(char *src)
conf.menu[i].y = get_opt(tmp, "0", "y").num;
}
tmp2 = _strdup(get_opt(tmp, "center", "align").str);
if(!strcmp(tmp2 ,"left"))
conf.menu[i].align = MA_Left;
else if(!strcmp(tmp2, "right"))
conf.menu[i].align = MA_Right;
else
conf.menu[i].align = MA_Center;
conf.menu[i].colors.focus.bg = getcolor(get_opt(tmp, "#000000", "bg_focus").str);
conf.menu[i].colors.focus.fg = get_opt(tmp, "#ffffff", "fg_focus").str;
conf.menu[i].colors.normal.bg = getcolor(get_opt(tmp, "#000000", "bg_normal").str);

View File

@ -63,15 +63,21 @@ menu_new_item(MenuItem *mi, char *name, void *func, char *cmd)
void
menu_draw(Menu menu, int x, int y)
{
int i, width;
int i, width, height, out;
XEvent ev;
BarWindow *item[menu.nitem];
BarWindow *frame;
width = menu_get_longer_string(menu.item, menu.nitem) + PAD;
height = menu.nitem * (INFOBARH - SHADH);
/* Frame barwin */
frame = barwin_create(ROOT, x, y, width + SHADH, menu.nitem * (INFOBARH - SHADH) + SHADH * 2,
screen_get_sel();
if((out = x + width - spgeo[selscreen].width) > 0) x -= out;
if((out = y + height - spgeo[selscreen].height) > 0) y -= out;
frame = barwin_create(ROOT, x, y, width + SHADH, height + SHADH * 2,
menu.colors.normal.bg, menu.colors.normal.fg, False, False, True);
barwin_map(frame);
@ -219,12 +225,23 @@ menu_focus_item(Menu *menu, int item, BarWindow *winitem[])
void
menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[])
{
int x;
int width = menu_get_longer_string(menu->item, menu->nitem) + PAD;
barwin_draw_text(winitem[item],
((width / 2) - (textw(menu->item[item].name) / 2)),
FHINFOBAR,
menu->item[item].name);
switch(menu->align)
{
case MA_Left:
x = PAD / 2;
break;
case MA_Right:
x = width - textw(menu->item[item].name) + PAD / 2;
break;
default:
case MA_Center:
x = width / 2 - textw(menu->item[item].name) / 2 + PAD / 2;
break;
}
barwin_draw_text(winitem[item], x, FHINFOBAR, menu->item[item].name);
return;
}

View File

@ -87,6 +87,9 @@ typedef unsigned char uchar;
enum { CurNormal, CurResize, CurRightResize, CurLeftResize, CurMove, CurLast };
enum { TagSel, TagTransfert, TagAdd, TagNext, TagPrev, TagActionLast };
/* Menu align */
enum { MA_Center = 0, MA_Left = 1, MA_Right = 2 };
/* Infobar position */
enum { IB_Hide = 0, IB_Bottom = 1, IB_Top = 2 };
@ -283,6 +286,7 @@ typedef struct
char *name;
/* Placement */
Bool place_at_mouse;
int align;
int x, y;
/* Color */
struct

View File

@ -142,6 +142,9 @@
# place_at_mouse = false
# x = 40 y = 50
# Available "center", "left", "right" menu align. Default: "center".
align = "left"
fg_focus = "#191919" bg_focus = "#7E89A2"
fg_normal = "#9F9AB3" bg_normal = "#191919"