X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=87c10efe1b4c6558ed3bf9e71358a46e9c49c716;hb=9b6998e7ae06ef4df14f84a902c24c49c0968a1d;hp=36f243e8febb9596a7d505ee79e78210b45d1daf;hpb=b3a4392923b26e81c4faa35907a4a2d071e2275f;p=surf.git diff --git a/surf.c b/surf.c index 36f243e..87c10ef 100644 --- a/surf.c +++ b/surf.c @@ -35,6 +35,15 @@ char *argv0; #define COOKIEJAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COOKIEJAR_TYPE, CookieJar)) enum { AtomFind, AtomGo, AtomUri, AtomLast }; +enum { + ClkDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT, + ClkLink = WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK, + ClkImg = WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE, + ClkMedia = WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA, + ClkSel = WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION, + ClkEdit = WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE, + ClkAny = ClkDoc | ClkLink | ClkImg | ClkMedia | ClkSel | ClkEdit, +}; typedef union Arg Arg; union Arg { @@ -61,6 +70,14 @@ typedef struct { const Arg arg; } Key; +typedef struct { + unsigned int click; + unsigned int mask; + guint button; + void (*func)(Client *c, const Arg *arg); + const Arg arg; +} Button; + typedef struct { SoupCookieJarText parent_instance; int lock; @@ -97,8 +114,7 @@ static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, WebKitNetworkRequest *req, WebKitNetworkResponse *resp, Client *c); static char *buildpath(const char *path); -static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, - GList *gl); +static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c); static void cleanup(void); static void clipboard(Client *c, const Arg *arg); @@ -168,6 +184,8 @@ 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); +static void linkopen(Client *c, const Arg *arg); +static void linkopenembed(Client *c, const Arg *arg); static void reload(Client *c, const Arg *arg); static void scroll_h(Client *c, const Arg *arg); static void scroll_v(Client *c, const Arg *arg); @@ -179,6 +197,7 @@ static void source(Client *c, const Arg *arg); static void spawn(Client *c, const Arg *arg); static void stop(Client *c, const Arg *arg); static void titlechange(WebKitWebView *view, GParamSpec *pspec, Client *c); +static void titlechangeleave(void *a, void *b, Client *c); static void toggle(Client *c, const Arg *arg); static void togglecookiepolicy(Client *c, const Arg *arg); static void togglegeolocation(Client *c, const Arg *arg); @@ -272,18 +291,19 @@ buildpath(const char *path) { } static gboolean -buttonrelease(WebKitWebView *web, GdkEventButton *e, GList *gl) { +buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c) { WebKitHitTestResultContext context; WebKitHitTestResult *result = webkit_web_view_get_hit_test_result(web, e); Arg arg; + unsigned int i; g_object_get(result, "context", &context, NULL); - if(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) { - if(e->button == 2 || - (e->button == 1 && CLEANMASK(e->state) == CLEANMASK(MODKEY))) { - g_object_get(result, "link-uri", &arg.v, NULL); - newwindow(NULL, &arg, e->state & GDK_CONTROL_MASK); + g_object_get(result, "link-uri", &arg.v, NULL); + for(i = 0; i < LENGTH(buttons); i++) { + if(context & buttons[i].click && e->button == buttons[i].button && + CLEANMASK(e->state) == CLEANMASK(buttons[i].mask) && buttons[i].func) { + buttons[i].func(c, buttons[i].click == ClkLink && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); return true; } } @@ -805,6 +825,9 @@ newclient(void) { g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c); + g_signal_connect(G_OBJECT(c->win), + "leave_notify_event", + G_CALLBACK(titlechangeleave), c); if(!kioskmode) addaccelgroup(c); @@ -1114,6 +1137,16 @@ progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { updatetitle(c); } +static void +linkopen(Client *c, const Arg *arg) { + newwindow(NULL, arg, 1); +} + +static void +linkopenembed(Client *c, const Arg *arg) { + newwindow(NULL, arg, 0); +} + static void reload(Client *c, const Arg *arg) { gboolean nocache = *(gboolean *)arg; @@ -1298,6 +1331,12 @@ titlechange(WebKitWebView *view, GParamSpec *pspec, Client *c) { } } +static void +titlechangeleave(void *a, void *b, Client *c) { + c->linkhover = NULL; + updatetitle(c); +} + static void toggle(Client *c, const Arg *arg) { WebKitWebSettings *settings;