+void
+newrequest(SoupSession *s, SoupMessage *msg, gpointer v) {
+ SoupMessageHeaders *h = msg->request_headers;
+ SoupURI *uri;
+ const char *c;
+
+ soup_message_headers_remove(h, "Cookie");
+ uri = soup_message_get_uri(msg);
+ if((c = getcookies(uri)))
+ soup_message_headers_append(h, "Cookie", c);
+ g_signal_connect_after(G_OBJECT(msg), "got-headers", G_CALLBACK(gotheaders), NULL);
+}
+
+void
+newwindow(Client *c, const Arg *arg) {
+ guint i = 0;
+ const char *cmd[10], *uri;
+ const Arg a = { .v = (void *)cmd };
+ char tmp[64];
+
+ cmd[i++] = progname;
+ if(embed) {
+ cmd[i++] = "-e";
+ snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed);
+ cmd[i++] = tmp;
+ }
+ if(!script)
+ cmd[i++] = "-s";
+ if(!plugin)
+ cmd[i++] = "-p";
+ if(!loadimage)
+ cmd[i++] = "-i";
+ if(showxid)
+ cmd[i++] = "-x";
+ cmd[i++] = "--";
+ uri = arg->v ? (char *)arg->v : c->linkhover;
+ if(uri)
+ cmd[i++] = uri;
+ cmd[i++] = NULL;
+ spawn(NULL, &a);
+}
+
+void
+pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) {
+ Arg arg = {.v = text };
+ if(text != NULL)
+ loaduri((Client *) d, &arg);
+}
+
+void
+print(Client *c, const Arg *arg) {
+ webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
+}
+
+GdkFilterReturn
+processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
+ Client *c = (Client *)d;
+ XPropertyEvent *ev;
+ Arg arg;
+
+ if(((XEvent *)e)->type == PropertyNotify) {
+ ev = &((XEvent *)e)->xproperty;
+ if(ev->state == PropertyNewValue) {
+ if(ev->atom == atoms[AtomFind]) {
+ arg.b = TRUE;
+ find(c, &arg);
+ return GDK_FILTER_REMOVE;
+ }
+ else if(ev->atom == atoms[AtomGo]) {
+ arg.v = getatom(c, AtomGo);
+ loaduri(c, &arg);
+ return GDK_FILTER_REMOVE;
+ }
+ }
+ }
+ return GDK_FILTER_CONTINUE;
+}
+
+void
+progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
+ c->progress = webkit_web_view_get_progress(c->view) * 100;
+ update(c);
+}
+
+void
+reload(Client *c, const Arg *arg) {
+ gboolean nocache = *(gboolean *)arg;
+ if(nocache)
+ webkit_web_view_reload_bypass_cache(c->view);
+ else
+ webkit_web_view_reload(c->view);
+}
+
+void
+resize(GtkWidget *w, GtkAllocation *a, Client *c) {
+ double zoom;
+
+ if(c->zoomed)
+ return;
+ zoom = webkit_web_view_get_zoom_level(c->view);
+ if(a->width * a->height < 300 * 400 && zoom != 0.2)
+ webkit_web_view_set_zoom_level(c->view, 0.2);
+ else if(zoom != 1.0)
+ webkit_web_view_set_zoom_level(c->view, 1.0);
+}
+
+void
+scroll(Client *c, const Arg *arg) {
+ gdouble v;
+ GtkAdjustment *a;
+
+ a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(c->scroll));
+ v = gtk_adjustment_get_value(a);
+ v += gtk_adjustment_get_step_increment(a) * arg->i;
+ v = MAX(v, 0.0);
+ v = MIN(v, gtk_adjustment_get_upper(a) - gtk_adjustment_get_page_size(a));
+ gtk_adjustment_set_value(a, v);
+}
+
+void
+setcookie(SoupCookie *c) {
+ int lock;
+
+ lock = open(cookiefile, 0);
+ flock(lock, LOCK_EX);
+ SoupDate *e;
+ SoupCookieJar *j = soup_cookie_jar_text_new(cookiefile, FALSE);
+ c = soup_cookie_copy(c);
+ if(c->expires == NULL && sessiontime) {
+ e = soup_date_new_from_time_t(time(NULL) + sessiontime);
+ soup_cookie_set_expires(c, e);
+ }
+ soup_cookie_jar_add_cookie(j, c);
+ g_object_unref(j);
+ flock(lock, LOCK_UN);
+ close(lock);
+}
+
+void
+setatom(Client *c, int a, const char *v) {
+ XSync(dpy, False);
+ XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), atoms[a],
+ XA_STRING, 8, PropModeReplace, (unsigned char *)v,
+ strlen(v) + 1);
+}