#include "ubl-settings-bootloader.h" void on_menu_chosen(GtkWidget *widget, dictionary *dict) { yon_menu_item *item = yon_dictionary_get_data(dict->first, yon_menu_item *); main_window *widgets = yon_dictionary_get_data(dict->first->next, main_window *); gtk_entry_set_text(GTK_ENTRY(widgets->OSEntry), item->target); yon_menu_window *window = yon_dictionary_get_data(dict->first->next->next, yon_menu_window *); GdkDisplay *display = gdk_display_get_default(); GdkSeat *seat = gdk_display_get_default_seat(display); gdk_seat_ungrab(seat); gtk_widget_destroy(window->MenuWindow); } void on_submenu_open(GtkWidget *widget, dictionary *dict) { yon_menu_window *window = yon_dictionary_get_data(dict->first, yon_menu_window *); yon_menu_item *item = yon_dictionary_get_data(dict->first->next, yon_menu_item *); main_window *widgets = yon_dictionary_get_data(dict->first->next->next, main_window *); on_children_clean(NULL, window); dictionary *dact = NULL; for_dictionaries(dact, item->children) { yon_menu_item *child = yon_dictionary_get_data(dact, yon_menu_item *); gtk_list_box_insert(GTK_LIST_BOX(window->ChildrenListBox), child->MenuItemBox, -1); dictionary *child_dict = NULL; yon_dictionary_add_or_create_if_exists_with_data(child_dict, "item", child); yon_dictionary_add_or_create_if_exists_with_data(child_dict, "widgets", widgets); yon_dictionary_add_or_create_if_exists_with_data(child_dict, "window", window); g_signal_connect(G_OBJECT(child->MenuButton), "clicked", G_CALLBACK(on_menu_chosen), child_dict); } gtk_revealer_set_reveal_child(GTK_REVEALER(window->ItemsRevealer), FALSE); gtk_revealer_set_reveal_child(GTK_REVEALER(window->ChildrenRevealer), TRUE); } yon_menu_window *yon_menu_window_open(GtkWidget *widget, main_window *widgets) { yon_menu_window *window = yon_menu_window_new(); int size; config_str parsed = yon_config_load(get_menus_entry_command, &size); for (int i = 0; i < size; i++) { yon_char_remove_last_symbol(parsed[i], '\n'); int param_size; config_str parameter = yon_char_parse(parsed[i], ¶m_size, ">"); yon_menu_item *item = yon_dictionary_get(window->menu_items, parameter[0]); if (!item) { item = yon_menu_item_new(); gtk_widget_hide(item->NextIconButton); gtk_label_set_text(GTK_LABEL(item->MenuTextLabel), parameter[0]); item->target = yon_char_new(parameter[0]); gtk_list_box_insert(GTK_LIST_BOX(window->ItemsListBox), item->MenuItemBox, -1); yon_dictionary_add_or_create_if_exists_with_data(window->menu_items, parameter[0], item); gtk_widget_show(item->MenuItemBox); } if (param_size == 2) { if (!item->children) item->children = NULL; yon_menu_item *item_child = yon_menu_item_new(); gtk_widget_hide(item_child->NextIconButton); gtk_label_set_text(GTK_LABEL(item_child->MenuTextLabel), parameter[1]); item_child->target = yon_char_new(parameter[1]); yon_dictionary_add_or_create_if_exists_with_data(item->children, parameter[1], item_child); dictionary *sub_dict = NULL; yon_dictionary_add_or_create_if_exists_with_data(sub_dict, "window", window); yon_dictionary_add_or_create_if_exists_with_data(sub_dict, "item", item); yon_dictionary_add_or_create_if_exists_with_data(sub_dict, "widgets", widgets); g_signal_connect(G_OBJECT(item->MenuButton), "clicked", G_CALLBACK(on_submenu_open), sub_dict); } else { dictionary *item_dict = NULL; yon_dictionary_add_or_create_if_exists_with_data(item_dict, "item", item); yon_dictionary_add_or_create_if_exists_with_data(item_dict, "widgets", widgets); yon_dictionary_add_or_create_if_exists_with_data(item_dict, "window", window); g_signal_connect(G_OBJECT(item->MenuButton), "clicked", G_CALLBACK(on_menu_chosen), item_dict); } } int x, y, x2, y2, width; gdk_window_get_position(gtk_widget_get_window(widgets->MenuButton), &x, &y); gtk_widget_translate_coordinates(widgets->MenuButton, widgets->Window, x, y, &x2, &y2); gtk_window_get_size(GTK_WINDOW(window->MenuWindow), &width, NULL); gtk_window_get_position(GTK_WINDOW(widgets->Window), &x, &y); gtk_window_move(GTK_WINDOW(window->MenuWindow), x + x2 - width, y + y2); gtk_widget_realize(window->MenuWindow); gtk_widget_show(window->MenuWindow); gdk_seat_grab(gdk_display_get_default_seat(gdk_display_get_default()), gtk_widget_get_window(window->MenuWindow), GDK_SEAT_CAPABILITY_POINTER, TRUE, NULL, NULL, NULL, NULL); return window; }