From 3255d91668e0d9b28540d207108f89ef827963ee Mon Sep 17 00:00:00 2001 From: Maksim <80415416+tmneth@users.noreply.github.com> Date: Sat, 19 Nov 2022 21:35:37 +0200 Subject: [PATCH] Add autocopy support for HSL, HSV, CMYK (#14) --- README.md | 2 +- src/events/Events.cpp | 6 ++++++ src/main.cpp | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 420c70a..b343795 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Launch it. Click. That's it. `-h | --help` prints a help message -`--autocopy` automatically copies the output to the clipboard (requires [wl-clipboard](https://github.com/bugaevc/wl-clipboard)) +`-a | --autocopy` automatically copies the output to the clipboard (requires [wl-clipboard](https://github.com/bugaevc/wl-clipboard)) # Building diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 63b3542..4c78c6e 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -158,6 +158,9 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint Debug::log(NONE, "\033[38;2;%i;%i;%im%g%% %g%% %g%% %g%%\033[0m", COL.r, COL.g, COL.b, c, m, y, k); else Debug::log(NONE, "%g%% %g%% %g%% %g%%", c, m, y, k); + + if (g_pHyprpicker->m_bAutoCopy) + Clipboard::copy("%g%% %g%% %g%% %g%%", c, m, y, k); break; } case OUTPUT_HEX: @@ -238,6 +241,9 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint Debug::log(NONE, "\033[38;2;%i;%i;%im%g %g%% %g%%\033[0m", COL.r, COL.g, COL.b, h, s, l_or_v); else Debug::log(NONE, "%g %g%% %g%%", h, s, l_or_v); + + if (g_pHyprpicker->m_bAutoCopy) + Clipboard::copy("%g %g%% %g%%", h, s, l_or_v); break; } } diff --git a/src/main.cpp b/src/main.cpp index 8afc7d0..4d7d689 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ static void help(void) { std::cout << "Hyprpicker usage: hyprpicker [arg [...]].\n\nArguments:\n" << " -f | --format=fmt | Specifies the output format (cmyk, hex, rgb, hsl, hsv)\n" << " -n | --no-fancy | Disables the \"fancy\" (aka. colored) outputting\n" << + " -a | --autocopy | Automatically copies the output to the clipboard (requires wl-clipboard)\n" << " -h | --help | Show this help message\n"; } @@ -18,10 +19,11 @@ int main(int argc, char** argv, char** envp) { {"format", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, {"no-fancy", no_argument, NULL, 'n'}, + {"autocopy", no_argument, NULL, 'a'}, {NULL, 0, NULL, 0 } }; - int c = getopt_long(argc, argv, ":f:hn", long_options, &option_index); + int c = getopt_long(argc, argv, ":f:hna", long_options, &option_index); if (c == -1) break; @@ -48,6 +50,9 @@ int main(int argc, char** argv, char** envp) { case 'n': g_pHyprpicker->m_bFancyOutput = false; break; + case 'a': + g_pHyprpicker->m_bAutoCopy = true; + break; default: help(); exit(1);