From 8b11d6f8f956fd255eadc3d64dbca5ede0e9db88 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sat, 23 Oct 2021 16:37:49 -0400 Subject: [PATCH] draft 4 --- .clang-format | 4 +- Makefile | 3 - browser.c | 93 ++++++++++++------------------ chorizo-usage.7 => chorizo-usage.1 | 2 +- config.h | 3 +- downloads.c | 7 +-- user-scripts/hints.js | 41 +++++-------- 7 files changed, 58 insertions(+), 95 deletions(-) rename chorizo-usage.7 => chorizo-usage.1 (99%) diff --git a/.clang-format b/.clang-format index 0e1993d..c33ab1d 100644 --- a/.clang-format +++ b/.clang-format @@ -77,8 +77,8 @@ PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Right ReflowComments: false -SortIncludes: false -SortUsingDeclarations: false # Unknown to clang-format-4.0 +SortIncludes: true +SortUsingDeclarations: true # Unknown to clang-format-4.0 SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true diff --git a/Makefile b/Makefile index f123f02..ca95305 100644 --- a/Makefile +++ b/Makefile @@ -25,14 +25,12 @@ extensions: install: all mkdir -p $(bindir) \ $(mandir)/man1 \ - $(mandir)/man7 \ $(libdir)/chorizo/web-extensions \ $(datadir)/chorizo/user-scripts cp chorizo $(bindir)/ cp chorizo.1 $(mandir)/man1/ - cp chorizo-usage.7 $(mandir)/man7/ makewhatis /usr/local/man cp -r extensions/*.so $(libdir)/chorizo/web-extensions/ @@ -42,7 +40,6 @@ uninstall: rm -rf $(bindir)/chorizo \ $(libdir)/chorizo \ $(mandir)/man1/chorizo* \ - $(mandir)/man7/chorizo* \ $(datadir)/chorizo reinstall: uninstall install diff --git a/browser.c b/browser.c index 84a2a4a..385f167 100644 --- a/browser.c +++ b/browser.c @@ -31,8 +31,10 @@ void show_web_view(WebKitWebView *, gpointer); void trust_user_certs(WebKitWebContext *); struct Client { - GtkWidget *jsbutton; GtkWidget *location; + GtkWidget *search; + GtkWidget *search_switch; + GtkWidget *isearch; GtkWidget *tabicon; GtkWidget *tablabel; GtkWidget *vbox; @@ -72,16 +74,6 @@ allocfail(void) exit(EXIT_FAILURE); } -void -togglejs(GtkButton *jsbutton, gpointer data) -{ - struct Client *c = (struct Client *)data; - webkit_settings_set_enable_javascript( - c->settings, - !webkit_settings_get_enable_javascript(c->settings)); - webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view), c->settings); -} - void client_destroy(GtkWidget *widget, gpointer data) { @@ -212,7 +204,6 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, c->settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)); - webkit_settings_set_enable_javascript(c->settings, cfg_js_default); if (cfg.verbose) webkit_settings_set_enable_write_console_messages_to_stdout( c->settings, true); @@ -235,8 +226,6 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, G_CALLBACK(decide_policy), NULL); g_signal_connect(G_OBJECT(c->web_view), "key-press-event", G_CALLBACK(key_web_view), c); - g_signal_connect(G_OBJECT(c->web_view), "button-release-event", - G_CALLBACK(key_web_view), c); g_signal_connect(G_OBJECT(c->web_view), "scroll-event", G_CALLBACK(key_web_view), c); g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed", @@ -245,16 +234,15 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, G_CALLBACK(crashed_web_view), c); GtkWidget *locbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - c->jsbutton = gtk_toggle_button_new_with_label("JS"); - gtk_widget_set_tooltip_text(c->jsbutton, "Toggle JavaScript execution"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->jsbutton), - cfg_js_default); - g_signal_connect(G_OBJECT(c->jsbutton), "toggled", G_CALLBACK(togglejs), - c); c->location = gtk_entry_new(); + gtk_entry_set_placeholder_text(GTK_ENTRY(c->location), "Web address"); 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); + if (cfg.private) { GtkWidget *privindicator = gtk_label_new("Private mode"); gtk_widget_set_tooltip_text( @@ -264,7 +252,6 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, gtk_box_pack_end(GTK_BOX(locbox), privindicator, FALSE, FALSE, 5); } - gtk_box_pack_start(GTK_BOX(locbox), c->jsbutton, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(c->location), "key-press-event", G_CALLBACK(key_location), c); @@ -284,6 +271,15 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, 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_container_set_focus_child(GTK_CONTAINER(c->vbox), c->web_view); c->tabicon = gtk_image_new_from_icon_name("text-html", @@ -291,7 +287,7 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, c->tablabel = gtk_label_new("chorizo"); gtk_label_set_ellipsize(GTK_LABEL(c->tablabel), PANGO_ELLIPSIZE_END); - gtk_label_set_width_chars(GTK_LABEL(c->tablabel), 20); + gtk_label_set_width_chars(GTK_LABEL(c->tablabel), cfg_tab_width); gtk_widget_set_has_tooltip(c->tablabel, TRUE); /* @@ -531,8 +527,8 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data) //No g_get_user_state_dir unfortunately gchar *state_env = getenv("XDG_STATE_DIR"); gchar *state_dir = (state_env) ? - state_env : - g_build_filename(g_get_home_dir(), + state_env : + g_build_filename(g_get_home_dir(), ".local", "state", "chorizo", NULL); @@ -732,7 +728,7 @@ init_default_web_context(void) WebKitWebContext *wc; WebKitCookieManager *cm; wc = (cfg.private) ? webkit_web_context_new_ephemeral() : - webkit_web_context_get_default(); + webkit_web_context_get_default(); p = g_build_filename(g_get_user_config_dir(), "chorizo", "adblock", NULL); @@ -816,6 +812,7 @@ search_init(struct Client *c, int direction) search(c, direction); } } + gboolean key_common(GtkWidget *widget, GdkEvent *event, gpointer data) { @@ -962,17 +959,6 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) gtk_notebook_next_page( GTK_NOTEBOOK(mw.notebook)); return TRUE; - } else if (GDK_KEY_p == key) { - gboolean on = - webkit_settings_get_enable_javascript( - c->settings); - webkit_settings_set_enable_javascript( - c->settings, !on); - webkit_web_view_set_settings( - WEBKIT_WEB_VIEW(c->web_view), - c->settings); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(c->jsbutton), !on); } else if (GDK_KEY_d == key) { gtk_widget_grab_focus(c->location); gtk_entry_set_text(GTK_ENTRY(c->location), @@ -1071,6 +1057,7 @@ key_tablabel(GtkWidget *widget, GdkEvent *event, gpointer data) } return FALSE; } + gboolean key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data) { @@ -1086,26 +1073,6 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data) gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), 0); } - } else if (event->type == GDK_BUTTON_RELEASE) { - GdkModifierType modifiers = - gtk_accelerator_get_default_mod_mask(); - switch (((GdkEventButton *)event)->button) { - case 1: - if ((((GdkEventButton *)event)->state & modifiers) == - GDK_CONTROL_MASK && - c->hover_uri != NULL) { - client_new(c->hover_uri, NULL, TRUE, FALSE); - return TRUE; - } - break; - case 8: - webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view)); - return TRUE; - case 9: - webkit_web_view_go_forward( - WEBKIT_WEB_VIEW(c->web_view)); - return TRUE; - } } else if (event->type == GDK_SCROLL) { event->scroll.delta_y *= cfg_scroll_lines; if (((GdkEventScroll *)event)->state & GDK_CONTROL_MASK) { @@ -1138,9 +1105,21 @@ mainwindow_setup(void) mw.notebook = gtk_notebook_new(); gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE); + gtk_notebook_set_tab_pos(GTK_NOTEBOOK(mw.notebook), GTK_POS_LEFT); gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook); g_signal_connect(G_OBJECT(mw.notebook), "switch-page", G_CALLBACK(notebook_switch_page), NULL); + + GtkCssProvider *css = gtk_css_provider_new(); + const char *css_data = "notebook header.left * { \ + margin: 0; \ + padding-top: 0; \ + padding-bottom: 0; \ + }"; + gtk_css_provider_load_from_data(css, css_data, strlen(css_data), NULL); + gtk_style_context_add_provider_for_screen( + gdk_screen_get_default(), GTK_STYLE_PROVIDER(css), + GTK_STYLE_PROVIDER_PRIORITY_USER); } void @@ -1163,6 +1142,7 @@ notebook_switch_page(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data) { mainwindow_title(idx); } + gboolean quit_if_nothing_active(void) { @@ -1308,7 +1288,6 @@ main(int argc, char **argv) gtk_main(); remove(fifopath); } - for (int i = 0; i < clients; i++) { free(&(client_arr[i])); } exit(EXIT_SUCCESS); } diff --git a/chorizo-usage.7 b/chorizo-usage.1 similarity index 99% rename from chorizo-usage.7 rename to chorizo-usage.1 index 5857863..d8a71fb 100644 --- a/chorizo-usage.7 +++ b/chorizo-usage.1 @@ -1,4 +1,4 @@ -.TH "chorizo-usage" "7" "2021-10-11" +.TH "chorizo-usage" "1" "2021-10-11" .P .SH NAME chorizo-usage - extended usage hints diff --git a/config.h b/config.h index d782887..840b0bc 100644 --- a/config.h +++ b/config.h @@ -13,5 +13,6 @@ int cfg_scroll_lines = 3; gchar *cfg_search_engine = "https://searx.be/search?q="; //Search engine int cfg_max_tabs_closed = 16; - +//Tab width in chars +int cfg_tab_width = 15; #endif diff --git a/downloads.c b/downloads.c index 439f2a0..1cf3bef 100644 --- a/downloads.c +++ b/downloads.c @@ -110,7 +110,7 @@ download_handle(WebKitDownload *download, gchar *suggested_filename, gtk_widget_destroy(chooser); - remove(uri + 7); + 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); @@ -153,7 +153,6 @@ const char * download_get_path(struct DownloadItem *payload) { const char *path = webkit_download_get_destination(payload->download); - // Offset by 7 to remove "file://" return path += 7; } @@ -186,8 +185,8 @@ void download_copy_path(GtkMenuItem *tb, gpointer data) { const char *path = download_get_path((struct DownloadItem *)data); - gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), - path + 7, strlen(path) - 7); + gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), path, + strlen(path)); } void diff --git a/user-scripts/hints.js b/user-scripts/hints.js index c1854c3..aa5daa2 100644 --- a/user-scripts/hints.js +++ b/user-scripts/hints.js @@ -1,6 +1,6 @@ // This is NOT a core component of chorizo, but an optional user script. -// Please refer to chorizo.usage(1) for more information on user scripts. - +// Please refer to chorizo-usage(1) for more information on user scripts. +// // Press "f" (open link in current window) or "F" (open in new window) // to activate link hints. After typing the characters for one of them, // press Enter to confirm. Press Escape to abort. @@ -8,7 +8,7 @@ // This is an "80% solution". It works for many web sites, but has // flaws. For more background on this topic, see this blog post: // https://www.uninformativ.de/blog/postings/2020-02-24/0/POSTING-en.html - +// // Based on the following, but modified for chorizo and personal taste: // // easy links for surf @@ -28,20 +28,13 @@ var key_follow_new_win = "F"; function update_highlights_or_abort() { var submatch; - var col_sel, col_unsel; var longest_id = 0; - if (document.chorizo_hints.state === "follow_new") { - col_unsel = "#DAFFAD"; - col_sel = "#FF5D00"; - } else { - col_unsel = "#A7FFF5"; - col_sel = "#33FF00"; - } + const color = (document.chorizo_hints.state === "follow_new") ? "#ffccff" + : "#99ffcc"; for (var id in document.chorizo_hints.labels) { var label = document.chorizo_hints.labels[id]; - var bgcol = col_unsel; longest_id = Math.max(longest_id, id.length); @@ -49,12 +42,9 @@ function update_highlights_or_abort() { submatch = id.match("^" + document.chorizo_hints.box.value); if (submatch !== null) { var href_suffix = ""; - var box_shadow_inner = "#B00000"; if (id === document.chorizo_hints.box.value) { - bgcol = col_sel; - box_shadow_inner = "red"; if (label.elem.tagName.toLowerCase() === "a") - href_suffix = ": " + + href_suffix = ": " + label.elem.href + ""; } @@ -65,8 +55,7 @@ function update_highlights_or_abort() { label.span.style.visibility = "visible"; save_parent_style(label); - label.elem.style.boxShadow = "0 0 5pt 2pt black, 0 0 0 2pt " + - box_shadow_inner + " inset"; + label.elem.style.boxShadow = "0 0 5px 5px red"; } else { label.span.style.visibility = "hidden"; reset_parent_style(label); @@ -76,7 +65,7 @@ function update_highlights_or_abort() { label.span.innerHTML = id; reset_parent_style(label); } - label.span.style.backgroundColor = bgcol; + label.span.style.backgroundColor = color; } if (document.chorizo_hints.box.value.length > longest_id) @@ -195,12 +184,13 @@ function create_labels() { } while (n !== 0); var span = document.createElement("span"); - span.style.border = "black 1pt solid"; + span.style.border = "black 1px solid"; span.style.color = "black"; span.style.fontFamily = "monospace"; - span.style.fontSize = "10pt"; + span.style.fontSize = "10px"; span.style.fontWeight = "normal"; - span.style.margin = "0px 2pt"; + span.style.margin = "0px 2px"; + span.style.padding = "1px 5px"; span.style.position = "absolute"; span.style.textTransform = "lowercase"; span.style.visibility = "hidden"; @@ -216,13 +206,10 @@ function create_labels() { // placement results, but we can *only* do this for ... var tag_name = elem.tagName.toLowerCase(); if (tag_name === "a") { - span.style.borderTopLeftRadius = "10pt"; - span.style.borderBottomLeftRadius = "10pt"; - span.style.padding = "0px 2pt 0px 5pt"; + span.style.borderRadius = "2px"; elem.appendChild(span); } else { - span.style.borderRadius = "10pt"; - span.style.padding = "0px 5pt"; + span.style.borderRadius = "10px"; elem.parentNode.insertBefore(span, elem); } -- 2.39.2