mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-19 16:13:21 +02:00
feat: first working stick prototype
This commit is contained in:
parent
85b89bc389
commit
204a79ebaf
3 changed files with 89 additions and 0 deletions
|
@ -5,11 +5,13 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
|
#include "render.hpp"
|
||||||
|
|
||||||
typedef void (*origRenderSofwareCursorsFor)(void*, SP<CMonitor>, timespec*, CRegion&, std::optional<Vector2D>);
|
typedef void (*origRenderSofwareCursorsFor)(void*, SP<CMonitor>, timespec*, CRegion&, std::optional<Vector2D>);
|
||||||
inline CFunctionHook* g_pRenderSoftwareCursorsForHook = nullptr;
|
inline CFunctionHook* g_pRenderSoftwareCursorsForHook = nullptr;
|
||||||
|
|
||||||
void hkRenderSoftwareCursorsFor(void* thisptr, SP<CMonitor> pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) {
|
void hkRenderSoftwareCursorsFor(void* thisptr, SP<CMonitor> pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) {
|
||||||
|
g_pDynamicCursors->render((CPointerManager*) thisptr, pMonitor, now, damage, overridePos);
|
||||||
//(*(origRenderSofwareCursorsFor)g_pRenderSoftwareCursorsForHook->m_pOriginal)(thisptr, pMonitor, now, damage, overridePos);
|
//(*(origRenderSofwareCursorsFor)g_pRenderSoftwareCursorsForHook->m_pOriginal)(thisptr, pMonitor, now, damage, overridePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +30,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
||||||
g_pRenderSoftwareCursorsForHook = HyprlandAPI::createFunctionHook(PHANDLE, METHODS[0].address, (void*) &hkRenderSoftwareCursorsFor);
|
g_pRenderSoftwareCursorsForHook = HyprlandAPI::createFunctionHook(PHANDLE, METHODS[0].address, (void*) &hkRenderSoftwareCursorsFor);
|
||||||
g_pRenderSoftwareCursorsForHook->hook();
|
g_pRenderSoftwareCursorsForHook->hook();
|
||||||
|
|
||||||
|
g_pDynamicCursors = std::make_unique<CDynamicCursors>();
|
||||||
|
|
||||||
return {"dynamic-cursors", "The most stupid cursor plugin.", "Virt", "1.1"};
|
return {"dynamic-cursors", "The most stupid cursor plugin.", "Virt", "1.1"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
66
src/render.cpp
Normal file
66
src/render.cpp
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
#include "globals.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <hyprland/src/Compositor.hpp>
|
||||||
|
|
||||||
|
#define private public
|
||||||
|
#include <hyprland/src/managers/PointerManager.hpp>
|
||||||
|
#undef private
|
||||||
|
|
||||||
|
#include "render.hpp"
|
||||||
|
|
||||||
|
void CDynamicCursors::render(CPointerManager* pointers, SP<CMonitor> pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) {
|
||||||
|
|
||||||
|
if (!pointers->hasCursor())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto state = pointers->stateFor(pMonitor);
|
||||||
|
|
||||||
|
if ((!state->hardwareFailed && state->softwareLocks == 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto box = state->box.copy();
|
||||||
|
if (overridePos.has_value()) {
|
||||||
|
box.x = overridePos->x;
|
||||||
|
box.y = overridePos->y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (box.intersection(CBox{{}, {pMonitor->vecSize}}).empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto texture = pointers->getCurrentCursorTexture();
|
||||||
|
if (!texture)
|
||||||
|
return;
|
||||||
|
|
||||||
|
box.scale(pMonitor->scale);
|
||||||
|
box.rot = this->calculate(&pointers->pointerPos);
|
||||||
|
|
||||||
|
g_pHyprOpenGL->renderTextureWithDamage(texture, &box, &damage, 1.F);
|
||||||
|
}
|
||||||
|
|
||||||
|
double CDynamicCursors::calculate(Vector2D* pos) {
|
||||||
|
// translate to origin
|
||||||
|
this->end.x -= pos->x;
|
||||||
|
this->end.y -= pos->y;
|
||||||
|
|
||||||
|
// normalize
|
||||||
|
double size = this->end.size();
|
||||||
|
this->end.x /= size;
|
||||||
|
this->end.y /= size;
|
||||||
|
|
||||||
|
// scale to length
|
||||||
|
this->end.x *= this->size;
|
||||||
|
this->end.y *= this->size;
|
||||||
|
|
||||||
|
// calculate angle
|
||||||
|
double angle = -atan(this->end.x / this->end.y);
|
||||||
|
if (this->end.y > 0) angle += PI;
|
||||||
|
angle += PI;
|
||||||
|
|
||||||
|
// translate back
|
||||||
|
this->end.x += pos->x;
|
||||||
|
this->end.y += pos->y;
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
19
src/render.hpp
Normal file
19
src/render.hpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include "globals.hpp"
|
||||||
|
#include <hyprland/src/managers/PointerManager.hpp>
|
||||||
|
#include <hyprutils/math/Vector2D.hpp>
|
||||||
|
|
||||||
|
class CDynamicCursors;
|
||||||
|
|
||||||
|
class CDynamicCursors {
|
||||||
|
public:
|
||||||
|
void render(CPointerManager* pointers, SP<CMonitor> pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos);
|
||||||
|
|
||||||
|
private:
|
||||||
|
double size = 10;
|
||||||
|
// calculates the current angle of the cursor
|
||||||
|
double calculate(Vector2D* pos);
|
||||||
|
// this is the end of the virtual stick
|
||||||
|
Vector2D end;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline std::unique_ptr<CDynamicCursors> g_pDynamicCursors;
|
Loading…
Add table
Add a link
Reference in a new issue