Skip to content

Commit

Permalink
Add hyprland version compatibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
outfoxxed committed Dec 5, 2023
1 parent 35e66dd commit 92244e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
2 changes: 1 addition & 1 deletion compile_commands_bear.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) \
Expand Down

0 comments on commit 92244e7

Please sign in to comment.