From 85b89bc389d7d7b2d3c1700fae851213dcdbad02 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Fri, 21 Jun 2024 13:40:57 +0200 Subject: [PATCH] chore: basic plugin project setup --- .gitignore | 3 +++ Makefile | 18 ++++++++++++++++++ src/globals.hpp | 5 +++++ src/main.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/globals.hpp create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64afe5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +compile_commands.json +out +.cache diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1eb1391 --- /dev/null +++ b/Makefile @@ -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 diff --git a/src/globals.hpp b/src/globals.hpp new file mode 100644 index 0000000..66c4f04 --- /dev/null +++ b/src/globals.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +inline HANDLE PHANDLE = nullptr; diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..733a93f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include + +#include "globals.hpp" + +typedef void (*origRenderSofwareCursorsFor)(void*, SP, timespec*, CRegion&, std::optional); +inline CFunctionHook* g_pRenderSoftwareCursorsForHook = nullptr; + +void hkRenderSoftwareCursorsFor(void* thisptr, SP pMonitor, timespec* now, CRegion& damage, std::optional 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; +}