+ self->priv->selected_app_info);
+}
+
+static GAppInfo *
+get_app_info_for_event (GtkAppChooserWidget *self,
+ GdkEventButton *event)
+{
+ GtkTreePath *path = NULL;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GAppInfo *info;
+ gboolean recommended;
+
+ if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (self->priv->program_list),
+ event->x, event->y,
+ &path,
+ NULL, NULL, NULL))
+ return NULL;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->priv->program_list));
+
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ {
+ gtk_tree_path_free (path);
+ return NULL;
+ }
+
+ /* we only allow interaction with recommended applications */
+ gtk_tree_model_get (model, &iter,
+ COLUMN_APP_INFO, &info,
+ COLUMN_RECOMMENDED, &recommended,
+ -1);
+
+ if (!recommended)
+ g_clear_object (&info);
+
+ return info;
+}
+
+static gboolean
+widget_button_press_event_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ GtkAppChooserWidget *self = user_data;
+
+ if (event->button == GDK_BUTTON_SECONDARY && event->type == GDK_BUTTON_PRESS)
+ {
+ GAppInfo *info;
+ GtkWidget *menu;
+ GList *children;
+ gint n_children;
+
+ info = get_app_info_for_event (self, event);
+
+ if (info == NULL)
+ return FALSE;
+
+ menu = gtk_menu_new ();
+
+ g_signal_emit (self, signals[SIGNAL_POPULATE_POPUP], 0,
+ menu, info);
+
+ g_object_unref (info);
+
+ /* see if clients added menu items to this container */
+ children = gtk_container_get_children (GTK_CONTAINER (menu));
+ n_children = g_list_length (children);
+
+ if (n_children > 0)
+ {
+ /* actually popup the menu */
+ gtk_menu_attach_to_widget (GTK_MENU (menu), self->priv->program_list, NULL);
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
+ event->button, event->time);
+ }
+
+ g_list_free (children);
+ }
+
+ return FALSE;