chore: basic plugin project setup

This commit is contained in:
Virt 2024-06-21 13:40:57 +02:00
commit 85b89bc389
4 changed files with 67 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
compile_commands.json
out
.cache

18
Makefile Normal file
View file

@ -0,0 +1,18 @@
PLUGIN_NAME=dynamic-cursors
SOURCE_FILES=$(wildcard ./src/*.cpp)
all: $(PLUGIN_NAME).so
$(PLUGIN_NAME).so: $(SOURCE_FILES)
mkdir -p out
g++ -shared -Wall -fPIC $(SOURCE_FILES) -g -DWLR_USE_UNSTABLE `pkg-config --cflags pixman-1 libdrm hyprland` -std=c++23 -o out/$(PLUGIN_NAME).so
clean:
rm -f out/$(PLUGIN_NAME).so
rm -f compile_commands.json
load: all unload
hyprctl plugin load ${PWD}/out/$(PLUGIN_NAME).so
unload:
hyprctl plugin unload ${PWD}/out/$(PLUGIN_NAME).so

5
src/globals.hpp Normal file
View file

@ -0,0 +1,5 @@
#pragma once
#include <hyprland/src/plugins/PluginAPI.hpp>
inline HANDLE PHANDLE = nullptr;

41
src/main.cpp Normal file
View file

@ -0,0 +1,41 @@
#include <hyprland/src/helpers/memory/Memory.hpp>
#include <hyprland/src/plugins/HookSystem.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/helpers/Monitor.hpp>
#include <unistd.h>
#include "globals.hpp"
typedef void (*origRenderSofwareCursorsFor)(void*, SP<CMonitor>, timespec*, CRegion&, std::optional<Vector2D>);
inline CFunctionHook* g_pRenderSoftwareCursorsForHook = nullptr;
void hkRenderSoftwareCursorsFor(void* thisptr, SP<CMonitor> pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) {
//(*(origRenderSofwareCursorsFor)g_pRenderSoftwareCursorsForHook->m_pOriginal)(thisptr, pMonitor, now, damage, overridePos);
}
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;
const std::string HASH = __hyprland_api_get_hash();
// check that header version aligns with running version
if (HASH != GIT_COMMIT_HASH) {
HyprlandAPI::addNotification(PHANDLE, "[dynamic-cursors] Mismatched headers! Can't proceed.", CColor{1.0, 0.2, 0.2, 1.0}, 5000);
throw std::runtime_error("[dynamic-cursors] Version mismatch");
}
static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "renderSoftwareCursorsFor");
g_pRenderSoftwareCursorsForHook = HyprlandAPI::createFunctionHook(PHANDLE, METHODS[0].address, (void*) &hkRenderSoftwareCursorsFor);
g_pRenderSoftwareCursorsForHook->hook();
return {"dynamic-cursors", "The most stupid cursor plugin.", "Virt", "1.1"};
}
APICALL EXPORT void PLUGIN_EXIT() {
// ...
}
// Do NOT change this function.
APICALL EXPORT std::string PLUGIN_API_VERSION() {
return HYPRLAND_API_VERSION;
}