X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=6c83405dbe7bd0dcb88d7007f5b4e2c99ca8c0d4;hb=b4e78555d020bd33981c50805f5480da22c8136d;hp=eb57824cc1dcde66b0ac1e49c54c1dab62ab8cb8;hpb=72905b8bfc0f91cd3b6d0ac845c5cae92f8e35db;p=surf.git diff --git a/surf.c b/surf.c index eb57824..6c83405 100644 --- a/surf.c +++ b/surf.c @@ -124,7 +124,8 @@ static void closeview(WebKitWebView *v, Client *c); static void destroyclient(Client *c); static void destroywin(GtkWidget* w, Client *c); static void die(const char *errstr, ...); -static void eval(Client *c, const Arg *arg); +static void evalscript(Client *c, const char *jsstr, ...); +static void runscript(Client *c); static void find(Client *c, const Arg *arg); static void fullscreen(Client *c, const Arg *arg); static gboolean permissionrequested(WebKitWebView *v, @@ -166,6 +167,7 @@ static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); static void print(Client *c, const Arg *arg); static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d); +static gboolean winevent(GtkWidget *w, GdkEvent *e, Client *c); static void progresschanged(WebKitWebView *v, GParamSpec *ps, Client *c); static void linkopen(Client *c, const Arg *arg); static void linkopenembed(Client *c, const Arg *arg); @@ -179,7 +181,6 @@ static void sigchld(int unused); static void spawn(Client *c, const Arg *arg); static void stop(Client *c, const Arg *arg); static void titlechanged(WebKitWebView *view, GParamSpec *ps, 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); @@ -336,29 +337,28 @@ cookiepolicy_set(const WebKitCookieAcceptPolicy ep) } void -evalscript(JSContextRef js, char *script, char* scriptname) +evalscript(Client *c, const char *jsstr, ...) { - JSStringRef jsscript, jsscriptname; - JSValueRef exception = NULL; + va_list ap; + gchar *script; + + va_start(ap, jsstr); + script = g_strdup_vprintf(jsstr, ap); + va_end(ap); - jsscript = JSStringCreateWithUTF8CString(script); - jsscriptname = JSStringCreateWithUTF8CString(scriptname); - JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), - jsscriptname, 0, &exception); - JSStringRelease(jsscript); - JSStringRelease(jsscriptname); + webkit_web_view_run_javascript(c->view, script, NULL, NULL, NULL); + g_free(script); } void -runscript(WebKitWebFrame *frame) +runscript(Client *c) { - char *script; - GError *error; + gchar *script; + gsize l; - if (g_file_get_contents(scriptfile, &script, NULL, &error)) { - evalscript(webkit_web_frame_get_global_context(frame), script, - scriptfile); - } + if (g_file_get_contents(scriptfile, &script, &l, NULL) && l) + evalscript(c, script); + g_free(script); } void @@ -1125,8 +1125,8 @@ createwindow(Client *c) g_signal_connect(G_OBJECT(w), "destroy", G_CALLBACK(destroywin), c); - g_signal_connect(G_OBJECT(w), "leave_notify_event", - G_CALLBACK(titlechangeleave), c); + g_signal_connect(G_OBJECT(w), "leave-notify-event", + G_CALLBACK(winevent), c); return w; } @@ -1318,14 +1318,6 @@ spawn(Client *c, const Arg *arg) } } -void -eval(Client *c, const Arg *arg) -{ - WebKitWebFrame *frame = webkit_web_view_get_main_frame(c->view); - evalscript(webkit_web_frame_get_global_context(frame), - ((char **)arg->v)[0], ""); -} - void stop(Client *c, const Arg *arg) { @@ -1339,11 +1331,19 @@ titlechanged(WebKitWebView *view, GParamSpec *ps, Client *c) updatetitle(c); } -void -titlechangeleave(void *a, void *b, Client *c) +gboolean +winevent(GtkWidget *w, GdkEvent *e, Client *c) { - c->linkhover = NULL; - updatetitle(c); + switch (e->type) { + case GDK_LEAVE_NOTIFY: + c->targeturi = NULL; + updatetitle(c); + break; + default: + return FALSE; + } + + return TRUE; } void