├── LICENSE ├── Makefile ├── README.md ├── wl-color-picker.desktop ├── wl-color-picker.png ├── wl-color-picker.sh └── wl-color-picker.svg /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jefferson González 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: install uninstall 2 | 3 | # Set default DESTDIR to empty 4 | DESTDIR ?= 5 | 6 | # Set default PREFIX 7 | PREFIX ?= /usr 8 | 9 | all: 10 | @echo "Nothing to compile. Use 'make [DESTDIR=dir] [PREFIX=dir] install' to install wl-color-picker." 11 | 12 | install: 13 | @if mkdir -p "$(DESTDIR)$(PREFIX)" && [ -w "$(DESTDIR)$(PREFIX)" ]; then \ 14 | echo "Created installation directories"; \ 15 | else \ 16 | echo "Error: You do not have write permissions for '$(DESTDIR)$(PREFIX)'."; \ 17 | exit 1; \ 18 | fi; 19 | 20 | @depends="grim slurp convert zenity wl-copy notify-send"; \ 21 | for dependency in $$(echo "$$depends" | xargs) ; do \ 22 | echo "Checking for: $$dependency."; \ 23 | if ! which "$$dependency" > /dev/null 2>&1 ; then \ 24 | echo " error: Required dependency '$$dependency' is missing."; \ 25 | exit 1; \ 26 | else \ 27 | echo " '$$dependency' found!"; \ 28 | fi; \ 29 | done; 30 | 31 | @echo 32 | 33 | @if [ -e "$(DESTDIR)$(PREFIX)/bin/wl-color-picker" ]; then \ 34 | echo "Please un-install the previous version first"; \ 35 | exit 1; \ 36 | fi; \ 37 | 38 | @if [ ! -d "$(DESTDIR)$(PREFIX)/bin" ]; then \ 39 | mkdir -p "$(DESTDIR)$(PREFIX)/bin"; \ 40 | fi; 41 | 42 | @if [ ! -d "$(DESTDIR)$(PREFIX)/share/applications" ]; then \ 43 | mkdir -p "$(DESTDIR)$(PREFIX)/share/applications"; \ 44 | fi; 45 | 46 | @if [ ! -d "$(DESTDIR)$(PREFIX)/share/icons" ]; then \ 47 | mkdir -p "$(DESTDIR)$(PREFIX)/share/icons"; \ 48 | fi; 49 | 50 | @if [ ! -d "$(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps" ]; then \ 51 | mkdir -p "$(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps"; \ 52 | fi; 53 | 54 | @echo 'Copying wl-color-picker' 55 | @echo 56 | 57 | cp wl-color-picker.sh "$(DESTDIR)$(PREFIX)/bin/wl-color-picker" 58 | cp wl-color-picker.png "$(DESTDIR)$(PREFIX)/share/icons/" 59 | cp wl-color-picker.svg "$(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/" 60 | cp wl-color-picker.desktop "$(DESTDIR)$(PREFIX)/share/applications/" 61 | 62 | @echo 63 | @echo 'Done!' 64 | 65 | @exit 0 66 | 67 | uninstall: 68 | @if [ ! -e "$(DESTDIR)$(PREFIX)/bin/wl-color-picker" ]; then \ 69 | echo "wl-color-picker not found, nothing to remove..."; \ 70 | exit 1; \ 71 | elif [ -w "$(DESTDIR)$(PREFIX)/bin/wl-color-picker" ]; then \ 72 | echo "Install at '$(DESTDIR)$(PREFIX)' is deletable..."; \ 73 | else \ 74 | echo "Install at '$(DESTDIR)$(PREFIX)' is not deletable..."; \ 75 | echo "Please execute uninstallation as root."; \ 76 | exit 1; \ 77 | fi; 78 | 79 | @echo 'Uninstalling wl-color-picker' 80 | @echo 81 | 82 | rm "$(DESTDIR)$(PREFIX)/bin/wl-color-picker" 83 | rm "$(DESTDIR)$(PREFIX)/share/icons/wl-color-picker.png" 84 | rm "$(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/wl-color-picker.svg" 85 | rm "$(DESTDIR)$(PREFIX)/share/applications/wl-color-picker.desktop" 86 | 87 | @echo 88 | @echo 'Done!' 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wl-color-picker 2 | 3 | A script that provides a working color picker for wayland and wlroots 4 | by leveraging [grim](https://github.com/emersion/grim) and 5 | [slurp](https://github.com/emersion/slurp). 6 | 7 | ## Usage 8 | - Command `wl-color-picker` - Select position on screen and open color picker window 9 | - Command `wl-color-picker clipboard` - Select position on screen without opening color picker window, just copy selected color to clipboard 10 | 11 | 12 | ## Inspiration 13 | 14 | This script is possible by the information provided on the following 15 | sites: 16 | 17 | * https://www.trst.co/simple-colour-picker-in-sway-wayland.html 18 | * https://unix.stackexchange.com/questions/320070/is-there-a-colour-picker-that-works-with-wayland-or-xwayland/523805#523805 19 | 20 | ## Artwork 21 | 22 | The icon was taken from the gcolor3 icon shipped with the 23 | [papirus icon theme](https://github.com/PapirusDevelopmentTeam/papirus-icon-theme), 24 | so all credits go to the papirus icon designers. 25 | 26 | ## Dependencies 27 | 28 | * __slurp__ - provides the screen location picker 29 | * __grim__ - uses the location provided by slurp and generates a pixel 30 | * __convert__ - uitlity from imagemagick to make the pixel a hex number (graphicsmagick is also supported) 31 | * __zenity__ - display a nice color selector dialog where the picked color can be tweaked further 32 | * __wl-copy__ - copy the selected color to the clipboard 33 | 34 | ## Packages 35 | 36 | ArchLinux - install from [AUR](https://aur.archlinux.org/packages/wl-color-picker) 37 | ```sh 38 | yay -S wl-color-picker 39 | ``` 40 | -------------------------------------------------------------------------------- /wl-color-picker.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Name=Color Picker for Wayland 4 | GenericName=Color Picker 5 | Comment=A simple wayland color picker that also works on wlroots. 6 | Keywords=color;picker;wl-color-picker; 7 | Categories=Graphics;2DGraphics; 8 | Exec=wl-color-picker 9 | Hidden=false 10 | Terminal=false 11 | Icon=wl-color-picker 12 | -------------------------------------------------------------------------------- /wl-color-picker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jgmdev/wl-color-picker/06fbf3bccbadd5ed9bde5f86740db0516c160034/wl-color-picker.png -------------------------------------------------------------------------------- /wl-color-picker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # License: MIT 4 | # 5 | # A script to easily pick a color on a wayland session by using: 6 | # slurp to select the location, grim to get the pixel, convert 7 | # to make the pixel a hex number and zenity to display a nice color 8 | # selector dialog where the picked color can be tweaked further. 9 | # 10 | # The script was possible thanks to the useful information on: 11 | # https://www.trst.co/simple-colour-picker-in-sway-wayland.html 12 | # https://unix.stackexchange.com/questions/320070/is-there-a-colour-picker-that-works-with-wayland-or-xwayland/523805#523805 13 | # 14 | 15 | showhelp() { 16 | echo "A basic wlroots compatible color picker script." 17 | echo "" 18 | echo "Usage:" 19 | echo " wl-color-picker [command] [options]" 20 | echo "" 21 | echo "Commands:" 22 | echo " clipboard Copy color to clipboard without dialog" 23 | echo " --no-notify Don't show a system notification of copied color" 24 | } 25 | 26 | CLIPBOARD=0 27 | NO_NOTIFY=0 28 | 29 | while [ "$1" ]; do 30 | case $1 in 31 | '-h' | '--help' | 'help' | '?' ) 32 | showhelp 33 | exit 34 | ;; 35 | 'clipboard' ) 36 | CLIPBOARD=1 37 | ;; 38 | '--no-notify' ) 39 | NO_NOTIFY=1 40 | ;; 41 | esac 42 | 43 | shift 44 | done 45 | 46 | # Check if running under wayland. 47 | if [ "$WAYLAND_DISPLAY" = "" ]; then 48 | zenity --error --width 400 \ 49 | --title "No wayland session found." \ 50 | --text "This color picker must be run under a valid wayland session." 51 | 52 | exit 1 53 | fi 54 | 55 | # Get color position 56 | position=$(slurp -b 00000000 -p) 57 | 58 | # Sleep at least for a second to prevet issues with grim always 59 | # returning improper color. 60 | sleep 1 61 | 62 | # Store the hex color value using graphicsmagick or imagemagick. 63 | if command -v /usr/bin/gm &> /dev/null; then 64 | color=$(grim -g "$position" -t png - \ 65 | | /usr/bin/gm convert - -format '%[pixel:p{0,0}]' txt:- \ 66 | | tail -n 1 \ 67 | | rev \ 68 | | cut -d ' ' -f 1 \ 69 | | rev 70 | ) 71 | else 72 | color=$(grim -g "$position" -t png - \ 73 | | convert - -format '%[pixel:p{0,0}]' txt:- \ 74 | | tail -n 1 \ 75 | | cut -d ' ' -f 4 76 | ) 77 | fi 78 | 79 | if [ $CLIPBOARD -eq 1 ]; then 80 | echo $color | wl-copy -n 81 | if [ $NO_NOTIFY -ne 1 ]; then 82 | notify-send "Color copied to clipboard." $color 83 | fi 84 | else 85 | # Display a color picker and store the returned rgb color 86 | rgb_color=$(zenity --color-selection \ 87 | --title="Copy color to Clipboard" \ 88 | --color="${color}" 89 | ) 90 | 91 | # Execute if user didn't click cancel 92 | if [ "$rgb_color" != "" ]; then 93 | # Convert rgb color to hex 94 | hex_color="#" 95 | for value in $(echo "${rgb_color}" | grep -E -o -m1 '[0-9]+'); do 96 | hex_color="$hex_color$(printf "%.2x" $value)" 97 | done 98 | 99 | # Copy user selection to clipboard 100 | echo $hex_color | wl-copy -n 101 | fi 102 | fi 103 | -------------------------------------------------------------------------------- /wl-color-picker.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------