fix: correct amount of padding

This commit is contained in:
Virt 2024-07-03 16:25:02 +02:00
commit d7c1fdf5f8

View file

@ -109,10 +109,13 @@ It is largely identical to hyprlands implementation, but expands the damage reag
*/ */
void CDynamicCursors::damageSoftware(CPointerManager* pointers) { 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; auto zoom = resultShown.scale;
Vector2D size = pointers->currentCursorImage.size / pointers->currentCursorImage.scale * zoom; 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<Hyprlang::INT>("cursor:no_hardware_cursors"); static auto PNOHW = CConfigValue<Hyprlang::INT>("cursor:no_hardware_cursors");
@ -139,8 +142,11 @@ wlr_buffer* CDynamicCursors::renderHardware(CPointerManager* pointers, SP<CPoint
auto zoom = resultShown.scale; auto zoom = resultShown.scale;
auto size = pointers->currentCursorImage.size * zoom; auto size = pointers->currentCursorImage.size * zoom;
// we try to allocate a buffer that is thrice as big, see software rendering float diagonal = size.size();
auto target = size * 3; 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) { if (output->impl->get_cursor_size) {
int w, h; int w, h;
@ -199,7 +205,7 @@ wlr_buffer* CDynamicCursors::renderHardware(CPointerManager* pointers, SP<CPoint
g_pHyprOpenGL->clear(CColor{0.F, 0.F, 0.F, 0.F}); g_pHyprOpenGL->clear(CColor{0.F, 0.F, 0.F, 0.F});
// the box should start in the middle portion, rotate by our calculated amount // 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; xbox.rot = resultShown.rotation;
// use our custom draw function // use our custom draw function
@ -225,8 +231,11 @@ bool CDynamicCursors::setHardware(CPointerManager* pointers, SP<CPointerManager:
auto P_MONITOR = state->monitor.lock(); auto P_MONITOR = state->monitor.lock();
if (!P_MONITOR->output->cursor_swapchain) return false; if (!P_MONITOR->output->cursor_swapchain) return false;
// we need to transform the hotspot manually as we need to indent it by the size // we need to transform the hotspot manually as we need to indent it by the padding
const auto HOTSPOT = CBox{((pointers->currentCursorImage.hotspot * P_MONITOR->scale) + pointers->currentCursorImage.size) * resultShown.scale, {0, 0}} 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) .transform(wlTransformToHyprutils(wlr_output_transform_invert(P_MONITOR->transform)), P_MONITOR->output->cursor_swapchain->width, P_MONITOR->output->cursor_swapchain->height)
.pos(); .pos();
@ -269,12 +278,10 @@ void CDynamicCursors::onCursorMoved(CPointerManager* pointers) {
} }
void CDynamicCursors::setShape(const std::string& shape) { void CDynamicCursors::setShape(const std::string& shape) {
Debug::log(WARN, "[dynamic-cursors] setting shape {}", shape);
g_pShapeRuleHandler->activate(shape); g_pShapeRuleHandler->activate(shape);
} }
void CDynamicCursors::unsetShape() { void CDynamicCursors::unsetShape() {
Debug::log(WARN, "[dynamic-cursors] setting shape to clientside");
g_pShapeRuleHandler->activate("clientside"); g_pShapeRuleHandler->activate("clientside");
} }