GtkWidget* systray_menu_add_submenu(GtkMenuShell* menu, menu_info_t* mi, const char* name, const char* tooltip, const char* icon) { GtkWidget* submenu = gtk_menu_new(); mi->menu = GTK_MENU_SHELL(submenu); mi->group = NULL; /* if this is the first item, remove the "none" placeholder label */ if(mi->parent) { menu_info_t* parent_mi = mi->parent->menu_info; if(g_hash_table_size(parent_mi->items) == 0) { GList* children = gtk_container_get_children(GTK_CONTAINER(parent_mi->menu)); if(children) gtk_container_remove(GTK_CONTAINER(parent_mi->menu), GTK_WIDGET(children->data)); } } GtkWidget* item = systray_add_menu_item(menu, name, tooltip, icon); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); return item; }
GtkWidget* systray_menu_add_item(GtkMenuShell* menu, const char* name, const char* icon, bool sensitive) { GtkWidget* item = systray_add_menu_item(menu, name, NULL, icon); gtk_widget_set_sensitive(item, sensitive); return item; }
void menu_info_item_add(menu_info_t* mi, uint32_t index, const char* name, const char* desc, const pa_cvolume* vol, int mute, char* tooltip, const char* icon, const char* address, uint32_t target) { menu_infos_t* mis = mi->menu_infos; menu_info_item_t* item = g_new(menu_info_item_t, 1); menu_info_item_init(item); item->menu_info = mi; g_debug("[menu_info] adding %s %u %s (target: %d)", menu_info_type_name(mi->type), index, desc, (int)target); item->index = index; item->name = g_strdup(name); item->desc = g_strdup(desc); item->volume = g_memdup(vol, sizeof(pa_cvolume)); item->target = target; item->mute = mute; item->icon = g_strdup(icon); item->address = g_strdup(address); menu_type_t submenu_type = menu_info_submenu_type(mi->type); menu_info_t* submenu = &mis->menu_info[submenu_type]; switch(item->menu_info->type) { case MENU_INPUT: case MENU_OUTPUT: item->submenu = menu_info_create(mis, submenu_type); item->submenu->parent = item; break; default: break; } switch(mi->type) { case MENU_SERVER: item->widget = systray_add_radio_item(mi, desc, tooltip); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item->widget), (item->address == mi->default_name) || (item->address && mi->default_name && g_str_equal(mi->default_name, item->address))); break; case MENU_SINK: case MENU_SOURCE: item->context = menu_info_item_context_menu(item); item->widget = systray_add_radio_item(mi, desc, tooltip); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item->widget), g_str_equal(mi->default_name, item->name)); systray_add_item_to_all_submenus(item, submenu); break; case MENU_INPUT: case MENU_OUTPUT: item->widget = systray_menu_add_submenu(mi->menu, item->submenu, desc, tooltip, icon); systray_add_all_items_to_submenu(submenu, item); break; case MENU_MODULE: item->context = menu_info_item_context_menu(item); item->widget = systray_add_menu_item(mi, desc, tooltip, icon); break; } g_signal_connect(item->widget, "button-press-event", G_CALLBACK(menu_info_item_clicked), item); gtk_widget_add_events(item->widget, GDK_SCROLL_MASK); g_signal_connect(item->widget, "scroll-event", G_CALLBACK(menu_info_item_scrolled), item); if(mi->type == MENU_SERVER) g_hash_table_insert(mi->items, item->name, item); else g_hash_table_insert(mi->items, GUINT_TO_POINTER(index), item); /* if this is the default sink, update status icon acording to volume */ if(mi->type == MENU_SINK && item == menu_info_item_get_by_name(mi, mi->default_name)) ui_update_systray_icon(item); }