X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=74a2d559c455b424de910d1d8034068c420465c4;hb=c5144c040f554f0320c744cb48a2d8dc1b646c4e;hp=64f2a753814238f0e9247d95c2cd167bd178aaa9;hpb=d536cb6fe1eca5e59adfe6cf20c30d43c7f72858;p=surf.git diff --git a/surf.c b/surf.c index 64f2a75..74a2d55 100644 --- a/surf.c +++ b/surf.c @@ -26,6 +26,7 @@ typedef struct Client { gint progress; struct Client *next; } Client; +SoupCookieJar *cookiejar; Client *clients = NULL; gboolean embed = FALSE; gboolean showxid = FALSE; @@ -40,7 +41,7 @@ static gboolean decidewindow(WebKitWebView *view, WebKitWebFrame *f, static void destroyclient(Client *c); static void destroywin(GtkWidget* w, gpointer d); static void die(char *str); -static gboolean download(WebKitWebView *view, GObject *o, gpointer d); +static gboolean download(WebKitWebView *view, WebKitDownload *o, gpointer d); static gchar *geturi(Client *c); static void hidesearch(Client *c); static void hideurl(Client *c); @@ -107,9 +108,20 @@ void die(char *str) { } gboolean -download(WebKitWebView *view, GObject *o, gpointer d) { +download(WebKitWebView *view, WebKitDownload *o, gpointer d) { /* TODO */ - return FALSE; + const gchar *home; + gchar *uri, *filename; + + home = g_get_home_dir(); + filename = g_build_filename(home, "Desktop", + webkit_download_get_suggested_filename(o), NULL); + uri = g_strconcat("file://", filename, NULL); + webkit_download_set_destination_uri(o, uri); + g_free(filename); + g_free(uri); + webkit_download_start(o); + return TRUE; } gchar * @@ -172,7 +184,7 @@ keypress(GtkWidget* w, GdkEventKey *ev, gpointer d) { return FALSE; } } - if(ev->state == GDK_CONTROL_MASK || ev->state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) { + else if(ev->state == GDK_CONTROL_MASK || ev->state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) { switch(ev->keyval) { case GDK_r: case GDK_R: @@ -197,6 +209,16 @@ keypress(GtkWidget* w, GdkEventKey *ev, gpointer d) { return TRUE; } } + else { + switch(ev->keyval) { + case GDK_k: + webkit_web_view_move_cursor(c->view, GTK_MOVEMENT_DISPLAY_LINES, -1); + return TRUE; + case GDK_j: + webkit_web_view_move_cursor(c->view, GTK_MOVEMENT_DISPLAY_LINES, 1); + return TRUE; + } + } return FALSE; } @@ -245,7 +267,7 @@ loadfile(const Client *c, const gchar *f) { g_string_prepend(uri, "file://"); loaduri(c, uri->str); } - + } void @@ -353,7 +375,7 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) { if(((XEvent *)e)->type == PropertyNotify) { ev = &((XEvent *)e)->xproperty; if(ignore_once == FALSE && ev->atom == urlprop && ev->state == PropertyNewValue) { - XGetWindowProperty(dpy, ev->window, urlprop, 0L, BUFSIZ, False, XA_STRING, + XGetWindowProperty(dpy, ev->window, urlprop, 0L, BUFSIZ, False, XA_STRING, &adummy, &idummy, &ldummy, &ldummy, &buf); loaduri(c, (gchar *)buf); XFree(buf); @@ -408,8 +430,10 @@ updatetitle(Client *c) { int main(int argc, char *argv[]) { gchar *uri = NULL, *file = NULL; + SoupSession *s; Client *c; int o; + const gchar *home, *filename; gtk_init(NULL, NULL); if (!g_thread_supported()) @@ -451,6 +475,14 @@ int main(int argc, char *argv[]) { goto argerr; if(!clients) newclient(); + + /* cookie persistance */ + s = webkit_get_default_session(); + home = g_get_home_dir(); + filename = g_build_filename(home, ".surf-cookies", NULL); + cookiejar = soup_cookie_jar_text_new(filename, FALSE); + soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar)); + gtk_main(); cleanup(); return EXIT_SUCCESS;