From 81d23cb76d40331656efd61338c0fb1ccc3422c2 Mon Sep 17 00:00:00 2001 From: Christoph Lohmann <20h@r-36.net> Date: Sat, 13 Oct 2012 07:28:16 +0200 Subject: The right click menu to copy the link URI will now work. Thanks to Carlos Pita! --- surf.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/surf.c b/surf.c index 097ecc9..3cf452f 100644 --- a/surf.c +++ b/surf.c @@ -93,6 +93,8 @@ static Client *newclient(void); static void newwindow(Client *c, const Arg *arg, gboolean noembed); 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); @@ -513,6 +515,7 @@ newclient(void) { 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), "button-release-event", G_CALLBACK(buttonrelease), c); + g_signal_connect(G_OBJECT(c->view), "populate-popup", G_CALLBACK(populatepopup), c); /* Indicator */ c->indicator = gtk_drawing_area_new(); @@ -615,6 +618,45 @@ newwindow(Client *c, const Arg *arg, gboolean noembed) { spawn(NULL, &a); } +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; + GtkClipboard *prisel; + + 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")) { + prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text(prisel, c->linkhover, -1); + } +} + void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) { Arg arg = {.v = text }; -- cgit v1.2.3