From 590acffb62337e88474a066a60c15547f3abf8ec Mon Sep 17 00:00:00 2001 From: OldMan Date: Sat, 10 Apr 2010 16:43:03 +0600 Subject: [PATCH] Bugfix: Menu get out of the screen view area. Feature: New menu option 'align'. --- src/config.c | 9 +++++++++ src/menu.c | 29 +++++++++++++++++++++++------ src/structs.h | 4 ++++ wmfsrc.in | 3 +++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/config.c b/src/config.c index 3c09ddb..58d9f65 100644 --- a/src/config.c +++ b/src/config.c @@ -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); diff --git a/src/menu.c b/src/menu.c index d48a1a9..b19a34c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -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; } diff --git a/src/structs.h b/src/structs.h index 112b1e3..66dc845 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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 diff --git a/wmfsrc.in b/wmfsrc.in index e01df62..819134e 100644 --- a/wmfsrc.in +++ b/wmfsrc.in @@ -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"