mirror of
https://github.com/hyprwm/hyprpicker.git
synced 2024-12-22 06:09:48 +01:00
Add autocopy option (#13)
* Add autocopy option * Specify autocopy requirements
This commit is contained in:
parent
06be1c9348
commit
a82b20e979
7 changed files with 39 additions and 0 deletions
|
@ -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
|
||||
|
|
19
src/clipboard/Clipboard.cpp
Normal file
19
src/clipboard/Clipboard.cpp
Normal 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);
|
||||
}
|
7
src/clipboard/Clipboard.hpp
Normal file
7
src/clipboard/Clipboard.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#define CLIPBOARDMESSAGESIZE 24
|
||||
|
||||
namespace Clipboard {
|
||||
void copy(const char* fmt, ...);
|
||||
};
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue