X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=1a798ff4f3b38cd726c778dc2d7cdffd0d5436ba;hb=d4ac9fb6f4b719607fa7ff13a44a78d057d27be5;hp=bacf78f33a83c591828b5601ef8671c9b4fcf28a;hpb=bd17d359d6a9eb2461a939a33d710b2f0dade4f1;p=surf.git diff --git a/surf.c b/surf.c index bacf78f..1a798ff 100644 --- a/surf.c +++ b/surf.c @@ -211,7 +211,7 @@ die(const char *errstr, ...) va_start(ap, errstr); vfprintf(stderr, errstr, ap); va_end(ap); - exit(EXIT_FAILURE); + exit(1); } void @@ -259,7 +259,8 @@ sigchld(int unused) { if (signal(SIGCHLD, sigchld) == SIG_ERR) die("Can't install SIGCHLD handler"); - while (0 < waitpid(-1, NULL, WNOHANG)); + while (waitpid(-1, NULL, WNOHANG) > 0) + ; } char * @@ -332,14 +333,12 @@ newclient(Client *rc) if (!(c = calloc(1, sizeof(Client)))) die("Cannot malloc!\n"); - c->title = NULL; - c->progress = 100; - c->next = clients; clients = c; - c->view = newview(c, rc ? rc->view : NULL); + c->progress = 100; c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1; + c->view = newview(c, rc ? rc->view : NULL); return c; } @@ -434,26 +433,24 @@ void updatetitle(Client *c) { char *title; + const char *name = c->targeturi ? c->targeturi : + c->title ? c->title : ""; if (showindicators) { gettogglestats(c); getpagestats(c); - if (c->progress != 100) { + if (c->progress != 100) title = g_strdup_printf("[%i%%] %s:%s | %s", - c->progress, togglestats, pagestats, - c->targeturi ? c->targeturi : c->title); - } else { + c->progress, togglestats, pagestats, name); + else title = g_strdup_printf("%s:%s | %s", - togglestats, pagestats, - c->targeturi ? c->targeturi : c->title); - } + togglestats, pagestats, name); gtk_window_set_title(GTK_WINDOW(c->win), title); g_free(title); } else { - gtk_window_set_title(GTK_WINDOW(c->win), c->title ? - c->title : ""); + gtk_window_set_title(GTK_WINDOW(c->win), name); } } @@ -948,6 +945,7 @@ showview(WebKitWebView *v, Client *c) GtkWidget * createwindow(Client *c) { + char *wmstr; GtkWidget *w; if (embed) { @@ -955,19 +953,14 @@ createwindow(Client *c) } else { w = gtk_window_new(GTK_WINDOW_TOPLEVEL); - /* TA: 20091214: Despite what the GNOME docs say, the ICCCM - * is always correct, so we should still call this function. - * But when doing so, we *must* differentiate between a - * WM_CLASS and a resource on the window. By convention, the - * window class (WM_CLASS) is capped, while the resource is in - * lowercase. Both these values come as a pair. - */ - gtk_window_set_wmclass(GTK_WINDOW(w), "surf", "Surf"); + wmstr = g_path_get_basename(argv0); + gtk_window_set_wmclass(GTK_WINDOW(w), wmstr, "Surf"); + g_free(wmstr); - /* TA: 20091214: And set the role here as well -- so that - * sessions can pick this up. - */ - gtk_window_set_role(GTK_WINDOW(w), "Surf"); + wmstr = g_strdup_printf("%s[%lu]", "Surf", + webkit_web_view_get_page_id(c->view)); + gtk_window_set_role(GTK_WINDOW(w), wmstr); + g_free(wmstr); gtk_window_set_default_size(GTK_WINDOW(w), 800, 600); } @@ -1223,7 +1216,7 @@ void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) { Arg a = {.v = text }; - if (!text) + if (text) loaduri((Client *) d, &a); } @@ -1546,18 +1539,18 @@ main(int argc, char *argv[]) } ARGEND; if (argc > 0) arg.v = argv[0]; + else + arg.v = "about:blank"; setup(); c = newclient(NULL); showview(NULL, c); - if (arg.v) - loaduri(clients, &arg); - else - updatetitle(c); + loaduri(c, &arg); + updatetitle(c); gtk_main(); cleanup(); - return EXIT_SUCCESS; + return 0; }