diff --git a/apps/panel.c b/apps/panel.c index 58e8af78..76c8272a 100644 --- a/apps/panel.c +++ b/apps/panel.c @@ -573,16 +573,22 @@ static void show_weather_status(void) { menu_update_title(weather_clouds_entry, weather_clouds_str); } if (!weather->window) { - menu_show(weather, yctx); - if (weather->window) { - if (weather_left + weather->window->width > (unsigned int)width - X_PAD) { - yutani_window_move(yctx, weather->window, weather_left + WIDGET_WIDTH * 2 - weather->window->width, DROPDOWN_OFFSET); + int mwidth, mheight, offset; + menu_calculate_dimensions(weather, &mheight, &mwidth); + if (weather_left + mwidth > width - X_PAD) { + if (weather_left + mwidth / 2 > width - X_PAD) { + offset = weather_left + WIDGET_WIDTH * 2 - mwidth / 2; weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_RIGHT; } else { - yutani_window_move(yctx, weather->window, weather_left, DROPDOWN_OFFSET); - weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_LEFT; + offset = weather_left + WIDGET_WIDTH - mwidth / 2; + weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_CENTER; } + } else { + offset = weather_left; + weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_LEFT; } + menu_show(weather, yctx); + yutani_window_move(yctx, weather->window, offset, DROPDOWN_OFFSET); } } diff --git a/base/usr/include/toaru/menu.h b/base/usr/include/toaru/menu.h index 2dcd9d4f..6e5d39b8 100644 --- a/base/usr/include/toaru/menu.h +++ b/base/usr/include/toaru/menu.h @@ -81,6 +81,7 @@ extern void menu_show_at(struct MenuList * menu, yutani_window_t * parent, int x extern int menu_process_event(yutani_t * yctx, yutani_msg_t * m); extern struct MenuList * menu_set_get_root(struct MenuSet * menu); extern struct MenuList * menu_set_get_menu(struct MenuSet * menu, char * submenu); +extern void menu_calculate_dimensions(struct MenuList * menu, int * height, int * width); extern void menu_free_entry(struct MenuEntry * ptr); extern void menu_free_menu(struct MenuList * ptr); diff --git a/lib/menu.c b/lib/menu.c index 21bef9c8..9f6f69f8 100644 --- a/lib/menu.c +++ b/lib/menu.c @@ -350,7 +350,7 @@ static char * read_line(FILE * f, char * out, ssize_t len) { return out; } -static void _menu_calculate_dimensions(struct MenuList * menu, int * height, int * width) { +void menu_calculate_dimensions(struct MenuList * menu, int * height, int * width) { list_t * list = menu->entries; *width = 0; *height = (menu->flags & MENU_FLAG_BUBBLE) ? 16 : 8; /* TODO top and height */ @@ -561,7 +561,7 @@ static void _menu_redraw(yutani_window_t * menu_window, yutani_t * yctx, struct void menu_show(struct MenuList * menu, yutani_t * yctx) { /* Calculate window dimensions */ int height, width; - _menu_calculate_dimensions(menu,&height, &width); + menu_calculate_dimensions(menu,&height, &width); my_yctx = yctx;