diff --git a/README.md b/README.md index 9a24f4c..f3ecfb2 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/events/Events.cpp b/src/events/Events.cpp index 446ec35..55c7ab0 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -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(); } diff --git a/src/hyprpicker.hpp b/src/hyprpicker.hpp index b652a3f..7f15af4 100644 --- a/src/hyprpicker.hpp +++ b/src/hyprpicker.hpp @@ -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> m_vMonitors; diff --git a/src/main.cpp b/src/main.cpp index 8a9b501..7e03361 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,34 @@ int main(int argc, char** argv, char** envp) { g_pHyprpicker = std::make_unique(); + + // 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;