2023-02-27 12:32:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
Hyprland Plugin API.
|
|
|
|
|
|
|
|
|
|
Most documentation will be made with comments in this code, but more info can be also found on the wiki.
|
|
|
|
|
|
|
|
|
|
!WARNING!
|
|
|
|
|
The Hyprland API passes C++ objects over, so no ABI compatibility is guaranteed.
|
|
|
|
|
Make sure to compile your plugins with the same compiler as Hyprland, and ideally,
|
|
|
|
|
on the same machine.
|
|
|
|
|
|
|
|
|
|
See examples/examplePlugin for an example plugin
|
|
|
|
|
|
2023-04-17 23:49:42 +01:00
|
|
|
* NOTE:
|
|
|
|
|
Feel like the API is missing something you'd like to use in your plugin? Open an issue on github!
|
|
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define HYPRLAND_API_VERSION "0.1"
|
|
|
|
|
|
|
|
|
|
#include "../helpers/Color.hpp"
|
|
|
|
|
#include "HookSystem.hpp"
|
2023-03-20 15:23:25 +00:00
|
|
|
#include "../SharedDefs.hpp"
|
2024-05-05 17:16:00 +01:00
|
|
|
#include "../defines.hpp"
|
2023-10-15 11:22:51 +00:00
|
|
|
#include "../version.h"
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
#include <any>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <string>
|
2025-10-21 22:47:50 +01:00
|
|
|
#include <string_view>
|
2024-06-19 16:28:54 +02:00
|
|
|
#include <hyprlang.hpp>
|
2023-02-27 12:32:38 +00:00
|
|
|
|
2025-05-31 18:02:02 +05:00
|
|
|
using PLUGIN_DESCRIPTION_INFO = struct {
|
2023-02-27 12:32:38 +00:00
|
|
|
std::string name;
|
|
|
|
|
std::string description;
|
|
|
|
|
std::string author;
|
|
|
|
|
std::string version;
|
2025-05-31 18:02:02 +05:00
|
|
|
};
|
2023-02-27 12:32:38 +00:00
|
|
|
|
2023-03-31 18:31:11 +01:00
|
|
|
struct SFunctionMatch {
|
|
|
|
|
void* address = nullptr;
|
|
|
|
|
std::string signature;
|
|
|
|
|
std::string demangled;
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-14 18:47:43 +01:00
|
|
|
struct SVersionInfo {
|
|
|
|
|
std::string hash;
|
|
|
|
|
std::string tag;
|
|
|
|
|
bool dirty = false;
|
|
|
|
|
std::string branch;
|
|
|
|
|
std::string message;
|
2024-04-05 00:44:21 +01:00
|
|
|
std::string commits;
|
2023-10-14 18:47:43 +01:00
|
|
|
};
|
|
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
#define APICALL extern "C"
|
|
|
|
|
#define EXPORT __attribute__((visibility("default")))
|
|
|
|
|
#define REQUIRED
|
|
|
|
|
#define OPTIONAL
|
|
|
|
|
#define HANDLE void*
|
|
|
|
|
|
2025-03-17 09:52:40 -05:00
|
|
|
// C ABI is needed to prevent symbol mangling, but we don't actually need C compatibility,
|
|
|
|
|
// so we ignore this warning about return types that are potentially incompatible with C.
|
2025-03-18 18:46:28 -05:00
|
|
|
#ifdef __clang__
|
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
|
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
|
|
|
|
|
#endif
|
2025-03-17 09:52:40 -05:00
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
class IHyprLayout;
|
|
|
|
|
class IHyprWindowDecoration;
|
|
|
|
|
struct SConfigValue;
|
2024-04-27 12:43:12 +01:00
|
|
|
|
2026-02-21 21:30:39 +00:00
|
|
|
namespace Layout {
|
|
|
|
|
class ITiledAlgorithm;
|
|
|
|
|
class IFloatingAlgorithm;
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
/*
|
|
|
|
|
These methods are for the plugin to implement
|
|
|
|
|
Methods marked with REQUIRED are required.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-03-17 09:52:40 -05:00
|
|
|
/*
|
2023-02-27 12:32:38 +00:00
|
|
|
called pre-plugin init.
|
|
|
|
|
In case of a version mismatch, will eject the .so.
|
|
|
|
|
|
|
|
|
|
This function should not be modified, see the example plugin.
|
|
|
|
|
*/
|
2025-05-31 18:02:02 +05:00
|
|
|
using PPLUGIN_API_VERSION_FUNC = REQUIRED std::string (*)();
|
2023-02-27 12:32:38 +00:00
|
|
|
#define PLUGIN_API_VERSION pluginAPIVersion
|
|
|
|
|
#define PLUGIN_API_VERSION_FUNC_STR "pluginAPIVersion"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
called on plugin init. Passes a handle as the parameter, which the plugin should keep for identification later.
|
|
|
|
|
The plugin should return a PLUGIN_DESCRIPTION_INFO struct with information about itself.
|
|
|
|
|
|
|
|
|
|
Keep in mind this is executed synchronously, and as such any blocking calls to hyprland might hang. (e.g. system("hyprctl ..."))
|
|
|
|
|
*/
|
2025-05-31 18:02:02 +05:00
|
|
|
using PPLUGIN_INIT_FUNC = REQUIRED PLUGIN_DESCRIPTION_INFO (*)(HANDLE);
|
2023-02-27 12:32:38 +00:00
|
|
|
#define PLUGIN_INIT pluginInit
|
|
|
|
|
#define PLUGIN_INIT_FUNC_STR "pluginInit"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
called on plugin unload, if that was a user action. If the plugin is being unloaded by an error,
|
|
|
|
|
this will not be called.
|
|
|
|
|
|
|
|
|
|
Hooks are unloaded after exit.
|
|
|
|
|
*/
|
2025-05-31 18:02:02 +05:00
|
|
|
using PPLUGIN_EXIT_FUNC = OPTIONAL void (*)();
|
2023-02-27 12:32:38 +00:00
|
|
|
#define PLUGIN_EXIT pluginExit
|
|
|
|
|
#define PLUGIN_EXIT_FUNC_STR "pluginExit"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
End plugin methods
|
|
|
|
|
*/
|
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
2023-02-27 12:32:38 +00:00
|
|
|
namespace HyprlandAPI {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Add a config value.
|
|
|
|
|
All config values MUST be in the plugin: namespace
|
|
|
|
|
This method may only be called in "pluginInit"
|
|
|
|
|
|
|
|
|
|
After you have registered ALL of your config values, you may call `getConfigValue`
|
|
|
|
|
|
|
|
|
|
returns: true on success, false on fail
|
|
|
|
|
*/
|
2024-02-18 15:00:34 +00:00
|
|
|
APICALL bool addConfigValue(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
2023-10-29 16:59:50 +00:00
|
|
|
/*
|
|
|
|
|
Add a config keyword.
|
|
|
|
|
This method may only be called in "pluginInit"
|
|
|
|
|
|
|
|
|
|
returns: true on success, false on fail
|
|
|
|
|
*/
|
2024-02-18 15:00:34 +00:00
|
|
|
APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts);
|
2023-10-29 16:59:50 +00:00
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
/*
|
|
|
|
|
Get a config value.
|
|
|
|
|
|
2025-06-20 01:45:06 +03:00
|
|
|
Please see the <hyprlang.hpp> header or https://hypr.land/hyprlang/ for docs regarding Hyprlang types.
|
2024-02-18 15:00:34 +00:00
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
returns: a pointer to the config value struct, which is guaranteed to be valid for the life of this plugin, unless another `addConfigValue` is called afterwards.
|
|
|
|
|
nullptr on error.
|
|
|
|
|
*/
|
2024-02-18 15:00:34 +00:00
|
|
|
APICALL Hyprlang::CConfigValue* getConfigValue(HANDLE handle, const std::string& name);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Register a dynamic (function) callback to a selected event.
|
|
|
|
|
Pointer will be free'd by Hyprland on unregisterCallback().
|
|
|
|
|
|
|
|
|
|
returns: a pointer to the newly allocated function. nullptr on fail.
|
2024-04-22 15:50:01 +01:00
|
|
|
|
|
|
|
|
WARNING: Losing this pointer will unregister the callback!
|
2023-02-27 12:32:38 +00:00
|
|
|
*/
|
2024-05-05 17:16:00 +01:00
|
|
|
APICALL [[nodiscard]] SP<HOOK_CALLBACK_FN> registerCallbackDynamic(HANDLE handle, const std::string& event, HOOK_CALLBACK_FN fn);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Unregisters a callback. If the callback was dynamic, frees the memory.
|
|
|
|
|
|
|
|
|
|
returns: true on success, false on fail
|
2024-04-22 15:50:01 +01:00
|
|
|
|
|
|
|
|
Deprecated: just reset the pointer you received with registerCallbackDynamic
|
2023-02-27 12:32:38 +00:00
|
|
|
*/
|
2024-05-05 17:16:00 +01:00
|
|
|
APICALL [[deprecated]] bool unregisterCallback(HANDLE handle, SP<HOOK_CALLBACK_FN> fn);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Calls a hyprctl command.
|
|
|
|
|
|
|
|
|
|
returns: the output (as in hyprctl)
|
|
|
|
|
*/
|
|
|
|
|
APICALL std::string invokeHyprctlCommand(const std::string& call, const std::string& args, const std::string& format = "");
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Adds a layout to Hyprland.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
2026-02-21 21:30:39 +00:00
|
|
|
|
|
|
|
|
deprecated: addTiledAlgo, addFloatingAlgo
|
2023-02-27 12:32:38 +00:00
|
|
|
*/
|
2026-02-21 21:30:39 +00:00
|
|
|
APICALL [[deprecated]] bool addLayout(HANDLE handle, const std::string& name, IHyprLayout* layout);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Removes an added layout from Hyprland.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
2026-02-21 21:30:39 +00:00
|
|
|
|
|
|
|
|
deprecated: V2 removeAlgo
|
|
|
|
|
*/
|
|
|
|
|
APICALL [[deprecated]] bool removeLayout(HANDLE handle, IHyprLayout* layout);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Algorithm fns. Used for registering and removing. Return success.
|
2023-02-27 12:32:38 +00:00
|
|
|
*/
|
2026-02-21 21:30:39 +00:00
|
|
|
APICALL bool addTiledAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function<UP<Layout::ITiledAlgorithm>()>&& factory);
|
|
|
|
|
APICALL bool addFloatingAlgo(HANDLE handle, const std::string& name, const std::type_info* typeInfo, std::function<UP<Layout::IFloatingAlgorithm>()>&& factory);
|
|
|
|
|
APICALL bool removeAlgo(HANDLE handle, const std::string& name);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Queues a config reload. Does not take effect immediately.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
|
|
|
|
APICALL bool reloadConfig();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Adds a notification.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
2024-12-03 18:58:24 +00:00
|
|
|
APICALL bool addNotification(HANDLE handle, const std::string& text, const CHyprColor& color, const float timeMs);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Creates a trampoline function hook to an internal hl func.
|
|
|
|
|
|
|
|
|
|
returns: CFunctionHook*
|
|
|
|
|
|
|
|
|
|
!WARNING! Hooks are *not* guaranteed any API stability. Internal methods may be removed, added, or renamed. Consider preferring the API whenever possible.
|
|
|
|
|
*/
|
|
|
|
|
APICALL CFunctionHook* createFunctionHook(HANDLE handle, const void* source, const void* destination);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Removes a trampoline function hook. Will unhook if still hooked.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
|
|
|
|
|
!WARNING! Hooks are *not* guaranteed any API stability. Internal methods may be removed, added, or renamed. Consider preferring the API whenever possible.
|
|
|
|
|
*/
|
|
|
|
|
APICALL bool removeFunctionHook(HANDLE handle, CFunctionHook* hook);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Gets a function address from a signature.
|
|
|
|
|
This is useful for hooking private functions.
|
|
|
|
|
|
|
|
|
|
returns: function address, or nullptr on fail.
|
2023-03-31 18:43:00 +01:00
|
|
|
|
|
|
|
|
Deprecated because of findFunctionsByName.
|
2023-02-27 12:32:38 +00:00
|
|
|
*/
|
2023-03-31 18:43:00 +01:00
|
|
|
APICALL [[deprecated]] void* getFunctionAddressFromSignature(HANDLE handle, const std::string& sig);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Adds a window decoration to a window
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
2025-01-23 21:55:41 +01:00
|
|
|
APICALL bool addWindowDecoration(HANDLE handle, PHLWINDOW pWindow, UP<IHyprWindowDecoration> pDecoration);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Removes a window decoration
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
|
|
|
|
APICALL bool removeWindowDecoration(HANDLE handle, IHyprWindowDecoration* pDecoration);
|
|
|
|
|
|
2024-12-19 20:23:32 +00:00
|
|
|
/*
|
|
|
|
|
Adds a keybind dispatcher.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
|
|
|
|
|
DEPRECATED: use addDispatcherV2
|
|
|
|
|
*/
|
|
|
|
|
APICALL [[deprecated]] bool addDispatcher(HANDLE handle, const std::string& name, std::function<void(std::string)> handler);
|
|
|
|
|
|
2023-02-27 12:32:38 +00:00
|
|
|
/*
|
|
|
|
|
Adds a keybind dispatcher.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
2024-12-19 20:23:32 +00:00
|
|
|
APICALL bool addDispatcherV2(HANDLE handle, const std::string& name, std::function<SDispatchResult(std::string)> handler);
|
2023-02-27 12:32:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Removes a keybind dispatcher.
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
|
|
|
|
APICALL bool removeDispatcher(HANDLE handle, const std::string& name);
|
2023-03-20 15:23:25 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Adds a notification.
|
|
|
|
|
|
|
|
|
|
data has to contain:
|
|
|
|
|
- text: std::string or const char*
|
|
|
|
|
- time: uint64_t
|
2024-12-03 18:58:24 +00:00
|
|
|
- color: CHyprColor -> CHyprColor(0) will apply the default color for the notification icon
|
2023-03-20 15:23:25 +00:00
|
|
|
|
|
|
|
|
data may contain:
|
|
|
|
|
- icon: eIcons
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
|
|
|
|
APICALL bool addNotificationV2(HANDLE handle, const std::unordered_map<std::string, std::any>& data);
|
2023-03-31 18:31:11 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Returns a vector of found functions matching the provided name.
|
|
|
|
|
|
|
|
|
|
These addresses will not change, and should be made static. Lookups are slow.
|
|
|
|
|
|
|
|
|
|
Empty means either none found or handle was invalid
|
|
|
|
|
*/
|
|
|
|
|
APICALL std::vector<SFunctionMatch> findFunctionsByName(HANDLE handle, const std::string& name);
|
2023-10-14 18:47:43 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Returns the hyprland version data. It's highly advised to not run plugins compiled
|
|
|
|
|
for a different hash.
|
|
|
|
|
*/
|
|
|
|
|
APICALL SVersionInfo getHyprlandVersion(HANDLE handle);
|
2024-02-05 01:56:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Registers a hyprctl command
|
|
|
|
|
|
|
|
|
|
returns: Pointer. Nullptr on fail.
|
|
|
|
|
*/
|
2024-05-05 17:16:00 +01:00
|
|
|
APICALL SP<SHyprCtlCommand> registerHyprCtlCommand(HANDLE handle, SHyprCtlCommand cmd);
|
2024-02-05 01:56:38 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Unregisters a hyprctl command
|
|
|
|
|
|
|
|
|
|
returns: true on success. False otherwise.
|
|
|
|
|
*/
|
2024-05-05 17:16:00 +01:00
|
|
|
APICALL bool unregisterHyprCtlCommand(HANDLE handle, SP<SHyprCtlCommand> cmd);
|
2023-10-14 18:47:43 +01:00
|
|
|
};
|
|
|
|
|
|
2024-12-07 18:51:18 +01:00
|
|
|
// NOLINTBEGIN
|
2023-10-14 18:47:43 +01:00
|
|
|
/*
|
2025-10-21 22:47:50 +01:00
|
|
|
Get the descriptive string this plugin/server was compiled with.
|
2023-10-14 18:47:43 +01:00
|
|
|
|
|
|
|
|
This function will end up in both hyprland and any/all plugins,
|
|
|
|
|
and can be found by a simple dlsym()
|
2023-10-29 21:21:54 +00:00
|
|
|
|
|
|
|
|
_get_hash() is server,
|
|
|
|
|
_get_client_hash() is client.
|
2023-10-14 18:47:43 +01:00
|
|
|
*/
|
2023-10-29 21:21:54 +00:00
|
|
|
APICALL EXPORT const char* __hyprland_api_get_hash();
|
|
|
|
|
APICALL inline EXPORT const char* __hyprland_api_get_client_hash() {
|
2025-10-21 22:47:50 +01:00
|
|
|
static auto stripPatch = [](const char* ver) -> std::string {
|
|
|
|
|
std::string_view v = ver;
|
|
|
|
|
if (!v.contains('.'))
|
|
|
|
|
return std::string{v};
|
|
|
|
|
|
|
|
|
|
return std::string{v.substr(0, v.find_last_of('.'))};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const std::string ver = (std::string{GIT_COMMIT_HASH} + "_aq_" + stripPatch(AQUAMARINE_VERSION) + "_hu_" + stripPatch(HYPRUTILS_VERSION) + "_hg_" +
|
|
|
|
|
stripPatch(HYPRGRAPHICS_VERSION) + "_hc_" + stripPatch(HYPRCURSOR_VERSION) + "_hlg_" + stripPatch(HYPRLANG_VERSION));
|
|
|
|
|
|
|
|
|
|
return ver.c_str();
|
2023-10-14 18:47:43 +01:00
|
|
|
}
|
2024-12-07 18:51:18 +01:00
|
|
|
// NOLINTEND
|
2025-03-17 09:52:40 -05:00
|
|
|
|
2025-03-18 18:46:28 -05:00
|
|
|
#ifdef __clang__
|
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
|
#endif
|