2024-06-21 14:32:42 +02:00
|
|
|
#include "globals.hpp"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#define private public
|
|
|
|
#include <hyprland/src/managers/PointerManager.hpp>
|
2024-06-21 16:06:55 +02:00
|
|
|
#include <hyprland/src/render/OpenGL.hpp>
|
2024-06-21 14:32:42 +02:00
|
|
|
#undef private
|
|
|
|
|
2024-06-21 16:06:55 +02:00
|
|
|
#include <hyprland/src/Compositor.hpp>
|
|
|
|
#include <hyprland/src/config/ConfigValue.hpp>
|
|
|
|
|
|
|
|
#include "cursor.hpp"
|
|
|
|
#include "renderer.hpp"
|
2024-06-21 14:32:42 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-06-21 16:06:55 +02:00
|
|
|
renderCursorTextureInternalWithDamage(texture, &box, &damage, 1.F, pointers->currentCursorImage.hotspot);
|
2024-06-21 14:32:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double CDynamicCursors::calculate(Vector2D* pos) {
|
2024-06-21 16:06:55 +02:00
|
|
|
static auto* const* PLENGTH = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, CONFIG_LENGTH)->getDataStaticPtr();
|
|
|
|
|
2024-06-21 14:32:42 +02:00
|
|
|
// translate to origin
|
2024-06-21 16:06:55 +02:00
|
|
|
end.x -= pos->x;
|
|
|
|
end.y -= pos->y;
|
2024-06-21 14:32:42 +02:00
|
|
|
|
|
|
|
// normalize
|
2024-06-21 16:06:55 +02:00
|
|
|
double size = end.size();
|
|
|
|
end.x /= size;
|
|
|
|
end.y /= size;
|
2024-06-21 14:32:42 +02:00
|
|
|
|
|
|
|
// scale to length
|
2024-06-21 16:06:55 +02:00
|
|
|
end.x *= **PLENGTH;
|
|
|
|
end.y *= **PLENGTH;
|
2024-06-21 14:32:42 +02:00
|
|
|
|
|
|
|
// calculate angle
|
2024-06-21 16:06:55 +02:00
|
|
|
double angle = -atan(end.x / end.y);
|
|
|
|
if (end.y > 0) angle += PI;
|
2024-06-21 14:32:42 +02:00
|
|
|
angle += PI;
|
|
|
|
|
|
|
|
// translate back
|
2024-06-21 16:06:55 +02:00
|
|
|
end.x += pos->x;
|
|
|
|
end.y += pos->y;
|
2024-06-21 14:32:42 +02:00
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|