X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=browser.c;fp=browser.c;h=dfc1e9de22d582aea77df5920a0f968931a02700;hb=1e1cff8509043df4dbd5856b579c5cf2bb0cb0ba;hp=385f1671d2741eeb24f5e4ded80d5662aa85b4fe;hpb=8b11d6f8f956fd255eadc3d64dbca5ede0e9db88;p=chorizo.git
diff --git a/browser.c b/browser.c
index 385f167..dfc1e9d 100644
--- a/browser.c
+++ b/browser.c
@@ -16,6 +16,10 @@ gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
gboolean key_tablabel(GtkWidget *, GdkEvent *, gpointer);
gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
+gboolean key_common(GtkWidget *, GdkEvent *, gpointer);
+gboolean key_wsearch(GtkWidget *, GdkEvent *, gpointer);
+gboolean key_isearch(GtkWidget *, GdkEvent *, gpointer);
+gboolean isearch_counted_matches(GtkWidget *, guint, gpointer);
gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
gchar *ensure_uri_scheme(const gchar *);
void changed_favicon(GObject *, GParamSpec *, gpointer);
@@ -32,9 +36,10 @@ void trust_user_certs(WebKitWebContext *);
struct Client {
GtkWidget *location;
- GtkWidget *search;
- GtkWidget *search_switch;
+ GtkWidget *wsearch;
GtkWidget *isearch;
+ GtkWidget *isearch_box;
+ GtkWidget *isearch_matches;
GtkWidget *tabicon;
GtkWidget *tablabel;
GtkWidget *vbox;
@@ -62,7 +67,6 @@ gint clients = 0;
struct Client **client_arr;
int cooperative_pipe_fp = 0;
-gchar *search_text;
gchar *fifopath;
char **closed_tabs;
size_t num_closed = 0;
@@ -236,12 +240,18 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
GtkWidget *locbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
c->location = gtk_entry_new();
- gtk_entry_set_placeholder_text(GTK_ENTRY(c->location), "Web address");
+ gtk_entry_set_placeholder_text(GTK_ENTRY(c->location), "URL");
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
+ GTK_ENTRY_ICON_PRIMARY,
+ "text-x-generic-symbolic");
gtk_box_pack_start(GTK_BOX(locbox), c->location, TRUE, TRUE, 0);
- c->search = gtk_entry_new();
- gtk_entry_set_placeholder_text(GTK_ENTRY(c->search), "Search");
- gtk_box_pack_start(GTK_BOX(locbox), c->search, FALSE, TRUE, 0);
+ c->wsearch = gtk_entry_new();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(c->wsearch), "Search the web");
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->wsearch),
+ GTK_ENTRY_ICON_PRIMARY,
+ "system-search-symbolic");
+ gtk_box_pack_start(GTK_BOX(locbox), c->wsearch, FALSE, TRUE, 0);
if (cfg.private) {
GtkWidget *privindicator = gtk_label_new("Private mode");
@@ -257,28 +267,37 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
G_CALLBACK(key_location), c);
g_signal_connect(G_OBJECT(c->location), "icon-release",
G_CALLBACK(icon_location), c);
+ g_signal_connect(G_OBJECT(c->wsearch), "key-press-event",
+ G_CALLBACK(key_wsearch), c);
/*
- * XXX This is a workaround. Setting this to NULL (which is done in
- * grab_feeds_finished() if no feed has been detected) adds a little
- * padding left of the text. Not sure why. The point of this call
- * right here is to have that padding right from the start. This
- * avoids a graphical artifact.
- */
+ * XXX This is a workaround. Setting this to NULL (which is done in
+ * grab_feeds_finished() if no feed has been detected) adds a little
+ * padding left of the text. Not sure why. The point of this call
+ * right here is to have that padding right from the start. This
+ * avoids a graphical artifact.
+ */
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
GTK_ENTRY_ICON_SECONDARY, NULL);
+ c->isearch_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+ c->isearch = gtk_entry_new();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(c->isearch), "Search page");
+ gtk_box_pack_start(GTK_BOX(c->isearch_box), c->isearch, FALSE, TRUE, 0);
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->isearch),
+ GTK_ENTRY_ICON_PRIMARY,
+ "system-search-symbolic");
+ g_signal_connect(G_OBJECT(c->isearch), "key-press-event",
+ G_CALLBACK(key_isearch), c);
+
+ c->isearch_matches = gtk_label_new("0 matches");
+ gtk_box_pack_start(GTK_BOX(c->isearch_box), c->isearch_matches, FALSE,
+ TRUE, 5);
+
c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- gtk_box_pack_start(GTK_BOX(c->vbox), locbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(c->vbox), c->web_view, TRUE, TRUE, 0);
-
- GtkWidget *overlay = gtk_overlay_new();
- c->isearch = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(c->vbox), overlay);
- gtk_container_add(GTK_CONTAINER(overlay), c->isearch);
- gtk_widget_set_halign (overlay, GTK_ALIGN_CENTER);
- gtk_widget_set_valign (overlay, GTK_ALIGN_CENTER);
- gtk_widget_show_all(overlay);
+ gtk_box_pack_start(GTK_BOX(c->vbox), c->isearch_box, FALSE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(c->vbox), locbox, FALSE, FALSE, 0);
gtk_container_set_focus_child(GTK_CONTAINER(c->vbox), c->web_view);
@@ -291,9 +310,9 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
gtk_widget_set_has_tooltip(c->tablabel, TRUE);
/*
- * XXX I don't own a HiDPI screen, so I don't know if scale_factor
- * does the right thing.
- */
+ * XXX I don't own a HiDPI screen, so I don't know if scale_factor
+ * does the right thing.
+ */
tabbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,
5 * gtk_widget_get_scale_factor(mw.win));
gtk_box_pack_start(GTK_BOX(tabbox), c->tabicon, FALSE, FALSE, 0);
@@ -308,14 +327,14 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
g_signal_connect(G_OBJECT(evbox), "scroll-event",
G_CALLBACK(key_tablabel), c);
- //For easy access, store a reference to our label.
+ // For easy access, store a reference to our label.
g_object_set_data(G_OBJECT(evbox), "chorizo-tab-label", c->tablabel);
/*
- * This only shows the event box and the label inside, nothing else.
- * Needed because the evbox/label is "internal" to the notebook and
- * not part of the normal "widget tree" (IIUC).
- */
+ * This only shows the event box and the label inside, nothing else.
+ * Needed because the evbox/label is "internal" to the notebook and
+ * not part of the normal "widget tree" (IIUC).
+ */
gtk_widget_show_all(evbox);
int page = gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook)) + 1;
@@ -343,7 +362,7 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
client_arr[clients] = c;
- if (clients == 1 || uri == NULL) gtk_widget_grab_focus(c->location);
+ if (uri == NULL) gtk_widget_grab_focus(c->location);
return WEBKIT_WEB_VIEW(c->web_view);
}
@@ -397,9 +416,9 @@ cooperation_setup(void)
} 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,
@@ -443,11 +462,11 @@ changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
p = 0;
/*
- * The page has loaded fully. We now run the short JavaScript
- * snippet above that operates on the DOM. It tries to grab
- * all occurences of , i.e.
- * RSS/Atom feed references.
- */
+ * The page has loaded fully. We now run the short JavaScript
+ * snippet above that operates on the DOM. It tries to grab
+ * all occurences of , i.e.
+ * RSS/Atom feed references.
+ */
webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view),
grab_feeds, NULL,
grab_feeds_finished, c);
@@ -500,10 +519,9 @@ changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
gchar *name = malloc(strlen(t) + 4);
if (!name) allocfail();
-
gboolean mute =
webkit_web_view_get_is_muted(WEBKIT_WEB_VIEW(c->web_view));
- gchar *muted = (mute) ? "[m] " : "";
+ gchar *muted = (mute) ? "[M] " : "";
sprintf(name, "%s%s", muted, t);
gtk_label_set_text(GTK_LABEL(c->tablabel), name);
g_free(name);
@@ -524,7 +542,7 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
if (t != NULL && strlen(t) > 0) {
set_uri(t, c);
- //No g_get_user_state_dir unfortunately
+ // No g_get_user_state_dir unfortunately
gchar *state_env = getenv("XDG_STATE_DIR");
gchar *state_dir = (state_env) ?
state_env :
@@ -553,10 +571,11 @@ gboolean
crashed_web_view(WebKitWebView *web_view, gpointer data)
{
struct Client *c = (struct Client *)data;
+
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
GtkWidget *dialog = gtk_message_dialog_new(
- GTK_WINDOW(c->vbox), flags, GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE, "ERROR: Web process %s crashed.",
+ GTK_WINDOW(mw.win), flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "ERROR: Web process %s crashed.\n%s",
webkit_web_view_get_uri(WEBKIT_WEB_VIEW(web_view)),
g_strerror(errno));
gtk_dialog_run(GTK_DIALOG(dialog));
@@ -564,6 +583,7 @@ crashed_web_view(WebKitWebView *web_view, gpointer data)
return TRUE;
}
+
gboolean
decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
WebKitPolicyDecisionType type, gpointer data)
@@ -578,7 +598,7 @@ decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
webkit_policy_decision_use(decision);
break;
default:
- //Use whatever default there is.
+ // Use whatever default there is.
return FALSE;
}
return TRUE;
@@ -618,11 +638,11 @@ grab_feeds_finished(GObject *object, GAsyncResult *result, gpointer data)
c->feed_html = NULL;
/*
- * This was taken almost verbatim from the example in WebKit's
- * documentation:
- *
- * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html
- */
+ * This was taken almost verbatim from the example in WebKit's
+ * documentation:
+ *
+ * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html
+ */
js_result = webkit_web_view_run_javascript_finish(
WEBKIT_WEB_VIEW(object), result, &err);
@@ -700,20 +720,20 @@ icon_location(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
"