gboolean javascript_disabled;
gboolean private;
gboolean spellcheck_disabled;
+ gchar *default_uri;
gchar *download_dir;
gchar *fifo_suffix;
gchar *history_file;
quit_if_nothing_active();
}
+void
+set_uri(const char *uri, struct Client *c) {
+ if (!gtk_widget_is_focus(c->location)) {
+ gtk_entry_set_text(GTK_ENTRY(c->location), uri);
+ }
+}
+
WebKitWebView *
client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
gboolean focus_tab) {
g_free(f);
}
- clients++;
+ set_uri(uri, c);
+ clients++;
return WEBKIT_WEB_VIEW(c->web_view);
}
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);
* 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");
cfg.accepted_language[0] = NULL;
cfg.accepted_language[1] = NULL;
cfg.cooperative_alone = TRUE;
- cfg.cooperative_alone = TRUE;
+ cfg.cooperative_instances = TRUE;
cfg.fifo_suffix = "main";
const char *e = g_getenv(__NAME_UPPERCASE__ "_FIFO_SUFFIX");
}
}
+ 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;
/* 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);
}
if (!gtk_widget_is_focus(c->location))
- gtk_entry_set_text(GTK_ENTRY(c->location), to_show);
+ set_uri(to_show, c);
}
void
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();
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://";
+ 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("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(
search_text = g_strdup(t + 2);
search(c, 0);
} else if (t != NULL && t[0] == 'w' && t[1] == '/') {
- const char *engine = cfg.search_engine;
- int len = strlen(engine) + strlen(t) - 2;
- char *f = (char *)malloc(len);
- snprintf(f, len + 1, "%s%s", engine, t + 2);
+ int len = strlen(cfg.search_engine) + strlen(t) - 2;
+ gchar *f = malloc(len + 1);
+ snprintf(f, len + 1, "%s%s", cfg.search_engine, t + 2);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
- free(f);
+ g_free(f);
} else {
f = ensure_uri_scheme(t);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
g_signal_connect(G_OBJECT(mw.win), "destroy", gtk_main_quit, NULL);
gchar *priv = (cfg.private) ? "-private" : "";
- gchar *title = malloc(strlen(priv) + strlen(__NAME__));
+ gchar *title = malloc(strlen(priv) + strlen(__NAME__) + 1);
sprintf(title, "%s%s", __NAME__, priv);
gtk_window_set_title(GTK_WINDOW(mw.win), title);