]> git.armaanb.net Git - chorizo.git/commitdiff
Don't overwrite url bar if already focused
authorArmaan Bhojwani <me@armaanb.net>
Wed, 9 Jun 2021 23:53:25 +0000 (19:53 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Thu, 10 Jun 2021 14:13:45 +0000 (10:13 -0400)
src/browser.c

index d3f9e12d1a01fe99cb0d2fe8d66b634be3f4a84e..b8e219d12947c5c38c58e4d3740a7fd50204613d 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 *
@@ -320,8 +319,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 +442,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 +588,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 +641,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 +802,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 =