static Display *dpy;
static Atom uriprop;
-static SoupCookieJar *cookiejar;
+static SoupCookieJar *cookies;
static SoupSession *session;
static Client *clients = NULL;
static GdkNativeWindow embed = 0;
static gboolean ignore_once = FALSE;
static char winid[64];
static char *progname;
+static gboolean lockcookie = FALSE;
static const char *autouri(Client *c);
static char *buildpath(const char *path);
+static void changecookie(SoupCookieJar *jar, SoupCookie *o, SoupCookie *n, gpointer p);
static void cleanup(void);
static void clipboard(Client *c, const Arg *arg);
static void context(WebKitWebView *v, GtkMenu *m, Client *c);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
static void print(Client *c, const Arg *arg);
static void progresschange(WebKitWebView *v, gint p, Client *c);
+static void reloadcookies();
static void reload(Client *c, const Arg *arg);
+static void resize(GtkWidget *w, GtkAllocation *a, Client *c);
static void sigchld(int unused);
static void setup(void);
static void spawn(Client *c, const Arg *arg);
-static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c);
static void scroll(Client *c, const Arg *arg);
static void searchtext(Client *c, const Arg *arg);
static void source(Client *c, const Arg *arg);
return apath;
}
+void
+changecookie(SoupCookieJar *j, SoupCookie *oc, SoupCookie *c, gpointer p) {
+ SoupDate *e;
+ SoupCookieJar *jar;
+
+ if(lockcookie)
+ return;
+ if(c && c->expires == NULL) {
+ e = soup_date_new_from_time_t(time(NULL) + sessiontime);
+ c = soup_cookie_copy(c);
+ soup_cookie_set_expires(c, e);
+ }
+
+ jar = soup_cookie_jar_text_new(cookiefile, FALSE);
+ if(c)
+ soup_cookie_jar_add_cookie(jar, soup_cookie_copy(c));
+ else
+ soup_cookie_jar_delete_cookie(jar, oc);
+ g_object_unref(jar);
+}
+
void
cleanup(void) {
while(clients)
if(parent)
gtk_container_remove(parent, c->items[i]);
gtk_menu_shell_append(GTK_MENU_SHELL(m), c->items[i]);
- g_signal_connect(G_OBJECT(c->items[i]), "activate",
- G_CALLBACK(itemclick), c);
gtk_widget_show(c->items[i]);
}
}
XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), uriprop,
XA_STRING, 8, PropModeReplace, (unsigned char *)uri,
strlen(uri) + 1);
+
+ reloadcookies();
}
void
gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
+ g_signal_connect(G_OBJECT(c->win), "size-allocate", G_CALLBACK(resize), c);
if(!(c->items = calloc(1, sizeof(GtkWidget *) * LENGTH(items))))
die("Cannot malloc!\n");
/* contextmenu */
- for(i = 0; i < LENGTH(items); i++)
+ for(i = 0; i < LENGTH(items); i++) {
c->items[i] = gtk_menu_item_new_with_label(items[i].label);
-
+ g_signal_connect(G_OBJECT(c->items[i]), "activate",
+ G_CALLBACK(itemclick), c);
+ }
/* VBox */
c->vbox = gtk_vbox_new(FALSE, 0);
webkit_web_view_reload(c->view);
}
+void
+reloadcookies() {
+ SoupCookieJar *jar;
+ GSList *l, *e;
+
+ lockcookie = TRUE;
+ for(l = e = soup_cookie_jar_all_cookies(cookies); e; e = e->next)
+ soup_cookie_jar_delete_cookie(cookies, (SoupCookie *)e->data);
+ soup_cookies_free(l);
+ jar = soup_cookie_jar_text_new(cookiefile, TRUE);
+ for(l = e = soup_cookie_jar_all_cookies(jar); e; e = e->next)
+ soup_cookie_jar_add_cookie(cookies, (SoupCookie *)e->data);
+ g_slist_free(l);
+ lockcookie = FALSE;
+ g_object_unref(jar);
+}
+
void
scroll(Client *c, const Arg *arg) {
gdouble v;
gtk_adjustment_set_value(a, v);
}
+void
+resize(GtkWidget *w, GtkAllocation *a, Client *c) {
+ double zoom;
+
+ zoom = webkit_web_view_get_zoom_level(c->view);
+ if(a->width * a->height < 300 * 300 && 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
sigchld(int unused) {
if(signal(SIGCHLD, sigchld) == SIG_ERR)
dpy = GDK_DISPLAY();
session = webkit_get_default_session();
- uriprop = XInternAtom(dpy, "_SURF_uri", False);
+ uriprop = XInternAtom(dpy, "_SURF_URI", False);
/* create dirs and files */
cookiefile = buildpath(cookiefile);
/* cookie persistance */
s = webkit_get_default_session();
- cookiejar = soup_cookie_jar_text_new(cookiefile, FALSE);
- soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
+ cookies = soup_cookie_jar_new();
+ soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookies));
+ g_signal_connect(cookies, "changed", G_CALLBACK(changecookie), NULL);
+ reloadcookies();
}
void
close(ConnectionNumber(dpy));
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
- fprintf(stderr, "tabbed: execvp %s", ((char **)arg->v)[0]);
+ fprintf(stderr, "surf: execvp %s", ((char **)arg->v)[0]);
perror(" failed");
exit(0);
}