X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=3193540c2a9fa26ab8166eee352cc72677b06ab7;hb=24bbd6be02e87926e803028477538ce929253626;hp=cd80c21a4a7fc76ffb63c241d685c4e5df69a79c;hpb=029dac1504f9da97a3481d5e0fde0b18c2b33562;p=surf.git diff --git a/surf.c b/surf.c index cd80c21..3193540 100644 --- a/surf.c +++ b/surf.c @@ -86,7 +86,6 @@ static gboolean keypress(GtkWidget* w, GdkEventKey *ev, Client *c); static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, Client *c); static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, Client *c); static void loadstart(WebKitWebView *view, WebKitWebFrame *f, Client *c); -static void loadfile(Client *c, const gchar *f); static void loaduri(Client *c, const Arg *arg); static void navigate(Client *c, const Arg *arg); static Client *newclient(void); @@ -136,7 +135,6 @@ buildpath(const gchar *path) { /* creating file (gives error when apath ends with "/") */ if((f = g_fopen(apath, "a"))) fclose(f); - puts(apath); return apath; } @@ -176,7 +174,7 @@ void destroyclient(Client *c) { Client *p; - gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new())); + gtk_widget_destroy(GTK_WIDGET(c->view)); gtk_widget_destroy(c->scroll); gtk_widget_destroy(c->urlbar); gtk_widget_destroy(c->searchbar); @@ -339,39 +337,6 @@ loadstart(WebKitWebView *view, WebKitWebFrame *f, Client *c) { update(c); } -void -loadfile(Client *c, const gchar *f) { - GIOChannel *chan = NULL; - GError *e = NULL; - GString *code; - gchar *line, *uri; - Arg arg; - - if(strcmp(f, "-") == 0) { - chan = g_io_channel_unix_new(STDIN_FILENO); - if (chan) { - code = g_string_new(""); - while(g_io_channel_read_line(chan, &line, NULL, NULL, - &e) == G_IO_STATUS_NORMAL) { - g_string_append(code, line); - g_free(line); - } - webkit_web_view_load_html_string(c->view, code->str, - "file://."); - g_io_channel_shutdown(chan, FALSE, NULL); - g_string_free(code, TRUE); - } - arg.v = uri = g_strdup("stdin"); - } - else { - arg.v = uri = g_strdup_printf("file://%s", f); - loaduri(c, &arg); - } - c->title = copystr(&c->title, uri); - update(c); - g_free(uri); -} - void loaduri(Client *c, const Arg *arg) { gchar *u; @@ -630,10 +595,10 @@ showsearch(Client *c, const Arg *arg) { void source(Client *c, const Arg *arg) { Arg a = { .b = FALSE }; - /*gboolean s; + gboolean s; s = webkit_web_view_get_view_source_mode(c->view); - webkit_web_view_set_view_source_mode(c->view, c->source);*/ + webkit_web_view_set_view_source_mode(c->view, !s); reload(c, &a); } @@ -726,7 +691,6 @@ zoom(Client *c, const Arg *arg) { int main(int argc, char *argv[]) { int i; Arg arg; - Client *c; /* command line args */ for(i = 1, arg.v = NULL; i < argc; i++) { @@ -748,12 +712,9 @@ int main(int argc, char *argv[]) { arg.v = argv[i]; } setup(); - c = newclient(); + newclient(); if(arg.v) { - if(strchr("./", ((char *)arg.v)[0]) || strcmp("-", (char *)arg.v) == 0) - loadfile(c, (char *)arg.v); - else - loaduri(c, &arg); + loaduri(clients, &arg); } gtk_main(); cleanup();