From c760d9b8e9f3e7f6a5a1d1a0f16335f1abcb8cbc Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Wed, 9 Jun 2021 15:26:00 -0400 Subject: [PATCH] Add default_uri option and focus bar on new tabs --- man/chorizo-config.5.scd | 5 +++++ src/browser.c | 25 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/man/chorizo-config.5.scd b/man/chorizo-config.5.scd index 11ad785..d99d788 100644 --- a/man/chorizo-config.5.scd +++ b/man/chorizo-config.5.scd @@ -64,6 +64,11 @@ subsection. Choose a custom user agent. ## UI +*default_uri*++ + Type: string++ + Default: "https://"++ + The URI to fill the location bar with when entering the it from the homepage. + *scroll_lines*++ Type: integer++ Default: 3++ diff --git a/src/browser.c b/src/browser.c index d338c11..1d25b77 100644 --- a/src/browser.c +++ b/src/browser.c @@ -62,6 +62,7 @@ struct Configuration { gboolean javascript_disabled; gboolean private; gboolean spellcheck_disabled; + gchar *default_uri; gchar *download_dir; gchar *fifo_suffix; gchar *history_file; @@ -119,6 +120,14 @@ client_destroy(GtkWidget *widget, gpointer data) { quit_if_nothing_active(); } +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); +} + WebKitWebView * client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, gboolean focus_tab) { @@ -280,8 +289,9 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, g_free(f); } - clients++; + set_uri(uri, c); + clients++; return WEBKIT_WEB_VIEW(c->web_view); } @@ -542,6 +552,8 @@ get_config(void) { } } + cfg.default_uri = g_key_file_get_string(config, "ui", "default_uri", NULL); + cfg.default_uri = (cfg.default_uri) ? cfg.default_uri : "https://"; cfg.tab_width_chars = g_key_file_get_integer(config, "ui", "tab_width", NULL); cfg.tab_width_chars = (cfg.tab_width_chars) ? cfg.tab_width_chars : 20; @@ -777,6 +789,8 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) { if (event->type == GDK_KEY_PRESS) { if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) { + const char *uri = + webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)); int key = ((GdkEventKey *)event)->keyval; if (def_key("download_manager", GDK_KEY_y) == key) { downloadmanager_show(); @@ -788,12 +802,7 @@ 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) { - gtk_widget_grab_focus(c->location); - const char *uri = - webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)); - const char *goal = (uri) ? uri : "https://"; - gtk_entry_set_text(GTK_ENTRY(c->location), goal); - gtk_editable_set_position(GTK_EDITABLE(c->location), -1); + set_uri(uri, c); return TRUE; } else if (def_key("print", GDK_KEY_Print) == key) { WebKitPrintOperation *operation = @@ -805,8 +814,6 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) { } else if (def_key("quit", GDK_KEY_g) == key) { search(c, 2); gtk_widget_grab_focus(c->web_view); - const gchar *uri = - webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)); gtk_entry_set_text(GTK_ENTRY(c->location), uri); gtk_editable_set_position(GTK_EDITABLE(c->location), -1); webkit_web_view_run_javascript( -- 2.39.2