Reverting the cleanmask change.
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index 097ecc9..56051e9 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -21,7 +21,6 @@
 #include <sys/file.h>
 
 #define LENGTH(x)               (sizeof x / sizeof x[0])
-#define CLEANMASK(mask)         (mask & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
 
 enum { AtomFind, AtomGo, AtomUri, AtomLast };
 
@@ -93,6 +92,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);
@@ -379,7 +380,7 @@ keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
        updatewinid(c);
        for(i = 0; i < LENGTH(keys); i++) {
                if(gdk_keyval_to_lower(ev->keyval) == keys[i].keyval
-                               && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
+                               && (ev->state & keys[i].mod) == keys[i].mod
                                && keys[i].func) {
                        keys[i].func(c, &(keys[i].arg));
                        processed = TRUE;
@@ -513,6 +514,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 +617,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 };