From 92244e72858a9a0df28db20fb80b94a36f0a9b92 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 5 Dec 2023 00:48:26 -0800 Subject: [PATCH] Add hyprland version compatibility check --- CMakeLists.txt | 6 ++++++ compile_commands_bear.sh | 2 +- src/main.cpp | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d886f50..e4e83ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,12 @@ add_library(hy3 SHARED src/SelectionHook.cpp ) +option(HY3_NO_VERSION_CHECK "Disable hyprland version check" FALSE) + +if (HY3_NO_VERSION_CHECK) + target_compile_definitions(hy3 PRIVATE -DHY3_NO_VERSION_CHECK=TRUE) +endif() + target_include_directories(hy3 PRIVATE ${DEPS_INCLUDE_DIRS}) install(TARGETS hy3 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/compile_commands_bear.sh b/compile_commands_bear.sh index 8803482..83b4946 100755 --- a/compile_commands_bear.sh +++ b/compile_commands_bear.sh @@ -1,4 +1,4 @@ rm -rf build -cmake -DCMAKE_BUILD_TYPE=Debug -B build bear -- cmake --build build +cmake -DCMAKE_BUILD_TYPE=Debug -DHY3_NO_VERSION_CHECK=TRUE -B build sed -i 's/-std=gnu++23/-std=gnu++2b/g' compile_commands.json diff --git a/src/main.cpp b/src/main.cpp index f4e9c9e..b0820f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include +#include #include #include +#include #include "SelectionHook.hpp" #include "dispatchers.hpp" @@ -12,6 +14,19 @@ APICALL EXPORT std::string PLUGIN_API_VERSION() { return HYPRLAND_API_VERSION; } APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { PHANDLE = handle; +#ifndef HY3_NO_VERSION_CHECK + if (GIT_COMMIT_HASH != std::string(__hyprland_api_get_hash())) { + HyprlandAPI::addNotification( + PHANDLE, + "[hy3] Hy3 was compiled for a different version of hyprland; refusing to start.", + CColor {1.0, 0.2, 0.2, 1.0}, + 10000 + ); + + throw std::runtime_error("[hy3] target hyprland version mismatch"); + } +#endif + selection_hook::init(); #define CONF(NAME, TYPE, VALUE) \