Is there a colour picker that works with Wayland or XWayland? has an answer for Sway:
grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:-
After clicking on a target, output like this appears in the terminal:
# ImageMagick pixel enumeration: 1,1,255,srgb
0,0: (64,69,82) #404552 srgb(64,69,82)
Code in this comment extracts the hex value and puts it in Sway’s clipboard:
bindsym $mod+Shift+p exec grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:- | tail -n 1 | cut -d ' ' -f 4 | wl-copy
(Instead of tail -n 1 | cut -d ' ' -f 4
, one could use awk 'NR==2 { print $3 }'
)