Skip to content

Commit 2dfd5bc

Browse files
committed
upstream/omarchy: X11 cursors no smaller than Hyprland's own
Chromium and Electron apps, Steam and Wine draw XCURSOR_SIZE as it is, so dividing their cursor by the X11 scale made it half the size of Hyprland's. An X11 cursor is now divided by the X11 scale only down to Hyprland's cursor size, and its hotspot is set again when Xwayland commits the new buffer. Both patches, 0.56.2 (as in omacom/omarchy-pkgs#1757) and 0.57.0.
1 parent f645d8b commit 2dfd5bc

3 files changed

Lines changed: 173 additions & 31 deletions

File tree

‎upstream/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ change as proposed there in
1717
`patches/hyprland-xwayland-scale.patch` without the `xwayland_shell_v1`
1818
version 2 part. Hyprland lays X11 out at `xwayland:scale` and scales X11
1919
windows and cursors down to their logical size itself, so it works with
20-
Arch's stock Xwayland and changes no protocol. With the version 2 part on top,
20+
Arch's stock Xwayland and changes no protocol. An X11 cursor is shown at its
21+
size divided by the X11 scale, but never below Hyprland's cursor size: GTK and
22+
Qt draw theirs at `XCURSOR_SIZE` times the scale, while Chromium and Electron
23+
apps, Steam and Wine draw `XCURSOR_SIZE` as it is, and both come out the size
24+
of Hyprland's own cursor. With the version 2 part on top,
2125
an Xwayland that takes the scale shows its windows at their logical size
2226
itself, and Hyprland leaves them as they come.
2327

‎upstream/omarchy/xwayland-scale-0.57.0.patch‎

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ logical size itself, so a window is pixel for pixel on a monitor of that
1414
scale, downscaled with linear filtering on a lower one, and never upscaled.
1515
It needs nothing of Xwayland and changes no protocol. An X11 cursor is
1616
shown 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

2022
The scale is laid out with the monitors, so a config reload that changes
2123
only 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

490492
diff --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:
572641
diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp
573642
index dc4f4f9..c90e126 100644
574643
--- a/src/protocols/XDGOutput.cpp

‎upstream/omarchy/xwayland-scale.patch‎

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ logical size itself, so a window is pixel for pixel on a monitor of that
1414
scale, downscaled with linear filtering on a lower one, and never upscaled.
1515
It needs nothing of Xwayland and changes no protocol. An X11 cursor is
1616
shown 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

2022
The scale is laid out with the monitors, so a config reload that changes
2123
only xwayland:scale lays them out again, as a monitor change does.
@@ -586,25 +588,29 @@ index b1a547c..55f92e2 100644
586588
result += pMonitor->m_position;
587589

588590
diff --git a/src/pointer/PointerManager.cpp b/src/pointer/PointerManager.cpp
589-
index e3e81af..216361a 100644
591+
index e3e81af..0639adf 100644
590592
--- a/src/pointer/PointerManager.cpp
591593
+++ b/src/pointer/PointerManager.cpp
592-
@@ -22,6 +22,8 @@
594+
@@ -22,6 +22,9 @@
593595
#include "../helpers/Drm.hpp"
594596
#include "../event/EventBus.hpp"
595597
#include "../state/MonitorState.hpp"
596598
+#include "../desktop/view/Window.hpp"
597599
+#include "../xwayland/XWayland.hpp"
600+
+#include "cursor/CursorManager.hpp"
598601
#include <climits>
599602
#include <cstring>
600603
#include <gbm.h>
601-
@@ -33,6 +35,22 @@
604+
@@ -33,6 +36,34 @@
602605
using namespace Hyprutils::Utils;
603606
using namespace Pointer;
604607

605-
+// An X11 cursor is drawn in X11 pixels, at the size the X11 scale tells apps to draw it: with
606-
+// xwayland:scale it is shown, as the X11 window under it is, at its size divided by that window's
607-
+// X11 scale. Without xwayland:scale it is shown at its size, as before.
608+
+// An X11 cursor is drawn in X11 pixels. With xwayland:scale it is shown, as the X11 window under it
609+
+// is, at its size divided by that window's X11 scale, but not below the cursor size: an app told the
610+
+// scale draws its cursor at the cursor size times the scale, many take XCURSOR_SIZE as it is
611+
+// (Chromium and Electron apps, Steam, Wine) and would get theirs shrunk by the scale. A cursor drawn
612+
+// smaller than the cursor size is shown at its size. Without xwayland:scale it is shown at its size,
613+
+// as before.
608614
+static float x11CursorScale(SP<Desktop::View::CWLSurface> surf) {
609615
+ static auto PXWLSCALE = CConfigValue<Config::FLOAT>("xwayland:scale");
610616
+ if (*PXWLSCALE == 0.F || !surf || !surf->resource())
@@ -615,13 +621,22 @@ index e3e81af..216361a 100644
615621
+
616622
+ const auto FOCUS = Desktop::View::CWLSurface::fromResource(g_pSeatManager->m_state.pointerFocus.lock());
617623
+ const auto PWINDOW = FOCUS ? Desktop::View::CWindow::fromView(FOCUS->view()) : nullptr;
618-
+ return PWINDOW && PWINDOW->m_isX11 ? PWINDOW->x11PixelScale() : 1.F;
624+
+ if (!PWINDOW || !PWINDOW->m_isX11)
625+
+ return 1.F;
626+
+
627+
+ const float X11SCALE = PWINDOW->x11PixelScale();
628+
+ const auto BUFFER = surf->resource()->m_current.bufferSize;
629+
+ const float SIZE = Cursor::mgr()->getSize();
630+
+ if (X11SCALE <= 1.F || BUFFER.x <= 0 || BUFFER.y <= 0 || SIZE <= 0.F)
631+
+ return X11SCALE;
632+
+
633+
+ return std::clamp(sc<float>(std::max(BUFFER.x, BUFFER.y)) / SIZE, 1.F, X11SCALE);
619634
+}
620635
+
621636
UP<CPointerManager>& Pointer::mgr() {
622637
static UP<CPointerManager> p = makeUnique<CPointerManager>();
623638
return p;
624-
@@ -156,10 +174,12 @@ void CPointerManager::setCursorBuffer(SP<Aquamarine::IBuffer> buf, const Vector2
639+
@@ -156,10 +187,13 @@ void CPointerManager::setCursorBuffer(SP<Aquamarine::IBuffer> buf, const Vector2
625640
void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const Vector2D& hotspot) {
626641
damageIfSoftware();
627642

@@ -631,13 +646,14 @@ index e3e81af..216361a 100644
631646
- if (hotspot != m_currentCursorImage.hotspot || (surf && surf->resource() ? surf->resource()->m_current.scale : 1.F) != m_currentCursorImage.scale) {
632647
- m_currentCursorImage.hotspot = hotspot;
633648
- m_currentCursorImage.scale = surf && surf->resource() ? surf->resource()->m_current.scale : 1.F;
649+
+ m_cursorSurfaceHotspot = hotspot;
634650
+ if (hotspot / X11SCALE != m_currentCursorImage.hotspot || (surf && surf->resource() ? surf->resource()->m_current.scale * X11SCALE : 1.F) != m_currentCursorImage.scale) {
635651
+ m_currentCursorImage.hotspot = hotspot / X11SCALE;
636652
+ m_currentCursorImage.scale = surf && surf->resource() ? surf->resource()->m_current.scale * X11SCALE : 1.F;
637653
updateCursorBackend();
638654
damageIfSoftware();
639655
m_events.cursorChanged.emit();
640-
@@ -172,7 +192,7 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
656+
@@ -172,7 +206,7 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
641657

642658
if (surf) {
643659
m_currentCursorImage.surface = surf;
@@ -646,25 +662,78 @@ index e3e81af..216361a 100644
646662

647663
surf->resource()->map();
648664

649-
@@ -180,7 +200,8 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
665+
@@ -180,7 +214,10 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
650666
m_currentCursorImage.commitSurface = surf->resource()->m_events.commit.listen([this] {
651667
damageIfSoftware();
652668
m_currentCursorImage.size = m_currentCursorImage.surface->resource()->m_current.texture ? m_currentCursorImage.surface->resource()->m_current.bufferSize : Vector2D{};
653669
- m_currentCursorImage.scale = m_currentCursorImage.surface ? m_currentCursorImage.surface->resource()->m_current.scale : 1.F;
654-
+ m_currentCursorImage.scale =
655-
+ m_currentCursorImage.surface ? m_currentCursorImage.surface->resource()->m_current.scale * x11CursorScale(m_currentCursorImage.surface.lock()) : 1.F;
670+
+ // an X11 cursor's scale follows its buffer's size, and Xwayland sets the hotspot before it commits the buffer
671+
+ const float X11SCALE = x11CursorScale(m_currentCursorImage.surface.lock());
672+
+ m_currentCursorImage.scale = m_currentCursorImage.surface ? m_currentCursorImage.surface->resource()->m_current.scale * X11SCALE : 1.F;
673+
+ m_currentCursorImage.hotspot = m_cursorSurfaceHotspot / X11SCALE;
656674
recheckEnteredOutputs();
657675
updateCursorBackend();
658676
damageIfSoftware();
659-
@@ -193,7 +214,7 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
677+
@@ -193,7 +230,8 @@ void CPointerManager::setCursorSurface(SP<Desktop::View::CWLSurface> surf, const
660678
}
661679
}
662680

663681
- m_currentCursorImage.hotspot = hotspot;
682+
+ m_cursorSurfaceHotspot = hotspot;
664683
+ m_currentCursorImage.hotspot = hotspot / X11SCALE;
665684

666685
recheckEnteredOutputs();
667686
updateCursorBackend();
687+
@@ -259,6 +297,7 @@ void CPointerManager::resetCursorImage(bool apply) {
688+
689+
m_currentCursorImage.scale = 1.F;
690+
m_currentCursorImage.hotspot = {0, 0};
691+
+ m_cursorSurfaceHotspot = {0, 0};
692+
693+
for (auto const& s : m_monitorStates) {
694+
if (s->monitor.expired() || s->monitor->isMirror() || !s->monitor->m_enabled)
695+
diff --git a/src/pointer/PointerManager.hpp b/src/pointer/PointerManager.hpp
696+
index 867473f..b8ccdab 100644
697+
--- a/src/pointer/PointerManager.hpp
698+
+++ b/src/pointer/PointerManager.hpp
699+
@@ -196,6 +196,10 @@ namespace Pointer {
700+
CHyprSignalListener monitorLayoutChanged;
701+
CHyprSignalListener monitorPreRender;
702+
} m_hooks;
703+
+
704+
+ // the hotspot as the cursor surface's client set it: an X11 cursor's is in X11 pixels and scaled with its
705+
+ // buffer. Last, so plugins built against Hyprland's headers before it keep their layout.
706+
+ Vector2D m_cursorSurfaceHotspot;
707+
};
708+
709+
UP<CPointerManager>& mgr();
710+
diff --git a/src/pointer/cursor/CursorManager.cpp b/src/pointer/cursor/CursorManager.cpp
711+
index ef95100..f25a0b2 100644
712+
--- a/src/pointer/cursor/CursorManager.cpp
713+
+++ b/src/pointer/cursor/CursorManager.cpp
714+
@@ -352,6 +352,10 @@ void CCursorManager::syncGsettings() {
715+
m_xcursor->syncGsettings();
716+
}
717+
718+
+float CCursorManager::getSize() const {
719+
+ return m_size;
720+
+}
721+
+
722+
float CCursorManager::getScaledSize() const {
723+
return m_size * m_cursorScale;
724+
}
725+
diff --git a/src/pointer/cursor/CursorManager.hpp b/src/pointer/cursor/CursorManager.hpp
726+
index 7ff98a4..0f8d72e 100644
727+
--- a/src/pointer/cursor/CursorManager.hpp
728+
+++ b/src/pointer/cursor/CursorManager.hpp
729+
@@ -56,6 +56,7 @@ namespace Pointer::Cursor {
730+
731+
void tickAnimatedCursor();
732+
733+
+ float getSize() const;
734+
float getScaledSize() const;
735+
736+
private:
668737
diff --git a/src/protocols/PointerConstraints.cpp b/src/protocols/PointerConstraints.cpp
669738
index 0cfefed..c494832 100644
670739
--- a/src/protocols/PointerConstraints.cpp

0 commit comments

Comments
 (0)