clipmenu

Simple clipboard management using dmenu
git clone https://git.sinitax.com/cdown/clipmenu
Log | Files | Refs | README | LICENSE | sfeed.txt

commit eb7d2b94817e8b66f62dc372a204a78a12e3ef0f
parent 55407ba3f622c99b1efafbe6b6371680f6abd8f6
Author: Chris Down <chris@chrisdown.name>
Date:   Mon, 19 Feb 2018 15:01:21 +0000

Take clipboard ownership prior to clipnotify

This avoids infinite loop if we make the work block async

Diffstat:
Mclipmenud | 28+++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/clipmenud b/clipmenud @@ -97,6 +97,19 @@ exec {lock_fd}> "$lock_file" sleep_cmd=(sleep "${CM_SLEEP:-0.5}") while true; do + # We need to take ownership synchronously before we run `clipnotify` as + # otherwise we could enter an infinite loop. + if (( CM_OWN_CLIPBOARD )); 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. + _xsel -k --clipboard + fi + if ! (( CM_ONESHOT )); then if (( has_clipnotify )); then # Fall back to polling if clipnotify fails @@ -146,21 +159,6 @@ while true; do debug "Writing $first_line to $cache_file" printf '%s\n' "$first_line" >> "$cache_file" - if (( CM_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. - _xsel -k --"$selection" - fi - if (( CM_MAX_CLIPS )); then mapfile -t to_remove < <( head -n -"$CM_MAX_CLIPS" "$cache_file" |