surf

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit cb9520b33e3ca6701da5a058f9a0d937ea44ccea
parent 9eb4f964f337edc42728827901dcca0704cc9687
Author: Derek Taylor <contact@unabot.com>
Date:   Fri, 27 Mar 2020 16:45:36 -0500

Adding some patches, editing some keybindings.

Diffstat:
MFAQ.md | 0
MLICENSE | 0
MMakefile | 0
MTODO.md | 0
Marg.h | 0
Mcommon.c | 0
Mcommon.h | 0
Mconfig.def.h | 25+++++++++++++++++++++++--
Mconfig.def.h.orig | 27+++++++++++++++++++++++++--
Mconfig.h | 30+++++++++++++++++++++++-------
Mconfig.mk | 0
Mlibsurf-webext.c | 0
Msurf | 0
Msurf.1 | 0
Msurf.c | 52+++++++++++++++++++++++++++++++++++++++++++++-------
Msurf.o | 0
Msurf.png | 0
17 files changed, 116 insertions(+), 18 deletions(-)

diff --git a/FAQ.md b/FAQ.md diff --git a/LICENSE b/LICENSE diff --git a/Makefile b/Makefile diff --git a/TODO.md b/TODO.md diff --git a/arg.h b/arg.h diff --git a/common.c b/common.c diff --git a/common.h b/common.h diff --git a/config.def.h b/config.def.h @@ -6,6 +6,8 @@ static char *styledir = "~/.surf/styles/"; static char *certdir = "~/.surf/certificates/"; static char *cachedir = "~/.surf/cache/"; static char *cookiefile = "~/.surf/cookies.txt"; +static char *historyfile = "~/.surf/history.txt"; +static char *searchurl = "duckduckgo.com/?q=%s"; /* Webkit default features */ /* Highest priority value will be used. @@ -77,6 +79,14 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | } \ } +#define SEARCH() { \ + .v = (const char *[]){ "/bin/sh", "-c", \ + "xprop -id $1 -f $2 8s -set $2 \"" \ + "$(dmenu -p Search: -w $1 < /dev/null)\"", \ + "surf-search", winid, "_SURF_SEARCH", NULL \ + } \ +} + /* DOWNLOAD(URI, referer) */ #define DOWNLOAD(u, r) { \ .v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\ @@ -114,6 +124,11 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | } \ } +#define SETURI(p) { .v = (char *[]){ "/bin/sh", "-c", \ +"prop=\"`surf_history_dmenu.sh`\" &&" \ +"xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ +p, winid, NULL } } + /* styles */ /* * The iteration will stop at the first match, beginning at the beginning of @@ -121,7 +136,12 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | */ static SiteSpecific styles[] = { /* regexp file in $styledir */ - { ".*", "default.css" }, + /* { ".*", "default.css" }, */ + { ".*archlinux.org.*", "archlinux.css" }, + { ".*arcolinux.info.*", "arcolinux-info.css" }, + { ".*arcolinuxforum.com.*", "arcolinuxforum.css" }, + { ".*suckless.org.*", "suckless.css" }, + { ".*wikipedia.org.*", "wikipedia.css" }, }; /* certificates */ @@ -146,6 +166,7 @@ static Key keys[] = { { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, { MODKEY, GDK_KEY_m, spawn, BM_ADD("_SURF_URI") }, + { MODKEY, GDK_KEY_s, spawn, SEARCH() }, { 0, GDK_KEY_Escape, stop, { 0 } }, { MODKEY, GDK_KEY_c, stop, { 0 } }, @@ -164,7 +185,6 @@ static Key keys[] = { { MODKEY, GDK_KEY_i, scrollh, { .i = +10 } }, { MODKEY, GDK_KEY_u, scrollh, { .i = -10 } }, - { MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } }, @@ -193,6 +213,7 @@ static Key keys[] = { { MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, + { MODKEY , GDK_KEY_Return, spawn, SETURI("_SURF_GO") }, }; /* button definitions */ diff --git a/config.def.h.orig b/config.def.h.orig @@ -6,6 +6,7 @@ static char *styledir = "~/.surf/styles/"; static char *certdir = "~/.surf/certificates/"; static char *cachedir = "~/.surf/cache/"; static char *cookiefile = "~/.surf/cookies.txt"; +static char *searchurl = "duckduckgo.com/?q=%s"; /* Webkit default features */ /* Highest priority value will be used. @@ -70,12 +71,21 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | #define SETPROP(r, s, p) { \ .v = (const char *[]){ "/bin/sh", "-c", \ "prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \ - "| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\")\" " \ - "| dmenu -p \"$4\" -w $1)\" && xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ + "| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\" && cat ~/.surf/bookmarks)\" " \ + "| dmenu -l 10 -p \"$4\" -w $1)\" && " \ + "xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ "surf-setprop", winid, r, s, p, NULL \ } \ } +#define SEARCH() { \ + .v = (const char *[]){ "/bin/sh", "-c", \ + "xprop -id $1 -f $2 8s -set $2 \"" \ + "$(dmenu -p Search: -w $1 < /dev/null)\"", \ + "surf-search", winid, "_SURF_SEARCH", NULL \ + } \ +} + /* DOWNLOAD(URI, referer) */ #define DOWNLOAD(u, r) { \ .v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\ @@ -102,6 +112,17 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | } \ } +/* BM_ADD(readprop) */ +#define BM_ADD(r) {\ + .v = (const char *[]){ "/bin/sh", "-c", \ + "(echo $(xprop -id $0 $1) | cut -d '\"' -f2 " \ + "| sed 's/.*https*:\\/\\/\\(www\\.\\)\\?//' && cat ~/.surf/bookmarks) " \ + "| awk '!seen[$0]++' > ~/.surf/bookmarks.tmp && " \ + "mv ~/.surf/bookmarks.tmp ~/.surf/bookmarks", \ + winid, r, NULL \ + } \ +} + /* styles */ /* * The iteration will stop at the first match, beginning at the beginning of @@ -133,6 +154,8 @@ static Key keys[] = { { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, + { MODKEY, GDK_KEY_m, spawn, BM_ADD("_SURF_URI") }, + { MODKEY, GDK_KEY_s, spawn, SEARCH() }, { 0, GDK_KEY_Escape, stop, { 0 } }, { MODKEY, GDK_KEY_c, stop, { 0 } }, diff --git a/config.h b/config.h @@ -6,6 +6,8 @@ static char *styledir = "~/.surf/styles/"; static char *certdir = "~/.surf/certificates/"; static char *cachedir = "~/.surf/cache/"; static char *cookiefile = "~/.surf/cookies.txt"; +static char *historyfile = "~/.surf/history.txt"; +static char *searchurl = "duckduckgo.com/?q=%s"; /* Webkit default features */ /* Highest priority value will be used. @@ -77,6 +79,14 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | } \ } +#define SEARCH() { \ + .v = (const char *[]){ "/bin/sh", "-c", \ + "xprop -id $1 -f $2 8s -set $2 \"" \ + "$(dmenu -p Search: -w $1 < /dev/null)\"", \ + "surf-search", winid, "_SURF_SEARCH", NULL \ + } \ +} + /* DOWNLOAD(URI, referer) */ #define DOWNLOAD(u, r) { \ .v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\ @@ -114,6 +124,11 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | } \ } +#define SETURI(p) { .v = (char *[]){ "/bin/sh", "-c", \ +"prop=\"`surf_history_dmenu.sh`\" &&" \ +"xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ +p, winid, NULL } } + /* styles */ /* * The iteration will stop at the first match, beginning at the beginning of @@ -121,12 +136,12 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | */ static SiteSpecific styles[] = { /* regexp file in $styledir */ - /* { ".*", "default.css" }, */ - { ".*archlinux.org.*", "archlinux.css" }, - { ".*arcolinux.info.*", "arcolinux-info.css" }, - { ".*arcolinuxforum.com.*", "arcolinuxforum.css" }, - { ".*suckless.org.*", "suckless.css" }, - { ".*wikipedia.org.*", "wikipedia.css" }, + /* { ".*", "default.css" }, */ + { ".*archlinux.org.*", "archlinux.css" }, + { ".*arcolinux.info.*", "arcolinux-info.css" }, + { ".*arcolinuxforum.com.*", "arcolinuxforum.css" }, + { ".*suckless.org.*", "suckless.css" }, + { ".*wikipedia.org.*", "wikipedia.css" }, }; /* certificates */ @@ -151,6 +166,7 @@ static Key keys[] = { { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, { MODKEY, GDK_KEY_m, spawn, BM_ADD("_SURF_URI") }, + { MODKEY, GDK_KEY_s, spawn, SEARCH() }, { 0, GDK_KEY_Escape, stop, { 0 } }, { MODKEY, GDK_KEY_c, stop, { 0 } }, @@ -169,7 +185,6 @@ static Key keys[] = { { MODKEY, GDK_KEY_i, scrollh, { .i = +10 } }, { MODKEY, GDK_KEY_u, scrollh, { .i = -10 } }, - { MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } }, @@ -198,6 +213,7 @@ static Key keys[] = { { MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } }, { MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, + { MODKEY , GDK_KEY_Return, spawn, SETURI("_SURF_GO") }, }; /* button definitions */ diff --git a/config.mk b/config.mk diff --git a/libsurf-webext.c b/libsurf-webext.c diff --git a/surf b/surf Binary files differ. diff --git a/surf.1 b/surf.1 diff --git a/surf.c b/surf.c @@ -35,7 +35,7 @@ #define LENGTH(x) (sizeof(x) / sizeof(x[0])) #define CLEANMASK(mask) (mask & (MODKEY|GDK_SHIFT_MASK)) -enum { AtomFind, AtomGo, AtomUri, AtomLast }; +enum { AtomFind, AtomSearch, AtomGo, AtomUri, AtomLast }; enum { OnDoc = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT, @@ -175,6 +175,7 @@ static void spawn(Client *c, const Arg *a); static void msgext(Client *c, char type, const Arg *a); static void destroyclient(Client *c); static void cleanup(void); +static void updatehistory(const char *u, const char *t); /* GTK/WebKit */ static WebKitWebView *newview(Client *c, WebKitWebView *rv); @@ -231,6 +232,7 @@ static void togglefullscreen(Client *c, const Arg *a); static void togglecookiepolicy(Client *c, const Arg *a); static void toggleinspector(Client *c, const Arg *a); static void find(Client *c, const Arg *a); +static void search(Client *c, const Arg *a); /* Buttons */ static void clicknavigate(Client *c, const Arg *a, WebKitHitTestResult *h); @@ -326,6 +328,7 @@ setup(void) /* atoms */ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False); + atoms[AtomSearch] = XInternAtom(dpy, "_SURF_SEARCH", False); atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False); atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False); @@ -336,10 +339,11 @@ setup(void) curconfig = defconfig; /* dirs and files */ - cookiefile = buildfile(cookiefile); - scriptfile = buildfile(scriptfile); - cachedir = buildpath(cachedir); - certdir = buildpath(certdir); + cookiefile = buildfile(cookiefile); + historyfile = buildfile(historyfile); + scriptfile = buildfile(scriptfile); + cachedir = buildpath(cachedir); + certdir = buildpath(certdir); gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy)); @@ -577,6 +581,19 @@ loaduri(Client *c, const Arg *a) g_free(url); } +void +search(Client *c, const Arg *a) +{ + Arg arg; + char *url; + + url = g_strdup_printf(searchurl, a->v); + arg.v = url; + loaduri(c, &arg); + + g_free(url); +} + const char * geturi(Client *c) { @@ -732,8 +749,8 @@ setparameter(Client *c, int refresh, ParamName p, const Arg *a) { GdkRGBA bgcolor = { 0 }; WebKitSettings *s = webkit_web_view_get_settings(c->view); - - modparams[p] = curconfig[p].prio; + + modparams[p] = curconfig[p].prio; switch (p) { case AcceleratedCanvas: @@ -1076,12 +1093,28 @@ cleanup(void) close(pipein[0]); close(pipeout[1]); g_free(cookiefile); + g_free(historyfile); g_free(scriptfile); g_free(stylefile); g_free(cachedir); XCloseDisplay(dpy); } +void +updatehistory(const char *u, const char *t) +{ + FILE *f; + f = fopen(historyfile, "a+"); + + char b[20]; + time_t now = time (0); + strftime (b, 20, "%Y-%m-%d %H:%M:%S", localtime (&now)); + fputs(b, f); + + fprintf(f, " %s %s\n", u, t); + fclose(f); +} + WebKitWebView * newview(Client *c, WebKitWebView *rv) { @@ -1311,6 +1344,9 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) find(c, NULL); return GDK_FILTER_REMOVE; + } else if (ev->atom == atoms[AtomSearch]) { + a.v = getatom(c, AtomSearch); + search(c, &a); } else if (ev->atom == atoms[AtomGo]) { a.v = getatom(c, AtomGo); loaduri(c, &a); @@ -1491,6 +1527,7 @@ loadfailedtls(WebKitWebView *v, gchar *uri, GTlsCertificate *cert, return TRUE; } + void loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c) { @@ -1519,6 +1556,7 @@ loadchanged(WebKitWebView *v, WebKitLoadEvent e, Client *c) break; case WEBKIT_LOAD_FINISHED: seturiparameters(c, uri, loadfinished); + updatehistory(uri, c->title); /* Disabled until we write some WebKitWebExtension for * manipulating the DOM directly. evalscript(c, "document.documentElement.style.overflow = '%s'", diff --git a/surf.o b/surf.o Binary files differ. diff --git a/surf.png b/surf.png Binary files differ.