1 /* See LICENSE file for copyright and license details.
3 * To understand surf, start reading main().
11 #include <gdk/gdkkeysyms.h>
13 #include <sys/types.h>
18 #include <webkit/webkit.h>
19 #include <glib/gstdio.h>
20 #include <JavaScriptCore/JavaScript.h>
23 #define LENGTH(x) (sizeof x / sizeof x[0])
24 #define CLEANMASK(mask) (mask & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
26 enum { AtomFind, AtomGo, AtomUri, AtomLast };
28 typedef union Arg Arg;
35 typedef struct Client {
36 GtkWidget *win, *scroll, *vbox, *indicator;
38 char *title, *linkhover;
39 const char *uri, *needle;
48 void (*func)(Client *c, const Arg *arg);
55 void (*func)(Client *c, const Arg *arg);
60 static Atom atoms[AtomLast];
61 static Client *clients = NULL;
62 static GdkNativeWindow embed = 0;
63 static gboolean showxid = FALSE;
64 static char winid[64];
65 static char *progname;
66 static gboolean loadimage = 1, plugin = 1, script = 1;
68 static char *buildpath(const char *path);
69 static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, GList *gl);
70 static void cleanup(void);
71 static void clipboard(Client *c, const Arg *arg);
72 static char *copystr(char **str, const char *src);
73 static WebKitWebView *createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c);
74 static gboolean decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m, WebKitWebPolicyDecision *p, Client *c);
75 static gboolean decidewindow(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c);
76 static void destroyclient(Client *c);
77 static void destroywin(GtkWidget* w, Client *c);
78 static void die(char *str);
79 static void drawindicator(Client *c);
80 static gboolean exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c);
81 static void find(Client *c, const Arg *arg);
82 static const char *getatom(Client *c, int a);
83 static const char *getcookies(SoupURI *uri);
84 static char *geturi(Client *c);
85 void gotheaders(SoupMessage *msg, gpointer user_data);
86 static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
87 static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
88 static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
89 static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
90 static void loaduri(Client *c, const Arg *arg);
91 static void navigate(Client *c, const Arg *arg);
92 static Client *newclient(void);
93 static void newwindow(Client *c, const Arg *arg, gboolean noembed);
94 static void newrequest(SoupSession *s, SoupMessage *msg, gpointer v);
95 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
96 static void populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c);
97 static void popupactivate(GtkMenuItem *menu, Client *);
98 static void print(Client *c, const Arg *arg);
99 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
100 static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
101 static void reload(Client *c, const Arg *arg);
102 static void scroll_h(Client *c, const Arg *arg);
103 static void scroll_v(Client *c, const Arg *arg);
104 static void scroll(GtkAdjustment *a, const Arg *arg);
105 static void setatom(Client *c, int a, const char *v);
106 static void setcookie(SoupCookie *c);
107 static void setup(void);
108 static void sigchld(int unused);
109 static void source(Client *c, const Arg *arg);
110 static void spawn(Client *c, const Arg *arg);
111 static void eval(Client *c, const Arg *arg);
112 static void stop(Client *c, const Arg *arg);
113 static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c);
114 static void update(Client *c);
115 static void updatewinid(Client *c);
116 static void usage(void);
117 static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c);
118 static void zoom(Client *c, const Arg *arg);
120 /* configuration, allows nested code to access above variables */
124 buildpath(const char *path) {
128 /* creating directory */
130 apath = g_strdup(path);
132 apath = g_strconcat(g_get_home_dir(), "/", path, NULL);
133 if((p = strrchr(apath, '/'))) {
135 g_mkdir_with_parents(apath, 0700);
136 g_chmod(apath, 0700); /* in case it existed */
139 /* creating file (gives error when apath ends with "/") */
140 if((f = fopen(apath, "a"))) {
141 g_chmod(apath, 0600); /* always */
148 buttonrelease(WebKitWebView *web, GdkEventButton *e, GList *gl) {
149 WebKitHitTestResultContext context;
150 WebKitHitTestResult *result = webkit_web_view_get_hit_test_result(web, e);
153 g_object_get(result, "context", &context, NULL);
154 if(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
156 g_object_get(result, "link-uri", &arg.v, NULL);
157 newwindow(NULL, &arg, e->state & GDK_CONTROL_MASK);
167 destroyclient(clients);
174 evalscript(JSContextRef js, char *script, char* scriptname) {
175 JSStringRef jsscript, jsscriptname;
176 JSValueRef exception = NULL;
178 jsscript = JSStringCreateWithUTF8CString(script);
179 jsscriptname = JSStringCreateWithUTF8CString(scriptname);
180 JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), jsscriptname, 0, &exception);
181 JSStringRelease(jsscript);
182 JSStringRelease(jsscriptname);
186 runscript(WebKitWebFrame *frame) {
190 if(g_file_get_contents(scriptfile, &script, NULL, &error)) {
191 evalscript(webkit_web_frame_get_global_context(frame), script, scriptfile);
196 clipboard(Client *c, const Arg *arg) {
197 gboolean paste = *(gboolean *)arg;
200 gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pasteuri, c);
202 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), c->linkhover ? c->linkhover : geturi(c), -1);
206 copystr(char **str, const char *src) {
218 createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c) {
219 Client *n = newclient();
224 decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m, WebKitWebPolicyDecision *p, Client *c) {
225 if(!webkit_web_view_can_show_mime_type(v, m)) {
226 webkit_web_policy_decision_download(p);
233 decidewindow(WebKitWebView *view, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c) {
236 if(webkit_web_navigation_action_get_reason(n) == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
237 webkit_web_policy_decision_ignore(p);
238 arg.v = (void *)webkit_network_request_get_uri(r);
239 newwindow(NULL, &arg, 0);
246 destroyclient(Client *c) {
249 webkit_web_view_stop_loading(c->view);
250 gtk_widget_destroy(c->indicator);
251 gtk_widget_destroy(GTK_WIDGET(c->view));
252 gtk_widget_destroy(c->scroll);
253 gtk_widget_destroy(c->vbox);
254 gtk_widget_destroy(c->win);
256 for(p = clients; p && p->next != c; p = p->next);
267 destroywin(GtkWidget* w, Client *c) {
278 drawindicator(Client *c) {
287 width = c->progress * w->allocation.width / 100;
288 gc = gdk_gc_new(w->window);
289 if(strstr(uri, "https://") == uri)
290 gdk_color_parse(c->sslfailed ?
291 progress_untrust : progress_trust, &fg);
293 gdk_color_parse(progress, &fg);
294 gdk_gc_set_rgb_fg_color(gc, &fg);
295 gdk_draw_rectangle(w->window,
296 w->style->bg_gc[GTK_WIDGET_STATE(w)],
297 TRUE, 0, 0, w->allocation.width, w->allocation.height);
298 gdk_draw_rectangle(w->window, gc, TRUE, 0, 0, width,
299 w->allocation.height);
304 exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c) {
310 find(Client *c, const Arg *arg) {
313 s = getatom(c, AtomFind);
314 gboolean forward = *(gboolean *)arg;
315 webkit_web_view_search_text(c->view, s, FALSE, forward, TRUE);
319 getcookies(SoupURI *uri) {
321 SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, TRUE);
322 c = soup_cookie_jar_get_cookies(j, uri, TRUE);
328 getatom(Client *c, int a) {
329 static char buf[BUFSIZ];
332 unsigned long ldummy;
333 unsigned char *p = NULL;
335 XGetWindowProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window),
336 atoms[a], 0L, BUFSIZ, False, XA_STRING,
337 &adummy, &idummy, &ldummy, &ldummy, &p);
339 strncpy(buf, (char *)p, LENGTH(buf)-1);
350 if(!(uri = (char *)webkit_web_view_get_uri(c->view)))
356 gotheaders(SoupMessage *msg, gpointer v) {
359 for(p = l = soup_cookies_from_response(msg); p;
360 p = g_slist_next(p)) {
361 setcookie((SoupCookie *)p->data);
363 soup_cookies_free(l);
367 initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
371 arg = (Arg)DOWNLOAD((char *)webkit_download_get_uri(o));
377 keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
379 gboolean processed = FALSE;
382 for(i = 0; i < LENGTH(keys); i++) {
383 if(gdk_keyval_to_lower(ev->keyval) == keys[i].keyval
384 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
386 keys[i].func(c, &(keys[i].arg));
394 linkhover(WebKitWebView *v, const char* t, const char* l, Client *c) {
396 c->linkhover = copystr(&c->linkhover, l);
398 else if(c->linkhover) {
406 loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
407 WebKitWebFrame *frame;
408 WebKitWebDataSource *src;
409 WebKitNetworkRequest *request;
413 switch(webkit_web_view_get_load_status (c->view)) {
414 case WEBKIT_LOAD_COMMITTED:
416 if(strstr(uri, "https://") == uri) {
417 frame = webkit_web_view_get_main_frame(c->view);
418 src = webkit_web_frame_get_data_source(frame);
419 request = webkit_web_data_source_get_request(src);
420 msg = webkit_network_request_get_message(request);
421 c->sslfailed = soup_message_get_flags(msg)
422 ^ SOUP_MESSAGE_CERTIFICATE_TRUSTED;
424 setatom(c, AtomUri, uri);
426 case WEBKIT_LOAD_FINISHED:
436 loaduri(Client *c, const Arg *arg) {
438 const char *uri = (char *)arg->v;
439 Arg a = { .b = FALSE };
441 if(strcmp(uri, "") == 0)
443 u = g_strrstr(uri, "://") ? g_strdup(uri)
444 : g_strdup_printf("http://%s", uri);
445 /* prevents endless loop */
446 if(c->uri && strcmp(u, c->uri) == 0) {
450 webkit_web_view_load_uri(c->view, u);
452 c->title = copystr(&c->title, u);
459 navigate(Client *c, const Arg *arg) {
460 int steps = *(int *)arg;
461 webkit_web_view_go_back_or_forward(c->view, steps);
467 WebKitWebSettings *settings;
468 WebKitWebFrame *frame;
469 GdkGeometry hints = { 1, 1 };
472 if(!(c = calloc(1, sizeof(Client))))
473 die("Cannot malloc!\n");
476 c->win = gtk_plug_new(embed);
479 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
480 /* TA: 20091214: Despite what the GNOME docs say, the ICCCM
481 * is always correct, so we should still call this function.
482 * But when doing so, we *must* differentiate between a
483 * WM_CLASS and a resource on the window. By convention, the
484 * window class (WM_CLASS) is capped, while the resource is in
485 * lowercase. Both these values come as a pair.
487 gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "Surf");
489 /* TA: 20091214: And set the role here as well -- so that
490 * sessions can pick this up.
492 gtk_window_set_role(GTK_WINDOW(c->win), "Surf");
494 gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
495 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
496 g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
499 c->vbox = gtk_vbox_new(FALSE, 0);
501 /* Scrolled Window */
502 c->scroll = gtk_scrolled_window_new(NULL, NULL);
503 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll),
504 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
507 c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
508 g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c);
509 g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
510 g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(createwindow), c);
511 g_signal_connect(G_OBJECT(c->view), "new-window-policy-decision-requested", G_CALLBACK(decidewindow), c);
512 g_signal_connect(G_OBJECT(c->view), "mime-type-policy-decision-requested", G_CALLBACK(decidedownload), c);
513 g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c);
514 g_signal_connect(G_OBJECT(c->view), "notify::load-status", G_CALLBACK(loadstatuschange), c);
515 g_signal_connect(G_OBJECT(c->view), "notify::progress", G_CALLBACK(progresschange), c);
516 g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
517 g_signal_connect(G_OBJECT(c->view), "button-release-event", G_CALLBACK(buttonrelease), c);
518 g_signal_connect(G_OBJECT(c->view), "populate-popup", G_CALLBACK(populatepopup), c);
521 c->indicator = gtk_drawing_area_new();
522 gtk_widget_set_size_request(c->indicator, 0, 2);
523 g_signal_connect (G_OBJECT (c->indicator), "expose_event",
524 G_CALLBACK (exposeindicator), c);
527 gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
528 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
529 gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
530 gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
533 gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START);
534 gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
535 gtk_widget_grab_focus(GTK_WIDGET(c->view));
536 gtk_widget_show(c->vbox);
537 gtk_widget_show(c->indicator);
538 gtk_widget_show(c->scroll);
539 gtk_widget_show(GTK_WIDGET(c->view));
540 gtk_widget_show(c->win);
541 gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, GDK_HINT_MIN_SIZE);
542 gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK);
543 gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c);
544 webkit_web_view_set_full_content_zoom(c->view, TRUE);
545 frame = webkit_web_view_get_main_frame(c->view);
547 settings = webkit_web_view_get_settings(c->view);
548 if(!(ua = getenv("SURF_USERAGENT")))
550 g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
551 uri = g_strconcat("file://", stylefile, NULL);
552 g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
553 g_object_set(G_OBJECT(settings), "auto-load-images", loadimage, NULL);
554 g_object_set(G_OBJECT(settings), "enable-plugins", plugin, NULL);
555 g_object_set(G_OBJECT(settings), "enable-scripts", script, NULL);
556 g_object_set(G_OBJECT(settings), "enable-spatial-navigation", SPATIAL_BROWSING, NULL);
560 setatom(c, AtomFind, "");
561 setatom(c, AtomUri, "about:blank");
563 webkit_web_view_set_transparent(c->view, TRUE);
569 gdk_display_sync(gtk_widget_get_display(c->win));
570 printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
572 if (fclose(stdout) != 0) {
573 die("Error closing stdout");
580 newrequest(SoupSession *s, SoupMessage *msg, gpointer v) {
581 SoupMessageHeaders *h = msg->request_headers;
585 soup_message_headers_remove(h, "Cookie");
586 uri = soup_message_get_uri(msg);
587 if((c = getcookies(uri)))
588 soup_message_headers_append(h, "Cookie", c);
589 g_signal_connect_after(G_OBJECT(msg), "got-headers", G_CALLBACK(gotheaders), NULL);
593 newwindow(Client *c, const Arg *arg, gboolean noembed) {
595 const char *cmd[10], *uri;
596 const Arg a = { .v = (void *)cmd };
600 if(embed && !noembed) {
602 snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed);
614 uri = arg->v ? (char *)arg->v : c->linkhover;
622 populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c) {
623 GList *items = gtk_container_get_children(GTK_CONTAINER(menu));
625 for(GList *l = items; l; l = l->next) {
626 g_signal_connect(l->data, "activate", G_CALLBACK(popupactivate), c);
633 popupactivate(GtkMenuItem *menu, Client *c) {
635 * context-menu-action-2000 open link
636 * context-menu-action-1 open link in window
637 * context-menu-action-2 download linked file
638 * context-menu-action-3 copy link location
639 * context-menu-action-13 reload
640 * context-menu-action-10 back
641 * context-menu-action-11 forward
642 * context-menu-action-12 stop
647 GtkClipboard *prisel;
649 a = gtk_activatable_get_related_action(GTK_ACTIVATABLE(menu));
653 name = gtk_action_get_name(a);
654 if(!g_strcmp0(name, "context-menu-action-3")) {
655 prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
656 gtk_clipboard_set_text(prisel, c->linkhover, -1);
661 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {
662 Arg arg = {.v = text };
664 loaduri((Client *) d, &arg);
668 print(Client *c, const Arg *arg) {
669 webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
673 processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
674 Client *c = (Client *)d;
678 if(((XEvent *)e)->type == PropertyNotify) {
679 ev = &((XEvent *)e)->xproperty;
680 if(ev->state == PropertyNewValue) {
681 if(ev->atom == atoms[AtomFind]) {
684 return GDK_FILTER_REMOVE;
686 else if(ev->atom == atoms[AtomGo]) {
687 arg.v = getatom(c, AtomGo);
689 return GDK_FILTER_REMOVE;
693 return GDK_FILTER_CONTINUE;
697 progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
698 c->progress = webkit_web_view_get_progress(c->view) * 100;
703 reload(Client *c, const Arg *arg) {
704 gboolean nocache = *(gboolean *)arg;
706 webkit_web_view_reload_bypass_cache(c->view);
708 webkit_web_view_reload(c->view);
712 scroll_h(Client *c, const Arg *arg) {
713 scroll(gtk_scrolled_window_get_hadjustment(
714 GTK_SCROLLED_WINDOW(c->scroll)), arg);
718 scroll_v(Client *c, const Arg *arg) {
719 scroll(gtk_scrolled_window_get_vadjustment(
720 GTK_SCROLLED_WINDOW(c->scroll)), arg);
724 scroll(GtkAdjustment *a, const Arg *arg) {
727 v = gtk_adjustment_get_value(a);
731 v += gtk_adjustment_get_page_increment(a) *
737 v += gtk_adjustment_get_step_increment(a) * arg->i;
741 v = MIN(v, gtk_adjustment_get_upper(a) -
742 gtk_adjustment_get_page_size(a));
743 gtk_adjustment_set_value(a, v);
747 setcookie(SoupCookie *c) {
750 lock = open(cookiefile, 0);
751 flock(lock, LOCK_EX);
753 SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, FALSE);
754 c = soup_cookie_copy(c);
755 if(c->expires == NULL && sessiontime) {
756 e = soup_date_new_from_time_t(time(NULL) + sessiontime);
757 soup_cookie_set_expires(c, e);
759 soup_cookie_jar_add_cookie(j, c);
761 flock(lock, LOCK_UN);
766 setatom(Client *c, int a, const char *v) {
768 XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), atoms[a],
769 XA_STRING, 8, PropModeReplace, (unsigned char *)v,
780 /* clean up any zombies immediately */
782 gtk_init(NULL, NULL);
783 if (!g_thread_supported())
787 s = webkit_get_default_session();
790 atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
791 atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
792 atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
795 cookiefile = buildpath(cookiefile);
796 scriptfile = buildpath(scriptfile);
797 stylefile = buildpath(stylefile);
799 /* request handler */
800 s = webkit_get_default_session();
801 soup_session_remove_feature_by_type(s, soup_cookie_get_type());
802 soup_session_remove_feature_by_type(s, soup_cookie_jar_get_type());
803 g_signal_connect_after(G_OBJECT(s), "request-started", G_CALLBACK(newrequest), NULL);
806 g_object_set(G_OBJECT(s), "ssl-ca-file", cafile, NULL);
807 g_object_set(G_OBJECT(s), "ssl-strict", strictssl, NULL);
810 if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
811 new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
812 g_strdup_printf("http://%s", proxy);
813 puri = soup_uri_new(new_proxy);
814 g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
821 sigchld(int unused) {
822 if(signal(SIGCHLD, sigchld) == SIG_ERR)
823 die("Can't install SIGCHLD handler");
824 while(0 < waitpid(-1, NULL, WNOHANG));
828 source(Client *c, const Arg *arg) {
829 Arg a = { .b = FALSE };
832 s = webkit_web_view_get_view_source_mode(c->view);
833 webkit_web_view_set_view_source_mode(c->view, !s);
838 spawn(Client *c, const Arg *arg) {
841 close(ConnectionNumber(dpy));
843 execvp(((char **)arg->v)[0], (char **)arg->v);
844 fprintf(stderr, "surf: execvp %s", ((char **)arg->v)[0]);
851 eval(Client *c, const Arg *arg) {
852 WebKitWebFrame *frame = webkit_web_view_get_main_frame(c->view);
853 evalscript(webkit_web_frame_get_global_context(frame),
854 ((char **)arg->v)[0], "");
858 stop(Client *c, const Arg *arg) {
859 webkit_web_view_stop_loading(c->view);
863 titlechange(WebKitWebView *v, WebKitWebFrame *f, const char *t, Client *c) {
864 c->title = copystr(&c->title, t);
873 t = g_strdup(c->linkhover);
874 else if(c->progress != 100)
875 t = g_strdup_printf("[%i%%] %s", c->progress, c->title);
877 t = g_strdup(c->title);
879 gtk_window_set_title(GTK_WINDOW(c->win), t);
884 updatewinid(Client *c) {
885 snprintf(winid, LENGTH(winid), "%u",
886 (int)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
891 fputs("surf - simple browser\n", stderr);
892 die("usage: surf [-e xid] [-i] [-p] [-s] [-v] [-x] [uri]\n");
896 windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c) {
901 zoom(Client *c, const Arg *arg) {
903 if(arg->i < 0) /* zoom out */
904 webkit_web_view_zoom_out(c->view);
905 else if(arg->i > 0) /* zoom in */
906 webkit_web_view_zoom_in(c->view);
909 webkit_web_view_set_zoom_level(c->view, 1.0);
914 main(int argc, char *argv[]) {
919 /* command line args */
920 for(i = 1, arg.v = NULL; i < argc && argv[i][0] == '-' &&
921 argv[i][1] != '\0' && argv[i][2] == '\0'; i++) {
922 if(!strcmp(argv[i], "--")) {
929 embed = strtol(argv[i], NULL, 0);
946 die("surf-"VERSION", ©2009-2012 surf engineers, see LICENSE for details\n");
956 loaduri(clients, &arg);