mirror of
https://github.com/hyprwm/hyprpicker.git
synced 2024-12-22 06:09:48 +01:00
added format
This commit is contained in:
parent
b3bb8ea12e
commit
fb56dc68ca
4 changed files with 63 additions and 1 deletions
|
@ -8,6 +8,10 @@ A wlroots-compatible Wayland color picker that does not suck.
|
|||
|
||||
Launch it. Click. That's it.
|
||||
|
||||
## Options
|
||||
|
||||
`--format [fmt]` to specify the output format (`hex`, `rgb`)
|
||||
|
||||
# Building
|
||||
|
||||
It's also on the AUR as `hyprpicker-git`
|
||||
|
|
|
@ -122,7 +122,30 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
|
|||
|
||||
const auto COL = g_pHyprpicker->getColorFromPixel(g_pHyprpicker->m_pLastSurface, CLICKPOS);
|
||||
|
||||
Debug::log(NONE, "Result RGBA: %i %i %i %i", COL.r, COL.g, COL.b, COL.a);
|
||||
switch (g_pHyprpicker->m_bSelectedOutputMode) {
|
||||
case OUTPUT_HEX:
|
||||
{
|
||||
auto toHex = [](int i) -> std::string {
|
||||
const char* DS = "0123456789ABCDEF";
|
||||
|
||||
std::string result = "";
|
||||
|
||||
result += DS[i / 16];
|
||||
result += DS[i % 16];
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
Debug::log(NONE, "0x%s%s%s", toHex(COL.r).c_str(), toHex(COL.g).c_str(), toHex(COL.b).c_str());
|
||||
|
||||
break;
|
||||
}
|
||||
case OUTPUT_RGB:
|
||||
{
|
||||
Debug::log(NONE, "%i %i %i", COL.r, COL.g, COL.b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_pHyprpicker->finish();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
#include "helpers/LayerSurface.hpp"
|
||||
#include "helpers/PoolBuffer.hpp"
|
||||
|
||||
enum eOutputMode {
|
||||
OUTPUT_HEX = 0,
|
||||
OUTPUT_RGB
|
||||
};
|
||||
|
||||
class CHyprpicker {
|
||||
public:
|
||||
void init();
|
||||
|
@ -17,6 +22,8 @@ public:
|
|||
zwlr_layer_shell_v1* m_pLayerShell;
|
||||
zwlr_screencopy_manager_v1* m_pSCMgr;
|
||||
|
||||
eOutputMode m_bSelectedOutputMode = OUTPUT_HEX;
|
||||
|
||||
bool m_bRunning = true;
|
||||
|
||||
std::vector<std::unique_ptr<SMonitor>> m_vMonitors;
|
||||
|
|
28
src/main.cpp
28
src/main.cpp
|
@ -4,6 +4,34 @@
|
|||
|
||||
int main(int argc, char** argv, char** envp) {
|
||||
g_pHyprpicker = std::make_unique<CHyprpicker>();
|
||||
|
||||
// parse args
|
||||
// 1 - format
|
||||
int currentlyParsing = 0;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
std::string arg = argv[i];
|
||||
|
||||
if (currentlyParsing == 0) {
|
||||
if (arg == "--format") {
|
||||
currentlyParsing = 1;
|
||||
continue;
|
||||
} else {
|
||||
Debug::log(NONE, "Unrecognized option %s", arg.c_str());
|
||||
exit(1);
|
||||
}
|
||||
} else if (currentlyParsing == 1) {
|
||||
if (arg == "hex") g_pHyprpicker->m_bSelectedOutputMode = OUTPUT_HEX;
|
||||
else if (arg == "rgb") g_pHyprpicker->m_bSelectedOutputMode = OUTPUT_RGB;
|
||||
else {
|
||||
Debug::log(NONE, "Unrecognized format %s", arg.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
currentlyParsing = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
g_pHyprpicker->init();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue