Skip to content

Commit

Permalink
Added initial working script with Makefile for easy packaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgmdev committed Jan 4, 2021
1 parent c57b4bf commit 300f947
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 1 deletion.
76 changes: 76 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.PHONY: install uninstall

all:
@echo "Nothing to compile. Use 'make [DESTDIR=dir] install' to install wl-color-picker."

install:
@if [ "$$DESTDIR" = "" ]; then \
if [ "$$(id -u)" -ne 0 ]; then \
echo "Please execute this script as root."; \
exit 1; \
fi; \
fi;

@depends="grim slurp convert zenity wl-copy"; \
for dependency in $$(echo "$$depends" | xargs) ; do \
echo "Checking for: $$dependency."; \
if ! which "$$dependency" > /dev/null 2>&1 ; then \
echo " error: Required dependency '$$dependency' is missing."; \
exit 1; \
else \
echo " '$$dependency' found!"; \
fi; \
done;

@echo

@if [ -e "$$DESTDIR/usr/bin/wl-color-picker" ]; then \
echo "Please un-install the previous version first"; \
exit 1; \
fi; \

@if [ ! -d "$$DESTDIR/usr/bin" ]; then \
mkdir -p "$$DESTDIR/usr/bin"; \
fi;

@if [ ! -d "$$DESTDIR/usr/share/applications" ]; then \
mkdir -p "$$DESTDIR/usr/share/applications"; \
fi;

@if [ ! -d "$$DESTDIR/usr/share/icons" ]; then \
mkdir -p "$$DESTDIR/usr/share/icons"; \
fi;

@if [ ! -d "$$DESTDIR/usr/share/icons/hicolor/scalable/apps" ]; then \
mkdir -p "$$DESTDIR/usr/share/icons/hicolor/scalable/apps"; \
fi;

@echo 'Copying wl-color-picker'
@echo

cp wl-color-picker.sh "$$DESTDIR/usr/bin/wl-color-picker"
cp wl-color-picker.png "$$DESTDIR/usr/share/icons/"
cp wl-color-picker.svg "$$DESTDIR/usr/share/icons/hicolor/scalable/apps/"
cp wl-color-picker.desktop "$$DESTDIR/usr/share/applications/"

@echo
@echo 'Done!'

@exit 0

uninstall:
@if [ "$$(id -u)" != "0" ]; then \
echo "Please execute uninstallation as root."; \
exit 1; \
fi;

@echo 'Uninstalling wl-color-picker'
@echo

rm "/usr/bin/wl-color-picker"
rm "/usr/share/icons/wl-color-picker.png"
rm "/usr/share/icons/hicolor/scalable/apps/wl-color-picker.svg"
rm "/usr/share/applications/wl-color-picker.desktop"

@echo
@echo 'Done!'
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# wl-color-picker
A wayland color picker that also works on wlroots

A script that provides a working color picker for wayland and wlroots
by leveraging [grim](https://github.com/emersion/grim) and
[slurp](https://github.com/emersion/slurp).

## Inspiration

This script is possible by the information provided on the following
sites:

* https://www.trst.co/simple-colour-picker-in-sway-wayland.html
* https://unix.stackexchange.com/questions/320070/is-there-a-colour-picker-that-works-with-wayland-or-xwayland/523805#523805

## Artwork

The icon was taken from the gcolor3 icon shipped with the
[papirus icon theme](https://github.com/PapirusDevelopmentTeam/papirus-icon-theme),
so all credits go to the papirus icon designers.

## Dependencies

* __slurp__ - provides the screen location picker
* __grim__ - uses the location provided by slurp and generates a pixel
* __convert__ - uitlity from imagemagick to make the pixel a hex number
* __zenity__ - display a nice color selector dialog where the picked color can be tweaked further
* __wl-copy__ - copy the selected color to the clipboard
11 changes: 11 additions & 0 deletions wl-color-picker.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Desktop Entry]
Type=Application
Name=Color Picker for Wayland
GenericName=Color Picker
Comment=A simple wayland color picker that also works on wlroots.
Keywords=color;picker;wl-color-picker;
Categories=Graphics;2DGraphics;
Exec=wl-color-picker
Hidden=false
Terminal=false
Icon=wl-color-picker
Binary file added wl-color-picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions wl-color-picker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#
# License: MIT
#
# A script to easily pick a color on a wayland session by using:
# slurp to select the location, grim to get the pixel, convert
# to make the pixel a hex number and zenity to display a nice color
# selector dialog where the picked color can be tweaked further.
#
# The script was possible thanks to the useful information on:
# https://www.trst.co/simple-colour-picker-in-sway-wayland.html
# https://unix.stackexchange.com/questions/320070/is-there-a-colour-picker-that-works-with-wayland-or-xwayland/523805#523805
#

# Get color position
position=$(slurp -b 00000000 -p)

# Sleep at least for a second to prevet issues with grim always
# returning improper color.
sleep 1

# Store the hex color value
color=$(grim -g "$position" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:- | tail -n 1 | cut -d ' ' -f 4)

# Display a color picker and store the returned rgb color
rgb_color=$(zenity --color-selection --title="Copy color to Clipboard" --color="${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

# Copy user selection to clipboard
echo $hex_color | wl-copy
fi
14 changes: 14 additions & 0 deletions wl-color-picker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 300f947

Please sign in to comment.