diff options
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | config.h (renamed from config.def.h) | 26 | ||||
-rw-r--r-- | config.mk | 16 | ||||
-rwxr-xr-x | gitorigin.sh | 3 | ||||
-rwxr-xr-x | surf-menu | 106 | ||||
-rwxr-xr-x | surf-open.sh | 32 | ||||
-rw-r--r-- | surf.c | 4 | ||||
-rw-r--r-- | surf.desktop | 12 |
8 files changed, 155 insertions, 53 deletions
@@ -52,15 +52,24 @@ install: all @mkdir -p $(DESTDIR)$(PREFIX)/bin @cp -f surf $(DESTDIR)$(PREFIX)/bin @chmod 755 $(DESTDIR)$(PREFIX)/bin/surf + @echo installing surf-menu to $(DESTDIR)$(PREFIX)/bin + @cp -f surf-menu $(DESTDIR)$(PREFIX)/bin + @chmod 755 $(DESTDIR)$(PREFIX)/bin/surf-menu @echo installing manual page to $(DESTDIR)$(MANPREFIX)/man1 @mkdir -p $(DESTDIR)$(MANPREFIX)/man1 @sed "s/VERSION/$(VERSION)/g" < surf.1 > $(DESTDIR)$(MANPREFIX)/man1/surf.1 @chmod 644 $(DESTDIR)$(MANPREFIX)/man1/surf.1 + @echo installing desktop file to $(DESTDIR)/usr/share/applications + @mkdir -p $(DESTDIR)/usr/share/applications + @cp -f surf.desktop $(DESTDIR)/usr/share/applications/surf.desktop uninstall: @echo removing executable file from $(DESTDIR)$(PREFIX)/bin @rm -f $(DESTDIR)$(PREFIX)/bin/surf + @rm -f $(DESTDIR)$(PREFIX)/bin/surf-menu @echo removing manual page from $(DESTDIR)$(MANPREFIX)/man1 @rm -f $(DESTDIR)$(MANPREFIX)/man1/surf.1 + @echo removing desktop page from $(DESTDIR)/usr/share/applications + @rm -f $(DESTDIR)/usr/share/applications/surf.desktop .PHONY: all options clean dist install uninstall @@ -18,12 +18,12 @@ static Parameter defconfig[ParameterLast] = { [AcceleratedCanvas] = { { .i = 1 }, }, [AccessMicrophone] = { { .i = 0 }, }, [AccessWebcam] = { { .i = 0 }, }, - [Certificate] = { { .i = 0 }, }, + [Certificate] = { { .i = 1 }, }, [CaretBrowsing] = { { .i = 0 }, }, [CookiePolicies] = { { .v = "@Aa" }, }, [DefaultCharset] = { { .v = "UTF-8" }, }, [DiskCache] = { { .i = 1 }, }, - [DNSPrefetch] = { { .i = 0 }, }, + [DNSPrefetch] = { { .i = 1 }, }, [FileURLsCrossAccess] = { { .i = 0 }, }, [FontSize] = { { .i = 12 }, }, [FrameFlattening] = { { .i = 0 }, }, @@ -34,19 +34,19 @@ static Parameter defconfig[ParameterLast] = { [JavaScript] = { { .i = 1 }, }, [KioskMode] = { { .i = 0 }, }, [LoadImages] = { { .i = 1 }, }, - [MediaManualPlay] = { { .i = 1 }, }, + [MediaManualPlay] = { { .i = 0 }, }, [Plugins] = { { .i = 1 }, }, - [PreferredLanguages] = { { .v = (char *[]){ NULL } }, }, + [PreferredLanguages] = { { .v = (char *[]){ "en_US", "cs_CZ", NULL } }, }, [RunInFullscreen] = { { .i = 0 }, }, [ScrollBars] = { { .i = 1 }, }, [ShowIndicators] = { { .i = 1 }, }, [SiteQuirks] = { { .i = 1 }, }, - [SmoothScrolling] = { { .i = 0 }, }, - [SpellChecking] = { { .i = 0 }, }, - [SpellLanguages] = { { .v = ((char *[]){ "en_US", NULL }) }, }, + [SmoothScrolling] = { { .i = 1 }, }, + [SpellChecking] = { { .i = 1 }, }, + [SpellLanguages] = { { .v = ((char *[]){ "en_US", "cs_CZ", NULL }) }, }, [StrictTLS] = { { .i = 1 }, }, [Style] = { { .i = 1 }, }, - [WebGL] = { { .i = 0 }, }, + [WebGL] = { { .i = 1 }, }, [ZoomLevel] = { { .f = 1.0 }, }, }; @@ -63,7 +63,6 @@ static int winsize[] = { 800, 600 }; static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND; -#define PROMPT_GO "Go:" #define PROMPT_FIND "Find:" /* SETPROP(readprop, setprop, prompt)*/ @@ -76,9 +75,14 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | } \ } +/* Goto */ +#define GOTO { \ + .v = (const char *[]){ "/usr/bin/surf-menu", "--xid", winid, NULL } \ +} + /* DOWNLOAD(URI, referer) */ #define DOWNLOAD(u, r) { \ - .v = (const char *[]){ "st", "-e", "/bin/sh", "-c",\ + .v = (const char *[]){ "urxvt", "-e", "/bin/sh", "-c",\ "curl -g -L -J -O -A \"$1\" -b \"$2\" -c \"$2\"" \ " -e \"$3\" \"$4\"; read", \ "surf-download", useragent, cookiefile, r, u, NULL \ @@ -130,7 +134,7 @@ static SiteSpecific certs[] = { */ static Key keys[] = { /* modifier keyval function arg */ - { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, + { MODKEY, GDK_KEY_g, spawn, GOTO }, { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, @@ -1,22 +1,22 @@ # surf version VERSION = 2.0 -# Customize below to fit your system +PKG_CONFIG ?= pkg-config # paths -PREFIX = /usr/local +PREFIX = /usr MANPREFIX = $(PREFIX)/share/man LIBPREFIX = $(PREFIX)/lib/surf -X11INC = /usr/X11R6/include -X11LIB = /usr/X11R6/lib +X11INC = $(shell $(PKG_CONFIG) --cflags x11) +X11LIB = $(shell $(PKG_CONFIG) --libs x11) -GTKINC = `pkg-config --cflags gtk+-3.0 gcr-3 webkit2gtk-4.0` -GTKLIB = `pkg-config --libs gtk+-3.0 gcr-3 webkit2gtk-4.0` +GTKINC = $(shell $(PKG_CONFIG) --cflags gtk+-3.0 gthread-2.0 gcr-3 webkit2gtk-4.0) +GTKLIB = $(shell $(PKG_CONFIG) --libs gtk+-3.0 gthread-2.0 gcr-3 webkit2gtk-4.0) # includes and libs -INCS = -I$(X11INC) $(GTKINC) -LIBS = -L$(X11LIB) -lX11 $(GTKLIB) -lgthread-2.0 +INCS = $(X11INC) $(GTKINC) +LIBS = $(X11LIB) $(GTKLIB) # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -DWEBEXTDIR=\"${LIBPREFIX}\" \ diff --git a/gitorigin.sh b/gitorigin.sh new file mode 100755 index 0000000..ea07b48 --- /dev/null +++ b/gitorigin.sh @@ -0,0 +1,3 @@ +#!/bin/sh +git remote add origin git://git.suckless.org/surf +git fetch remote diff --git a/surf-menu b/surf-menu new file mode 100755 index 0000000..975f0b1 --- /dev/null +++ b/surf-menu @@ -0,0 +1,106 @@ +#!/bin/sh +set -e + +BOOKMARDS=~/notes/bookmarks.md +# TODO history +#HISTORY=~/notes/.surf_history + +set_uri() { + if [ -n "$XID" ]; then + xprop -id "$XID" -f "_SURF_GO" 8s -set "_SURF_GO" "$1" + else + surf "$1" & + fi +} + +run() { + if echo "$1" | grep -qE '^\?'; then # We do search on duckduckgo + + set_uri "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web" + + elif echo "$1" | grep -qE '^~?/'; then # This is local path + + set_uri "${1/#\~/$HOME}" + + elif echo "$1" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'; then # This ipv4 address + + set_uri "$1" + + # TODO ipv6 address + + else # We follow address + + LPROTOCOL="$(echo "$1" | sed -n 's#^\([^:]*\)://.*#\1#p')" + LHOST="$(echo "$1" | sed -n 's#^[^:]*://##;s#^\([^/]\+\)/\?.*#\1#p')" + LPATH="$(echo "$1" | sed 's#^[^:]*://##;s#^[^/]\+/\?##')" + + if ! getent hosts "$LHOST" >/dev/null; then + if getent hosts "$LHOST.cz" >/dev/null; then + LHOST="$LHOST.cz" + elif getent hosts "$LHOST.org" >/dev/null; then + LHOST="$LHOST.org" + elif getent hosts "$LHOST.com" >/dev/null; then + LHOST="$LHOST.com" + fi + # TODO what to do when we can't expand it? + fi + # Decide on protocol (if connection to 443 is not possible then use http otherwise https) + if [ -z "$LPROTOCOL" ]; then # We already have protocol (given explicitly) + if nc -z -w1 "$LHOST" 443 2>/dev/null; then + LPROTOCOL="https" + else + LPROTOCOL="http" + fi + fi + + set_uri "$LPROTOCOL://$LHOST/$LPATH" + + fi +} + +XID="" +ADDCH="" + +while [ $# -gt 0 ]; do + case "$1" in + -h|--h) + echo "This is menu script for surf web browser." + echo "Usage: $0 [OPTION]..." + echo + echo "Options:" + echo " --help, -h" + echo " Print this help text." + echo " --xid XID" + echo " Instead of opening new surf instance set url to existing one" + exit + ;; + --xid) + XID="$2" + shift + ;; + -a|--add) + shift + ADDCH="$ADDCH +$1" + ;; + *) + echo "Unknown option $1" >&2 + exit 1 + ;; + esac + shift +done + +# If XID is given then as first one add current uri +if [ -n "$XID" ]; then + ADDCH="$(xprop -id "$XID" _SURF_URI | sed -n 's/.*(STRING) = "\(.*\)"/\1/p')" + DMENU_ARGS="-w $XID -p Go:" +fi + +# Note: Bookmarks starts with '* ' +CHOOSE="$ADDCH +$(sed -n 's/\* //p' "$BOOKMARDS")" + +echo "$CHOOSE" | sed '/^\s*$/d' | dmenu -p 'surf' $DMENU_ARGS | while read L; do + run "$L" +done diff --git a/surf-open.sh b/surf-open.sh deleted file mode 100755 index c22edc2..0000000 --- a/surf-open.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# -# See the LICENSE file for copyright and license details. -# - -xidfile="$HOME/tmp/tabbed-surf.xid" -uri="" - -if [ "$#" -gt 0 ]; -then - uri="$1" -fi - -runtabbed() { - tabbed -dn tabbed-surf -r 2 surf -e '' "$uri" >"$xidfile" \ - 2>/dev/null & -} - -if [ ! -r "$xidfile" ]; -then - runtabbed -else - xid=$(cat "$xidfile") - xprop -id "$xid" >/dev/null 2>&1 - if [ $? -gt 0 ]; - then - runtabbed - else - surf -e "$xid" "$uri" >/dev/null 2>&1 & - fi -fi - @@ -1741,11 +1741,11 @@ clipboard(Client *c, const Arg *a) { if (a->i) { /* load clipboard uri */ gtk_clipboard_request_text(gtk_clipboard_get( - GDK_SELECTION_PRIMARY), + GDK_SELECTION_CLIPBOARD), pasteuri, c); } else { /* copy uri */ gtk_clipboard_set_text(gtk_clipboard_get( - GDK_SELECTION_PRIMARY), c->targeturi + GDK_SELECTION_CLIPBOARD), c->targeturi ? c->targeturi : geturi(c), -1); } } diff --git a/surf.desktop b/surf.desktop new file mode 100644 index 0000000..57ca5f8 --- /dev/null +++ b/surf.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Type=Application +Version=1.0 +Name=Surf +GenericName=Web Browser +TryExec=/usr/bin/surf +Exec=/usr/bin/surf %u +Terminal=false +Categories=Network;WebBrowser; +StartupNotify=true +StartupWMClass=Surf +MimeType=x-scheme-handler/unknown;x-scheme-handler/about;x-scheme-handler/https;x-scheme-handler/http;text/html;text/xml; |