43

I tried gpick, gcolor2, gcolor3, pick, pychrom and none of them seem to work with Wayland. I am running Arch Linux 64-bit with GNOME 3.22.1 through XWayland (default since 3.22.x). I don't want to change into an X session just to pick a colour.

Anyone had success with this?

4
  • None that I know of... afaik the dbus api that should allow apps to access those resources is not implemented yet. Oct 31, 2016 at 12:50
  • Any update on this?
    – tanenbring
    Nov 16, 2017 at 17:51
  • i also stuck on X11 with gcolor2. seems that gcolor3 is on the way but i dont expect it too fast Dec 5, 2017 at 8:55
  • 2
    I don't think this is currently possible with wayland, because wayland applications don't have access to the surfaces of other apps.
    – Thayne
    Feb 10, 2018 at 23:48

9 Answers 9

17

grim is a screenshot tool for Wayland that is able to do that:

grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:-

After selecting a point on the screen with the mouse, it produces output like this:

# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (40,85,119)  #285577  srgb(40,85,119)
7
  • 1
    Note that grim uses the wlr-screencopy protocol and slurp uses wlr-layer-shell. These should be supported by wlroots-based compositors, but probably not any others.
    – tobib
    Nov 26, 2019 at 12:07
  • 5
    I've added the following line to my Sway config. It lets me select a pixel on the screen and puts its color as a hex value on the system 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 Apr 5, 2020 at 12:12
  • I get slurp: invalid option -- 'p'. The man page for slurp doesn't list p.
    – Erhannis
    Jun 4, 2020 at 20:13
  • 2
    slurp doesn't work on my wayland with gnome in terminal: compositor doesn't support zwlr_layer_shell_v1 Mar 31, 2021 at 14:08
  • 1
    @MatthiasBraun, please try bindsym $mod+Shift+p exec slurp -p | grim -g - - | convert - txt: | awk 'NR==2 { print $3 }' | wl-copy from here
    – DK Bose
    Apr 6, 2022 at 12:05
10

For gnome/wayalnd you can use the dbus api:

gdbus call --session --dest org.gnome.Shell.Screenshot --object-path /org/gnome/Shell/Screenshot --method org.gnome.Shell.Screenshot.PickColor
2
  • 1
    This worked for me on gnome Wayland. But you have to multiply the output numbers by 255 if you need RGB.
    – Parsa
    Aug 24, 2022 at 17:44
  • 1
    This color picker worked for me on Ubuntu 22.04. Finally something that works for Ubuntu. I wrote a simple bash script to convert gdbus float output to RGB and HEX in a nicer output (BSD-3 license, enjoy): gist.github.com/byrro/7a74e54f63667bbb066fa309208a6cba Nov 3, 2022 at 20:44
3

No, security requires only a trusted app to be permitted access to the output of other apps.

"In GNOME, you can use Screenshot tool (available in overview or as Printscreen hotkey or as gnome-screenshot command) to capture a screenshot of the full desktop or a particular window."

Then use gimp/krita/etc to get the color off the image.

https://fedoraproject.org/wiki/How_to_debug_Wayland_problems#Screen_capture_is_not_available_with_usual_apps

3
  • KolourPaint serves that purpose too. Thank you! May 14, 2019 at 18:57
  • @AntonioViniciusMenezesMedei KolourPaint captures a black screenshot on my Debian 10 (Buster) running Wayland. I believe there has been some changes in the new Wayland version as I wasnt facing issues of black screen in Debian 9 (I was using a simple but cool app Picker previously, which is no longer working).
    – Sufian
    Aug 4, 2019 at 14:56
  • Gnome can publish a color picker(trusted) like screenshot tool
    – shantanu
    Apr 23, 2020 at 8:14
3

There is azote wallpaper manager for wayland and it has a built in color picker https://github.com/nwg-piotr/azote

Also you can use:

grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:-

or if you are using sway wm:

swaynag -t warning -m "$(grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:-)"
3

Expanding upon @sigmasd's answer, I have this BASH script called colorpicker that has a GUI picker and it works for Wayland / Ubuntu 22.04:

#!/bin/bash

# Get the gdbus output
output=$(gdbus call --session --dest org.gnome.Shell.Screenshot --object-path /org/gnome/Shell/Screenshot --method org.gnome.Shell.Screenshot.PickColor)
colors=($(echo $output | command grep -o "[0-9\.]*"))

# Convert to 255-based RGB format
for ((i = 0; i < ${#colors[@]}; i++)); do
    colors[$i]=$(printf '%.0f' $(echo "${colors[$i]} * 255" | bc))
done

echo   "RGB: ${colors[0]} ${colors[1]} ${colors[2]}"
printf "HEX: #%02x%02x%02x\n" "${colors[0]}" "${colors[1]}" "${colors[2]}"

Example usage:

./colorpicker
RGB: 255 255 255
HEX: #ffffff
1
  • 1
    Love this! For those who haven't tried this out, it produces a cursor featuring a color magnifier. Once you click with the cursor, the output is printed in the terminal. Nov 26, 2022 at 22:35
2

I'm using wayfire on ArchLinuxARM and was also looking into this.

Based on the solutions provided here I put up a script to make it easy. The script uses grim, slurp and convert as suggested above and also uses zenity to generate a nice color selector dialog to tweak the selected color if necessary. Once the "Select" button of the dialog is clicked it uses wl-copy to store it on the clipboard. The provided Makefile installs .desktop and icon files for easy application menu access. Hope this is of any use:

Repository: https://github.com/jgmdev/wl-color-picker

AUR: https://aur.archlinux.org/packages/wl-color-picker/

1
1

I just recently stumbled over this: https://github.com/hyprwm/hyprpicker

This is a wl-roots based color picker and therefore a native wayland application. Once started it freezes your screen and gives you a cursor with a kind of magnification area to select a pixel. When clicked the screen returns to normal and the color is show in the terminal (an auto-copy option, which writes the value to the clipboard is available too, but this could be done via piping into wl-clipboard too and there currently is a bug in this feature which stops hyprpicker to work after a number of runs).

This is quite nice and seems to work reasonably well, but I personally prefer the grim/slurp/convert solution mentioned here since I have those tools installed already.

0

Using yad dialog:

yad --color
2
  • Welcome to the site, and thank you for your contribution. Can you confirm/point to the relevant documentation that states the compatibility with (X)Wayland, as required by the OP?
    – AdminBee
    Jul 12, 2021 at 11:30
  • This just brings up a colour dialog. I think the OP is looking for an app where you can click somewhere on the screen and find out what colour that pixel is.
    – mhwombat
    Nov 19, 2021 at 20:38
0

There is a Gnome Shell Extension Color Picker that works fine for me:

https://extensions.gnome.org/extension/3396/color-picker/

It is also really easy to install.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .