menu: smarter context menu spawning

This commit is contained in:
K. Lange 2019-01-07 14:04:55 +09:00
parent e3a966232d
commit c4ffc28b1f
3 changed files with 18 additions and 6 deletions

View File

@ -2016,12 +2016,7 @@ int main(int argc, char * argv[]) {
if (f && !f->selected) {
toggle_selected(hilighted_offset, me->modifiers);
}
menu_show(context_menu, main_window->ctx);
if (me->new_x + context_menu->window->width + main_window->x > main_window->ctx->display_width) {
yutani_window_move(main_window->ctx, context_menu->window, me->new_x + main_window->x - context_menu->window->width, me->new_y + main_window->y);
} else {
yutani_window_move(main_window->ctx, context_menu->window, me->new_x + main_window->x, me->new_y + main_window->y);
}
menu_show_at(context_menu, main_window, me->new_x, me->new_y);
}
}

View File

@ -75,6 +75,7 @@ extern struct MenuSet * menu_set_from_description(const char * path, void (*call
extern void menu_insert(struct MenuList * menu, struct MenuEntry * entry);
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);
extern struct MenuList * menu_set_get_root(struct MenuSet * menu);
extern struct MenuList * menu_set_get_menu(struct MenuSet * menu, char * submenu);

View File

@ -549,6 +549,22 @@ void menu_show(struct MenuList * menu, yutani_t * yctx) {
hashmap_set(menu_windows, (void*)menu_window->wid, menu_window);
}
void menu_show_at(struct MenuList * menu, yutani_window_t * parent, int x, int y) {
int final_x;
int final_y;
menu_show(menu, parent->ctx);
final_x = x + parent->x;
final_y = y + parent->y;
if (final_x + menu->window->width > parent->ctx->display_width) final_x -= menu->window->width;
if (final_y + menu->window->height > parent->ctx->display_height) final_y -= menu->window->height;
yutani_window_move(parent->ctx, menu->window, final_x, final_y);
}
int menu_has_eventual_child(struct MenuList * root, struct MenuList * child) {
if (!child) return 0;