From d7c1fdf5f81ddceae18db387a6805e8e7fe17170 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:25:02 +0200 Subject: [PATCH] fix: correct amount of padding --- src/cursor.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cursor.cpp b/src/cursor.cpp index 3cce358..5abacc9 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -109,10 +109,13 @@ It is largely identical to hyprlands implementation, but expands the damage reag */ void CDynamicCursors::damageSoftware(CPointerManager* pointers) { - // we damage a 3x3 area around the cursor, to accomodate for all possible hotspots and rotations + // we damage a padding of the diagonal around the hotspot, to accomodate for all possible hotspots and rotations auto zoom = resultShown.scale; Vector2D size = pointers->currentCursorImage.size / pointers->currentCursorImage.scale * zoom; - CBox b = CBox{pointers->pointerPos, size * 3}.translate(-(pointers->currentCursorImage.hotspot * zoom + size)); + float diagonal = size.size(); + Vector2D padding = {diagonal, diagonal}; + + CBox b = CBox{pointers->pointerPos, size + (padding * 2)}.translate(-(pointers->currentCursorImage.hotspot * zoom + padding)); static auto PNOHW = CConfigValue("cursor:no_hardware_cursors"); @@ -139,8 +142,11 @@ wlr_buffer* CDynamicCursors::renderHardware(CPointerManager* pointers, SPcurrentCursorImage.size * zoom; - // we try to allocate a buffer that is thrice as big, see software rendering - auto target = size * 3; + float diagonal = size.size(); + Vector2D padding = {diagonal, diagonal}; + + // we try to allocate a buffer with padding, see software damage + auto target = size + padding * 2; if (output->impl->get_cursor_size) { int w, h; @@ -199,7 +205,7 @@ wlr_buffer* CDynamicCursors::renderHardware(CPointerManager* pointers, SPclear(CColor{0.F, 0.F, 0.F, 0.F}); // the box should start in the middle portion, rotate by our calculated amount - CBox xbox = {size, Vector2D{pointers->currentCursorImage.size / pointers->currentCursorImage.scale * state->monitor->scale * zoom}.round()}; + CBox xbox = {padding, Vector2D{pointers->currentCursorImage.size / pointers->currentCursorImage.scale * state->monitor->scale * zoom}.round()}; xbox.rot = resultShown.rotation; // use our custom draw function @@ -225,8 +231,11 @@ bool CDynamicCursors::setHardware(CPointerManager* pointers, SPmonitor.lock(); if (!P_MONITOR->output->cursor_swapchain) return false; - // we need to transform the hotspot manually as we need to indent it by the size - const auto HOTSPOT = CBox{((pointers->currentCursorImage.hotspot * P_MONITOR->scale) + pointers->currentCursorImage.size) * resultShown.scale, {0, 0}} + // we need to transform the hotspot manually as we need to indent it by the padding + float diagonal = pointers->currentCursorImage.size.size(); + Vector2D padding = {diagonal, diagonal}; + + const auto HOTSPOT = CBox{((pointers->currentCursorImage.hotspot * P_MONITOR->scale) + padding) * resultShown.scale, {0, 0}} .transform(wlTransformToHyprutils(wlr_output_transform_invert(P_MONITOR->transform)), P_MONITOR->output->cursor_swapchain->width, P_MONITOR->output->cursor_swapchain->height) .pos(); @@ -269,12 +278,10 @@ void CDynamicCursors::onCursorMoved(CPointerManager* pointers) { } void CDynamicCursors::setShape(const std::string& shape) { - Debug::log(WARN, "[dynamic-cursors] setting shape {}", shape); g_pShapeRuleHandler->activate(shape); } void CDynamicCursors::unsetShape() { - Debug::log(WARN, "[dynamic-cursors] setting shape to clientside"); g_pShapeRuleHandler->activate("clientside"); }