panel: try some smarter popup placement

This commit is contained in:
K. Lange 2021-07-25 20:38:33 +09:00
parent 14027e83dc
commit decf3517c6
3 changed files with 15 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;