Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# clipmenud as the operator's user unit starts it, written by the mesh (module clipmenu). Replaced at every push.
|
||||
#
|
||||
# The account's service manager starts before the X server does, and has a DISPLAY only once the session's
|
||||
# xinitrc has handed it over (module xorg). So this waits, quietly, until the display is known, and exits
|
||||
# only when the session ends with it: a quick exit would run the unit into its start limit. DISPLAY, when
|
||||
# the manager has it, wins. Without it, exactly one X socket names the display; none or several (a
|
||||
# second server beside the session) wait for the session's own to arrive.
|
||||
# A running process does not see what the session hands the manager later, so each pass asks the manager.
|
||||
until [ -n "$DISPLAY" ]; do
|
||||
for pair in $(systemctl --user show-environment 2>/dev/null | grep -E '^(DISPLAY|XAUTHORITY)='); do
|
||||
export "$pair"
|
||||
done
|
||||
[ -n "$DISPLAY" ] && break
|
||||
set -- /tmp/.X11-unix/X*
|
||||
if [ $# -eq 1 ] && [ -S "$1" ]; then
|
||||
DISPLAY=":${1##*/X}"
|
||||
export DISPLAY
|
||||
else
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
if [ -z "$XAUTHORITY" ] && [ -r "$HOME/.Xauthority" ]; then
|
||||
XAUTHORITY="$HOME/.Xauthority"
|
||||
export XAUTHORITY
|
||||
fi
|
||||
# clipmenud allows one daemon per account: it takes an exclusive flock on its session_lock file and exits
|
||||
# with status 2 when that is held. After a delivery without a new login, the session's older clipmenud (from
|
||||
# its xinitrc) still holds it, and a start would run the unit round its restart loop. So this waits, quietly,
|
||||
# until the lock is free: it looks at the same file clipmenud locks (the directory is clipmenud's own rule)
|
||||
# and lets go at once. Exit status 1 is "held" for util-linux and BusyBox flock alike (no -E: BusyBox lacks it); any other outcome starts clipmenud, which says its own
|
||||
# error. Another daemon winning the gap between look and start costs one restart, not a loop.
|
||||
lock="${CM_DIR:-${XDG_RUNTIME_DIR-${TMPDIR-/tmp}}}/clipmenu.6.$USER/session_lock"
|
||||
while [ -e "$lock" ]; do
|
||||
flock -n "$lock" true
|
||||
[ $? -eq 1 ] || break
|
||||
sleep 2
|
||||
done
|
||||
PATH="/usr/local/lib/mesh-clipmenu:$PATH"
|
||||
export PATH
|
||||
exec clipmenud
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# xsel as clipmenud sees it, written by the mesh (module clipmenu). Replaced at every push.
|
||||
#
|
||||
# clipmenud records text, and reads a selection with `timeout 1 xsel -o`. A selection holding an
|
||||
# image (a screenshot copied as image/png) is sent in pieces; one second is too short for megabytes,
|
||||
# timeout kills xsel half way, and the program owning the image waits for ever for a reader that is
|
||||
# gone. From then on nothing can ask the clipboard anything: pastes hang, and an Electron app that
|
||||
# asks on its main thread freezes. So a read goes ahead only when the selection offers text.
|
||||
case " $* " in
|
||||
*" -o "* | *" --output "*)
|
||||
selection=clipboard
|
||||
case " $* " in
|
||||
*" --primary "* | *" -p "*) selection=primary ;;
|
||||
*" --secondary "* | *" -s "*) selection=secondary ;;
|
||||
esac
|
||||
targets=$(timeout 1 xclip -selection "$selection" -t TARGETS -o 2>/dev/null) || exit 1
|
||||
printf '%s\n' "$targets" | grep -qxE 'UTF8_STRING|STRING|TEXT|text/plain(;charset=utf-8)?' || exit 1
|
||||
;;
|
||||
esac
|
||||
exec /usr/bin/xsel "$@"
|
||||
Reference in New Issue
Block a user