update colorpicker to use kdialog

This commit is contained in:
Penelope Gwen 2026-06-30 12:11:35 -07:00 committed by Penelope Gwen
parent c256e098ec
commit 146a79063a

View file

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