Simplify handling of c->title

This commit is contained in:
Quentin Rameau 2015-11-22 13:24:24 +01:00
parent 10105c8b87
commit d4ac9fb6f4
1 changed files with 13 additions and 17 deletions

30
surf.c
View File

@ -333,14 +333,12 @@ newclient(Client *rc)
if (!(c = calloc(1, sizeof(Client)))) if (!(c = calloc(1, sizeof(Client))))
die("Cannot malloc!\n"); die("Cannot malloc!\n");
c->title = NULL;
c->progress = 100;
c->next = clients; c->next = clients;
clients = c; clients = c;
c->view = newview(c, rc ? rc->view : NULL); c->progress = 100;
c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1; c->tlsflags = G_TLS_CERTIFICATE_VALIDATE_ALL + 1;
c->view = newview(c, rc ? rc->view : NULL);
return c; return c;
} }
@ -435,26 +433,24 @@ void
updatetitle(Client *c) updatetitle(Client *c)
{ {
char *title; char *title;
const char *name = c->targeturi ? c->targeturi :
c->title ? c->title : "";
if (showindicators) { if (showindicators) {
gettogglestats(c); gettogglestats(c);
getpagestats(c); getpagestats(c);
if (c->progress != 100) { if (c->progress != 100)
title = g_strdup_printf("[%i%%] %s:%s | %s", title = g_strdup_printf("[%i%%] %s:%s | %s",
c->progress, togglestats, pagestats, c->progress, togglestats, pagestats, name);
c->targeturi ? c->targeturi : c->title); else
} else {
title = g_strdup_printf("%s:%s | %s", title = g_strdup_printf("%s:%s | %s",
togglestats, pagestats, togglestats, pagestats, name);
c->targeturi ? c->targeturi : c->title);
}
gtk_window_set_title(GTK_WINDOW(c->win), title); gtk_window_set_title(GTK_WINDOW(c->win), title);
g_free(title); g_free(title);
} else { } else {
gtk_window_set_title(GTK_WINDOW(c->win), c->title ? gtk_window_set_title(GTK_WINDOW(c->win), name);
c->title : "");
} }
} }
@ -1543,15 +1539,15 @@ main(int argc, char *argv[])
} ARGEND; } ARGEND;
if (argc > 0) if (argc > 0)
arg.v = argv[0]; arg.v = argv[0];
else
arg.v = "about:blank";
setup(); setup();
c = newclient(NULL); c = newclient(NULL);
showview(NULL, c); showview(NULL, c);
if (arg.v) loaduri(c, &arg);
loaduri(clients, &arg); updatetitle(c);
else
updatetitle(c);
gtk_main(); gtk_main();
cleanup(); cleanup();