closing bars when unfocusing them.
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index 3339d5d..3460e36 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -90,7 +90,7 @@ 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();
+static Client *newclient(void);
 static WebKitWebView *newwindow(WebKitWebView  *v, WebKitWebFrame *f, Client *c);
 static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
@@ -99,9 +99,9 @@ static void proccookies(SoupMessage *m, Client *c);
 static void progresschange(WebKitWebView *view, gint p, Client *c);
 static void request(SoupSession *s, SoupMessage *m, Client *c);
 static void reload(Client *c, const Arg *arg);
-static void rereadcookies();
+static void rereadcookies(void);
 static void setcookie(char *name, char *val, char *dom, char *path, long exp);
-static void setup();
+static void setup(void);
 static void titlechange(WebKitWebView* view, WebKitWebFrame* frame,
                const gchar* title, Client *c);
 static void scroll(Client *c, const Arg *arg);
@@ -111,7 +111,8 @@ static void showsearch(Client *c, const Arg *arg);
 static void showurl(Client *c, const Arg *arg);
 static void stop(Client *c, const Arg *arg);
 static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, Client *c);
-static void usage();
+static gboolean unfocusbar(GtkWidget *w, GdkEventFocus *e, Client *c);
+static void usage(void);
 static void update(Client *c);
 static void zoom(Client *c, const Arg *arg);
 
@@ -196,7 +197,7 @@ drawindicator(Client *c) {
                        TRUE, 0, 0, w->allocation.width, w->allocation.height);
        gdk_draw_rectangle(w->window, gc, TRUE, 0, 0, width,
                        w->allocation.height);
-       g_object_unref(gc);/*g_free(gc);*/
+       g_object_unref(gc);
 }
 
 gboolean
@@ -408,10 +409,12 @@ newclient(void) {
        /* urlbar */
        c->urlbar = gtk_entry_new();
        gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE);
+       g_signal_connect(G_OBJECT(c->urlbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
 
        /* searchbar */
        c->searchbar = gtk_entry_new();
        gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
+       g_signal_connect(G_OBJECT(c->searchbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
 
        /* indicator */
        c->indicator = gtk_drawing_area_new();
@@ -541,7 +544,7 @@ reload(Client *c, const Arg *arg) {
 }
 
 void
-rereadcookies() {
+rereadcookies(void) {
        const gchar *filename, *home;
 
        home = g_get_home_dir();
@@ -567,7 +570,7 @@ setcookie(char *name, char *val, char *dom, char *path, long exp) {
 }
 
 void
-setup() {
+setup(void) {
        dpy = GDK_DISPLAY();
        session = webkit_get_default_session();
        urlprop = XInternAtom(dpy, "_SURF_URL", False);
@@ -626,8 +629,15 @@ titlechange(WebKitWebView *v, WebKitWebFrame *f, const gchar *t, Client *c) {
        update(c);
 }
 
+gboolean
+unfocusbar(GtkWidget *w, GdkEventFocus *e, Client *c) {
+       hidesearch(c, NULL);
+       hideurl(c, NULL);
+       return TRUE;
+}
+
 void
-usage() {
+usage(void) {
        fputs("surf - simple browser\n", stderr);
        die("usage: surf [-e] [-x] [uri]\n");
 }