#include <webkit/webkit.h>
#include <glib/gstdio.h>
-#define LENGTH(x) (sizeof x / sizeof x[0])
+#define LENGTH(x) (sizeof x / sizeof x[0])
#define CLEANMASK(mask) (mask & ~(GDK_MOD2_MASK))
Display *dpy;
SoupSession *session;
Client *clients = NULL;
Cookie *cookies = NULL;
-gboolean embed = FALSE;
+GdkNativeWindow embed = 0;
gboolean showxid = FALSE;
gboolean ignore_once = FALSE;
gchar *workdir;
die("Cannot malloc!\n");
/* Window */
if(embed) {
- c->win = gtk_plug_new(0);
+ c->win = gtk_plug_new(embed);
}
else {
c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
void
setup(void) {
- const gchar *home;
+ const gchar *home, *name;
+ SoupSession *s;
+ FILE *tmp;
+
dpy = GDK_DISPLAY();
session = webkit_get_default_session();
urlprop = XInternAtom(dpy, "_SURF_URL", False);
+
+ /* create dirs and files */
home = g_get_home_dir();
workdir = g_build_filename(home, ".surf", NULL);
+ g_mkdir_with_parents(workdir, 0755);
+ name = g_build_filename(workdir, "dl", NULL);
+ g_mkdir(name, 0755);
+ name = g_build_filename(workdir, "style.css", NULL);
+ if((tmp = g_fopen(name, "a")));
+ fclose(tmp);
+
+
+ /* cookie persistance */
+ s = webkit_get_default_session();
+ name = g_build_filename(workdir, "cookies.txt", NULL);
+ cookiejar = soup_cookie_jar_text_new(name, FALSE);
+ soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
}
void
unfocusbar(GtkWidget *w, GdkEventFocus *e, Client *c) {
hidesearch(c, NULL);
hideurl(c, NULL);
- return TRUE;
+ return FALSE;
}
void
usage(void) {
fputs("surf - simple browser\n", stderr);
- die("usage: surf [-e] [-x] [uri]\n");
+ die("usage: surf [-e Window] [-x] [uri]\n");
}
void
}
int main(int argc, char *argv[]) {
- SoupSession *s;
Client *c;
- gint o;
- const gchar *filename;
+ gint o, a;
Arg arg;
gtk_init(NULL, NULL);
if (!g_thread_supported())
g_thread_init(NULL);
- setup();
- while((o = getopt(argc, argv, "vhxeu:f:")) != -1)
+ while((o = getopt(argc, argv, "vhxe:")) != -1)
switch(o) {
case 'x':
showxid = TRUE;
break;
case 'e':
- showxid = TRUE;
- embed = TRUE;
+ if(!(a = atoi(optarg)))
+ usage();
+ embed = a;
break;
case 'v':
die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
}
else if(optind != argc)
usage();
+ setup();
if(!clients)
newclient();
- /* make dirs */
- filename = g_build_filename(workdir, "dl", NULL);
- g_mkdir_with_parents(filename, 0755);
-
- /* cookie persistance */
- s = webkit_get_default_session();
- filename = g_build_filename(workdir, "cookies.jar", NULL);
- cookiejar = soup_cookie_jar_text_new(filename, FALSE);
- soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
gtk_main();
cleanup();