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 & ~(GDK_MOD2_MASK))
26 typedef union Arg Arg;
33 typedef struct Client {
34 GtkWidget *win, *scroll, *vbox, *indicator;
37 WebKitDownload *download;
38 char *title, *linkhover;
39 const char *uri, *needle;
47 void (*func)(Client *c, const Arg *arg);
54 void (*func)(Client *c, const Arg *arg);
59 static Atom uriprop, findprop;
60 static Client *clients = NULL;
61 static GdkNativeWindow embed = 0;
62 static gboolean showxid = FALSE;
63 static int ignorexprop = 0;
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 void cleanup(void);
70 static void clipboard(Client *c, const Arg *arg);
71 static void context(WebKitWebView *v, GtkMenu *m, Client *c);
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 download(Client *c, const Arg *arg);
80 static void drawindicator(Client *c);
81 static gboolean exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c);
82 static void find(Client *c, const Arg *arg);
83 static const char *getatom(Client *c, Atom a);
84 static const char *getcookies(SoupURI *uri);
85 static char *geturi(Client *c);
86 void gotheaders(SoupMessage *msg, gpointer user_data);
87 static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
88 static void itemclick(GtkMenuItem *mi, Client *c);
89 static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
90 static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
91 static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
92 static void loaduri(Client *c, const Arg *arg);
93 static void navigate(Client *c, const Arg *arg);
94 static Client *newclient(void);
95 static void newwindow(Client *c, const Arg *arg);
96 static void newrequest(SoupSession *s, SoupMessage *msg, gpointer v);
97 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
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 resize(GtkWidget *w, GtkAllocation *a, Client *c);
103 static void scroll(Client *c, const Arg *arg);
104 static void setatom(Client *c, Atom a, const char *v);
105 static void setcookie(SoupCookie *c);
106 static void setup(void);
107 static void sigchld(int unused);
108 static void source(Client *c, const Arg *arg);
109 static void spawn(Client *c, const Arg *arg);
110 static void stop(Client *c, const Arg *arg);
111 static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c);
112 static void update(Client *c);
113 static void updatedownload(WebKitDownload *o, GParamSpec *pspec, Client *c);
114 static void updatewinid(Client *c);
115 static void usage(void);
116 static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c);
117 static void zoom(Client *c, const Arg *arg);
119 /* configuration, allows nested code to access above variables */
123 buildpath(const char *path) {
127 /* creating directory */
129 apath = g_strdup(path);
131 apath = g_strconcat(g_get_home_dir(), "/", path, NULL);
132 if((p = strrchr(apath, '/'))) {
134 g_mkdir_with_parents(apath, 0755);
137 /* creating file (gives error when apath ends with "/") */
138 if((f = g_fopen(apath, "a")))
146 destroyclient(clients);
154 runscript(WebKitWebFrame *frame, JSContextRef js) {
155 JSStringRef jsscript;
157 JSValueRef exception = NULL;
160 if(g_file_get_contents(scriptfile, &script, NULL, &error)) {
161 jsscript = JSStringCreateWithUTF8CString(script);
162 JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), NULL, 0, &exception);
167 clipboard(Client *c, const Arg *arg) {
168 gboolean paste = *(gboolean *)arg;
171 gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pasteuri, c);
173 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), c->linkhover ? c->linkhover : geturi(c), -1);
177 context(WebKitWebView *v, GtkMenu *m, Client *c) {
179 GtkContainer *parent;
181 gtk_widget_hide_all(GTK_WIDGET(m));
182 gtk_widget_show(GTK_WIDGET(m));
183 for(i = 0; i < LENGTH(items); i++) {
184 parent = GTK_CONTAINER(gtk_widget_get_parent(c->items[i]));
186 gtk_container_remove(parent, c->items[i]);
187 gtk_menu_shell_append(GTK_MENU_SHELL(m), c->items[i]);
188 gtk_widget_show(c->items[i]);
193 copystr(char **str, const char *src) {
205 createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c) {
206 Client *n = newclient();
211 decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m, WebKitWebPolicyDecision *p, Client *c) {
212 if(!webkit_web_view_can_show_mime_type(v, m)) {
213 webkit_web_policy_decision_download(p);
220 decidewindow(WebKitWebView *view, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c) {
223 if(webkit_web_navigation_action_get_reason(n) == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
224 webkit_web_policy_decision_ignore(p);
225 arg.v = (void *)webkit_network_request_get_uri(r);
226 newwindow(NULL, &arg);
233 destroyclient(Client *c) {
237 gtk_widget_destroy(c->indicator);
238 gtk_widget_destroy(GTK_WIDGET(c->view));
239 gtk_widget_destroy(c->scroll);
240 gtk_widget_destroy(c->vbox);
241 gtk_widget_destroy(c->win);
242 for(i = 0; i < LENGTH(items); i++)
243 gtk_widget_destroy(c->items[i]);
246 for(p = clients; p && p->next != c; p = p->next);
257 destroywin(GtkWidget* w, Client *c) {
268 download(Client *c, const Arg *arg) {
270 WebKitNetworkRequest *r;
274 uri = (char *)arg->v;
276 uri = c->linkhover ? c->linkhover : geturi(c);
277 r = webkit_network_request_new(uri);
278 dl = webkit_download_new(r);
279 initdownload(c->view, dl, c);
280 webkit_download_start(c->download);
284 drawindicator(Client *c) {
291 uri = getatom(c, uriprop);
293 width = c->progress * w->allocation.width / 100;
294 gc = gdk_gc_new(w->window);
295 gdk_color_parse(strstr(uri, "https://") == uri ?
296 progress_trust : progress, &fg);
297 gdk_gc_set_rgb_fg_color(gc, &fg);
298 gdk_draw_rectangle(w->window,
299 w->style->bg_gc[GTK_WIDGET_STATE(w)],
300 TRUE, 0, 0, w->allocation.width, w->allocation.height);
301 gdk_draw_rectangle(w->window, gc, TRUE, 0, 0, width,
302 w->allocation.height);
307 exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c) {
313 find(Client *c, const Arg *arg) {
316 s = getatom(c, findprop);
317 gboolean forward = *(gboolean *)arg;
318 webkit_web_view_search_text(c->view, s, FALSE, forward, TRUE);
322 getcookies(SoupURI *uri) {
324 SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, TRUE);
325 c = soup_cookie_jar_get_cookies(j, uri, TRUE);
331 getatom(Client *c, Atom a) {
332 static char buf[BUFSIZ];
335 unsigned long ldummy;
336 unsigned char *p = NULL;
338 XGetWindowProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window),
339 a, 0L, BUFSIZ, False, XA_STRING,
340 &adummy, &idummy, &ldummy, &ldummy, &p);
342 strncpy(buf, (char *)p, LENGTH(buf)-1);
353 if(!(uri = (char *)webkit_web_view_get_uri(c->view)))
359 gotheaders(SoupMessage *msg, gpointer v) {
363 uri = soup_message_get_uri(msg);
364 for(p = l = soup_cookies_from_response(msg); p;
365 p = g_slist_next(p)) {
366 setcookie((SoupCookie *)p->data);
368 soup_cookies_free(l);
372 initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) {
373 const char *filename;
375 WebKitWebBackForwardList *h;
376 WebKitWebHistoryItem *i;
379 filename = webkit_download_get_suggested_filename(o);
380 if(!strcmp("", filename))
381 filename = "index.html";
382 uri = g_strconcat("file://", dldir, "/", filename, NULL);
383 webkit_download_set_destination_uri(c->download, uri);
385 h = webkit_web_view_get_back_forward_list(c->view);
386 i = webkit_web_history_item_new_with_data(webkit_download_get_uri(c->download), filename);
387 webkit_web_back_forward_list_add_item(h, i);
388 g_signal_connect(c->download, "notify::progress", G_CALLBACK(updatedownload), c);
389 g_signal_connect(c->download, "notify::status", G_CALLBACK(updatedownload), c);
391 c->title = copystr(&c->title, filename);
397 itemclick(GtkMenuItem *mi, Client *c) {
401 label = gtk_menu_item_get_label(mi);
402 for(i = 0; i < LENGTH(items); i++)
403 if(!strcmp(items[i].label, label))
404 items[i].func(c, &(items[i].arg));
408 keypress(GtkWidget* w, GdkEventKey *ev, Client *c) {
410 gboolean processed = FALSE;
413 for(i = 0; i < LENGTH(keys); i++) {
414 if(gdk_keyval_to_lower(ev->keyval) == keys[i].keyval
415 && CLEANMASK(ev->state) == keys[i].mod
417 keys[i].func(c, &(keys[i].arg));
425 linkhover(WebKitWebView *v, const char* t, const char* l, Client *c) {
427 c->linkhover = copystr(&c->linkhover, l);
428 else if(c->linkhover) {
436 loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
437 switch(webkit_web_view_get_load_status (c->view)) {
438 case WEBKIT_LOAD_COMMITTED:
441 setatom(c, uriprop, geturi(c));
443 case WEBKIT_LOAD_FINISHED:
453 loaduri(Client *c, const Arg *arg) {
455 const char *uri = (char *)arg->v;
456 Arg a = { .b = FALSE };
458 if(strcmp(uri, "") == 0)
460 u = g_strrstr(uri, "://") ? g_strdup(uri)
461 : g_strdup_printf("http://%s", uri);
462 /* prevents endless loop */
463 if(c->uri && strcmp(u, c->uri) == 0) {
467 webkit_web_view_load_uri(c->view, u);
469 c->title = copystr(&c->title, u);
476 navigate(Client *c, const Arg *arg) {
477 int steps = *(int *)arg;
478 webkit_web_view_go_back_or_forward(c->view, steps);
485 WebKitWebSettings *settings;
486 WebKitWebFrame *frame;
487 GdkGeometry hints = { 1, 1 };
490 if(!(c = calloc(1, sizeof(Client))))
491 die("Cannot malloc!\n");
494 c->win = gtk_plug_new(embed);
497 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
498 /* TA: 20091214: Despite what the GNOME docs say, the ICCCM
499 * is always correct, so we should still call this function.
500 * But when doing so, we *must* differentiate between a
501 * WM_CLASS and a resource on the window. By convention, the
502 * window class (WM_CLASS) is capped, while the resource is in
503 * lowercase. Both these values come as a pair.
505 gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf");
507 /* TA: 20091214: And set the role here as well -- so that
508 * sessions can pick this up.
510 gtk_window_set_role(GTK_WINDOW(c->win), "Surf");
512 gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
513 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
514 g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
515 g_signal_connect(G_OBJECT(c->win), "size-allocate", G_CALLBACK(resize), c);
517 if(!(c->items = calloc(1, sizeof(GtkWidget *) * LENGTH(items))))
518 die("Cannot malloc!\n");
521 for(i = 0; i < LENGTH(items); i++) {
522 c->items[i] = gtk_menu_item_new_with_label(items[i].label);
523 g_signal_connect(G_OBJECT(c->items[i]), "activate",
524 G_CALLBACK(itemclick), c);
528 c->vbox = gtk_vbox_new(FALSE, 0);
530 /* Scrolled Window */
531 c->scroll = gtk_scrolled_window_new(NULL, NULL);
532 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll),
533 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
536 c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
537 g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c);
538 g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
539 g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(createwindow), c);
540 g_signal_connect(G_OBJECT(c->view), "new-window-policy-decision-requested", G_CALLBACK(decidewindow), c);
541 g_signal_connect(G_OBJECT(c->view), "mime-type-policy-decision-requested", G_CALLBACK(decidedownload), c);
542 g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
543 g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c);
544 g_signal_connect(G_OBJECT(c->view), "populate-popup", G_CALLBACK(context), c);
545 g_signal_connect(G_OBJECT(c->view), "notify::load-status", G_CALLBACK(loadstatuschange), c);
546 g_signal_connect(G_OBJECT(c->view), "notify::progress", G_CALLBACK(progresschange), c);
549 c->indicator = gtk_drawing_area_new();
550 gtk_widget_set_size_request(c->indicator, 0, 2);
551 g_signal_connect (G_OBJECT (c->indicator), "expose_event",
552 G_CALLBACK (exposeindicator), c);
555 gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
556 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
557 gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
558 gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
561 gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START);
562 gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
563 gtk_widget_grab_focus(GTK_WIDGET(c->view));
564 gtk_widget_show(c->vbox);
565 gtk_widget_show(c->indicator);
566 gtk_widget_show(c->scroll);
567 gtk_widget_show(GTK_WIDGET(c->view));
568 gtk_widget_show(c->win);
569 gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, GDK_HINT_MIN_SIZE);
570 gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK);
571 gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c);
572 webkit_web_view_set_full_content_zoom(c->view, TRUE);
573 frame = webkit_web_view_get_main_frame(c->view);
574 runscript(frame, webkit_web_frame_get_global_context(frame));
575 settings = webkit_web_view_get_settings(c->view);
576 if(!(ua = getenv("SURF_USERAGENT")))
578 g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
579 uri = g_strconcat("file://", stylefile, NULL);
580 g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
581 g_object_set(G_OBJECT(settings), "auto-load-images", loadimage, NULL);
582 g_object_set(G_OBJECT(settings), "enable-plugins", plugin, NULL);
583 g_object_set(G_OBJECT(settings), "enable-scripts", script, NULL);
585 setatom(c, findprop, "");
586 setatom(c, uriprop, "");
588 webkit_web_view_set_transparent(c->view, TRUE);
595 gdk_display_sync(gtk_widget_get_display(c->win));
596 printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
603 newrequest(SoupSession *s, SoupMessage *msg, gpointer v) {
604 SoupMessageHeaders *h = msg->request_headers;
608 soup_message_headers_remove(h, "Cookie");
609 uri = soup_message_get_uri(msg);
610 if((c = getcookies(uri)))
611 soup_message_headers_append(h, "Cookie", c);
612 g_signal_connect_after(G_OBJECT(msg), "got-headers", G_CALLBACK(gotheaders), NULL);
616 newwindow(Client *c, const Arg *arg) {
618 const char *cmd[10], *uri;
619 const Arg a = { .v = (void *)cmd };
625 snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed);
637 uri = arg->v ? (char *)arg->v : c->linkhover;
645 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {
646 Arg arg = {.v = text };
648 loaduri((Client *) d, &arg);
652 print(Client *c, const Arg *arg) {
653 webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
657 processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
658 Client *c = (Client *)d;
662 if(((XEvent *)e)->type == PropertyNotify) {
663 ev = &((XEvent *)e)->xproperty;
666 else if(ev->state == PropertyNewValue) {
667 if(ev->atom == uriprop) {
668 arg.v = getatom(c, uriprop);
671 else if(ev->atom == findprop) {
675 return GDK_FILTER_REMOVE;
678 return GDK_FILTER_CONTINUE;
682 progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
683 c->progress = webkit_web_view_get_progress(c->view) * 100;
688 reload(Client *c, const Arg *arg) {
689 gboolean nocache = *(gboolean *)arg;
691 webkit_web_view_reload_bypass_cache(c->view);
693 webkit_web_view_reload(c->view);
697 resize(GtkWidget *w, GtkAllocation *a, Client *c) {
702 zoom = webkit_web_view_get_zoom_level(c->view);
703 if(a->width * a->height < 300 * 400 && zoom != 0.2)
704 webkit_web_view_set_zoom_level(c->view, 0.2);
706 webkit_web_view_set_zoom_level(c->view, 1.0);
710 scroll(Client *c, const Arg *arg) {
714 a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(c->scroll));
715 v = gtk_adjustment_get_value(a);
716 v += gtk_adjustment_get_step_increment(a) * arg->i;
718 v = MIN(v, gtk_adjustment_get_upper(a) - gtk_adjustment_get_page_size(a));
719 gtk_adjustment_set_value(a, v);
723 setcookie(SoupCookie *c) {
726 lock = open(cookiefile, 0);
727 flock(lock, LOCK_EX);
729 SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, FALSE);
730 c = soup_cookie_copy(c);
731 if(c->expires == NULL && sessiontime) {
732 e = soup_date_new_from_time_t(time(NULL) + sessiontime);
733 soup_cookie_set_expires(c, e);
735 soup_cookie_jar_add_cookie(j, c);
737 flock(lock, LOCK_UN);
742 setatom(Client *c, Atom a, const char *v) {
745 XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), a,
746 XA_STRING, 8, PropModeReplace, (unsigned char *)v,
757 /* clean up any zombies immediately */
759 gtk_init(NULL, NULL);
760 if (!g_thread_supported())
764 s = webkit_get_default_session();
765 uriprop = XInternAtom(dpy, "_SURF_URI", False);
766 findprop = XInternAtom(dpy, "_SURF_FIND", False);
769 cookiefile = buildpath(cookiefile);
770 dldir = buildpath(dldir);
771 scriptfile = buildpath(scriptfile);
772 stylefile = buildpath(stylefile);
774 /* request handler */
775 s = webkit_get_default_session();
776 soup_session_remove_feature_by_type(s, soup_cookie_get_type());
777 soup_session_remove_feature_by_type(s, soup_cookie_jar_get_type());
778 g_signal_connect_after(G_OBJECT(s), "request-started", G_CALLBACK(newrequest), NULL);
781 if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
782 new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
783 g_strdup_printf("http://%s", proxy);
785 puri = soup_uri_new(new_proxy);
786 g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
793 sigchld(int unused) {
794 if(signal(SIGCHLD, sigchld) == SIG_ERR)
795 die("Can't install SIGCHLD handler");
796 while(0 < waitpid(-1, NULL, WNOHANG));
800 source(Client *c, const Arg *arg) {
801 Arg a = { .b = FALSE };
804 s = webkit_web_view_get_view_source_mode(c->view);
805 webkit_web_view_set_view_source_mode(c->view, !s);
810 spawn(Client *c, const Arg *arg) {
813 close(ConnectionNumber(dpy));
815 execvp(((char **)arg->v)[0], (char **)arg->v);
816 fprintf(stderr, "surf: execvp %s", ((char **)arg->v)[0]);
823 stop(Client *c, const Arg *arg) {
825 webkit_download_cancel(c->download);
827 webkit_web_view_stop_loading(c->view);
832 titlechange(WebKitWebView *v, WebKitWebFrame *f, const char *t, Client *c) {
833 c->title = copystr(&c->title, t);
841 if(c->progress != 100)
842 t = g_strdup_printf("[%i%%] %s", c->progress, c->title);
843 else if(c->linkhover)
844 t = g_strdup(c->linkhover);
846 t = g_strdup(c->title);
848 gtk_window_set_title(GTK_WINDOW(c->win), t);
853 updatedownload(WebKitDownload *o, GParamSpec *pspec, Client *c) {
854 WebKitDownloadStatus status;
856 status = webkit_download_get_status(c->download);
857 if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) {
858 c->progress = (gint)(webkit_download_get_progress(c->download)*100);
866 updatewinid(Client *c) {
867 snprintf(winid, LENGTH(winid), "%u",
868 (int)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
873 fputs("surf - simple browser\n", stderr);
874 die("usage: surf [-e xid] [-i] [-p] [-s] [-v] [-x] [uri]\n");
878 windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c) {
879 runscript(frame, js);
883 zoom(Client *c, const Arg *arg) {
885 if(arg->i < 0) /* zoom out */
886 webkit_web_view_zoom_out(c->view);
887 else if(arg->i > 0) /* zoom in */
888 webkit_web_view_zoom_in(c->view);
891 webkit_web_view_set_zoom_level(c->view, 1.0);
896 main(int argc, char *argv[]) {
901 /* command line args */
902 for(i = 1, arg.v = NULL; i < argc && argv[i][0] == '-' &&
903 argv[i][1] != '\0' && argv[i][2] == '\0'; i++) {
904 if(!strcmp(argv[i], "--")) {
911 embed = atoi(argv[i]);
928 die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
938 loaduri(clients, &arg);