menu: Really, seriously don't show menus before moving them

This commit is contained in:
K Lange 2021-08-19 00:13:03 +09:00
parent e171d91af7
commit e4fd48a007
4 changed files with 52 additions and 29 deletions

View File

@ -262,8 +262,11 @@ static void _window_menu_close(struct MenuEntry * self) {
static void window_show_menu(yutani_wid_t wid, int y, int x) {
if (window_menu->window) return;
_window_menu_wid = wid;
menu_show(window_menu, yctx);
yutani_window_move(yctx, window_menu->window, y, x);
menu_prepare(window_menu, yctx);
if (window_menu->window) {
yutani_window_move(yctx, window_menu->window, y, x);
yutani_flip(yctx, window_menu->window);
}
}
@ -335,13 +338,14 @@ static void show_volume_status(void) {
/* TODO We could also show a nice slider... if we had one... */
if (!volume_menu->window) {
menu_show(volume_menu, yctx);
menu_prepare(volume_menu, yctx);
if (volume_menu->window) {
if (volume_left + volume_menu->window->width > (unsigned int)width) {
yutani_window_move(yctx, volume_menu->window, width - volume_menu->window->width, DROPDOWN_OFFSET);
} else {
yutani_window_move(yctx, volume_menu->window, volume_left, DROPDOWN_OFFSET);
}
yutani_flip(yctx,volume_menu->window);
}
}
}
@ -501,36 +505,40 @@ static void update_network_status(void) {
static void show_logout_menu(void) {
if (!logout_menu->window) {
menu_show(logout_menu, yctx);
menu_prepare(logout_menu, yctx);
if (logout_menu->window) {
yutani_window_move(yctx, logout_menu->window, width - logout_menu->window->width - X_PAD, DROPDOWN_OFFSET);
yutani_flip(yctx, logout_menu->window);
}
}
}
static void show_app_menu(void) {
if (!appmenu->window) {
menu_show(appmenu, yctx);
menu_prepare(appmenu, yctx);
if (appmenu->window) {
yutani_window_move(yctx, appmenu->window, X_PAD, DROPDOWN_OFFSET);
yutani_flip(yctx, appmenu->window);
}
}
}
static void show_cal_menu(void) {
if (!calmenu->window) {
menu_show(calmenu, yctx);
menu_prepare(calmenu, yctx);
if (calmenu->window) {
yutani_window_move(yctx, calmenu->window, width - TIME_LEFT - date_widget_width / 2 - calmenu->window->width / 2, DROPDOWN_OFFSET);
yutani_flip(yctx, calmenu->window);
}
}
}
static void show_clock_menu(void) {
if (!clockmenu->window) {
menu_show(clockmenu, yctx);
menu_prepare(clockmenu, yctx);
if (clockmenu->window) {
yutani_window_move(yctx, clockmenu->window, width - LOGOUT_WIDTH - clockmenu->window->width, DROPDOWN_OFFSET);
yutani_flip(yctx, clockmenu->window);
}
}
}
@ -589,8 +597,11 @@ static void show_weather_status(void) {
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);
menu_prepare(weather, yctx);
if (weather->window) {
yutani_window_move(yctx, weather->window, offset, DROPDOWN_OFFSET);
yutani_flip(yctx, weather->window);
}
}
}
@ -614,13 +625,14 @@ static void show_network_status(void) {
}
}
if (!netstat->window) {
menu_show(netstat, yctx);
menu_prepare(netstat, yctx);
if (netstat->window) {
if (netstat_left + netstat->window->width > (unsigned int)width) {
yutani_window_move(yctx, netstat->window, width - netstat->window->width, DROPDOWN_OFFSET);
} else {
yutani_window_move(yctx, netstat->window, netstat_left, DROPDOWN_OFFSET);
}
yutani_flip(yctx, netstat->window);
}
}
}

View File

@ -2109,11 +2109,14 @@ static void * handle_incoming(void) {
scroll_down(5);
} else if (me->buttons & YUTANI_MOUSE_BUTTON_RIGHT) {
if (!menu_right_click->window) {
menu_show(menu_right_click, yctx);
if (window->x + me->new_x + menu_right_click->window->width > yctx->display_width) {
yutani_window_move(yctx, menu_right_click->window, window->x + me->new_x - menu_right_click->window->width, window->y + me->new_y);
} else {
yutani_window_move(yctx, menu_right_click->window, window->x + me->new_x, window->y + me->new_y);
menu_prepare(menu_right_click, yctx);
if (menu_right_click->window) {
if (window->x + me->new_x + menu_right_click->window->width > yctx->display_width) {
yutani_window_move(yctx, menu_right_click->window, window->x + me->new_x - menu_right_click->window->width, window->y + me->new_y);
} else {
yutani_window_move(yctx, menu_right_click->window, window->x + me->new_x, window->y + me->new_y);
}
yutani_flip(yctx, menu_right_click->window);
}
}
}

View File

@ -76,6 +76,7 @@ extern struct MenuList * menu_create(void);
extern struct MenuSet * menu_set_from_description(const char * path, void (*callback)(struct MenuEntry *));
extern void menu_insert(struct MenuList * menu, struct MenuEntry * entry);
extern void menu_prepare(struct MenuList * menu, yutani_t * yctx);
extern void menu_show(struct MenuList * menu, yutani_t * yctx);
extern void menu_show_at(struct MenuList * menu, yutani_window_t * parent, int x, int y);
extern int menu_process_event(yutani_t * yctx, yutani_msg_t * m);

View File

@ -182,7 +182,7 @@ void _menu_activate_MenuEntry_Submenu(struct MenuEntry * self, int focused) {
new_menu->parent->child = new_menu;
_self->_my_child = new_menu;
if (new_menu->closed) {
menu_show(new_menu, _self->_owner->window->ctx);
menu_prepare(new_menu, _self->_owner->window->ctx);
int offset_x = _self->_owner->window->width - 2;
if (_self->_owner->window->width + _self->_owner->window->x - 2 + new_menu->window->width > _self->_owner->window->ctx->display_width) {
offset_x = 2 - new_menu->window->width;
@ -507,7 +507,7 @@ failure:
return NULL;
}
static void _menu_redraw(yutani_window_t * menu_window, yutani_t * yctx, struct MenuList * menu) {
static void _menu_redraw(yutani_window_t * menu_window, yutani_t * yctx, struct MenuList * menu, int expose) {
gfx_context_t * ctx = menu->ctx;
list_t * entries = menu->entries;
@ -552,12 +552,14 @@ static void _menu_redraw(yutani_window_t * menu_window, yutani_t * yctx, struct
offset += entry->height;
}
/* Expose menu */
flip(ctx);
yutani_flip(yctx, menu_window);
if (expose) {
yutani_flip(yctx, menu_window);
}
}
void menu_show(struct MenuList * menu, yutani_t * yctx) {
void menu_prepare(struct MenuList * menu, yutani_t * yctx) {
/* Calculate window dimensions */
int height, width;
menu_calculate_dimensions(menu,&height, &width);
@ -579,14 +581,19 @@ void menu_show(struct MenuList * menu, yutani_t * yctx) {
menu_window->user_data = menu;
menu->window = menu_window;
_menu_redraw(menu_window, yctx, menu);
_menu_redraw(menu_window, yctx, menu, 0);
hashmap_set(menu_windows, (void*)(uintptr_t)menu_window->wid, menu_window);
}
void menu_show(struct MenuList * menu, yutani_t * yctx) {
menu_prepare(menu, yctx);
yutani_flip(yctx, menu->window);
}
void menu_show_at(struct MenuList * menu, yutani_window_t * parent, int x, int y) {
menu_show(menu, parent->ctx);
menu_prepare(menu, parent->ctx);
if (parent->x + x + menu->window->width > parent->ctx->display_width) x -= menu->window->width;
if (parent->y + y + menu->window->height > parent->ctx->display_height) y -= menu->window->height;
@ -708,7 +715,7 @@ void menu_key_action(struct MenuList * menu, struct yutani_msg_key_event * me) {
hilighted = menu->entries->head->value;
}
hilighted->hilight = 1;
_menu_redraw(window,yctx,menu);
_menu_redraw(window,yctx,menu,1);
} else if (me->event.keycode == KEY_ARROW_UP) {
if (hilighted) {
hilighted->hilight = 0;
@ -719,7 +726,7 @@ void menu_key_action(struct MenuList * menu, struct yutani_msg_key_event * me) {
hilighted = menu->entries->tail->value;
}
hilighted->hilight = 1;
_menu_redraw(window,yctx,menu);
_menu_redraw(window,yctx,menu,1);
} else if (me->event.keycode == KEY_ARROW_RIGHT) {
if (!hilighted) {
hilighted = menu->entries->head->value;
@ -728,7 +735,7 @@ void menu_key_action(struct MenuList * menu, struct yutani_msg_key_event * me) {
hilighted->hilight = 1;
if (hilighted->_type == MenuEntry_Submenu) {
hilighted->activate(hilighted, 0);
_menu_redraw(window,yctx,menu);
_menu_redraw(window,yctx,menu,1);
} else {
struct menu_bar * bar = NULL;
struct MenuList * p = menu;
@ -747,7 +754,7 @@ void menu_key_action(struct MenuList * menu, struct yutani_msg_key_event * me) {
}
menu_bar_show_menu(yctx, bar->window, bar, -1, bar->active_entry);
} else {
_menu_redraw(window,yctx,menu);
_menu_redraw(window,yctx,menu,1);
}
}
}
@ -810,14 +817,14 @@ void menu_mouse_action(struct MenuList * menu, struct yutani_msg_window_mouse_ev
offset += entry->height;
}
if (changed) {
_menu_redraw(window,yctx,menu);
_menu_redraw(window,yctx,menu,1);
}
}
void menu_force_redraw(struct MenuList * menu) {
yutani_window_t * window = menu->window;
yutani_t * yctx = window->ctx;
_menu_redraw(window,yctx,menu);
_menu_redraw(window,yctx,menu,1);
}
struct MenuList * menu_any_contains(int x, int y) {
@ -964,7 +971,7 @@ void menu_bar_show_menu(yutani_t * yctx, yutani_window_t * window, struct menu_b
}
}
menu_show(new_menu, yctx);
menu_prepare(new_menu, yctx);
yutani_window_move_relative(yctx, new_menu->window, window, offset, self->y + MENU_BAR_HEIGHT);
yutani_flip(yctx, new_menu->window);