From 1e1cff8509043df4dbd5856b579c5cf2bb0cb0ba Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sun, 24 Oct 2021 11:49:57 -0400 Subject: [PATCH] draft 5 --- .clang-format | 4 +- browser.c | 345 +++++++++++++++++++++++++----------------- config.h | 24 ++- downloads.c | 82 +++++----- user-scripts/hints.js | 2 +- 5 files changed, 268 insertions(+), 189 deletions(-) diff --git a/.clang-format b/.clang-format index c33ab1d..cbd2a0c 100644 --- a/.clang-format +++ b/.clang-format @@ -63,7 +63,7 @@ IndentWidth: 8 IndentWrappedFunctionNames: false JavaScriptQuotes: Leave JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtTheStartOfBlocks: true MacroBlockBegin: '' MacroBlockEnd: '' @@ -76,7 +76,7 @@ PenaltyExcessCharacter: 100 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Right -ReflowComments: false +ReflowComments: true SortIncludes: true SortUsingDeclarations: true # Unknown to clang-format-4.0 SpaceAfterCStyleCast: false 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, ""; if (c->feed_html != NULL) { /* - * What we're actually trying to do is show a simple HTML - * page that lists all the feeds on the current page. The - * function webkit_web_view_load_html() looks like the proper - * way to do that. Sad thing is, it doesn't create a history - * entry, but instead simply replaces the content of the - * current page. This is not what we want. - * - * RFC 2397 [0] defines the data URI scheme [1]. We abuse this - * mechanism to show my custom HTML snippet* and*create a - * history entry. - * - * [0]: https://tools.ietf.org/html/rfc2397 [1]: - * https://en.wikipedia.org/wiki/Data_URI_scheme - */ + * What we're actually trying to do is show a simple HTML + * page that lists all the feeds on the current page. The + * function webkit_web_view_load_html() looks like the proper + * way to do that. Sad thing is, it doesn't create a history + * entry, but instead simply replaces the content of the + * current page. This is not what we want. + * + * RFC 2397 [0] defines the data URI scheme [1]. We abuse this + * mechanism to show my custom HTML snippet* and*create a + * history entry. + * + * [0]: https://tools.ietf.org/html/rfc2397 [1]: + * https://en.wikipedia.org/wiki/Data_URI_scheme + */ d = g_strdup_printf(data_template, c->feed_html); webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), d); @@ -770,21 +790,23 @@ init_default_web_context(void) } void -search(gpointer data, gint direction) +isearch(gpointer data, gint direction) { struct Client *c = (struct Client *)data; WebKitWebView *web_view = WEBKIT_WEB_VIEW(c->web_view); WebKitFindController *fc = webkit_web_view_get_find_controller(web_view); - if (search_text == NULL) return; + const gchar *isearch_text = gtk_entry_get_text(GTK_ENTRY(c->isearch)); + if (isearch_text == NULL) return; switch (direction) { case 0: - webkit_find_controller_search( - fc, search_text, - WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | - WEBKIT_FIND_OPTIONS_WRAP_AROUND, - G_MAXUINT); + g_signal_connect(G_OBJECT(fc), "counted-matches", + G_CALLBACK(isearch_counted_matches), c); + webkit_find_controller_count_matches( + fc, isearch_text, cfg_isearch_options, G_MAXUINT); + webkit_find_controller_search(fc, isearch_text, + cfg_isearch_options, G_MAXUINT); break; case 1: webkit_find_controller_search_next(fc); @@ -799,30 +821,36 @@ search(gpointer data, gint direction) } void -search_init(struct Client *c, int direction) +isearch_init(struct Client *c, int direction) { - gtk_widget_grab_focus(c->location); - const gchar *contents = gtk_entry_get_text(GTK_ENTRY(c->location)); - if (strcspn(contents, "s/")) { - gtk_entry_set_text(GTK_ENTRY(c->location), "s/"); - gtk_editable_set_position(GTK_EDITABLE(c->location), -1); - } else { - search(c, 0); - search(c, -1); - search(c, direction); + if (webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view))) { + gtk_widget_show(c->isearch_box); + gtk_widget_show(c->isearch); + gtk_widget_grab_focus(c->isearch); } } +void +reopen_tab(void) +{ + if (num_closed == 0) return; + client_new(closed_tabs[num_closed - 1], NULL, TRUE, TRUE); + num_closed--; + closed_tabs = realloc(closed_tabs, num_closed * sizeof(closed_tabs[0])); + if (!closed_tabs) allocfail(); +} gboolean key_common(GtkWidget *widget, GdkEvent *event, gpointer data) { struct Client *c = (struct Client *)data; gdouble now; if (event->type == GDK_KEY_PRESS) { - if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) { + guint mask = gtk_accelerator_get_default_mod_mask(); + int key = ((GdkEventKey *)event)->keyval; + if ((((GdkEventKey *)event)->state & mask) == + GDK_CONTROL_MASK) { const char *uri = webkit_web_view_get_uri( WEBKIT_WEB_VIEW(c->web_view)); - int key = ((GdkEventKey *)event)->keyval; if (GDK_KEY_y == key) { downloadmanager_show(); return TRUE; @@ -834,10 +862,10 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) webkit_web_view_go_forward( WEBKIT_WEB_VIEW(c->web_view)); return TRUE; - } else if (GDK_KEY_o == key) { + } else if (GDK_KEY_s == key) { gtk_widget_grab_focus(c->location); return TRUE; - } else if (GDK_KEY_Print == key) { + } else if (GDK_KEY_p == key) { WebKitPrintOperation *operation = webkit_print_operation_new( WEBKIT_WEB_VIEW(c->web_view)); @@ -847,10 +875,8 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) operation, GTK_WINDOW(toplevel)); return TRUE; } else if (GDK_KEY_g == key) { - search(c, 2); + isearch(c, 2); gtk_widget_grab_focus(c->web_view); - gtk_editable_set_position( - GTK_EDITABLE(c->location), -1); if (uri) gtk_entry_set_text( GTK_ENTRY(c->location), uri); @@ -859,8 +885,13 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) "window.getSelection().removeAllRanges();" "document.activeElement.blur();", NULL, NULL, c); + gtk_widget_hide(c->isearch_box); + gtk_editable_set_position( + GTK_EDITABLE(c->location), -1); + gtk_editable_set_position( + GTK_EDITABLE(c->wsearch), -1); return TRUE; - } else if (GDK_KEY_semicolon == key) { + } else if (GDK_KEY_r == key) { webkit_web_view_reload_bypass_cache( WEBKIT_WEB_VIEW(c->web_view)); return TRUE; @@ -879,19 +910,8 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) } return TRUE; } else if (GDK_KEY_f == key) { - event->key.keyval = GDK_KEY_Page_Down; - gdk_event_put(event); - return TRUE; - } else if (GDK_KEY_b == key) { - event->key.keyval = GDK_KEY_Page_Up; - gdk_event_put(event); - return TRUE; - } else if (GDK_KEY_s == key) { - search_init(c, 1); - return TRUE; - } else if (GDK_KEY_r == key) { - search_init(c, -1); - return TRUE; + isearch_init(c, 1); + return FALSE; } else if (GDK_KEY_q == key) { client_destroy(NULL, c); return TRUE; @@ -946,25 +966,14 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) client_new(cfg_home_uri, NULL, TRUE, TRUE); return TRUE; } else if (GDK_KEY_bracketleft == key) { - if (num_closed == 0) return TRUE; - client_new(closed_tabs[num_closed - 1], NULL, - TRUE, TRUE); - num_closed--; - closed_tabs = realloc( - closed_tabs, - num_closed * sizeof(closed_tabs[0])); - if (!closed_tabs) allocfail(); + reopen_tab(); return TRUE; - } else if (GDK_KEY_i == key) { + } else if ((GDK_KEY_i == key) || (GDK_KEY_Tab == key)) { gtk_notebook_next_page( GTK_NOTEBOOK(mw.notebook)); return TRUE; } else if (GDK_KEY_d == key) { - gtk_widget_grab_focus(c->location); - gtk_entry_set_text(GTK_ENTRY(c->location), - "w/"); - gtk_editable_set_position( - GTK_EDITABLE(c->location), -1); + gtk_widget_grab_focus(c->wsearch); return TRUE; } else if (GDK_KEY_equal == key) { now = webkit_web_view_get_zoom_level( @@ -985,10 +994,84 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) WEBKIT_WEB_VIEW(c->web_view), 1); return TRUE; } + } else if ((((GdkEventKey *)event)->state & mask) == + (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) { + if (GDK_KEY_ISO_Left_Tab == key) { + gtk_notebook_prev_page( + GTK_NOTEBOOK(mw.notebook)); + return TRUE; + } else if (GDK_KEY_T == key) { + reopen_tab(); + return TRUE; + } } } return FALSE; } + +gboolean +isearch_counted_matches(GtkWidget *widget, guint matches, gpointer data) +{ + struct Client *c = (struct Client *)data; + char *text = malloc(12); + sprintf(text, "%d matches", matches); + gtk_label_set_text(GTK_LABEL(c->isearch_matches), text); + free(text); + return TRUE; +} + +gboolean +key_isearch(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + struct Client *c = (struct Client *)data; + if (key_common(widget, event, data)) return TRUE; + + if (event->type == GDK_KEY_PRESS) { + int key = ((GdkEventKey *)event)->keyval; + if ((GDK_KEY_KP_Enter == key) || (GDK_KEY_Return == key)) { + int direction = (((GdkEventKey *)event)->state & + GDK_SHIFT_MASK) ? + -1 : + 1; + isearch(c, 0); + isearch(c, -1); + isearch(c, direction); + return TRUE; + } else if (GDK_KEY_Escape == key) { + isearch(c, 2); + gtk_widget_hide(c->isearch_box); + gtk_widget_grab_focus(c->web_view); + } + } + return FALSE; +} + +gboolean +key_wsearch(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + struct Client *c = (struct Client *)data; + if (key_common(widget, event, data)) return TRUE; + + if (event->type == GDK_KEY_PRESS) { + int key = ((GdkEventKey *)event)->keyval; + if ((GDK_KEY_KP_Enter == key) || (GDK_KEY_Return == key)) { + const gchar *t = + gtk_entry_get_text(GTK_ENTRY(c->wsearch)); + int len = strlen(cfg_search_engine) + strlen(t); + gchar *f = malloc(len + 1); + if (!f) allocfail(); + + snprintf(f, len + 1, "%s%s", cfg_search_engine, t); + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), + f); + g_free(f); + gtk_widget_grab_focus(c->web_view); + return TRUE; + } + } + return FALSE; +} + gboolean key_location(GtkWidget *widget, GdkEvent *event, gpointer data) { @@ -1001,25 +1084,8 @@ key_location(GtkWidget *widget, GdkEvent *event, gpointer data) if ((GDK_KEY_KP_Enter == key) || (GDK_KEY_Return == key)) { gtk_widget_grab_focus(c->web_view); t = gtk_entry_get_text(GTK_ENTRY(c->location)); - if (t != NULL && t[0] == 's' && t[1] == '/') { - if (search_text != NULL) g_free(search_text); - search_text = g_strdup(t + 2); - search(c, 0); - } else if (t != NULL && t[0] == 'w' && t[1] == '/') { - int len = strlen(cfg_search_engine) + - strlen(t) - 2; - gchar *f = malloc(len + 1); - if (!f) allocfail(); - snprintf(f, len + 1, "%s%s", cfg_search_engine, - t + 2); - webkit_web_view_load_uri( - WEBKIT_WEB_VIEW(c->web_view), f); - g_free(f); - } else { - webkit_web_view_load_uri( - WEBKIT_WEB_VIEW(c->web_view), - ensure_uri_scheme(t)); - } + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), + ensure_uri_scheme(t)); return TRUE; } else if (GDK_KEY_Escape == key) { t = webkit_web_view_get_uri( @@ -1064,7 +1130,7 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data) struct Client *c = (struct Client *)data; gdouble dx, dy; gfloat z; - if (key_common(widget, event, data)) return TRUE; + if (key_common(c->web_view, event, data)) return TRUE; if (event->type == GDK_KEY_PRESS) { if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape) { @@ -1178,6 +1244,11 @@ show_web_view(WebKitWebView *web_view, gpointer data) gtk_widget_show_all(mw.win); + // TODO: Fix this hack + for (int i = 1; i <= clients; i++) + gtk_widget_hide(client_arr[i]->isearch_box); + gtk_widget_hide(c->isearch_box); + if (c->focus_new_tab) { idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox); if (idx != -1) @@ -1231,7 +1302,7 @@ main(int argc, char **argv) { int opt, i; - //TODO:pretty this + // TODO:pretty this cfg.noncooperative_instances = FALSE; cfg.cooperative_alone = TRUE; closed_tabs = malloc(0); diff --git a/config.h b/config.h index 840b0bc..5cea9ea 100644 --- a/config.h +++ b/config.h @@ -2,17 +2,29 @@ #define CONFIG_H #define VERSION "1.1.0" +// Should JavaScript be enabled by default gboolean cfg_js_default = TRUE; -//Should JavaScript be enabled by default + +// Cookie policy WebKitCookieAcceptPolicy cfg_cookie_policy = WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS; -//Cookie policy + +// Default URI gchar *cfg_home_uri = NULL; -//Default URI + +// Number of lines to scroll at a time int cfg_scroll_lines = 3; -//Number of lines to scroll at a time + +// Search engine gchar *cfg_search_engine = "https://searx.be/search?q="; -//Search engine + +// Max number of closed tabs int cfg_max_tabs_closed = 16; -//Tab width in chars + +// Tab width in chars int cfg_tab_width = 15; + +// isearch options +WebKitFindOptions cfg_isearch_options = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | + WEBKIT_FIND_OPTIONS_WRAP_AROUND; + #endif diff --git a/downloads.c b/downloads.c index 1cf3bef..9f8c73d 100644 --- a/downloads.c +++ b/downloads.c @@ -85,9 +85,9 @@ download_handle(WebKitDownload *download, gchar *suggested_filename, GtkToolItem *tb; GtkWidget *chooser = gtk_file_chooser_dialog_new( - "Choose download location", GTK_WINDOW(dm.win), - GTK_FILE_CHOOSER_ACTION_SAVE, "Save file", GTK_RESPONSE_ACCEPT, - "Cancel", GTK_RESPONSE_CANCEL, NULL); + "Save File", GTK_WINDOW(dm.win), GTK_FILE_CHOOSER_ACTION_SAVE, + "Cancel", GTK_RESPONSE_CANCEL, "Save", GTK_RESPONSE_ACCEPT, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), (char *)data); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser), @@ -95,48 +95,44 @@ download_handle(WebKitDownload *download, gchar *suggested_filename, gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER(chooser), TRUE); gint res = gtk_dialog_run(GTK_DIALOG(chooser)); - switch (res) { - case GTK_RESPONSE_ACCEPT: + + if (res != GTK_RESPONSE_ACCEPT) { + gtk_widget_destroy(chooser); + } else { uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(chooser)); - webkit_download_set_destination( - download, - gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(chooser))); - break; - case GTK_RESPONSE_CANCEL: - return FALSE; - default: - return FALSE; + webkit_download_set_destination(download, uri); + + remove(uri + 7); // Remove before overwrite + + gtk_widget_destroy(chooser); + + tb = gtk_tool_button_new(NULL, NULL); + gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), + "network-receive"); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), uri); + gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0); + gtk_widget_show_all(dm.win); + + g_signal_connect(G_OBJECT(download), + "notify::estimated-progress", + G_CALLBACK(changed_download_progress), tb); + + downloads++; + g_signal_connect(G_OBJECT(download), "finished", + G_CALLBACK(download_finished), tb); + + g_object_ref(download); + + struct DownloadItem *payload = malloc(sizeof(*payload)); + payload->tb = (GtkToolButton *)tb; + payload->download = download; + g_signal_connect(G_OBJECT(tb), "clicked", + G_CALLBACK(download_click), payload); + g_signal_connect(G_OBJECT(payload->download), "failed", + G_CALLBACK(download_cancel), payload); + g_signal_connect(G_OBJECT(tb), "destroy_event", + G_CALLBACK(g_free), payload); } - - gtk_widget_destroy(chooser); - - remove(uri + 7); // Remove before overwrite - tb = gtk_tool_button_new(NULL, NULL); - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "network-receive"); - gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), uri); - gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0); - gtk_widget_show_all(dm.win); - - g_signal_connect(G_OBJECT(download), "notify::estimated-progress", - G_CALLBACK(changed_download_progress), tb); - - downloads++; - g_signal_connect(G_OBJECT(download), "finished", - G_CALLBACK(download_finished), tb); - - g_object_ref(download); - - struct DownloadItem *payload = malloc(sizeof(*payload)); - payload->tb = (GtkToolButton *)tb; - payload->download = download; - g_signal_connect(G_OBJECT(tb), "clicked", G_CALLBACK(download_click), - payload); - g_signal_connect(G_OBJECT(tb), "failed", G_CALLBACK(download_cancel), - payload); - g_signal_connect(G_OBJECT(tb), "destroy_event", G_CALLBACK(g_free), - payload); - - //Propagate-- to whom it may concern. return FALSE; } diff --git a/user-scripts/hints.js b/user-scripts/hints.js index aa5daa2..d17b006 100644 --- a/user-scripts/hints.js +++ b/user-scripts/hints.js @@ -187,7 +187,7 @@ function create_labels() { span.style.border = "black 1px solid"; span.style.color = "black"; span.style.fontFamily = "monospace"; - span.style.fontSize = "10px"; + span.style.fontSize = "12px"; span.style.fontWeight = "normal"; span.style.margin = "0px 2px"; span.style.padding = "1px 5px"; -- 2.39.2