diff --git a/apps/file-browser.c b/apps/file-browser.c index 86269e4e..1037cb3a 100644 --- a/apps/file-browser.c +++ b/apps/file-browser.c @@ -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); } } diff --git a/base/usr/include/toaru/menu.h b/base/usr/include/toaru/menu.h index 47280395..e6eaca0f 100644 --- a/base/usr/include/toaru/menu.h +++ b/base/usr/include/toaru/menu.h @@ -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); diff --git a/lib/menu.c b/lib/menu.c index d2a87bb9..53285963 100644 --- a/lib/menu.c +++ b/lib/menu.c @@ -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;