On Mon, May 17, 2010 at 09:40:01AM +0200, Enno Boland (Gottox) wrote: > > 2010/5/17 pancake <panc...@youterm.com>: > > Copy URL doesn't works for images > I'm open for patches to copy a pictures URI. I think, I will strip > down things in surf.
Here is a possibility, i just removed the context menu and a few lines to get rid of warnings at compile and got the gtk menu with a "copy img link" entry. I'm not a coder and that was done with a hammer, but it works. I guess you have good reasons to have your own context menu, but the default gtk one with the underlined letters is keyboard friendlier to me as one just need to hit the underlined letter to select an entry.
diff -up surf/config.def.h surf_img_link/config.def.h --- surf/config.def.h 2010-05-17 09:23:49.000000000 +0200 +++ surf_img_link/config.def.h 2010-05-17 10:11:24.000000000 +0200 @@ -19,6 +19,7 @@ static Key keys[] = { { MODKEY|GDK_SHIFT_MASK,GDK_r, reload, { .b = TRUE } }, { MODKEY, GDK_r, reload, { .b = FALSE } }, { MODKEY|GDK_SHIFT_MASK,GDK_p, print, { 0 } }, + { MODKEY, GDK_d, download, { 0 } }, { MODKEY, GDK_p, clipboard, { .b = TRUE } }, { MODKEY, GDK_y, clipboard, { .b = FALSE } }, { MODKEY|GDK_SHIFT_MASK,GDK_j, zoom, { .i = -1 } }, @@ -35,14 +36,3 @@ static Key keys[] = { { MODKEY, GDK_n, find, { .b = TRUE } }, { MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } }, }; - -static Item items[] = { - { "Back", navigate, { .i = -1 } }, - { "Forward", navigate, { .i = +1 } }, - { "New Window", newwindow, { .v = NULL } }, - { "Reload", reload, { .b = FALSE } }, - { "Stop", stop, { 0 } }, - { "Paste URI", clipboard, { .b = TRUE } }, - { "Copy URI", clipboard, { .b = FALSE } }, - { "Download", download, { 0 } }, -}; diff -up surf/surf.c surf_img_link/surf.c --- surf/surf.c 2010-05-17 09:23:49.000000000 +0200 +++ surf_img_link/surf.c 2010-05-17 10:12:22.000000000 +0200 @@ -68,7 +68,6 @@ static gboolean loadimage = 1, plugin = static char *buildpath(const char *path); static void cleanup(void); static void clipboard(Client *c, const Arg *arg); -static void context(WebKitWebView *v, GtkMenu *m, Client *c); static char *copystr(char **str, const char *src); static WebKitWebView *createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c); static gboolean decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m, WebKitWebPolicyDecision *p, Client *c); @@ -85,7 +84,6 @@ static const char *getcookies(SoupURI *u static char *geturi(Client *c); void gotheaders(SoupMessage *msg, gpointer user_data); static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c); -static void itemclick(GtkMenuItem *mi, Client *c); static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c); static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c); static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c); @@ -173,22 +171,6 @@ clipboard(Client *c, const Arg *arg) { gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), c->linkhover ? c->linkhover : geturi(c), -1); } -void -context(WebKitWebView *v, GtkMenu *m, Client *c) { - int i; - GtkContainer *parent; - - gtk_widget_hide_all(GTK_WIDGET(m)); - gtk_widget_show(GTK_WIDGET(m)); - for(i = 0; i < LENGTH(items); i++) { - parent = GTK_CONTAINER(gtk_widget_get_parent(c->items[i])); - if(parent) - gtk_container_remove(parent, c->items[i]); - gtk_menu_shell_append(GTK_MENU_SHELL(m), c->items[i]); - gtk_widget_show(c->items[i]); - } -} - char * copystr(char **str, const char *src) { char *tmp; @@ -231,7 +213,6 @@ decidewindow(WebKitWebView *view, WebKit void destroyclient(Client *c) { - int i; Client *p; gtk_widget_destroy(c->indicator); @@ -239,9 +220,6 @@ destroyclient(Client *c) { gtk_widget_destroy(c->scroll); gtk_widget_destroy(c->vbox); gtk_widget_destroy(c->win); - for(i = 0; i < LENGTH(items); i++) - gtk_widget_destroy(c->items[i]); - free(c->items); for(p = clients; p && p->next != c; p = p->next); if(p) @@ -388,17 +366,6 @@ initdownload(WebKitWebView *view, WebKit return TRUE; } -void -itemclick(GtkMenuItem *mi, Client *c) { - int i; - const char *label; - - label = gtk_menu_item_get_label(mi); - for(i = 0; i < LENGTH(items); i++) - if(!strcmp(items[i].label, label)) - items[i].func(c, &(items[i].arg)); -} - gboolean keypress(GtkWidget* w, GdkEventKey *ev, Client *c) { guint i; @@ -475,7 +442,6 @@ navigate(Client *c, const Arg *arg) { Client * newclient(void) { - int i; Client *c; WebKitWebSettings *settings; WebKitWebFrame *frame; @@ -509,16 +475,6 @@ newclient(void) { g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c); g_signal_connect(G_OBJECT(c->win), "size-allocate", G_CALLBACK(resize), c); - if(!(c->items = calloc(1, sizeof(GtkWidget *) * LENGTH(items)))) - die("Cannot malloc!\n"); - - /* contextmenu */ - for(i = 0; i < LENGTH(items); i++) { - c->items[i] = gtk_menu_item_new_with_label(items[i].label); - g_signal_connect(G_OBJECT(c->items[i]), "activate", - G_CALLBACK(itemclick), c); - } - /* VBox */ c->vbox = gtk_vbox_new(FALSE, 0); @@ -536,7 +492,6 @@ newclient(void) { g_signal_connect(G_OBJECT(c->view), "mime-type-policy-decision-requested", G_CALLBACK(decidedownload), c); g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c); g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c); - g_signal_connect(G_OBJECT(c->view), "populate-popup", G_CALLBACK(context), c); 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);