~kris/suckless

surf

cb9520b33e3ca6701da5a058f9a0d937ea44ccea — Derek Taylor 6 years ago 9eb4f96
Adding some patches, editing some keybindings.
17 files changed, 116 insertions(+), 18 deletions(-)

M FAQ.md -rwxr-xr-x => -rw-r--r--
M LICENSE -rwxr-xr-x => -rw-r--r--
M Makefile -rwxr-xr-x => -rw-r--r--
M TODO.md -rwxr-xr-x => -rw-r--r--
M arg.h -rwxr-xr-x => -rw-r--r--
M common.c -rwxr-xr-x => -rw-r--r--
M common.h -rwxr-xr-x => -rw-r--r--
M config.def.h -rwxr-xr-x => -rw-r--r--
M config.def.h.orig -rwxr-xr-x => -rw-r--r--
M config.h -rwxr-xr-x => -rw-r--r--
M config.mk -rwxr-xr-x => -rw-r--r--
M libsurf-webext.c -rwxr-xr-x => -rw-r--r--
M surf
M surf.1 -rwxr-xr-x => -rw-r--r--
M surf.c -rwxr-xr-x => -rw-r--r--
M surf.o
M surf.png -rwxr-xr-x => -rw-r--r--
M FAQ.md => FAQ.md +0 -0
M LICENSE => LICENSE +0 -0
M Makefile => Makefile +0 -0
M TODO.md => TODO.md +0 -0
M arg.h => arg.h +0 -0
M common.c => common.c +0 -0
M common.h => common.h +0 -0
M config.def.h => config.def.h +23 -2
@@ 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 */

M config.def.h.orig => config.def.h.orig +25 -2
@@ 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 } },

M config.h => config.h +23 -7
@@ 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 */

M config.mk => config.mk +0 -0
M libsurf-webext.c => libsurf-webext.c +0 -0
M surf => surf +0 -0
M surf.1 => surf.1 +0 -0
M surf.c => surf.c +45 -7
@@ 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'",

M surf.o => surf.o +0 -0
M surf.png => surf.png +0 -0