Add autocopy option (#13)

* Add autocopy option

* Specify autocopy requirements
This commit is contained in:
Maksim 2022-11-19 16:53:05 +02:00 committed by GitHub
parent 06be1c9348
commit a82b20e979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 0 deletions

View File

@ -14,6 +14,8 @@ Launch it. Click. That's it.
`--no-fancy` disables the "fancy" (aka. colored) outputting
`--autocopy` automatically copies the output to the clipboard (requires [wl-clipboard](https://github.com/bugaevc/wl-clipboard))
# Building
## Arch

View File

@ -0,0 +1,19 @@
#include "Clipboard.hpp"
#include "../includes.hpp"
void Clipboard::copy(const char* fmt, ...) {
char buf[CLIPBOARDMESSAGESIZE] = "";
char* outputStr;
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof buf, fmt, args);
va_end(args);
outputStr = strdup(buf);
execlp("wl-copy", "wl-copy", outputStr, NULL);
free(outputStr);
}

View File

@ -0,0 +1,7 @@
#pragma once
#define CLIPBOARDMESSAGESIZE 24
namespace Clipboard {
void copy(const char* fmt, ...);
};

View File

@ -5,6 +5,7 @@
#include "includes.hpp"
#include "helpers/Monitor.hpp"
#include "helpers/Color.hpp"
#include "clipboard/Clipboard.hpp"
// git stuff
#ifndef GIT_COMMIT_HASH

View File

@ -147,6 +147,8 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
else
Debug::log(NONE, "#%s%s%s", toHex(COL.r).c_str(), toHex(COL.g).c_str(), toHex(COL.b).c_str());
if (g_pHyprpicker->m_bAutoCopy)
Clipboard::copy("#%s%s%s", toHex(COL.r).c_str(), toHex(COL.g).c_str(), toHex(COL.b).c_str());
break;
}
case OUTPUT_RGB:
@ -155,6 +157,9 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
Debug::log(NONE, "\033[38;2;%i;%i;%im %i %i %i\033[0m", COL.r, COL.g, COL.b, COL.r, COL.g, COL.b);
else
Debug::log(NONE, "%i %i %i", COL.r, COL.g, COL.b);
if (g_pHyprpicker->m_bAutoCopy)
Clipboard::copy("%i %i %i", COL.r, COL.g, COL.b);
break;
}
}

View File

@ -26,6 +26,8 @@ public:
bool m_bFancyOutput = true;
bool m_bAutoCopy = false;
bool m_bRunning = true;
std::vector<std::unique_ptr<SMonitor>> m_vMonitors;

View File

@ -17,10 +17,13 @@ int main(int argc, char** argv, char** envp) {
continue;
} else if (arg == "--no-fancy") {
g_pHyprpicker->m_bFancyOutput = false;
} else if (arg == "--autocopy") {
g_pHyprpicker->m_bAutoCopy = true;
} else {
std::cout << "Hyprpicker usage: hyprpicker [arg [...]].\n\nArguments:\n" <<
" --format [fmt] | Specifies the output format (hex, rgb)\n" <<
" --no-fancy | Disables the \"fancy\" (aka. colored) outputting\n" <<
" --autocopy | Automatically copies the output to the clipboard (requires wl-clipboard)\n" <<
" --help | Show this help message\n";
exit(1);
}