@@ -14,8 +14,10 @@ logical size itself, so a window is pixel for pixel on a monitor of that
1414scale, downscaled with linear filtering on a lower one, and never upscaled.
1515It needs nothing of Xwayland and changes no protocol. An X11 cursor is
1616shown the same way, at its size divided by the X11 scale of the window under
17- it, so an app that draws its cursor at the X11 scale gets one the size of
18- Hyprland's own.
17+ it, but not below Hyprland's cursor size. An app that draws its cursor at
18+ the X11 scale (GTK, Qt) and one that takes XCURSOR_SIZE as it is (Chromium
19+ and Electron apps, Steam, Wine) both get one the size of Hyprland's own, and
20+ a cursor drawn smaller than that is shown at its own size, as today.
1921
2022The scale is laid out with the monitors, so a config reload that changes
2123only xwayland:scale lays them out again, as a monitor change does.
@@ -488,25 +490,29 @@ index c870853..4704402 100644
488490 result += pMonitor->m_position;
489491
490492diff --git a/src/pointer/PointerManager.cpp b/src/pointer/PointerManager.cpp
491- index 54eb8cb..e51f3b8 100644
493+ index 54eb8cb..db8e9d3 100644
492494--- a/src/pointer/PointerManager.cpp
493495+++ b/src/pointer/PointerManager.cpp
494- @@ -23,6 +23,8 @@
496+ @@ -23,6 +23,9 @@
495497 #include "../helpers/Drm.hpp"
496498 #include "../event/EventBus.hpp"
497499 #include "../state/MonitorState.hpp"
498500+ #include "../desktop/view/window/Window.hpp"
499501+ #include "../xwayland/XWayland.hpp"
502+ + #include "cursor/CursorManager.hpp"
500503 #include <climits>
501504 #include <cstring>
502505 #include <gbm.h>
503- @@ -34,6 +36,22 @@
506+ @@ -34,6 +37,34 @@
504507 using namespace Hyprutils::Utils;
505508 using namespace Pointer;
506509
507- + // An X11 cursor is drawn in X11 pixels, at the size the X11 scale tells apps to draw it: with
508- + // xwayland:scale it is shown, as the X11 window under it is, at its size divided by that window's
509- + // X11 scale. Without xwayland:scale it is shown at its size, as before.
510+ + // An X11 cursor is drawn in X11 pixels. With xwayland:scale it is shown, as the X11 window under it
511+ + // is, at its size divided by that window's X11 scale, but not below the cursor size: an app told the
512+ + // scale draws its cursor at the cursor size times the scale, many take XCURSOR_SIZE as it is
513+ + // (Chromium and Electron apps, Steam, Wine) and would get theirs shrunk by the scale. A cursor drawn
514+ + // smaller than the cursor size is shown at its size. Without xwayland:scale it is shown at its size,
515+ + // as before.
510516+ static float x11CursorScale(SP<Desktop::View::CWLSurface> surf) {
511517+ if (!surf || !surf->resource() || !g_pXWayland || !g_pXWayland->m_server || surf->resource()->client() != g_pXWayland->m_server->m_xwaylandClient)
512518+ return 1.F;
@@ -517,13 +523,22 @@ index 54eb8cb..e51f3b8 100644
517523+
518524+ const auto FOCUS = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock());
519525+ const auto PWINDOW = FOCUS ? Desktop::View::CWindow::fromView(FOCUS->view()) : nullptr;
520- + return PWINDOW && PWINDOW->backend().isX11() ? sc<float>(PWINDOW->backend().surfaceScale()) : 1.F;
526+ + if (!PWINDOW || !PWINDOW->backend().isX11())
527+ + return 1.F;
528+ +
529+ + const float X11SCALE = sc<float>(PWINDOW->backend().surfaceScale());
530+ + const auto BUFFER = surf->resource()->m_current.bufferSize;
531+ + const float SIZE = Cursor::mgr()->getSize();
532+ + if (X11SCALE <= 1.F || BUFFER.x <= 0 || BUFFER.y <= 0 || SIZE <= 0.F)
533+ + return X11SCALE;
534+ +
535+ + return std::clamp(sc<float>(std::max(BUFFER.x, BUFFER.y)) / SIZE, 1.F, X11SCALE);
521536+ }
522537+
523538 UP<CPointerManager>& Pointer::mgr() {
524539 static UP<CPointerManager> p = makeUnique<CPointerManager>();
525540 return p;
526- @@ -258,10 +276,12 @@ void CPointerManager::setCursorBuffers(const std::vector<SCursorImageData>& imag
541+ @@ -258,10 +289,13 @@ void CPointerManager::setCursorBuffers(const std::vector<SCursorImageData>& imag
527542 void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const Vector2D& hotspot) {
528543 damageIfSoftware();
529544
@@ -533,13 +548,14 @@ index 54eb8cb..e51f3b8 100644
533548- if (hotspot != m_currentCursorImage.hotspot || (surf && surf->resource() ? surf->resource()->m_current.scale : 1.F) != m_currentCursorImage.scale) {
534549- m_currentCursorImage.hotspot = hotspot;
535550- m_currentCursorImage.scale = surf && surf->resource() ? surf->resource()->m_current.scale : 1.F;
551+ + m_cursorSurfaceHotspot = hotspot;
536552+ if (hotspot / X11SCALE != m_currentCursorImage.hotspot || (surf && surf->resource() ? surf->resource()->m_current.scale * X11SCALE : 1.F) != m_currentCursorImage.scale) {
537553+ m_currentCursorImage.hotspot = hotspot / X11SCALE;
538554+ m_currentCursorImage.scale = surf && surf->resource() ? surf->resource()->m_current.scale * X11SCALE : 1.F;
539555 recheckEnteredOutputs();
540556 updateCursorBackend();
541557 damageIfSoftware();
542- @@ -275,7 +295 ,7 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
558+ @@ -275,7 +309 ,7 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
543559
544560 if (surf) {
545561 m_currentCursorImage.surface = surf;
@@ -548,27 +564,80 @@ index 54eb8cb..e51f3b8 100644
548564
549565 surf->resource()->m_pending.updated.bits.cursor = true;
550566
551- @@ -284,8 +304,9 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
567+ @@ -284,8 +318,11 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
552568 m_currentCursorImage.destroySurface = surf->m_events.destroy.listen([this] { resetCursorImage(); });
553569 m_currentCursorImage.commitSurface = surf->resource()->m_events.commit.listen([this] {
554570 damageIfSoftware();
555571- m_currentCursorImage.size = m_currentCursorImage.surface->resource()->m_current.texture ? m_currentCursorImage.surface->resource()->m_current.bufferSize : Vector2D{};
556572- m_currentCursorImage.scale = m_currentCursorImage.surface ? m_currentCursorImage.surface->resource()->m_current.scale : 1.F;
557573+ m_currentCursorImage.size = m_currentCursorImage.surface->resource()->m_current.texture ? m_currentCursorImage.surface->resource()->m_current.bufferSize : Vector2D{};
558- + m_currentCursorImage.scale =
559- + m_currentCursorImage.surface ? m_currentCursorImage.surface->resource()->m_current.scale * x11CursorScale(m_currentCursorImage.surface.lock()) : 1.F;
574+ + // an X11 cursor's scale follows its buffer's size, and Xwayland sets the hotspot before it commits the buffer
575+ + const float X11SCALE = x11CursorScale(m_currentCursorImage.surface.lock());
576+ + m_currentCursorImage.scale = m_currentCursorImage.surface ? m_currentCursorImage.surface->resource()->m_current.scale * X11SCALE : 1.F;
577+ + m_currentCursorImage.hotspot = m_cursorSurfaceHotspot / X11SCALE;
560578 recheckEnteredOutputs();
561579 updateCursorBackend();
562580 damageIfSoftware();
563- @@ -298,7 +319,7 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
581+ @@ -298,7 +335,8 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
564582 }
565583 }
566584
567585- m_currentCursorImage.hotspot = hotspot;
586+ + m_cursorSurfaceHotspot = hotspot;
568587+ m_currentCursorImage.hotspot = hotspot / X11SCALE;
569588
570589 recheckEnteredOutputs();
571590 updateCursorBackend();
591+ @@ -364,6 +402,7 @@ void CPointerManager::resetCursorImage(bool apply) {
592+ m_currentCursorImage.scale = 1.F;
593+ m_currentCursorImage.hotspot = {0, 0};
594+ m_currentCursorImage.size = {};
595+ + m_cursorSurfaceHotspot = {0, 0};
596+
597+ for (auto const& s : m_monitorStates) {
598+ if (s->monitor.expired() || s->monitor->isMirror() || !s->monitor->m_enabled)
599+ diff --git a/src/pointer/PointerManager.hpp b/src/pointer/PointerManager.hpp
600+ index 72e24d7..5a03057 100644
601+ --- a/src/pointer/PointerManager.hpp
602+ +++ b/src/pointer/PointerManager.hpp
603+ @@ -235,6 +235,10 @@ namespace Pointer {
604+ CHyprSignalListener monitorLayoutChanged;
605+ CHyprSignalListener monitorPreRender;
606+ } m_hooks;
607+ +
608+ + // the hotspot as the cursor surface's client set it: an X11 cursor's is in X11 pixels and scaled with its
609+ + // buffer. Last, so plugins built against Hyprland's headers before it keep their layout.
610+ + Vector2D m_cursorSurfaceHotspot;
611+ };
612+
613+ UP<CPointerManager>& mgr();
614+ diff --git a/src/pointer/cursor/CursorManager.cpp b/src/pointer/cursor/CursorManager.cpp
615+ index aafc953..f6e97ad 100644
616+ --- a/src/pointer/cursor/CursorManager.cpp
617+ +++ b/src/pointer/cursor/CursorManager.cpp
618+ @@ -402,6 +402,10 @@ void CCursorManager::syncGsettings() {
619+ m_xcursor->syncGsettings();
620+ }
621+
622+ + float CCursorManager::getSize() const {
623+ + return m_size;
624+ + }
625+ +
626+ float CCursorManager::getScaledSize() const {
627+ return m_size * m_cursorScale;
628+ }
629+ diff --git a/src/pointer/cursor/CursorManager.hpp b/src/pointer/cursor/CursorManager.hpp
630+ index e383a37..8205087 100644
631+ --- a/src/pointer/cursor/CursorManager.hpp
632+ +++ b/src/pointer/cursor/CursorManager.hpp
633+ @@ -59,6 +59,7 @@ namespace Pointer::Cursor {
634+
635+ void tickAnimatedCursor();
636+
637+ + float getSize() const;
638+ float getScaledSize() const;
639+
640+ private:
572641diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp
573642index dc4f4f9..c90e126 100644
574643--- a/src/protocols/XDGOutput.cpp
0 commit comments