commit fd665a298a1ace0637b5a6f3c4cd017c03c51216
parent f576a116fde40328e5c0967b90f476b5416acc9b
Author: Chris Down <chris@chrisdown.name>
Date: Thu, 8 Feb 2018 00:58:19 +0000
Merge branch 'release/4.1.0'
Diffstat:
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
@@ -26,14 +26,14 @@ there, but it basically works like this:
## clipmenud
-1. `clipmenud` polls the clipboard every 0.5 seconds (or another interval as
- configured with the `CM_SLEEP` environment variable). Unfortunately there's
- no interface to subscribe for changes in X11, so we must poll.
-
- Instead of polling, you can bind your copy key binding to also issue
- `CM_ONESHOT=1 clipmenud`. However, there's no generic way to do this, since
- any keys or mouse buttons could be bound to do this action in a number of
- ways.
+1. `clipmenud` uses [clipnotify](https://github.com/cdown/clipnotify) to wait
+ for new clipboard events. If clipnotify is not present on the system, we
+ poll every 0.5 seconds (or another interval as configured with the
+ `CM_SLEEP` environment variable).
+
+ You can also bind your copy key binding to also issue `CM_ONESHOT=1
+ clipmenud`. However, there's no generic way to do this, since any keys or
+ mouse buttons could be bound to do this action in a number of ways.
2. If `clipmenud` detects changes to the clipboard contents, it writes them out
to the cache directory.
diff --git a/clipmenud b/clipmenud
@@ -11,6 +11,7 @@ cache_dir=$CM_DIR/clipmenu.$major_version.$USER/
cache_file=$cache_dir/line_cache
lock_file=$cache_dir/lock
lock_timeout=2
+has_clipnotify=0
xsel_log=/dev/null
for file in /proc/self/fd/2 /dev/stderr; do
@@ -86,9 +87,25 @@ mkdir -p -m0700 "$cache_dir"
declare -A last_data
+command -v clipnotify >/dev/null 2>&1 && has_clipnotify=1
+
+if ! (( has_clipnotify )); then
+ echo "WARN: Consider installing clipnotify for better performance." >&2
+ echo "WARN: See https://github.com/cdown/clipnotify." >&2
+fi
+
exec {lock_fd}> "$lock_file"
-while (( CM_ONESHOT )) || sleep "${CM_SLEEP:-0.5}"; do
+while true; do
+ if ! (( CM_ONESHOT )); then
+ if (( has_clipnotify )); then
+ clipnotify
+ else
+ # Use old polling method
+ sleep "${CM_SLEEP:-0.5}"
+ fi
+ fi
+
if ! flock -x -w "$lock_timeout" "$lock_fd"; then
if (( CM_ONESHOT )); then
printf 'ERROR: %s\n' 'Timed out waiting for lock' >&2