update colorpicker to use kdialog
This commit is contained in:
parent
c256e098ec
commit
146a79063a
1 changed files with 59 additions and 57 deletions
|
|
@ -13,43 +13,42 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
showhelp() {
|
showhelp() {
|
||||||
echo "A basic wlroots compatible color picker script."
|
echo "A basic wlroots compatible color picker script."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo " wl-color-picker [command] [options]"
|
echo " wl-color-picker [command] [options]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " clipboard Copy color to clipboard without dialog"
|
echo " clipboard Copy color to clipboard without dialog"
|
||||||
echo " --no-notify Don't show a system notification of copied color"
|
echo " --no-notify Don't show a system notification of copied color"
|
||||||
}
|
}
|
||||||
|
|
||||||
CLIPBOARD=0
|
CLIPBOARD=0
|
||||||
NO_NOTIFY=0
|
NO_NOTIFY=0
|
||||||
|
|
||||||
while [ "$1" ]; do
|
while [ "$1" ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
'-h' | '--help' | 'help' | '?' )
|
'-h' | '--help' | 'help' | '?')
|
||||||
showhelp
|
showhelp
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
'clipboard' )
|
'clipboard')
|
||||||
CLIPBOARD=1
|
CLIPBOARD=1
|
||||||
;;
|
;;
|
||||||
'--no-notify' )
|
'--no-notify')
|
||||||
NO_NOTIFY=1
|
NO_NOTIFY=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check if running under wayland.
|
# Check if running under wayland.
|
||||||
if [ "$WAYLAND_DISPLAY" = "" ]; then
|
if [ "$WAYLAND_DISPLAY" = "" ]; then
|
||||||
zenity --error --width 400 \
|
kdialog --error "This color picker must be run under a valid wayland session." \
|
||||||
--title "No wayland session found." \
|
--title "No wayland session found."
|
||||||
--text "This color picker must be run under a valid wayland session."
|
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get color position
|
# Get color position
|
||||||
|
|
@ -60,43 +59,46 @@ position=$(slurp -b 00000000 -p)
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
# Store the hex color value using graphicsmagick or imagemagick.
|
# Store the hex color value using graphicsmagick or imagemagick.
|
||||||
if command -v /usr/bin/gm &> /dev/null; then
|
if command -v /usr/bin/gm &>/dev/null; then
|
||||||
color=$(grim -g "$position" -t png - \
|
color=$(
|
||||||
| /usr/bin/gm convert - -format '%[pixel:p{0,0}]' txt:- \
|
grim -g "$position" -t png - |
|
||||||
| tail -n 1 \
|
/usr/bin/gm convert - -format '%[pixel:p{0,0}]' txt:- |
|
||||||
| rev \
|
tail -n 1 |
|
||||||
| cut -d ' ' -f 1 \
|
rev |
|
||||||
| rev
|
cut -d ' ' -f 1 |
|
||||||
)
|
rev
|
||||||
|
)
|
||||||
else
|
else
|
||||||
color=$(grim -g "$position" -t png - \
|
color=$(
|
||||||
| convert - -format '%[pixel:p{0,0}]' txt:- \
|
grim -g "$position" -t png - |
|
||||||
| tail -n 1 \
|
convert - -format '%[pixel:p{0,0}]' txt:- |
|
||||||
| cut -d ' ' -f 4
|
tail -n 1 |
|
||||||
)
|
cut -d ' ' -f 4
|
||||||
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $CLIPBOARD -eq 1 ]; then
|
if [ $CLIPBOARD -eq 1 ]; then
|
||||||
echo $color | wl-copy -n
|
echo $color | wl-copy -n
|
||||||
if [ $NO_NOTIFY -ne 1 ]; then
|
if [ $NO_NOTIFY -ne 1 ]; then
|
||||||
notify-send "Color copied to clipboard." $color
|
notify-send "Color copied to clipboard." $color
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Display a color picker and store the returned rgb color
|
# Display a color picker and store the returned rgb color
|
||||||
rgb_color=$(zenity --color-selection \
|
rgb_color=$(
|
||||||
--title="Copy color to Clipboard" \
|
kdialog --getcolor \
|
||||||
--color="${color}"
|
--title="Copy color to Clipboard" \
|
||||||
)
|
--default "${color}"
|
||||||
|
)
|
||||||
|
|
||||||
# Execute if user didn't click cancel
|
# Execute if user didn't click cancel
|
||||||
if [ "$rgb_color" != "" ]; then
|
if [ "$rgb_color" != "" ]; then
|
||||||
# Convert rgb color to hex
|
# Convert rgb color to hex
|
||||||
hex_color="#"
|
hex_color="#"
|
||||||
for value in $(echo "${rgb_color}" | grep -E -o -m1 '[0-9]+'); do
|
for value in $(echo "${rgb_color}" | grep -E -o -m1 '[0-9]+'); do
|
||||||
hex_color="$hex_color$(printf "%.2x" $value)"
|
hex_color="$hex_color$(printf "%.2x" $value)"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Copy user selection to clipboard
|
# Copy user selection to clipboard
|
||||||
echo $hex_color | wl-copy -n
|
echo $hex_color | wl-copy -n
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue