sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

surf-multijs-20190325-d068a38.diff (3096B)


      1 From 8d8ca34a8e61733711e23ce43b88435bfdfd4962 Mon Sep 17 00:00:00 2001
      2 From: knary <theknary@gmail.com>
      3 Date: Mon, 25 Mar 2019 15:03:15 -0400
      4 Subject: [PATCH] This patch replaces scriptfile with an array of
      5  scriptfiles[]. This allows for the inclusion of multiple javascript files
      6  instead of filling up one file with multiple script plugins.
      7 
      8 ---
      9  config.def.h |  4 +++-
     10  surf.c       | 23 +++++++++++++++--------
     11  2 files changed, 18 insertions(+), 9 deletions(-)
     12 
     13 diff --git a/config.def.h b/config.def.h
     14 index 34265f6..7d7d68e 100644
     15 --- a/config.def.h
     16 +++ b/config.def.h
     17 @@ -1,11 +1,13 @@
     18  /* modifier 0 means no modifier */
     19  static int surfuseragent    = 1;  /* Append Surf version to default WebKit user agent */
     20  static char *fulluseragent  = ""; /* Or override the whole user agent string */
     21 -static char *scriptfile     = "~/.surf/script.js";
     22  static char *styledir       = "~/.surf/styles/";
     23  static char *certdir        = "~/.surf/certificates/";
     24  static char *cachedir       = "~/.surf/cache/";
     25  static char *cookiefile     = "~/.surf/cookies.txt";
     26 +static char *scriptfiles[]  = {
     27 +	"~/.surf/script.js",
     28 +};
     29  
     30  /* Webkit default features */
     31  /* Highest priority value will be used.
     32 diff --git a/surf.c b/surf.c
     33 index 2b54e3c..34a75de 100644
     34 --- a/surf.c
     35 +++ b/surf.c
     36 @@ -337,9 +337,11 @@ setup(void)
     37  
     38  	/* dirs and files */
     39  	cookiefile = buildfile(cookiefile);
     40 -	scriptfile = buildfile(scriptfile);
     41  	cachedir   = buildpath(cachedir);
     42  	certdir    = buildpath(certdir);
     43 +	for (i = 0; i < LENGTH(scriptfiles); i++) {
     44 +		scriptfiles[i] = buildfile(scriptfiles[i]);
     45 +	}
     46  
     47  	gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
     48  
     49 @@ -945,9 +947,11 @@ runscript(Client *c)
     50  	gchar *script;
     51  	gsize l;
     52  
     53 -	if (g_file_get_contents(scriptfile, &script, &l, NULL) && l)
     54 -		evalscript(c, "%s", script);
     55 -	g_free(script);
     56 +	for (int i = 0; i < LENGTH(scriptfiles); i++) {
     57 +		if (g_file_get_contents(scriptfiles[i], &script, &l, NULL) && l)
     58 +			evalscript(c, "%s", script);
     59 +		g_free(script);
     60 +	}
     61  }
     62  
     63  void
     64 @@ -1010,9 +1014,9 @@ newwindow(Client *c, const Arg *a, int noembed)
     65  	cmd[i++] = curconfig[Style].val.i ?           "-M" : "-m" ;
     66  	cmd[i++] = curconfig[Inspector].val.i ?       "-N" : "-n" ;
     67  	cmd[i++] = curconfig[Plugins].val.i ?         "-P" : "-p" ;
     68 -	if (scriptfile && g_strcmp0(scriptfile, "")) {
     69 +	if (scriptfiles[0] && g_strcmp0(scriptfiles[0], "")) {
     70  		cmd[i++] = "-r";
     71 -		cmd[i++] = scriptfile;
     72 +		cmd[i++] = scriptfiles[0];
     73  	}
     74  	cmd[i++] = curconfig[JavaScript].val.i ? "-S" : "-s";
     75  	cmd[i++] = curconfig[StrictTLS].val.i ? "-T" : "-t";
     76 @@ -1076,9 +1080,12 @@ cleanup(void)
     77  	close(pipein[0]);
     78  	close(pipeout[1]);
     79  	g_free(cookiefile);
     80 -	g_free(scriptfile);
     81  	g_free(stylefile);
     82  	g_free(cachedir);
     83 +	for (int i = 0; i < LENGTH(scriptfiles); i++) {
     84 +		g_free(scriptfiles[i]);
     85 +	}
     86 +
     87  	XCloseDisplay(dpy);
     88  }
     89  
     90 @@ -2067,7 +2074,7 @@ main(int argc, char *argv[])
     91  		defconfig[Plugins].prio = 2;
     92  		break;
     93  	case 'r':
     94 -		scriptfile = EARGF(usage());
     95 +		scriptfiles[0] = EARGF(usage());
     96  		break;
     97  	case 's':
     98  		defconfig[JavaScript].val.i = 0;
     99 -- 
    100 2.21.0
    101