From 7097296cc83f50855caf95549f3d4fbecec7300c Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 29 Jul 2009 17:42:50 +0200 Subject: [PATCH] Menu: Fix segfault if there is no menu {} section in config. --- src/config.c | 5 +---- src/event.c | 6 +++--- src/menu.c | 9 ++++++--- src/structs.h | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/config.c b/src/config.c index 138fa87..4d25bb8 100644 --- a/src/config.c +++ b/src/config.c @@ -298,8 +298,6 @@ conf_layout_section(cfg_t *cfg_l) conf.colors.bar, conf.colors.text); - menulayout.special = True; - if(!conf.layout[0].symbol && !conf.layout[0].func) { @@ -425,9 +423,8 @@ conf_menu_section(cfg_t *cfg_m) conf.nmenu = cfg_size(cfg_m, "set_menu"); CHECK(conf.nmenu); - conf.menu = emalloc(conf.nmenu + 1, sizeof(Menu)); + conf.menu = emalloc(conf.nmenu, sizeof(Menu)); - conf.menu[conf.nmenu] = menulayout; for(i = 0; i < conf.nmenu; ++i) { diff --git a/src/event.c b/src/event.c index 2e4b107..f6d096a 100644 --- a/src/event.c +++ b/src/event.c @@ -113,11 +113,11 @@ buttonpress(XButtonEvent *ev) { if(conf.layout_system && (ev->button == Button1 || ev->button == Button3)) /* True -> menu */ { - conf.menu[conf.nmenu].y = spgeo[selscreen].y + infobar[selscreen].layout_button->geo.y + INFOBARH; - conf.menu[conf.nmenu].x = infobar[selscreen].layout_button->geo.x + (sgeo[selscreen].x - BORDH); + menulayout.y = spgeo[selscreen].y + infobar[selscreen].layout_button->geo.y + INFOBARH; + menulayout.x = infobar[selscreen].layout_button->geo.x + (sgeo[selscreen].x - BORDH); if(infobar[selscreen].geo.y != spgeo[selscreen].y) - conf.menu[conf.nmenu].y = infobar[selscreen].geo.y - (INFOBARH * menulayout.nitem) - SHADH; + menulayout.y = infobar[selscreen].geo.y - (INFOBARH * menulayout.nitem) - SHADH; uicb_menu("menulayout"); } diff --git a/src/menu.c b/src/menu.c index 0beca3d..0ef54c9 100644 --- a/src/menu.c +++ b/src/menu.c @@ -247,7 +247,10 @@ uicb_menu(uicb_t cmd) int i, d, u, x, y; Window w; - for(i = 0; i < conf.nmenu + conf.layout_system; ++i) + if(!strcmp(cmd, "menulayout")) + menu_draw(menulayout, menulayout.x, menulayout.y); + + for(i = 0; i < conf.nmenu; ++i) if(!strcmp(cmd, conf.menu[i].name)) { if(conf.menu[i].place_at_mouse) @@ -255,8 +258,8 @@ uicb_menu(uicb_t cmd) else { screen_get_sel(); - x = conf.menu[i].x + ((conf.menu[i].special) ? 0 : spgeo[selscreen].x); - y = conf.menu[i].y + ((conf.menu[i].special) ? 0 : spgeo[selscreen].y);; + x = conf.menu[i].x + spgeo[selscreen].x; + y = conf.menu[i].y + spgeo[selscreen].y; } menu_draw(conf.menu[i], x, y); } diff --git a/src/structs.h b/src/structs.h index d2206f1..2756338 100644 --- a/src/structs.h +++ b/src/structs.h @@ -237,7 +237,6 @@ typedef struct char *name; /* Placement */ Bool place_at_mouse; - Bool special; int x, y; /* Color */ struct