surf

surf
git clone git@git.zachrice.app:repos/surf.git
Log | Files | Refs | README | LICENSE

config.def.h (9734B)


      1 /* modifier 0 means no modifier */
      2 static int surfuseragent    = 1;  /* Append Surf version to default WebKit user agent */
      3 static char *fulluseragent  = ""; /* Or override the whole user agent string */
      4 static char *scriptfile     = "~/.surf/script.js";
      5 static char *styledir       = "~/.surf/styles/";
      6 static char *certdir        = "~/.surf/certificates/";
      7 static char *cachedir       = "~/.surf/cache/";
      8 static char *cookiefile     = "~/.surf/cookies.txt";
      9 static char *adblockdir    = "~/.surf/adblock/";
     10 static char *adblockfile   = "~/.surf/adblock.json";
     11 
     12 /* Webkit default features */
     13 /* Highest priority value will be used.
     14  * Default parameters are priority 0
     15  * Per-uri parameters are priority 1
     16  * Command parameters are priority 2
     17  */
     18 static Parameter defconfig[ParameterLast] = {
     19 	/* parameter                    Arg value       priority */
     20 	[AccessMicrophone]    =       { { .i = 1 },     },
     21 	[AccessWebcam]        =       { { .i = 1 },     },
     22 	[Certificate]         =       { { .i = 0 },     },
     23 	[CaretBrowsing]       =       { { .i = 0 },     },
     24 	[CookiePolicies]      =       { { .v = "@Aa" }, },
     25 	[DarkMode]            =       { { .i = 0 },     },
     26 	[DefaultCharset]      =       { { .v = "UTF-8" }, },
     27 	[DiskCache]           =       { { .i = 1 },     },
     28 	[DNSPrefetch]         =       { { .i = 0 },     },
     29 	[Ephemeral]           =       { { .i = 0 },     },
     30 	[FileURLsCrossAccess] =       { { .i = 0 },     },
     31 	[FontSize]            =       { { .i = 12 },    },
     32 	[Geolocation]         =       { { .i = 0 },     },
     33 	[HardwareAcceleration] =      { { .i = 1 },     },
     34 	[HideBackground]      =       { { .i = 0 },     },
     35 	[Inspector]           =       { { .i = 1 },     },
     36 	[JavaScript]          =       { { .i = 1 },     },
     37 	[KioskMode]           =       { { .i = 0 },     },
     38 	[LoadImages]          =       { { .i = 1 },     },
     39 	[MediaManualPlay]     =       { { .i = 1 },     },
     40 	[PDFJSviewer]         =       { { .i = 1 },     },
     41 	[PreferredLanguages]  =       { { .v = (char *[]){ NULL } }, },
     42 	[RunInFullscreen]     =       { { .i = 0 },     },
     43 	[ScrollBars]          =       { { .i = 1 },     },
     44 	[ShowIndicators]      =       { { .i = 1 },     },
     45 	[SiteQuirks]          =       { { .i = 1 },     },
     46 	[SmoothScrolling]     =       { { .i = 1 },     },
     47 	[SpellChecking]       =       { { .i = 1 },     },
     48 	[SpellLanguages]      =       { { .v = ((char *[]){ "en_US", NULL }) }, },
     49 	[StrictTLS]           =       { { .i = 1 },     },
     50 	[Style]               =       { { .i = 1 },     },
     51 	[WebGL]               =       { { .i = 1 },     },
     52 	[ZoomLevel]           =       { { .f = 1.0 },   },
     53 };
     54 
     55 static UriParameters uriparams[] = {
     56 	{ "(://|\\.)suckless\\.org(/|$)", {
     57 	  [JavaScript] = { { .i = 0 }, 1 },
     58 	}, },
     59 };
     60 
     61 /* default window size: width, height */
     62 static int winsize[] = { 800, 600 };
     63 
     64 static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
     65                                     WEBKIT_FIND_OPTIONS_WRAP_AROUND;
     66 
     67 #define PROMPT_GO     "Go:"
     68 #define PROMPT_FIND   "Find:"
     69 #define PROMPT_SEARCH "Search:"
     70 
     71 #define SEARCH_URL "https://duckduckgo.com/?q="
     72 
     73 /* SEARCHPROP(prompt) — dmenu prompt, URL-encode input, navigate via _SURF_GO */
     74 #define SEARCHPROP(p) { \
     75         .v = (const char *[]){ "/bin/sh", "-c", \
     76              "prop=\"$(dmenu -p '"p"' -w $1 </dev/null" \
     77              " | sed 's/ /+/g')\"" \
     78              " && [ -n \"$prop\" ]" \
     79              " && xprop -id $1 -f _SURF_GO 8u -set _SURF_GO" \
     80              " \""SEARCH_URL"$prop\"", \
     81              "surf-search", winid, NULL \
     82         } \
     83 }
     84 
     85 /* SETPROP(readprop, setprop, prompt)*/
     86 #define SETPROP(r, s, p) { \
     87         .v = (const char *[]){ "/bin/sh", "-c", \
     88              "prop=\"$(printf '%b' \"$(xprop -id $1 "r" " \
     89              "| sed -e 's/^"r"(UTF8_STRING) = \"\\(.*\\)\"/\\1/' " \
     90              "      -e 's/\\\\\\(.\\)/\\1/g' && cat ~/.surf/bookmarks)\" " \
     91              "| dmenu -l 10 -p '"p"' -w $1)\" " \
     92              "&& xprop -id $1 -f "s" 8u -set "s" \"$prop\"", \
     93              "surf-setprop", winid, NULL \
     94         } \
     95 }
     96 
     97 /* DOWNLOAD(URI, referer) */
     98 #define DOWNLOAD(u, r) { \
     99         .v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\
    100              "curl -g -L -J -O -A \"$1\" -b \"$2\" -c \"$2\"" \
    101              " -e \"$3\" \"$4\"; read", \
    102              "surf-download", useragent, cookiefile, r, u, NULL \
    103         } \
    104 }
    105 
    106 /* PLUMB(URI) */
    107 /* This called when some URI which does not begin with "about:",
    108  * "http://" or "https://" should be opened.
    109  */
    110 #define PLUMB(u) {\
    111         .v = (const char *[]){ "/bin/sh", "-c", \
    112              "xdg-open \"$0\"", u, NULL \
    113         } \
    114 }
    115 
    116 /* VIDEOPLAY(URI) */
    117 #define VIDEOPLAY(u) {\
    118         .v = (const char *[]){ "/bin/sh", "-c", \
    119              "mpv --really-quiet \"$0\"", u, NULL \
    120         } \
    121 }
    122 
    123 /* BM_ADD(readprop) */
    124 #define BM_ADD(r) {\
    125         .v = (const char *[]){ "/bin/sh", "-c", \
    126              "(echo $(xprop -id $0 "r") | cut -d '\"' -f2 " \
    127              "| sed 's/.*https*:\\/\\/\\(www\\.\\)\\?//' && cat ~/.surf/bookmarks) " \
    128              "| awk '!seen[$0]++' > ~/.surf/bookmarks.tmp && " \
    129              "mv ~/.surf/bookmarks.tmp ~/.surf/bookmarks", \
    130              winid, NULL \
    131         } \
    132 }
    133 
    134 /* styles */
    135 /*
    136  * The iteration will stop at the first match, beginning at the beginning of
    137  * the list.
    138  */
    139 static SiteSpecific styles[] = {
    140 	/* regexp               file in $styledir */
    141 	{ ".*",                 "default.css" },
    142 };
    143 
    144 /* certificates */
    145 /*
    146  * Provide custom certificate for urls
    147  */
    148 static SiteSpecific certs[] = {
    149 	/* regexp               file in $certdir */
    150 	{ "://suckless\\.org/", "suckless.org.crt" },
    151 };
    152 
    153 #define MODKEY GDK_CONTROL_MASK
    154 
    155 /* hotkeys */
    156 /*
    157  * If you use anything else but MODKEY and GDK_SHIFT_MASK, don't forget to
    158  * edit the CLEANMASK() macro.
    159  */
    160 static Key keys[] = {
    161 	/* modifier              keyval          function    arg */
    162 	{ MODKEY,                GDK_KEY_g,      spawn,      SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) },
    163 	{ MODKEY,                GDK_KEY_s,      spawn,      SEARCHPROP(PROMPT_SEARCH) },
    164 	{ MODKEY,                GDK_KEY_f,      spawn,      SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
    165 	{ MODKEY,                GDK_KEY_slash,  spawn,      SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) },
    166 
    167 	{ MODKEY,                GDK_KEY_m,      spawn,      BM_ADD("_SURF_URI") },
    168 
    169 	{ 0,                     GDK_KEY_Escape, stop,       { 0 } },
    170 	{ MODKEY,                GDK_KEY_c,      stop,       { 0 } },
    171 
    172 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_r,      reload,     { .i = 1 } },
    173 	{ MODKEY,                GDK_KEY_r,      reload,     { .i = 0 } },
    174 
    175 	{ MODKEY,                GDK_KEY_l,      navigate,   { .i = +1 } },
    176 	{ MODKEY,                GDK_KEY_h,      navigate,   { .i = -1 } },
    177 
    178 	/* vertical and horizontal scrolling, in viewport percentage */
    179 	{ MODKEY,                GDK_KEY_j,      scrollv,    { .i = +10 } },
    180 	{ MODKEY,                GDK_KEY_k,      scrollv,    { .i = -10 } },
    181 	{ MODKEY,                GDK_KEY_space,  scrollv,    { .i = +50 } },
    182 	{ MODKEY,                GDK_KEY_b,      scrollv,    { .i = -50 } },
    183 	{ MODKEY,                GDK_KEY_i,      scrollh,    { .i = +10 } },
    184 	{ MODKEY,                GDK_KEY_u,      scrollh,    { .i = -10 } },
    185 
    186 	/* scroll to top/bottom of page (vim gg / G) */
    187 	{ MODKEY,                GDK_KEY_comma,   scrolltop,    { 0 } },
    188 	{ MODKEY,                GDK_KEY_period,  scrollbottom, { 0 } },
    189 
    190 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_j,      zoom,       { .i = -1 } },
    191 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_k,      zoom,       { .i = +1 } },
    192 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_q,      zoom,       { .i = 0  } },
    193 	{ MODKEY,                GDK_KEY_minus,  zoom,       { .i = -1 } },
    194 	{ MODKEY,                GDK_KEY_plus,   zoom,       { .i = +1 } },
    195 	{ MODKEY,                GDK_KEY_equal,  zoom,       { .i = +1 } },
    196 
    197 	{ MODKEY,                GDK_KEY_p,      clipboard,  { .i = 1 } },
    198 	{ MODKEY,                GDK_KEY_y,      clipboard,  { .i = 0 } },
    199 
    200 	{ MODKEY,                GDK_KEY_n,      find,       { .i = +1 } },
    201 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_n,      find,       { .i = -1 } },
    202 
    203 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_p,      print,      { 0 } },
    204 	{ MODKEY,                GDK_KEY_t,      showcert,   { 0 } },
    205 
    206 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_a,      togglecookiepolicy, { 0 } },
    207 	{ 0,                     GDK_KEY_F11,    togglefullscreen, { 0 } },
    208 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_o,      toggleinspector, { 0 } },
    209 
    210 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_c,      toggle,     { .i = CaretBrowsing } },
    211 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_g,      toggle,     { .i = Geolocation } },
    212 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_s,      toggle,     { .i = JavaScript } },
    213 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_i,      toggle,     { .i = LoadImages } },
    214 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_b,      toggle,     { .i = ScrollBars } },
    215 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_t,      toggle,     { .i = StrictTLS } },
    216 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_m,      toggle,     { .i = Style } },
    217 	{ MODKEY|GDK_SHIFT_MASK, GDK_KEY_d,      toggle,     { .i = DarkMode } },
    218 };
    219 
    220 /* button definitions */
    221 /* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */
    222 static Button buttons[] = {
    223 	/* target       event mask      button  function        argument        stop event */
    224 	{ OnLink,       0,              2,      clicknewwindow, { .i = 0 },     1 },
    225 	{ OnLink,       MODKEY,         2,      clicknewwindow, { .i = 1 },     1 },
    226 	{ OnLink,       MODKEY,         1,      clicknewwindow, { .i = 1 },     1 },
    227 	{ OnAny,        0,              8,      clicknavigate,  { .i = -1 },    1 },
    228 	{ OnAny,        0,              9,      clicknavigate,  { .i = +1 },    1 },
    229 	{ OnMedia,      MODKEY,         1,      clickexternplayer, { 0 },       1 },
    230 };