-fullscreen(Client *c, const Arg *arg)
-{
- if (c->fullscreen)
- gtk_window_unfullscreen(GTK_WINDOW(c->win));
- else
- gtk_window_fullscreen(GTK_WINDOW(c->win));
- c->fullscreen = !c->fullscreen;
-}
-
-gboolean
-permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c)
-{
- if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) {
- if (allowgeolocation)
- webkit_permission_request_allow(r);
- else
- webkit_permission_request_deny(r);
- return TRUE;
- }
-
- return FALSE;
-}
-
-const char *
-getatom(Client *c, int a)
-{
- static char buf[BUFSIZ];
- Atom adummy;
- int idummy;
- unsigned long ldummy;
- unsigned char *p = NULL;
-
- XGetWindowProperty(dpy, c->xid,
- atoms[a], 0L, BUFSIZ, False, XA_STRING,
- &adummy, &idummy, &ldummy, &ldummy, &p);
- if (p)
- strncpy(buf, (char *)p, LENGTH(buf)-1);
- else
- buf[0] = '\0';
- XFree(p);
-
- return buf;
-}
-
-char *
-geturi(Client *c)
-{
- char *uri;
-
- if (!(uri = (char *)webkit_web_view_get_uri(c->view)))
- uri = "about:blank";
- return uri;
-}
-
-const gchar *
-getstyle(const char *uri)
-{
- int i;
-
- if (stylefile != NULL)
- return stylefile;
-
- for (i = 0; i < LENGTH(styles); i++) {
- if (styles[i].regex && !regexec(&(styles[i].re), uri, 0,
- NULL, 0))
- return styles[i].style;
- }
-
- return "";
-}
-
-void
-setstyle(Client *c, const char *style)
-{
- WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
-
- g_object_set(G_OBJECT(settings), "user-stylesheet-uri", style, NULL);
-}
-
-void
-handleplumb(Client *c, WebKitWebView *w, const gchar *uri)
-{
- Arg arg;
-
- webkit_web_view_stop_loading(w);
- arg = (Arg)PLUMB((char *)uri);
- spawn(c, &arg);
-}
-
-gboolean
-initdownload(WebKitWebView *view, WebKitDownload *o, Client *c)
-{
- Arg arg;
-
- updatewinid(c);
- arg = (Arg)DOWNLOAD((char *)webkit_download_get_uri(o), geturi(c));
- spawn(c, &arg);
- return FALSE;
-}
-
-void
-inspector(Client *c, const Arg *arg)
-{
- if (enableinspector) {
- if (c->isinspecting)
- webkit_web_inspector_close(c->inspector);
- else
- webkit_web_inspector_show(c->inspector);
- }
-}
-
-WebKitWebView *
-inspector_new(WebKitWebInspector *i, WebKitWebView *v, Client *c)
-{
- return WEBKIT_WEB_VIEW(webkit_web_view_new());
-}
-
-gboolean
-inspector_show(WebKitWebInspector *i, Client *c)
-{
- WebKitWebView *w;
-
- if (c->isinspecting)
- return false;
-
- w = webkit_web_inspector_get_web_view(i);
- gtk_paned_pack2(GTK_PANED(c->pane), GTK_WIDGET(w), TRUE, TRUE);
- gtk_widget_show(GTK_WIDGET(w));
- c->isinspecting = true;
-
- return true;
-}
-
-gboolean
-inspector_close(WebKitWebInspector *i, Client *c)
-{
- GtkWidget *w;
-
- if (!c->isinspecting)
- return false;
-
- w = GTK_WIDGET(webkit_web_inspector_get_web_view(i));
- gtk_widget_hide(w);
- gtk_widget_destroy(w);
- c->isinspecting = false;
-
- return true;
-}
-
-void
-inspector_finished(WebKitWebInspector *i, Client *c)
-{
- g_free(c->inspector);
-}
-
-gboolean
-keypress(GtkAccelGroup *group, GObject *obj, guint key, GdkModifierType mods,
- Client *c)
-{
- guint i;
- gboolean processed = FALSE;
-
- mods = CLEANMASK(mods);
- key = gdk_keyval_to_lower(key);
- updatewinid(c);
- for (i = 0; i < LENGTH(keys); i++) {
- if (key == keys[i].keyval
- && mods == keys[i].mod
- && keys[i].func) {
- keys[i].func(c, &(keys[i].arg));
- processed = TRUE;
- }
- }
-
- return processed;
-}
-
-void
-mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
- Client *c)
-{
- WebKitHitTestResultContext hc;
-
- /* Keep the hit test to know where is the pointer on the next click */
- c->mousepos = h;
-
- hc = webkit_hit_test_result_get_context(h);
-
- if (hc & OnLink)
- c->targeturi = webkit_hit_test_result_get_link_uri(h);
- else if (hc & OnImg)
- c->targeturi = webkit_hit_test_result_get_image_uri(h);
- else if (hc & OnMedia)
- c->targeturi = webkit_hit_test_result_get_media_uri(h);
- else
- c->targeturi = NULL;
- updatetitle(c);
-}
-
-void
-loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c)
-{
- switch (e) {
- case WEBKIT_LOAD_STARTED:
- c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
- break;
- case WEBKIT_LOAD_REDIRECTED:
- setatom(c, AtomUri, geturi(c));
- break;
- case WEBKIT_LOAD_COMMITTED:
- if (!webkit_web_view_get_tls_info(c->view, NULL, &(c->tlsflags)))
- c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
-
- setatom(c, AtomUri, geturi(c));
-
- if (enablestyle)
- setstyle(c, getstyle(geturi(c)));
- break;
- case WEBKIT_LOAD_FINISHED:
- /* Disabled until we write some WebKitWebExtension for
- * manipulating the DOM directly.
- evalscript(c, "document.documentElement.style.overflow = '%s'",
- enablescrollbars ? "auto" : "hidden");
- */
- runscript(c);
- break;
- }
- updatetitle(c);
-}
-
-void
-loaduri(Client *c, const Arg *arg)
-{
- char *u = NULL, *rp;
- const char *uri = (char *)arg->v;
- Arg a = { .b = FALSE };
- struct stat st;
-
- if (strcmp(uri, "") == 0)
- return;
-
- /* In case it's a file path. */
- if (stat(uri, &st) == 0) {
- rp = realpath(uri, NULL);
- u = g_strdup_printf("file://%s", rp);
- free(rp);
- } else {
- u = g_strrstr(uri, "://") ? g_strdup(uri)
- : g_strdup_printf("http://%s", uri);
- }
-
- setatom(c, AtomUri, uri);
-
- /* prevents endless loop */
- if (strcmp(u, geturi(c)) == 0) {
- reload(c, &a);
- } else {
- webkit_web_view_load_uri(c->view, u);
- c->progress = 0;
- c->title = copystr(&c->title, u);
- updatetitle(c);
- }
- g_free(u);
-}
-
-void
-navigate(Client *c, const Arg *arg)
-{
- int steps = *(int *)arg;
- webkit_web_view_go_back_or_forward(c->view, steps);
-}
-
-Client *
-newclient(Client *rc)