The wMenuCreate function is splitted in two functions, one to create the menu, without the screen, and other to map the menu on the screen.
Signed-off-by: Rodolfo García Peñas (kix) <[email protected]> --- src/menu.c | 118 ++++++++++++++++++++++++++++++++++--------------------------- src/menu.h | 2 ++ 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/menu.c b/src/menu.c index 25ce9da..dd5a70f 100644 --- a/src/menu.c +++ b/src/menu.c @@ -120,28 +120,54 @@ static void appearanceObserver(void *self, WMNotification * notif) } /************************************/ - -/* - *---------------------------------------------------------------------- - * wMenuCreate-- - * Creates a new empty menu with the specified title. If main_menu - * is True, the created menu will be a main menu, which has some special - * properties such as being placed over other normal menus. - * If title is NULL, the menu will have no titlebar. - * - * Returns: - * The created menu. - *---------------------------------------------------------------------- - */ -WMenu *wMenuCreate(WScreen *screen, const char *title, int main_menu) +WMenu *menu_create(const char *title, int main_menu) { WMenu *menu; static int brother = 0; - int tmp, flags; int width = 1; menu = wmalloc(sizeof(WMenu)); + menu->frame = wframewindow_create(width, 1); + menu->menu = wcore_create(width, 10); + + if (title) { + menu->frame->title = wstrdup(title); + menu->flags.titled = 1; + } + + menu->frame->flags.justification = WTJ_LEFT; + menu->entry_no = 0; + menu->alloced_entries = 0; + menu->selected_entry = -1; + menu->entries = NULL; + menu->frame->child = menu; + menu->flags.lowered = 0; + + /* create borders */ + if (title) { + /* setup object descriptors */ + menu->frame->on_mousedown_titlebar = menuTitleMouseDown; + menu->frame->on_dblclick_titlebar = menuTitleDoubleClick; + } + + menu->frame->on_click_right = menuCloseClick; + + if (!brother) { + brother = 1; + menu->brother = menu_create(title, main_menu); + brother = 0; + menu->brother->flags.brother = 1; + menu->brother->brother = menu; + } + + return menu; +} + +void menu_map(WMenu *menu, WScreen *screen) +{ + int tmp, flags; + #ifdef SINGLE_MENULEVEL tmp = WMSubmenuLevel; #else @@ -149,13 +175,8 @@ WMenu *wMenuCreate(WScreen *screen, const char *title, int main_menu) #endif flags = WFF_SINGLE_STATE | WFF_BORDER; - if (title) { + if (menu->flags.titled) flags |= WFF_TITLEBAR | WFF_RIGHT_BUTTON; - menu->flags.titled = 1; - } - - menu->frame = wframewindow_create(width, 1); - menu->menu = wcore_create(width, 10); wframewindow_map(menu->frame, screen, tmp, 8, 2, &wPreferences.menu_title_clearance, @@ -171,35 +192,11 @@ WMenu *wMenuCreate(WScreen *screen, const char *title, int main_menu) wFrameWindowHideButton(menu->frame, WFF_RIGHT_BUTTON); - if (title) { - menu->frame->title = wstrdup(title); - } - - menu->frame->flags.justification = WTJ_LEFT; - menu->frame->rbutton_image = screen->b_pixmaps[WBUT_CLOSE]; - menu->entry_no = 0; - menu->alloced_entries = 0; - menu->selected_entry = -1; - menu->entries = NULL; - menu->frame_x = screen->app_menu_x; menu->frame_y = screen->app_menu_y; - menu->frame->child = menu; - - menu->flags.lowered = 0; - - /* create borders */ - if (title) { - /* setup object descriptors */ - menu->frame->on_mousedown_titlebar = menuTitleMouseDown; - menu->frame->on_dblclick_titlebar = menuTitleDoubleClick; - } - - menu->frame->on_click_right = menuCloseClick; - wcore_map(menu->menu, menu->frame->core, menu->frame->core->screen_ptr, 0, menu->frame->top_width, 0, @@ -218,16 +215,31 @@ WMenu *wMenuCreate(WScreen *screen, const char *title, int main_menu) XFlush(dpy); - if (!brother) { - brother = 1; - menu->brother = wMenuCreate(screen, title, main_menu); - brother = 0; - menu->brother->flags.brother = 1; - menu->brother->brother = menu; - } - WMAddNotificationObserver(appearanceObserver, menu, WNMenuAppearanceSettingsChanged, menu); + if (menu->brother && menu->brother->flags.brother) + menu_map(menu->brother, screen); + WMAddNotificationObserver(appearanceObserver, menu, WNMenuAppearanceSettingsChanged, menu); WMAddNotificationObserver(appearanceObserver, menu, WNMenuTitleAppearanceSettingsChanged, menu); +} + +/* + *---------------------------------------------------------------------- + * wMenuCreate-- + * Creates a new empty menu with the specified title. If main_menu + * is True, the created menu will be a main menu, which has some special + * properties such as being placed over other normal menus. + * If title is NULL, the menu will have no titlebar. + * + * Returns: + * The created menu. + *---------------------------------------------------------------------- + */ +WMenu *wMenuCreate(WScreen *screen, const char *title, int main_menu) +{ + WMenu *menu; + + menu = menu_create(title, main_menu); + menu_map(menu, screen); return menu; } diff --git a/src/menu.h b/src/menu.h index 9df9f65..a493f06 100644 --- a/src/menu.h +++ b/src/menu.h @@ -133,5 +133,7 @@ WMenu *wMenuUnderPointer(WScreen *screen); void wMenuSaveState(WScreen *scr); void wMenuRestoreState(WScreen *scr); +WMenu *menu_create(const char *title, int main_menu); +void menu_map(WMenu *menu, WScreen *screen); #endif -- 1.8.4.rc3 -- To unsubscribe, send mail to [email protected].
