diff --git a/clipmenud b/clipmenud index 0a9002c..c6c0fb3 100755 --- a/clipmenud +++ b/clipmenud @@ -55,24 +55,9 @@ while sleep "${CLIPMENUD_SLEEP:-0.5}"; do if type -p xsel >/dev/null 2>&1; then debug 'Using xsel' data=$(xsel -o --"$selection"; printf x) - # Take ownership of the clipboard, in case the original application - # is unable to serve the clipboard request (due to being suspended, - # etc). - # - # Primary is excluded from the change of ownership as applications - # sometimes act up if clipboard focus is taken away from them -- - # for example, urxvt will unhilight text, which is undesirable. - if [[ $selection != primary ]]; then - xsel -o --"$selection" | xsel -i --"$selection" - fi else debug 'Using xclip' data=$(xclip -o -sel "$selection"; printf x) - # See above comments about taking ownership of the clipboard for - # context. - if [[ $selection != primary ]]; then - xclip -o -sel "$selection" | xclip -i -sel "$selection" - fi fi debug "Data before stripping: $data" @@ -110,5 +95,24 @@ while sleep "${CLIPMENUD_SLEEP:-0.5}"; do debug "Writing $data to $filename" printf '%s' "$data" > "$filename" + + if ! (( NO_OWN_CLIPBOARD )) && [[ $selection != primary ]]; then + # Take ownership of the clipboard, in case the original application + # is unable to serve the clipboard request (due to being suspended, + # etc). + # + # Primary is excluded from the change of ownership as applications + # sometimes act up if clipboard focus is taken away from them -- + # for example, urxvt will unhilight text, which is undesirable. + # + # We can't colocate this with the above copying code because + # https://github.com/cdown/clipmenu/issues/34 requires knowing if + # we would skip first. + if type -p xsel >/dev/null 2>&1; then + xsel -o --"$selection" | xsel -i --"$selection" + else + xclip -o -sel "$selection" | xclip -i -sel "$selection" + fi + fi done done