From 046ad79d11dbccc90ade48d63aaa340655d999fb Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 9 Apr 2023 13:48:20 +0100 Subject: GlobalShortcuts protocol impl (#1886) Implements the `hyprland-global-shortcuts-v1` protocol --------- Co-authored-by: Mihai Fufezan --- src/debug/HyprCtl.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index d4b765e2..bef7c68e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -536,6 +536,29 @@ std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) { return ret; } +std::string globalShortcutsRequest(HyprCtl::eHyprCtlOutputFormat format) { + std::string ret = ""; + const auto SHORTCUTS = g_pProtocolManager->m_pGlobalShortcutsProtocolManager->getAllShortcuts(); + if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL) { + for (auto& sh : SHORTCUTS) + ret += getFormat("%s:%s -> %s\n", sh.appid.c_str(), sh.id.c_str(), sh.description.c_str()); + } else { + ret += "["; + for (auto& sh : SHORTCUTS) { + ret += getFormat(R"#( +{ + "name": "%s", + "description": "%s" +},)#", + escapeJSONStrings(sh.appid + ":" + sh.id).c_str(), escapeJSONStrings(sh.description).c_str()); + } + ret.pop_back(); + ret += "]\n"; + } + + return ret; +} + std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) { std::string ret = ""; if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL) { @@ -1228,6 +1251,8 @@ std::string getReply(std::string request) { return cursorPosRequest(format); else if (request == "binds") return bindsRequest(format); + else if (request == "globalshortcuts") + return globalShortcutsRequest(format); else if (request == "animations") return animationsRequest(format); else if (request.find("plugin") == 0) -- cgit v1.2.3