+ s = getatom(c, findprop);
+ gboolean forward = *(gboolean *)arg;
+ webkit_web_view_search_text(c->view, s, FALSE, forward, TRUE);
+}
+
+void
+stop(Client *c, const Arg *arg) {
+ if(c->download)
+ webkit_download_cancel(c->download);
+ else
+ webkit_web_view_stop_loading(c->view);
+ c->download = NULL;
+}
+
+void
+spawn(Client *c, const Arg *arg) {
+ if(fork() == 0) {
+ if(dpy)
+ close(ConnectionNumber(dpy));
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+ fprintf(stderr, "surf: execvp %s", ((char **)arg->v)[0]);
+ perror(" failed");
+ exit(0);
+ }
+}
+
+void
+titlechange(WebKitWebView *v, WebKitWebFrame *f, const char *t, Client *c) {
+ c->title = copystr(&c->title, t);
+ update(c);
+}
+
+void
+usage(void) {
+ fputs("surf - simple browser\n", stderr);
+ die("usage: surf [-e Window] [-x] [uri]\n");
+}
+
+void
+update(Client *c) {
+ char *t;
+
+ if(c->progress != 100)
+ t = g_strdup_printf("%s [%i%%]", c->title, c->progress);
+ else if(c->linkhover)
+ t = g_strdup(c->linkhover);
+ else
+ t = g_strdup(c->title);
+ drawindicator(c);
+ gtk_window_set_title(GTK_WINDOW(c->win), t);
+ g_free(t);
+}
+
+void
+updatedownload(WebKitDownload *o, GParamSpec *pspec, Client *c) {
+ WebKitDownloadStatus status;
+
+ status = webkit_download_get_status(c->download);
+ if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) {
+ c->progress = (gint)(webkit_download_get_progress(c->download)*100);
+ }
+ update(c);
+}
+
+void
+updatewinid(Client *c) {
+ snprintf(winid, LENGTH(winid), "%u",
+ (int)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
+}
+
+void
+windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c) {
+ JSStringRef jsscript;
+ char *script;
+ JSValueRef exception = NULL;
+ GError *error;
+
+ if(g_file_get_contents(scriptfile, &script, NULL, &error)) {
+ jsscript = JSStringCreateWithUTF8CString(script);
+ JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), NULL, 0, &exception);
+ }
+}
+
+void
+zoom(Client *c, const Arg *arg) {
+ c->zoomed = TRUE;
+ if(arg->i < 0) /* zoom out */
+ webkit_web_view_zoom_out(c->view);
+ else if(arg->i > 0) /* zoom in */
+ webkit_web_view_zoom_in(c->view);
+ else { /* reset */
+ c->zoomed = FALSE;
+ webkit_web_view_set_zoom_level(c->view, 1.0);
+ }
+}
+
+int main(int argc, char *argv[]) {
+ int i;
+ Arg arg;
+
+ progname = argv[0];
+ /* command line args */
+ for(i = 1, arg.v = NULL; i < argc && argv[i][0] == '-'; i++) {
+ if(!strcmp(argv[i], "-x"))
+ showxid = TRUE;
+ else if(!strcmp(argv[i], "-e")) {
+ if(++i < argc)
+ embed = atoi(argv[i]);
+ else
+ usage();
+ }
+ else if(!strcmp(argv[i], "--")) {
+ i++;
+ break;
+ }
+ else if(!strcmp(argv[i], "-v"))
+ die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
+ else
+ usage();
+ }
+ if(i < argc)
+ arg.v = argv[i];
+ setup();
+ newclient();
+ if(arg.v) {
+ loaduri(clients, &arg);
+ }