Giter Site home page Giter Site logo

soft / xcolor Goto Github PK

View Code? Open in Web Editor NEW
432.0 6.0 21.0 607 KB

Lightweight color picker for X11

Home Page: https://soft.github.io/xcolor/

License: MIT License

Rust 96.05% Makefile 3.48% Nix 0.47%
color-picker x11 linux xcb lightweight kiss-principle color design cli rust

xcolor's People

Contributors

acheronfail avatar freddii avatar kianmeng avatar ltratt avatar moni-dz avatar orhun avatar soft avatar wfxr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xcolor's Issues

Large data transfer support

Currently, the save to selection functionality does not support very large data transfers. This is likely not too critical for xcolor's use case as color representations tend to be small but could in theory be a problem when using a custom template.

Locks up display on Xfce4/xfwm4

I'm using Xfce4/xfwm4 on Arch.
When I use xlock the display "freezes", however the mouse pointer itself is moveable. "Freezing" in this case means: Nothing is clickable and not even xeyes follows the mouse pointer.
After switching to a tty and right back to my X session, everything is working again like it should and I xcolor prints the hex code of the selected pixel to stdout.

What I also noticed: When I'm zoomed in (alt+mousewheel) and then use xcolor, it doesn't freeze. However, the circular zoomed-in preview of xcolor is not really displaying what is around the cursor in that case.

Edit: The preview seems to be the problem
xcolor -P 127 (and lower number) works without problem
xcolor -P 128 (and higher numbers; the default without -P has a higher number) let the problem appear

Integration tests

It would be really cool to better test xcolor in the CI. Currently, we only have unit tests for the parsing code but do not test X11 related code.

We could use Xorg with dummy output to test various features, check that colors can be selected and they are the correct colors and so on.

Sometimes xcolor does not respond to mouse clicks

If I left-click while moving the mouse (especially when moving fast), sometimes xcolor does not catch the left-click, and instead keep running as if there were no clicks.

My preliminary debugging shows that, in wait_for_location function, there are indeed no left-click event received when this happens. Maybe the event is somehow lost when there are too many events (the mouse moving) to handle.

Very high cpu usage when moving the cursor

Hi,

I see my cpu constantly staying at ~50% and spiking to ~60% on occasion when moving the cursor around with xcolor. Don't believe such high cpu usage should be necessary for whats being done.

Different color function outputs

Hello and thank you all for this amazing tool.

I was wondering if there's an interest in adding different color function outputs (particularly for HSL, for now). I was thinking of making a PR, but I wasn't certain if that fits within the vision of its maintainers.

In terms of implementation, I was thinking of performing a conversion from RGB, right before printing the output. However, and I'm not familiar with the problems in color conversions, conversions may be lossy (e.g. RGB to HSL). To make things worse, HSL, for example, uses decimals, i.e floating point math, which is

  1. difficult for accuracy
  2. adds complexity to testing

What do you all think? Is it worth pursuing?

[Request] Right click to cancel

Just a minor request; would it be possible to add a right click to cancel xcolor? Often times I find myself using xcolor just for the (pixel perfect) zoom.

Can't build on Ubuntu 20.04.2 LTS for some reason

I've installed the 2 dependencies:

Building and running xcolor requires xcb and Xlib libraries to be present.

$ sudo apt-get install libx11-dev libx11-xcb-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libx11-dev is already the newest version (2:1.6.9-2ubuntu1.2).
libx11-xcb-dev is already the newest version (2:1.6.9-2ubuntu1.2).
0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.

And this is the error I get when I try to install xcolor:

$ cargo install xcolor                                                                                                                                                          Updating crates.io index                                                                                                                                                                        
  Installing xcolor v0.5.1                                                                        
   Compiling libc v0.2.103                                                                        
   Compiling bitflags v1.2.1                                                                                                                                                                        
   Compiling autocfg v1.0.1
   Compiling pkg-config v0.3.20
   Compiling unicode-width v0.1.9
   Compiling memchr v2.4.1
   Compiling strsim v0.8.0
   Compiling vec_map v0.8.2
   Compiling ansi_term v0.11.0
   Compiling cfg-if v1.0.0
   Compiling log v0.4.14
   Compiling version_check v0.9.3
   Compiling anyhow v1.0.44
   Compiling minimal-lexical v0.1.4
   Compiling lazy_static v1.4.0
   Compiling memoffset v0.6.4
   Compiling textwrap v0.11.0
   Compiling x11 v2.19.1
   Compiling nom v7.0.0
error: failed to run custom build command for `x11 v2.19.1`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installMZTK9K/release/build/x11-fe4f423cee939653/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=X11_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=X11_STATIC
  cargo:rerun-if-env-changed=X11_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Command { command: "\"pkg-config\" \"--libs\" \"--cflags\" \"x11\" \"x11 >= 1.4.99.1\"", cause: Os { code: 2, kind: NotFound, message: "No such file or directory" } }', /home/vagrant/.cargo/registry/src/github.com-1ecc6299db9ec823/x11-2.19.1/build.rs:40:14
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `xcolor v0.5.1`, intermediate artifacts can be found at `/tmp/cargo-installMZTK9K`

Caused by:
  build failed

Any ideas?

Update aur package to 0.5.0

Hello!

I update the PKGBULD locally to get the latest release on aur and also fix the comments that mention the missing license file in /usr/share/licenses/%{pkgname}. If you want to apply the patch here it is:

diff --git a/.SRCINFO b/.SRCINFO
index 1d10a8c..fbe43c7 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,6 +1,6 @@
 pkgbase = xcolor
 	pkgdesc = Lightweight color picker for X11
-	pkgver = 0.4.0
+	pkgver = 0.5.0
 	pkgrel = 1
 	url = https://github.com/Soft/xcolor
 	arch = x86_64
@@ -9,8 +9,7 @@ pkgbase = xcolor
 	makedepends = cargo
 	makedepends = python
 	depends = libxcb
-	source = https://github.com/Soft/xcolor/archive/0.4.0.tar.gz
-	md5sums = 614f6c07a1c6ee6da065e7d1d68fd861
+	source = https://github.com/Soft/xcolor/archive/0.5.0.tar.gz
+	sha256sums = 23cdfd4e87c6f38000e36704bc83e157d6476967892b0e26eee55ed743076400
 
 pkgname = xcolor
-
diff --git a/PKGBUILD b/PKGBUILD
index f54bbdf..244bc82 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,6 +1,6 @@
 # Maintainer: Samuel Laurén <samuel dot lauren at iki dot fi>
 pkgname=xcolor
-pkgver=0.4.0
+pkgver=0.5.0
 pkgrel=1
 pkgdesc="Lightweight color picker for X11"
 arch=(x86_64)
@@ -9,7 +9,7 @@ license=(MIT)
 depends=("libxcb")
 makedepends=("rust" "cargo" "python")
 source=("https://github.com/Soft/xcolor/archive/${pkgver}.tar.gz")
-md5sums=("614f6c07a1c6ee6da065e7d1d68fd861")
+sha256sums=('23cdfd4e87c6f38000e36704bc83e157d6476967892b0e26eee55ed743076400')
 
 
 build() {
@@ -21,4 +21,5 @@ package() {
 	cd "$srcdir/xcolor-${pkgver}"
 	install -D -m755 -D target/release/xcolor "$pkgdir/usr/bin/xcolor"
 	install -D -m644 -D man/xcolor.1 "$pkgdir/usr/share/man/man1/xcolor.1"
+	install -D -m644 -D LICENSE "$pkgdir/usr/share/licenses/${pkgname}/LICENSE"
 }

Color isn't printed when using a graphical tablet

When I'm using a graphical tablet (Wacom CTL-471) color isn't printed on click. With mouse it works ok.

I suppose this is because tablet's pen is almost impossible to keep still and so it continuously updates the cursor position. When I move up the pen so it no longer is seen by the tablet and the cursor stops, and then execute xdottool click 1, xcolor is succesfully prints the color.

Probably it's the same issue as #32.

Saving to selection doesn't work

I tried both -s primary and -s secondary, but xcolor doesn't seem to save anything to the selection. I'm using Ubuntu 18.04 with Xfce.

Installation fails with 'cargo install xcolor' in Debian

I am facing an error while installing it through cargo, and even when trying to build the makefile. Here is the error I am facing with cargo install xcolor -


 Updating crates.io index
  Installing xcolor v0.5.1
   Compiling libc v0.2.117
   Compiling autocfg v1.0.1
   Compiling pkg-config v0.3.24
   Compiling unicode-width v0.1.9
   Compiling cfg-if v1.0.0
   Compiling log v0.4.14
   Compiling strsim v0.8.0
   Compiling bitflags v1.3.2
   Compiling vec_map v0.8.2
   Compiling version_check v0.9.4
   Compiling memchr v2.4.1
   Compiling ansi_term v0.12.1
   Compiling anyhow v1.0.53
   Compiling minimal-lexical v0.2.1
   Compiling lazy_static v1.4.0
   Compiling textwrap v0.11.0
   Compiling nom v7.1.0
   Compiling memoffset v0.6.5
   Compiling x11 v2.19.1
error: failed to run custom build command for `x11 v2.19.1`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installBYY04K/release/build/x11-2d181bd4a8edf764/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=X11_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=X11_STATIC
  cargo:rerun-if-env-changed=X11_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=SYSROOT
  cargo:rerun-if-env-changed=X11_STATIC
  cargo:rerun-if-env-changed=X11_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rustc-link-search=native=/usr/lib/x86_64-linux-gnu
  cargo:rustc-link-lib=X11
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=X11_STATIC
  cargo:rerun-if-env-changed=X11_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=XCURSOR_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=XCURSOR_STATIC
  cargo:rerun-if-env-changed=XCURSOR_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: `"pkg-config" "--libs" "--cflags" "xcursor" "xcursor >= 1.1"` did not exit successfully: exit status: 1
  error: could not find system library 'xcursor' required by the 'x11' crate

  --- stderr
  Package xcursor was not found in the pkg-config search path.
  Perhaps you should add the directory containing `xcursor.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'xcursor' found
  Package xcursor was not found in the pkg-config search path.
  Perhaps you should add the directory containing `xcursor.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'xcursor' found
  ', /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/x11-2.19.1/build.rs:40:14
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `xcolor v0.5.1`, intermediate artifacts can be found at `/tmp/cargo-installBYY04K`

Caused by:
  build failed

Complexity of color::is_dark(self: ARGB)

for $c_1 \lt c_2$ the following holds:

$\sqrt{(x - c_1)^2} \lt \sqrt{(x - c_2)^2} \iff 2 \times x \lt c_2 + c_1$

proof:

$\sqrt{(x - c_1)^2} \lt \sqrt{(x - c_2)^2}$
$(x - c_1)^2 \lt (x - c_2)^2$
$x^2 - 2 \times c_1 \times x + c_1^2 \lt x^2 - 2 \times c_2 \times x + c_2^2$
$2 \times (c_2 - c_1) \times x \lt c_2^2 - c_1^2$
$2 \times x \lt c_2 + c_1$

using the fact that $W_r - B_r = W_g - B_g = W_b - B_b$ the same logic can
be applied to r, g, b, (B)lack and (W)hite, which gives us:

$\sqrt{(r - B_r)^2 + (g - B_g)^2 + (b - B_b)^2} \lt \sqrt{(r - W_r)^2 + (g - W_g)^2 + (b - W_b)^2} \iff$
$\iff 2 \times (r + g + b) \lt (W_r + B_r) + (W_g + B_g) + (W_b + B_b)$

with the following possible implementation for color::is_dark(self: ARGB):

pub fn is_dark(self) -> bool {
    // should cast to a larger integer type to avoid overflow
    2 * (self.r + self.g + self.b)
        < (Self::WHITE.r + Self::BLACK.r)
            + (Self::WHITE.g + Self::BLACK.g)
            + (Self::WHITE.b + Self::BLACK.b)
}

considering $W_r = W_g = W_b = 255 \land B_r = B_g = B_b = 0$ we can simplify:

pub fn is_dark(self) -> bool {
    2 * (self.r as u32 + self.g as u32 + self.b as u32) < 3 * 0xff
}

HiDPI support

It would be nice to better support HiDPi screens. This mostly means scaling the preview window appropriately.

Error when launching xcolor from the Activities overview: Could not grab pointer

When trying to launch xcolor from the GNOME's Activities overview, nothing happens. Upon inspecting the system journal, however, you can see this message:

$ journalctl -b
< ... >
May 07 18:25:38 arch xcolor.desktop[164542]: error: Could not grab pointer

System information:

  • OS: Arch Linux
  • xcolor: 0.5.1
  • Desktop: GNOME 42.1

[feature request] notice with rgb value

It would be handy to display the rgb value as a notification, when its in clipboard.

Maybe like this:

notify-send "XColor" --icon=xcolor "$(echo -e "RGB value\n#65c9ff\ncopied to clipboard.")"

Multiple output formats?

Is there a way to specify multiple output formats?
For example, I would like the tool to return both, the hex and the rgb value of the color.

I would imagine a command like xcolor -f hex,rgb, providing both values as output.
It does not seem like that functionality is there yet, would it be possible to add this?

New release?

Hi there, Thanks for this wonderful software!

I was wondering if you had plans for a new release soon? The last release was over 3 years ago and it seems that there has been some major improvements since then.

I went to install xcolor on the AUR and realized that not all of the settings documented in the README were available

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.