mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-19 16:13:21 +02:00
parent
111669a699
commit
38c1d00f3c
8 changed files with 127 additions and 20 deletions
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ all: $(PLUGIN_NAME).so
|
|||
|
||||
$(PLUGIN_NAME).so: $(SOURCE_FILES)
|
||||
mkdir -p out
|
||||
g++ -shared -Wall --no-gnu-unique -fPIC $(SOURCE_FILES) -g `pkg-config --cflags hyprland | awk '{print $$NF "/src";}'` `pkg-config --cflags pixman-1 libdrm hyprland` -std=c++23 -o out/$(PLUGIN_NAME).so
|
||||
$(CXX) -shared -Wall --no-gnu-unique -fPIC $(SOURCE_FILES) -g `pkg-config --cflags hyprland | awk '{print $$NF "/src";}'` `pkg-config --cflags pixman-1 libdrm hyprland` -std=c++26 -o out/$(PLUGIN_NAME).so
|
||||
|
||||
clean:
|
||||
rm -f out/$(PLUGIN_NAME).so
|
||||
|
|
|
@ -11,6 +11,9 @@ commit_pins = [
|
|||
["a425fbebe4cf4238e48a42f724ef2208959d66cf", "81f4b964f997a3174596ef22c7a1dee8a5f616c7"], # v0.45.0
|
||||
["500d2a3580388afc8b620b0a3624147faa34f98b", "81f4b964f997a3174596ef22c7a1dee8a5f616c7"], # v0.45.1
|
||||
["12f9a0d0b93f691d4d9923716557154d74777b0a", "81f4b964f997a3174596ef22c7a1dee8a5f616c7"], # v0.45.2
|
||||
["788ae588979c2a1ff8a660f16e3c502ef5796755", "111669a699f998b5eb5a0d5610b5fcb748aab038"], # v0.46.0
|
||||
["254fc2bc6000075f660b4b8ed818a6af544d1d64", "111669a699f998b5eb5a0d5610b5fcb748aab038"], # v0.46.1
|
||||
["0bd541f2fd902dbfa04c3ea2ccf679395e316887", "111669a699f998b5eb5a0d5610b5fcb748aab038"], # v0.46.2
|
||||
]
|
||||
|
||||
[dynamic-cursors]
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
#include "config/config.hpp"
|
||||
#include "mode/Mode.hpp"
|
||||
#include "src/debug/Log.hpp"
|
||||
#include "src/helpers/math/Math.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
@ -10,19 +5,28 @@
|
|||
#include <hyprlang.hpp>
|
||||
#include <gbm.h>
|
||||
|
||||
#include <hyprland/src/managers/eventLoop/EventLoopTimer.hpp> // required so we don't "unprivate" chrono
|
||||
|
||||
#define private public
|
||||
#include <hyprland/src/managers/CursorManager.hpp>
|
||||
#include <hyprland/src/managers/PointerManager.hpp>
|
||||
#include <hyprland/src/render/OpenGL.hpp>
|
||||
#include <hyprland/src/render/Renderer.hpp>
|
||||
#include <hyprland/src/Compositor.hpp>
|
||||
#undef private
|
||||
|
||||
#include <hyprland/src/config/ConfigValue.hpp>
|
||||
#include <hyprland/src/protocols/core/Compositor.hpp>
|
||||
#include <hyprland/src/protocols/core/Seat.hpp>
|
||||
#include <hyprland/src/debug/Log.hpp>
|
||||
#include <hyprland/src/helpers/math/Math.hpp>
|
||||
|
||||
#include "cursor.hpp"
|
||||
#include "renderer.hpp"
|
||||
#include "render/renderer.hpp"
|
||||
#include "config/config.hpp"
|
||||
#include "mode/Mode.hpp"
|
||||
#include "render/CursorPassElement.hpp"
|
||||
#include "render/Renderer.hpp"
|
||||
|
||||
void tickRaw(SP<CEventLoopTimer> self, void* data) {
|
||||
if (isEnabled())
|
||||
|
@ -120,8 +124,20 @@ void CDynamicCursors::renderSoftware(CPointerManager* pointers, SP<CMonitor> pMo
|
|||
// we rotate the cursor by our calculated amount
|
||||
box.rot = resultShown.rotation;
|
||||
|
||||
// now pass the hotspot to rotate around
|
||||
renderCursorTextureInternalWithDamage(texture, &box, &damage, 1.F, nullptr, 0, pointers->currentCursorImage.hotspot * state->monitor->scale * zoom, nearest, resultShown.stretch.angle, resultShown.stretch.magnitude);
|
||||
CCursorPassElement::SRenderData data;
|
||||
data.tex = texture;
|
||||
data.box = box;
|
||||
data.syncTimeline = pointers->currentCursorImage.waitTimeline;
|
||||
data.syncPoint = pointers->currentCursorImage.waitPoint;
|
||||
data.hotspot = pointers->currentCursorImage.hotspot * state->monitor->scale * zoom;
|
||||
data.nearest = nearest;
|
||||
data.stretchAngle = resultShown.stretch.angle;
|
||||
data.stretchMagnitude = resultShown.stretch.magnitude;
|
||||
|
||||
g_pHyprRenderer->m_sRenderPass.add(makeShared<CCursorPassElement>(data));
|
||||
|
||||
pointers->currentCursorImage.waitTimeline.reset();
|
||||
pointers->currentCursorImage.waitPoint = 0;
|
||||
|
||||
if (pointers->currentCursorImage.surface)
|
||||
pointers->currentCursorImage.surface->resource()->frame(now);
|
||||
|
@ -298,7 +314,7 @@ SP<Aquamarine::IBuffer> CDynamicCursors::renderHardware(CPointerManager* pointer
|
|||
xbox.rot = resultShown.rotation;
|
||||
|
||||
// use our custom draw function
|
||||
renderCursorTextureInternalWithDamage(texture, &xbox, &damage, 1.F, pointers->currentCursorImage.waitTimeline, pointers->currentCursorImage.waitPoint, pointers->currentCursorImage.hotspot * state->monitor->scale * zoom, zoom > 1 && **PNEAREST, resultShown.stretch.angle, resultShown.stretch.magnitude);
|
||||
renderCursorTextureInternalWithDamage(texture, &xbox, damage, 1.F, pointers->currentCursorImage.waitTimeline, pointers->currentCursorImage.waitPoint, pointers->currentCursorImage.hotspot * state->monitor->scale * zoom, zoom > 1 && **PNEAREST, resultShown.stretch.angle, resultShown.stretch.magnitude);
|
||||
|
||||
g_pHyprOpenGL->end();
|
||||
glFlush();
|
||||
|
|
47
src/render/CursorPassElement.cpp
Normal file
47
src/render/CursorPassElement.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "CursorPassElement.hpp"
|
||||
#include "renderer.hpp"
|
||||
|
||||
#include <hyprland/src/render/pass/TexPassElement.hpp>
|
||||
#include <hyprland/src/render/OpenGL.hpp>
|
||||
|
||||
#include <hyprutils/utils/ScopeGuard.hpp>
|
||||
using namespace Hyprutils::Utils;
|
||||
|
||||
CCursorPassElement::CCursorPassElement(const CCursorPassElement::SRenderData& data_) : data(data_) {
|
||||
;
|
||||
}
|
||||
|
||||
void CCursorPassElement::draw(const CRegion& damage) {
|
||||
renderCursorTextureInternalWithDamage(
|
||||
data.tex,
|
||||
&data.box,
|
||||
data.damage.empty() ? damage : data.damage,
|
||||
1.F,
|
||||
data.syncTimeline,
|
||||
data.syncPoint,
|
||||
data.hotspot,
|
||||
data.nearest,
|
||||
data.stretchAngle,
|
||||
data.stretchMagnitude
|
||||
);
|
||||
}
|
||||
|
||||
bool CCursorPassElement::needsLiveBlur() {
|
||||
return false; // TODO?
|
||||
}
|
||||
|
||||
bool CCursorPassElement::needsPrecomputeBlur() {
|
||||
return false; // TODO?
|
||||
}
|
||||
|
||||
std::optional<CBox> CCursorPassElement::boundingBox() {
|
||||
return data.box.copy().scale(1.F / g_pHyprOpenGL->m_RenderData.pMonitor->scale).round();
|
||||
}
|
||||
|
||||
CRegion CCursorPassElement::opaqueRegion() {
|
||||
return {}; // TODO:
|
||||
}
|
||||
|
||||
void CCursorPassElement::discard() {
|
||||
;
|
||||
}
|
41
src/render/CursorPassElement.hpp
Normal file
41
src/render/CursorPassElement.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprland/src/render/pass/PassElement.hpp>
|
||||
#include <optional>
|
||||
|
||||
class CWLSurfaceResource;
|
||||
class CTexture;
|
||||
class CSyncTimeline;
|
||||
|
||||
class CCursorPassElement : public IPassElement {
|
||||
public:
|
||||
struct SRenderData {
|
||||
SP<CTexture> tex;
|
||||
CBox box;
|
||||
CRegion damage;
|
||||
SP<CSyncTimeline> syncTimeline;
|
||||
int64_t syncPoint = 0;
|
||||
|
||||
Vector2D hotspot;
|
||||
bool nearest;
|
||||
double stretchAngle;
|
||||
Vector2D stretchMagnitude;
|
||||
};
|
||||
|
||||
CCursorPassElement(const SRenderData& data);
|
||||
virtual ~CCursorPassElement() = default;
|
||||
|
||||
virtual void draw(const CRegion& damage);
|
||||
virtual bool needsLiveBlur();
|
||||
virtual bool needsPrecomputeBlur();
|
||||
virtual std::optional<CBox> boundingBox();
|
||||
virtual CRegion opaqueRegion();
|
||||
virtual void discard();
|
||||
|
||||
virtual const char* passName() {
|
||||
return "CCursorPassElement";
|
||||
}
|
||||
|
||||
private:
|
||||
SRenderData data;
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
#include "globals.hpp"
|
||||
#include "src/debug/Log.hpp"
|
||||
#include "../globals.hpp"
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#define private public
|
||||
|
@ -9,6 +8,7 @@
|
|||
|
||||
#include <hyprland/src/Compositor.hpp>
|
||||
#include <hyprland/src/config/ConfigValue.hpp>
|
||||
#include <hyprland/src/debug/Log.hpp>
|
||||
|
||||
#include "renderer.hpp"
|
||||
|
||||
|
@ -52,7 +52,7 @@ Mat3x3 projectCursorBox(CBox& box, eTransform transform, float rotation, const M
|
|||
/*
|
||||
This renders a texture with damage but rotates the texture around a given hotspot.
|
||||
*/
|
||||
void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, CRegion* damage, float alpha, SP<CSyncTimeline> waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch) {
|
||||
void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, const CRegion& damage, float alpha, SP<CSyncTimeline> waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch) {
|
||||
TRACY_GPU_ZONE("RenderDynamicCursor");
|
||||
|
||||
if (waitTimeline != nullptr) {
|
||||
|
@ -64,7 +64,7 @@ void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, CRegion
|
|||
|
||||
alpha = std::clamp(alpha, 0.f, 1.f);
|
||||
|
||||
if (damage->empty())
|
||||
if (damage.empty())
|
||||
return;
|
||||
|
||||
CBox newBox = *pBox;
|
||||
|
@ -129,7 +129,7 @@ void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, CRegion
|
|||
|
||||
if (g_pHyprOpenGL->m_RenderData.clipBox.width != 0 && g_pHyprOpenGL->m_RenderData.clipBox.height != 0) {
|
||||
CRegion damageClip{g_pHyprOpenGL->m_RenderData.clipBox.x, g_pHyprOpenGL->m_RenderData.clipBox.y, g_pHyprOpenGL->m_RenderData.clipBox.width, g_pHyprOpenGL->m_RenderData.clipBox.height};
|
||||
damageClip.intersect(*damage);
|
||||
damageClip.intersect(damage);
|
||||
|
||||
if (!damageClip.empty()) {
|
||||
for (auto& RECT : damageClip.getRects()) {
|
||||
|
@ -138,7 +138,7 @@ void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, CRegion
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for (auto& RECT : damage->getRects()) {
|
||||
for (auto& RECT : damage.getRects()) {
|
||||
g_pHyprOpenGL->scissor(&RECT);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
4
src/render/renderer.hpp
Normal file
4
src/render/renderer.hpp
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include <hyprland/src/render/OpenGL.hpp>
|
||||
#include <hyprland/src/helpers/math/Math.hpp>
|
||||
|
||||
void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, const CRegion& damage, float alpha, SP<CSyncTimeline> waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch);
|
|
@ -1,4 +0,0 @@
|
|||
#include <hyprland/src/render/OpenGL.hpp>
|
||||
#include <hyprland/src/helpers/math/Math.hpp>
|
||||
|
||||
void renderCursorTextureInternalWithDamage(SP<CTexture> tex, CBox* pBox, CRegion* damage, float alpha, SP<CSyncTimeline> waitTimeline, uint64_t waitPoint, Vector2D hotspot, bool nearest, float stretchAngle, Vector2D stretch);
|
Loading…
Add table
Add a link
Reference in a new issue