From e3b19e01319bdda7f3f5799f53e28dade0bd1265 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 22 Apr 2022 18:14:25 +0200 Subject: [PATCH] Added hyprctl version --- CMakeLists.txt | 19 +++++++++++++++++++ hyprctl/main.cpp | 2 ++ src/debug/HyprCtl.cpp | 18 ++++++++++++++++++ src/defines.hpp | 10 +++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7305aa8..34cd48c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,22 @@ set(CMAKE_MESSAGE_LOG_LEVEL "STATUS") message(STATUS "Configuring Hyprland!") +# Get git info +# hash and branch +execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) + +execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) +# +# + include_directories(.) add_compile_options(-std=c++20 -DWLR_USE_UNSTABLE ) add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-narrowing) @@ -36,6 +52,9 @@ ELSE() message(STATUS "Configuring Hyprland in Release with CMake!") ENDIF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) +target_compile_definitions(Hyprland PRIVATE "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") +target_compile_definitions(Hyprland PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"") + target_link_libraries(Hyprland rt) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 7fe745da..6d0b2fc9 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -24,6 +24,7 @@ usage: hyprctl [command] [(opt)args] layers dispatch keyword + version )#"; void request(std::string arg) { @@ -134,6 +135,7 @@ int main(int argc, char** argv) { else if (!strcmp(argv[1], "workspaces")) request("workspaces"); else if (!strcmp(argv[1], "activewindow")) request("activewindow"); else if (!strcmp(argv[1], "layers")) request("layers"); + else if (!strcmp(argv[1], "version")) request("version"); else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv); else if (!strcmp(argv[1], "keyword")) keywordRequest(argc, argv); else { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 123f3ceb..cb48b4d7 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -71,6 +71,22 @@ std::string layersRequest() { return result; } +std::string versionRequest() { + std::string result = "Hyprland, built from branch " + std::string(GIT_BRANCH) + " at commit " + GIT_COMMIT_HASH + ", flags: (if any)\n"; + +#ifdef LEGACY_RENDERER + result += "legacyrenderer\n"; +#endif +#ifndef NDEBUG + result += "debug\n"; +#endif +#ifdef NO_XWAYLAND + result += "no xwayland\n"; +#endif + + return result; +} + std::string dispatchRequest(std::string in) { // get rid of the dispatch keyword in = in.substr(in.find_first_of(' ') + 1); @@ -131,6 +147,8 @@ void HyprCtl::tickHyprCtl() { reply = activeWindowRequest(); else if (request == "layers") reply = layersRequest(); + else if (request == "version") + reply = versionRequest(); else if (request.find("dispatch") == 0) reply = dispatchRequest(request); else if (request.find("keyword") == 0) diff --git a/src/defines.hpp b/src/defines.hpp index ee3a6ccf..a54d7336 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -49,4 +49,12 @@ #define RASSERT(expr, reason, ...) #endif -#define ASSERT(expr) RASSERT(expr, "?") \ No newline at end of file +#define ASSERT(expr) RASSERT(expr, "?") + +// git stuff +#ifndef GIT_COMMIT_HASH +#define GIT_COMMIT_HASH "?" +#endif +#ifndef GIT_BRANCH +#define GIT_BRANCH "?" +#endif \ No newline at end of file