From 2b04a1eafe0db7e0a9d640750fa59e3cebb4c322 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Mon, 5 Feb 2018 23:49:41 +0000 Subject: [PATCH 1/3] Add optional support for clipnotify to avoid polling --- clipmenud | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/clipmenud b/clipmenud index d43d806..048c35f 100755 --- 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,20 @@ mkdir -p -m0700 "$cache_dir" declare -A last_data +command -v clipnotify >/dev/null 2>&1 && has_clipnotify=1 + 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 From 935c498dec752c669b568b3185b402f3ff8d2ecc Mon Sep 17 00:00:00 2001 From: Chris Down Date: Mon, 5 Feb 2018 23:52:37 +0000 Subject: [PATCH 2/3] Add note in readme about new non-polling mode --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d3f96db..3b421bc 100644 --- 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. +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). - 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. + 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. From b33d74cae5e93c9e2107eb6ea80af46f2450e608 Mon Sep 17 00:00:00 2001 From: Chris Down Date: Thu, 8 Feb 2018 00:55:29 +0000 Subject: [PATCH 3/3] Add messages when clipnotify is not detected --- clipmenud | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clipmenud b/clipmenud index 048c35f..5ee6e00 100755 --- a/clipmenud +++ b/clipmenud @@ -89,6 +89,11 @@ 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 true; do