From: Armaan Bhojwani Date: Wed, 9 Jun 2021 23:53:25 +0000 (-0400) Subject: Don't overwrite url bar if already focused X-Git-Tag: v1.0.0~18 X-Git-Url: https://git.armaanb.net/?p=chorizo.git;a=commitdiff_plain;h=7001c96bcd0c95e145511e271a90b27158550be8 Don't overwrite url bar if already focused --- diff --git a/src/browser.c b/src/browser.c index d3f9e12..b8e219d 100644 --- a/src/browser.c +++ b/src/browser.c @@ -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 =