Add hyprland version compatibility check

This commit is contained in:
outfoxxed 2023-12-05 00:48:26 -08:00
parent 35e66dd10a
commit 92244e7285
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
3 changed files with 22 additions and 1 deletions

View file

@ -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})

View file

@ -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

View file

@ -1,7 +1,9 @@
#include <optional>
#include <stdexcept>
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/version.h>
#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) \