]> git.armaanb.net Git - chorizo.git/blobdiff - src/browser.c
Clean up bar margins and add tooltips
[chorizo.git] / src / browser.c
index d3f9e12d1a01fe99cb0d2fe8d66b634be3f4a84e..75bde2cba5252c376417710880ce1c05dbc5c74e 100644 (file)
@@ -122,10 +122,9 @@ client_destroy(GtkWidget *widget, gpointer data) {
 
 void
 set_uri(const char *uri, struct Client *c) {
-    gtk_widget_grab_focus(c->location);
-    const char *goal = (strcmp(cfg.home_uri, uri) == 0) ? cfg.default_uri : uri;
-    gtk_entry_set_text(GTK_ENTRY(c->location), goal);
-    gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
+    if (!gtk_widget_is_focus(c->location)) {
+        gtk_entry_set_text(GTK_ENTRY(c->location), uri);
+    }
 }
 
 WebKitWebView *
@@ -201,20 +200,20 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
     GtkWidget *locbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
 
     c->jsbutton = gtk_toggle_button_new_with_label("JS");
+    gtk_widget_set_tooltip_text(c->jsbutton, "Toggle JavaScript execution");
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->jsbutton),
                                  !cfg.javascript_disabled);
     g_signal_connect(G_OBJECT(c->jsbutton), "toggled", G_CALLBACK(togglejs), c);
 
     c->imgbutton = gtk_toggle_button_new_with_label("IMG");
+    gtk_widget_set_tooltip_text(c->imgbutton, "Toggle image loading");
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->imgbutton),
                                  !cfg.images_disabled);
     g_signal_connect(G_OBJECT(c->imgbutton), "toggled", G_CALLBACK(toggleimg),
                      c);
 
     c->location = gtk_entry_new();
-    gtk_box_pack_start(GTK_BOX(locbox), c->location, TRUE, TRUE, 5);
-    gtk_box_pack_end(GTK_BOX(locbox), c->jsbutton, FALSE, FALSE, 0);
-    gtk_box_pack_end(GTK_BOX(locbox), c->imgbutton, FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(locbox), c->location, TRUE, TRUE, 0);
 
     if (cfg.private) {
         GtkWidget *privindicator = gtk_label_new("Private mode");
@@ -224,6 +223,9 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
         gtk_box_pack_end(GTK_BOX(locbox), privindicator, FALSE, FALSE, 5);
     }
 
+    gtk_box_pack_start(GTK_BOX(locbox), c->jsbutton, FALSE, FALSE, 5);
+    gtk_box_pack_start(GTK_BOX(locbox), c->imgbutton, FALSE, FALSE, 0);
+
     g_signal_connect(G_OBJECT(c->location), "key-press-event",
                      G_CALLBACK(key_location), c);
     g_signal_connect(G_OBJECT(c->location), "icon-release",
@@ -320,8 +322,8 @@ cooperation_setup(void) {
         fprintf(stderr, __NAME__ ": Can't open FIFO at all.\n");
     } else {
         if (write(cooperative_pipe_fp, "", 0) == -1) {
-            /* Could not do an empty write to the FIFO which means there's no
-             * one listening. */
+            /* Could not do an empty write to the FIFO which means there's
+             * no one listening. */
             close(cooperative_pipe_fp);
             towatch = g_io_channel_new_file(fifopath, "r+", NULL);
             g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
@@ -443,7 +445,7 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data) {
      * now. Not updating the location bar in this scenario is important,
      * because we would override the "WEB PROCESS CRASHED" message. */
     if (t != NULL && strlen(t) > 0) {
-        gtk_entry_set_text(GTK_ENTRY(c->location), t);
+        set_uri(t, c);
 
         if (cfg.history_file != NULL && !cfg.private) {
             fp = fopen(cfg.history_file, "a");
@@ -589,7 +591,8 @@ grab_feeds_finished(GObject *object, GAsyncResult *result, gpointer data) {
     /* This was taken almost verbatim from the example in WebKit's
      * documentation:
      *
-     * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html */
+     * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html
+     */
 
     js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object),
                                                       result, &err);
@@ -641,7 +644,7 @@ hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht,
     }
 
     if (!gtk_widget_is_focus(c->location))
-        gtk_entry_set_text(GTK_ENTRY(c->location), to_show);
+        set_uri(to_show, c);
 }
 
 void
@@ -802,7 +805,12 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) {
                 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
                 return TRUE;
             } else if (def_key("location", GDK_KEY_t) == key) {
-                set_uri(uri, c);
+                gtk_widget_grab_focus(c->location);
+                const char *goal = (strcmp(cfg.home_uri, uri) == 0 || !uri)
+                                       ? cfg.default_uri
+                                       : uri;
+                gtk_entry_set_text(GTK_ENTRY(c->location), goal);
+                gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
                 return TRUE;
             } else if (def_key("print", GDK_KEY_Print) == key) {
                 WebKitPrintOperation *operation =