diff options
author | Vaxry <[email protected]> | 2023-10-14 18:47:43 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2023-10-14 18:47:43 +0100 |
commit | d5a572bd39e5b29af8a17af792a43b409ae1cb06 (patch) | |
tree | 04f711b5e5f8639e20a07c78593ae81ca9815425 /src/plugins | |
parent | 424c9a7e704590db5c823557e5e388e366f7b1cd (diff) | |
download | Hyprland-d5a572bd39e5b29af8a17af792a43b409ae1cb06.tar.gz Hyprland-d5a572bd39e5b29af8a17af792a43b409ae1cb06.zip |
Plugin API: Add version query (#3545)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/PluginAPI.cpp | 11 | ||||
-rw-r--r-- | src/plugins/PluginAPI.hpp | 26 |
2 files changed, 35 insertions, 2 deletions
diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index f79af312..ae289396 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -277,7 +277,7 @@ APICALL std::vector<SFunctionMatch> HyprlandAPI::findFunctionsByName(HANDLE hand const auto FPATH = std::filesystem::canonical(exe); #elif defined(__OpenBSD__) // Neither KERN_PROC_PATHNAME nor /proc are supported - const auto FPATH = std::filesystem::canonical("/usr/local/bin/Hyprland"); + const auto FPATH = std::filesystem::canonical("/usr/local/bin/Hyprland"); #else const auto FPATH = std::filesystem::canonical("/proc/self/exe"); #endif @@ -338,3 +338,12 @@ APICALL std::vector<SFunctionMatch> HyprlandAPI::findFunctionsByName(HANDLE hand return matches; } + +APICALL SVersionInfo HyprlandAPI::getHyprlandVersion(HANDLE handle) { + auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); + + if (!PLUGIN) + return {}; + + return {GIT_COMMIT_HASH, GIT_TAG, GIT_DIRTY != std::string(""), GIT_BRANCH, GIT_COMMIT_MESSAGE}; +}
\ No newline at end of file diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index c14c820a..2809c3f6 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -42,6 +42,14 @@ struct SFunctionMatch { std::string demangled; }; +struct SVersionInfo { + std::string hash; + std::string tag; + bool dirty = false; + std::string branch; + std::string message; +}; + #define APICALL extern "C" #define EXPORT __attribute__((visibility("default"))) #define REQUIRED @@ -250,4 +258,20 @@ namespace HyprlandAPI { Empty means either none found or handle was invalid */ APICALL std::vector<SFunctionMatch> findFunctionsByName(HANDLE handle, const std::string& name); -};
\ No newline at end of file + + /* + Returns the hyprland version data. It's highly advised to not run plugins compiled + for a different hash. + */ + APICALL SVersionInfo getHyprlandVersion(HANDLE handle); +}; + +/* + Get the hash this plugin/server was compiled with. + + This function will end up in both hyprland and any/all plugins, + and can be found by a simple dlsym() +*/ +APICALL inline EXPORT const char* __hyprland_api_get_hash() { + return GIT_COMMIT_HASH; +} |