From 4d0f11a154ff6c2c39877298870e3aaad2e215e6 Mon Sep 17 00:00:00 2001 From: gutmet Date: Sun, 14 Mar 2021 01:39:15 +0100 Subject: [PATCH] applied bookmarking and clipboard instead of primary --- config.def.h | 18 ++++++++++++++++-- surf.c | 11 +++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index be168ab..575fb99 100644 --- a/config.def.h +++ b/config.def.h @@ -54,6 +54,7 @@ static Parameter defconfig[ParameterLast] = { [Style] = { { .i = 1 }, }, [WebGL] = { { .i = 0 }, }, [ZoomLevel] = { { .f = 1.0 }, }, + [ClipboardNotPrimary] = { { .i = 1 }, }, }; static UriParameters uriparams[] = { @@ -76,8 +77,9 @@ 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 ~/suckless/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 \ } \ } @@ -108,6 +110,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 ~/suckless/surf/bookmarks) " \ + "| awk '!seen[$0]++' > ~/suckless/surf/bookmarks.tmp && " \ + "mv ~/suckless/surf/bookmarks.tmp ~/suckless/surf/bookmarks", \ + winid, r, NULL \ + } \ +} + /* styles */ /* * The iteration will stop at the first match, beginning at the beginning of @@ -139,6 +152,7 @@ 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") }, { 0, GDK_KEY_Escape, stop, { 0 } }, { MODKEY, GDK_KEY_c, stop, { 0 } }, diff --git a/surf.c b/surf.c index edaf348..c4c3d99 100644 --- a/surf.c +++ b/surf.c @@ -83,6 +83,7 @@ typedef enum { Style, WebGL, ZoomLevel, + ClipboardNotPrimary, ParameterLast } ParamName; @@ -293,6 +294,7 @@ static ParamName loadcommitted[] = { SpellLanguages, Style, ZoomLevel, + ClipboardNotPrimary, ParameterLast }; @@ -1842,13 +1844,18 @@ showcert(Client *c, const Arg *a) void clipboard(Client *c, const Arg *a) { + /* User defined choice of selection, see config.h */ + GdkAtom selection = GDK_SELECTION_PRIMARY; + if (curconfig[ClipboardNotPrimary].val.i > 0) + selection = GDK_SELECTION_CLIPBOARD; + if (a->i) { /* load clipboard uri */ gtk_clipboard_request_text(gtk_clipboard_get( - GDK_SELECTION_PRIMARY), + selection), pasteuri, c); } else { /* copy uri */ gtk_clipboard_set_text(gtk_clipboard_get( - GDK_SELECTION_PRIMARY), c->targeturi + selection), c->targeturi ? c->targeturi : geturi(c), -1); } }