config.h (12572B)
1 /* modifier 0 means no modifier */ 2 //#define HOMEPAGE "https://mahdi.pw" 3 #define DOWNLOADS "~/Downloads" 4 #define HS_FILE "~/.config/surf/history" 5 #define BM_FILE "~/.config/surf/bookmarks" 6 7 static int surfuseragent = 1; /* Append Surf version to default WebKit user agent */ 8 static char *fulluseragent = ""; /* Or override the whole user agent string */ 9 static char *scriptfile = "~/.config/surf/script.js"; 10 static char *styledir = "~/.config/surf/styles/"; 11 static char *certdir = "~/.config/surf/certificates/"; 12 static char *cachedir = "~/.config/surf/cache/"; 13 static char *cookiefile = "~/.config/surf/cookies.txt"; 14 15 static char *bookmarkfile = BM_FILE; 16 static char *historyfile = HS_FILE; 17 18 static char *searchengine = "https://lite.duckduckgo.com/lite/?q="; 19 20 static SearchEngine searchengines[] = { 21 { "wt", "https://www.wiktionary.org/search-redirect.php?family=wiktionary&search=%s" }, 22 { "aw", "https://wiki.archlinux.org/index.php?search=%s" }, 23 { "yt", "https://www.youtube.com/results?search_query=%s" }, 24 }; 25 26 /* Webkit default features */ 27 /* Highest priority value will be used. 28 * Default parameters are priority 0 29 * Per-uri parameters are priority 1 30 * Command parameters are priority 2 31 */ 32 static Parameter defconfig[ParameterLast] = { 33 /* parameter Arg value priority */ 34 [AccessMicrophone] = { { .i = 0 }, }, 35 [AccessWebcam] = { { .i = 0 }, }, 36 [Certificate] = { { .i = 0 }, }, 37 [CaretBrowsing] = { { .i = 0 }, }, 38 [CookiePolicies] = { { .v = "@Aa" }, }, 39 [DarkMode] = { { .i = 1 }, }, 40 [DefaultCharset] = { { .v = "UTF-8" }, }, 41 [DiskCache] = { { .i = 1 }, }, 42 [DNSPrefetch] = { { .i = 0 }, }, 43 [Ephemeral] = { { .i = 0 }, }, 44 [FileURLsCrossAccess] = { { .i = 0 }, }, 45 [FontSize] = { { .i = 12 }, }, 46 [FrameFlattening] = { { .i = 0 }, }, 47 [Geolocation] = { { .i = 0 }, }, 48 [HideBackground] = { { .i = 0 }, }, 49 [Inspector] = { { .i = 0 }, }, 50 [Java] = { { .i = 0 }, }, 51 [JavaScript] = { { .i = 0 }, }, 52 [KioskMode] = { { .i = 0 }, }, 53 [LoadImages] = { { .i = 1 }, }, 54 [MediaManualPlay] = { { .i = 1 }, }, 55 [PreferredLanguages] = { { .v = (char *[]){ NULL } }, }, 56 [RunInFullscreen] = { { .i = 0 }, }, 57 [ScrollBars] = { { .i = 0 }, }, 58 [ShowIndicators] = { { .i = 0 }, }, 59 [SiteQuirks] = { { .i = 1 }, }, 60 [SmoothScrolling] = { { .i = 0 }, }, 61 [SpellChecking] = { { .i = 0 }, }, 62 [SpellLanguages] = { { .v = ((char *[]){ "en_US", NULL }) }, }, 63 [StrictTLS] = { { .i = 1 }, }, 64 [Style] = { { .i = 1 }, }, 65 [WebGL] = { { .i = 0 }, }, 66 [ZoomLevel] = { { .f = 0.8 }, }, 67 [ClipboardNotPrimary] = { { .i = 1 }, }, 68 }; 69 70 static UriParameters uriparams[] = { 71 { "(://|\\.)(github\\.com|gitlab\\.com)(/|$)", { 72 [JavaScript] = { { .i = 1 }, 1 }, 73 }, }, 74 { "(://|\\.)yewtu\\.be(/|$)", { 75 [JavaScript] = { { .i = 1 }, 1 }, 76 }, }, 77 { "(://|\\.)(localhost:9091|localhost:8080)(/|$)", { 78 [JavaScript] = { { .i = 1 }, 1 }, 79 [Style] = { { .i = 0 }, 1 }, 80 }, }, 81 { "(://|\\.)suckless\\.org(/|$)", { 82 [JavaScript] = { { .i = 0 }, 1 }, 83 }, }, 84 }; 85 86 /* default window size: width, height */ 87 static int winsize[] = { 800, 600 }; 88 89 static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | 90 WEBKIT_FIND_OPTIONS_WRAP_AROUND; 91 92 #define PROMPT_GO "Go:" 93 #define PROMPT_NEW "Go: (new window)" 94 #define PROMPT_FIND "Find:" 95 96 /* SETPROP(readprop, setprop, prompt)*/ 97 #define SETPROP(r, s, p) { \ 98 .v = (const char *[]){ "/bin/sh", "-c", \ 99 "WIDTH=$(xwininfo -id $1 | awk '/Width/{print int($2/20)}'); " \ 100 "HIST=$(tail -n 5000 " HS_FILE " 2>/dev/null | awk -F'|' '!a[$2]++' | sort -r); " \ 101 "if [ ${WIDTH} -lt 30 ]; then " \ 102 " HIST_TABLE=$(printf '%s\n' \"${HIST}\" | awk -F'|' '{print NR\"|\"$3}');" \ 103 "elif [ ${WIDTH} -lt 50 ]; then" \ 104 " HIST_TABLE=$(printf '%s\n' \"${HIST}\" | awk -F'|' '{if(length($2) > '\"$WIDTH\"'){print NR\"|\"substr($2,0,'\"$WIDTH\"')\"...|\"$3}else{print NR\"|\"$2\"|\"$3}}'); " \ 105 "else HIST_TABLE=$(printf '%s\n' \"${HIST}\" | awk -F'|' '{if(length($2) > '\"$WIDTH\"'){print NR\"|\"$1\"|\"substr($2,0,'\"$WIDTH\"')\"...|\"$3}else{print NR\"|\"$1\"|\"$2\"|\"$3}}'); fi; " \ 106 "BOOKMARKS=$(cat " BM_FILE " 2>/dev/null); " \ 107 "HISTORIES=$(printf '%s\n' \"${HIST_TABLE}\" | column -t -s '|'); " \ 108 "[ \"$HIST\" ] || HISTORIES=''; " \ 109 "prop=$(printf '%b' \"$(xprop -id $1 "r" " \ 110 "| sed -e 's/^"r"(UTF8_STRING) = \"\\(.*\\)\"/\\1/' " \ 111 " -e 's/\\\\\\(.\\)/\\1/g' "\ 112 " && [ \""p"\" != \""PROMPT_FIND"\" ]" \ 113 " && printf '%s\n' \"${BOOKMARKS:----Bookmarks go here---}\" \"${HISTORIES:----History records go here---}\")\" " \ 114 "| dmenu -i -b -l 20 -p '"p"' -w $1 | awk '{if(length($3)!=0){print $1}else{print $0}}'); " \ 115 "[ \"$prop\" ] || exit; " \ 116 "[ \"$(echo \"$prop\" | grep -Eo '^\-?[0-9]+$')\" -gt 0 ] && prop=\"$(printf '%s\n' \"${HIST}\" | sed \"${prop}q;d\" | awk -F'|' '{print $2}')\"; " \ 117 "if [ \""p"\" != \""PROMPT_NEW"\" ]; then xprop -id $1 -f "s" 8u -set "s" \"$prop\"; else surf-open \"$prop\"; fi", \ 118 "surf-setprop", winid, NULL \ 119 } \ 120 } 121 122 /* DOWNLOAD(URI, referer) */ 123 #define DOWNLOAD(u, r) { \ 124 .v = (const char *[]){ "st", "-c", "st-float", "-e", "/bin/sh", "-c",\ 125 "cd " DOWNLOADS ";" \ 126 "curl -g -L -J -O -A \"$1\" -b \"$2\" -c \"$2\"" \ 127 " -e \"$3\" \"$4\"; read", \ 128 "surf-download", useragent, cookiefile, r, u, NULL \ 129 } \ 130 } 131 132 /* PLUMB(URI) */ 133 /* This called when some URI which does not begin with "about:", 134 * "http://" or "https://" should be opened. 135 */ 136 #define PLUMB(u) {\ 137 .v = (const char *[]){ "/bin/sh", "-c", \ 138 "xdg-open \"$0\"", u, NULL \ 139 } \ 140 } 141 142 /* VIDEOPLAY(URI) */ 143 #define VIDEOPLAY(u) {\ 144 .v = (const char *[]){ "/bin/sh", "-c", \ 145 "mpv \"$0\"", u, NULL \ 146 } \ 147 } 148 149 /* BM_ADD(readprop) */ 150 #define BM_ADD(r) {\ 151 .v = (const char *[]){ "/bin/sh", "-c", \ 152 "(echo $(xprop -id $0 $1) | cut -d '\"' -f2 " \ 153 "| sed 's/.*https*:\\/\\/\\(www\\.\\)\\?//' && cat ~/.config/surf/bookmarks) " \ 154 "| awk '!seen[$0]++' > ~/.config/surf/bookmarks.tmp && " \ 155 "mv ~/.config/surf/bookmarks.tmp ~/.config/surf/bookmarks", \ 156 winid, r, NULL \ 157 } \ 158 } 159 160 /* styles */ 161 /* 162 * The iteration will stop at the first match, beginning at the beginning of 163 * the list. 164 */ 165 static SiteSpecific styles[] = { 166 /* regexp file in $styledir */ 167 { ".*", "default.css" }, 168 //{ ".*suckless.org.*", "default.css" }, 169 //{ ".*yandex.com.*", "default.css" }, 170 }; 171 172 /* certificates */ 173 /* 174 * Provide custom certificate for urls 175 */ 176 static SiteSpecific certs[] = { 177 /* regexp file in $certdir */ 178 { "://suckless\\.org/", "suckless.org.crt" }, 179 }; 180 181 #define MODKEY GDK_CONTROL_MASK 182 183 static char *editscreen[] = { "/bin/sh", "-c", "surf-edit-source", NULL }; 184 static char *linkselect_curwin [] = { "/bin/sh", "-c", 185 "surf-link-select $0 'Link:' | xargs -r xprop -id $0 -f _SURF_GO 8u -set _SURF_GO $1", 186 winid, NULL 187 }; 188 static char *linkselect_newwin [] = { "/bin/sh", "-c", 189 "surf-link-select $0 'Link: (new window)' | xargs -r surf-open", 190 winid, NULL 191 }; 192 static char *linkselect_open [] = { "/bin/sh", "-c", 193 "surf-link-select $0 'Link: (file handler)' | xargs -r xdg-open", 194 winid, NULL 195 }; 196 197 /* hotkeys */ 198 /* 199 * If you use anything else but MODKEY and GDK_SHIFT_MASK, don't forget to 200 * edit the CLEANMASK() macro. 201 */ 202 static Key keys[] = { 203 /* modifier keyval function arg */ 204 { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, 205 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_NEW) }, 206 { MODKEY, GDK_KEY_Return, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, 207 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_Return, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_NEW) }, 208 { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, 209 { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, 210 { MODKEY, GDK_KEY_m, spawn, BM_ADD("_SURF_URI") }, 211 212 { MODKEY, GDK_KEY_e, externalpipe, { .v = editscreen } }, 213 { MODKEY, GDK_KEY_o, externalpipe, { .v = linkselect_curwin } }, 214 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_o, externalpipe, { .v = linkselect_newwin } }, 215 216 { MODKEY, GDK_KEY_w, playexternal, { 0 } }, 217 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_w, externalpipe, { .v = linkselect_open } }, 218 219 { 0, GDK_KEY_Escape, stop, { 0 } }, 220 { MODKEY, GDK_KEY_c, stop, { 0 } }, 221 222 { GDK_SHIFT_MASK, GDK_KEY_F5, reload, { .i = 1 } }, 223 { 0, GDK_KEY_F5, reload, { .i = 0 } }, 224 225 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_r, reload, { .i = 1 } }, 226 { MODKEY, GDK_KEY_r, reload, { .i = 0 } }, 227 228 { MODKEY, GDK_KEY_l, navigate, { .i = +1 } }, 229 { MODKEY, GDK_KEY_h, navigate, { .i = -1 } }, 230 231 /* vertical and horizontal scrolling, in viewport percentage */ 232 { MODKEY, GDK_KEY_j, scrollv, { .i = +10 } }, 233 { MODKEY, GDK_KEY_k, scrollv, { .i = -10 } }, 234 { MODKEY, GDK_KEY_space, scrollv, { .i = +50 } }, 235 { MODKEY, GDK_KEY_b, scrollv, { .i = -50 } }, 236 { MODKEY, GDK_KEY_i, scrollh, { .i = +10 } }, 237 { MODKEY, GDK_KEY_u, scrollh, { .i = -10 } }, 238 239 240 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_j, zoom, { .i = -1 } }, 241 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_k, zoom, { .i = +1 } }, 242 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_q, zoom, { .i = 0 } }, 243 { MODKEY, GDK_KEY_minus, zoom, { .i = -1 } }, 244 { MODKEY, GDK_KEY_plus, zoom, { .i = +1 } }, 245 246 { MODKEY, GDK_KEY_p, clipboard, { .i = 1 } }, 247 { MODKEY, GDK_KEY_y, clipboard, { .i = 0 } }, 248 249 { MODKEY, GDK_KEY_n, find, { .i = +1 } }, 250 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_n, find, { .i = -1 } }, 251 252 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_p, print, { 0 } }, 253 { MODKEY, GDK_KEY_t, showcert, { 0 } }, 254 255 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_a, togglecookiepolicy, { 0 } }, 256 { 0, GDK_KEY_F11, togglefullscreen, { 0 } }, 257 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_o, toggleinspector, { 0 } }, 258 259 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_c, toggle, { .i = CaretBrowsing } }, 260 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_f, toggle, { .i = FrameFlattening } }, 261 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_g, toggle, { .i = Geolocation } }, 262 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_s, toggle, { .i = JavaScript } }, 263 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_i, toggle, { .i = LoadImages } }, 264 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_b, toggle, { .i = ScrollBars } }, 265 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_t, toggle, { .i = StrictTLS } }, 266 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_d, toggle, { .i = DarkMode } }, 267 { MODKEY|GDK_SHIFT_MASK, GDK_KEY_m, toggle, { .i = Style } }, 268 }; 269 270 /* button definitions */ 271 /* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */ 272 static Button buttons[] = { 273 /* target event mask button function argument stop event */ 274 { OnLink, 0, 2, clicknewwindow, { .i = 0 }, 1 }, 275 { OnLink, MODKEY, 2, clicknewwindow, { .i = 1 }, 1 }, 276 { OnLink, MODKEY, 1, clicknewwindow, { .i = 1 }, 1 }, 277 { OnAny, 0, 8, clicknavigate, { .i = -1 }, 1 }, 278 { OnAny, 0, 9, clicknavigate, { .i = +1 }, 1 }, 279 { OnMedia, MODKEY, 1, clickexternplayer, { 0 }, 1 }, 280 }; 281