Only take ownership of clipboard if we would not skip this clip

Fixes #34, an issue with pcmanfm GUI file copy/paste.
This commit is contained in:
Chris Down 2016-11-09 11:38:41 +00:00
parent 9efd96b405
commit 2ab5b5b502

View file

@ -55,24 +55,9 @@ while sleep "${CLIPMENUD_SLEEP:-0.5}"; do
if type -p xsel >/dev/null 2>&1; then if type -p xsel >/dev/null 2>&1; then
debug 'Using xsel' debug 'Using xsel'
data=$(xsel -o --"$selection"; printf x) 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 else
debug 'Using xclip' debug 'Using xclip'
data=$(xclip -o -sel "$selection"; printf x) 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 fi
debug "Data before stripping: $data" debug "Data before stripping: $data"
@ -110,5 +95,24 @@ while sleep "${CLIPMENUD_SLEEP:-0.5}"; do
debug "Writing $data to $filename" debug "Writing $data to $filename"
printf '%s' "$data" > "$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
done done