panel: try some smarter popup placement
This commit is contained in:
parent
14027e83dc
commit
decf3517c6
18
apps/panel.c
18
apps/panel.c
@ -573,16 +573,22 @@ static void show_weather_status(void) {
|
|||||||
menu_update_title(weather_clouds_entry, weather_clouds_str);
|
menu_update_title(weather_clouds_entry, weather_clouds_str);
|
||||||
}
|
}
|
||||||
if (!weather->window) {
|
if (!weather->window) {
|
||||||
menu_show(weather, yctx);
|
int mwidth, mheight, offset;
|
||||||
if (weather->window) {
|
menu_calculate_dimensions(weather, &mheight, &mwidth);
|
||||||
if (weather_left + weather->window->width > (unsigned int)width - X_PAD) {
|
if (weather_left + mwidth > width - X_PAD) {
|
||||||
yutani_window_move(yctx, weather->window, weather_left + WIDGET_WIDTH * 2 - weather->window->width, DROPDOWN_OFFSET);
|
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;
|
weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_RIGHT;
|
||||||
} else {
|
} else {
|
||||||
yutani_window_move(yctx, weather->window, weather_left, DROPDOWN_OFFSET);
|
offset = weather_left + WIDGET_WIDTH - mwidth / 2;
|
||||||
weather->flags = (weather->flags & ~MENU_FLAG_BUBBLE) | MENU_FLAG_BUBBLE_LEFT;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 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_root(struct MenuSet * menu);
|
||||||
extern struct MenuList * menu_set_get_menu(struct MenuSet * menu, char * submenu);
|
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_entry(struct MenuEntry * ptr);
|
||||||
extern void menu_free_menu(struct MenuList * ptr);
|
extern void menu_free_menu(struct MenuList * ptr);
|
||||||
|
@ -350,7 +350,7 @@ static char * read_line(FILE * f, char * out, ssize_t len) {
|
|||||||
return out;
|
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;
|
list_t * list = menu->entries;
|
||||||
*width = 0;
|
*width = 0;
|
||||||
*height = (menu->flags & MENU_FLAG_BUBBLE) ? 16 : 8; /* TODO top and height */
|
*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) {
|
void menu_show(struct MenuList * menu, yutani_t * yctx) {
|
||||||
/* Calculate window dimensions */
|
/* Calculate window dimensions */
|
||||||
int height, width;
|
int height, width;
|
||||||
_menu_calculate_dimensions(menu,&height, &width);
|
menu_calculate_dimensions(menu,&height, &width);
|
||||||
|
|
||||||
my_yctx = yctx;
|
my_yctx = yctx;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user