diff -r 1fd52653b84d surf.c --- a/surf.c Fri Oct 12 11:48:38 2012 +0200 +++ b/surf.c Fri Oct 12 19:20:59 2012 -0300 @@ -92,6 +92,8 @@ static void newwindow(Client *c, const Arg *arg); static void newrequest(SoupSession *s, SoupMessage *msg, gpointer v); static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); +static void populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c); +static void popupactivate(GtkMenuItem *menu, Client *); static void print(Client *c, const Arg *arg); static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d); static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c); @@ -494,6 +496,7 @@ g_signal_connect(G_OBJECT(c->view), "notify::load-status", G_CALLBACK(loadstatuschange), c); g_signal_connect(G_OBJECT(c->view), "notify::progress", G_CALLBACK(progresschange), c); g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c); + g_signal_connect(G_OBJECT(c->view), "populate-popup", G_CALLBACK(populatepopup), c); /* Indicator */ c->indicator = gtk_drawing_area_new(); @@ -603,6 +606,39 @@ loaduri((Client *) d, &arg); } +static void +populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c) { + GList *items = gtk_container_get_children(GTK_CONTAINER(menu)); + + for (GList *l = items; l; l=l->next) { + g_signal_connect(l->data, "activate", G_CALLBACK(popupactivate), c); + } + g_list_free(items); +} + +static void +popupactivate(GtkMenuItem *menu, Client *c) { + // context-menu-action-2000 open link + // context-menu-action-1 open link in window + // context-menu-action-2 download linked file + // context-menu-action-3 copy link location + // context-menu-action-13 reload + // context-menu-action-10 back + // context-menu-action-11 forward + // context-menu-action-12 stop + GtkAction *a = NULL; + const char *name; + + a = gtk_activatable_get_related_action(GTK_ACTIVATABLE(menu)); + if (a == NULL) + return; + name = gtk_action_get_name(a); + if (!g_strcmp0(name, "context-menu-action-3")) { + GtkClipboard *prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text(prisel, c->linkhover, -1); + } +} + void print(Client *c, const Arg *arg) { webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));