Skip to content

Commit 2c8a4bc

Browse files
committed
Hyprland: X11 filtered as before with xwayland:scale off, popups follow the switch
With xwayland:scale at 0, an X11 window enlarged by the monitor scale (force_zero_scaling off) is drawn with nearest neighbour again when xwayland:use_nearest_neighbor asks for it; only a window drawn at the X11 scale is filtered linearly. A menu or tooltip of a window under xwayland_unscaled is placed in its owner's pixels only while xwayland:unscaled_windows is on, so turning the switch off restores its position as well as its size. Both found by the review of omacom/omarchy-pkgs#1757.
1 parent e19e441 commit 2c8a4bc

3 files changed

Lines changed: 36 additions & 30 deletions

File tree

‎patches/hyprland-xwayland-scale.patch‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ index 7636325..e7c6113 100644
435435
WINDOW_RULE_EFFECT_LAST_STATIC,
436436
};
437437
diff --git a/src/desktop/view/Window.cpp b/src/desktop/view/Window.cpp
438-
index 8836f73..4088113 100644
438+
index 8836f73..926df06 100644
439439
--- a/src/desktop/view/Window.cpp
440440
+++ b/src/desktop/view/Window.cpp
441441
@@ -44,6 +44,7 @@
@@ -464,7 +464,7 @@ index 8836f73..4088113 100644
464464

465465
return REPORTSIZE;
466466
}
467-
@@ -1706,27 +1704,80 @@ Vector2D CWindow::realToReportPosition() {
467+
@@ -1706,27 +1704,81 @@ Vector2D CWindow::realToReportPosition() {
468468
}
469469

470470
Vector2D CWindow::xwaylandSizeToReal(Vector2D size) {
@@ -481,7 +481,8 @@ index 8836f73..4088113 100644
481481

482482
Vector2D CWindow::xwaylandPositionToReal(Vector2D pos) {
483483
+ // a menu or tooltip of an app that draws unscaled lies in its window's pixels, enlarged with them
484-
+ if (isX11OverrideRedirect()) {
484+
+ static auto PUNSCALED = CConfigValue<Config::BOOL>("xwayland:unscaled_windows");
485+
+ if (isX11OverrideRedirect() && *PUNSCALED) {
485486
+ if (const auto OWNER = x11UnscaledOwner(); OWNER && OWNER->m_xwaylandSurface)
486487
+ return OWNER->m_realPosition->goal() + (pos - OWNER->m_xwaylandSurface->m_geometry.pos());
487488
+ }
@@ -557,7 +558,7 @@ index 8836f73..4088113 100644
557558
}
558559

559560
void CWindow::sendWindowSize(bool force) {
560-
@@ -1859,8 +1910,10 @@ SP<CWLSurfaceResource> CWindow::getSolitaryResource() {
561+
@@ -1859,8 +1911,10 @@ SP<CWLSurfaceResource> CWindow::getSolitaryResource() {
561562
}
562563

563564
Vector2D CWindow::getReportedSize() {
@@ -569,7 +570,7 @@ index 8836f73..4088113 100644
569570
if (m_wlSurface && m_wlSurface->resource())
570571
return m_wlSurface->resource()->m_current.ackedSize;
571572
return m_reportedSize;
572-
@@ -2546,11 +2599,8 @@ void CWindow::mapWindow() {
573+
@@ -2546,11 +2600,8 @@ void CWindow::mapWindow() {
573574
if (m_workspace)
574575
m_workspace->updateWindows();
575576

@@ -583,7 +584,7 @@ index 8836f73..4088113 100644
583584

584585
Event::bus()->m_events.window.openLate.emit(m_self.lock());
585586
}
586-
@@ -2854,12 +2904,9 @@ void CWindow::unmanagedSetGeometry() {
587+
@@ -2854,12 +2905,9 @@ void CWindow::unmanagedSetGeometry() {
587588
return;
588589
}
589590

@@ -599,7 +600,7 @@ index 8836f73..4088113 100644
599600

600601
if (abs(std::floor(POS.x) - LOGICALPOS.x) > 2 || abs(std::floor(POS.y) - LOGICALPOS.y) > 2 || abs(std::floor(SIZ.x) - LOGICALGEOSIZE.x) > 2 ||
601602
abs(std::floor(SIZ.y) - LOGICALGEOSIZE.y) > 2) {
602-
@@ -2893,7 +2940,10 @@ std::optional<Vector2D> CWindow::minSize() {
603+
@@ -2893,7 +2941,10 @@ std::optional<Vector2D> CWindow::minSize() {
603604
if ((m_isX11 && !hasSizeHints) || (!m_isX11 && !hasTopLevel))
604605
return std::nullopt;
605606

@@ -611,7 +612,7 @@ index 8836f73..4088113 100644
611612

612613
minSize = minSize.clamp({1, 1});
613614

614-
@@ -2913,10 +2963,11 @@ std::optional<Vector2D> CWindow::maxSize() {
615+
@@ -2913,10 +2964,11 @@ std::optional<Vector2D> CWindow::maxSize() {
615616

616617
Vector2D maxSize = m_isX11 ? Vector2D(m_xwaylandSurface->m_sizeHints->max_width, m_xwaylandSurface->m_sizeHints->max_height) : m_xdgSurface->m_toplevel->layoutMaxSize();
617618

@@ -1090,7 +1091,7 @@ index 346bfe8..48e5d36 100644
10901091
friend class CXWaylandShellResource;
10911092
};
10921093
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
1093-
index 249f084..dbd4050 100644
1094+
index 249f084..e3249aa 100644
10941095
--- a/src/render/Renderer.cpp
10951096
+++ b/src/render/Renderer.cpp
10961097
@@ -20,6 +20,7 @@
@@ -1101,18 +1102,20 @@ index 249f084..dbd4050 100644
11011102
#include "../protocols/PresentationTime.hpp"
11021103
#include "../protocols/core/DataDevice.hpp"
11031104
#include "../protocols/core/Compositor.hpp"
1104-
@@ -671,7 +672,14 @@ void IHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T
1105+
@@ -671,7 +672,16 @@ void IHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T
11051106
}
11061107

11071108
static auto PXWLUSENN = CConfigValue<Config::INTEGER>("xwayland:use_nearest_neighbor");
11081109
- if ((pWindow->m_isX11 && *PXWLUSENN) || pWindow->m_ruleApplicator->nearestNeighbor().valueOrDefault())
1109-
+ // an X11 window drawn at another scale than the monitor's is filtered linearly unless each
1110-
+ // of its pixels becomes a whole number of the monitor's: nearest neighbour would drop whole
1111-
+ // rows of a window drawn at a higher scale (the one X11 scale for every monitor), and
1112-
+ // double some rows and not others of one enlarged by 1.6 (an unscaled window)
1110+
+ static auto PXWLSCALE = CConfigValue<Config::FLOAT>("xwayland:scale");
1111+
+ // with xwayland:scale, an X11 window drawn at another scale than the monitor's is filtered
1112+
+ // linearly unless each of its pixels becomes a whole number of the monitor's: nearest
1113+
+ // neighbour would drop whole rows of a window drawn at a higher scale (the one X11 scale for
1114+
+ // every monitor), and double some rows and not others of one enlarged by 1.6 (an unscaled
1115+
+ // window). Without it, X11 is filtered as it always was.
11131116
+ const float XWLBUFFERSCALE = pWindow->m_isX11 ? pWindow->x11PixelScale() : 1.F;
11141117
+ const float XWLRATIO = pMonitor->m_scale / XWLBUFFERSCALE;
1115-
+ const bool XWLRESAMPLED = pWindow->m_isX11 && (XWLRATIO < 0.999F || std::abs(XWLRATIO - std::round(XWLRATIO)) > 0.001F);
1118+
+ const bool XWLRESAMPLED = pWindow->m_isX11 && *PXWLSCALE != 0.F && (XWLRATIO < 0.999F || std::abs(XWLRATIO - std::round(XWLRATIO)) > 0.001F);
11161119
+ if ((pWindow->m_isX11 && *PXWLUSENN && !XWLRESAMPLED) || pWindow->m_ruleApplicator->nearestNeighbor().valueOrDefault())
11171120
renderdata.useNearestNeighbor = true;
11181121

‎pkg/hyprland/overlay.bash‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# >>> xscale: Hyprland with xwayland:scale and the xwayland_unscaled rule
22
# (patches/hyprland-xwayland-scale.patch). Raise _xscale_release whenever the
33
# patch changes, so the change is built and installed as a new release.
4-
_xscale_release=4
4+
_xscale_release=5
55
_xscale_patch=hyprland-xwayland-scale.patch
66
_xscale_dir=hyprland-source

‎upstream/omarchy/xwayland-scale.patch‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ index 7636325..e7c6113 100644
245245
WINDOW_RULE_EFFECT_LAST_STATIC,
246246
};
247247
diff --git a/src/desktop/view/Window.cpp b/src/desktop/view/Window.cpp
248-
index 8836f73..0d2a37b 100644
248+
index 8836f73..4c4cd36 100644
249249
--- a/src/desktop/view/Window.cpp
250250
+++ b/src/desktop/view/Window.cpp
251251
@@ -1686,14 +1686,11 @@ Vector2D CWindow::realToReportSize() {
@@ -266,7 +266,7 @@ index 8836f73..0d2a37b 100644
266266

267267
return REPORTSIZE;
268268
}
269-
@@ -1706,27 +1703,77 @@ Vector2D CWindow::realToReportPosition() {
269+
@@ -1706,27 +1703,78 @@ Vector2D CWindow::realToReportPosition() {
270270
}
271271

272272
Vector2D CWindow::xwaylandSizeToReal(Vector2D size) {
@@ -283,7 +283,8 @@ index 8836f73..0d2a37b 100644
283283

284284
Vector2D CWindow::xwaylandPositionToReal(Vector2D pos) {
285285
+ // a menu or tooltip of an app that draws unscaled lies in its window's pixels, enlarged with them
286-
+ if (isX11OverrideRedirect()) {
286+
+ static auto PUNSCALED = CConfigValue<Config::BOOL>("xwayland:unscaled_windows");
287+
+ if (isX11OverrideRedirect() && *PUNSCALED) {
287288
+ if (const auto OWNER = x11UnscaledOwner(); OWNER && OWNER->m_xwaylandSurface)
288289
+ return OWNER->m_realPosition->goal() + (pos - OWNER->m_xwaylandSurface->m_geometry.pos());
289290
+ }
@@ -356,7 +357,7 @@ index 8836f73..0d2a37b 100644
356357
}
357358

358359
void CWindow::sendWindowSize(bool force) {
359-
@@ -2546,11 +2593,8 @@ void CWindow::mapWindow() {
360+
@@ -2546,11 +2594,8 @@ void CWindow::mapWindow() {
360361
if (m_workspace)
361362
m_workspace->updateWindows();
362363

@@ -370,7 +371,7 @@ index 8836f73..0d2a37b 100644
370371

371372
Event::bus()->m_events.window.openLate.emit(m_self.lock());
372373
}
373-
@@ -2854,12 +2898,9 @@ void CWindow::unmanagedSetGeometry() {
374+
@@ -2854,12 +2899,9 @@ void CWindow::unmanagedSetGeometry() {
374375
return;
375376
}
376377

@@ -386,7 +387,7 @@ index 8836f73..0d2a37b 100644
386387

387388
if (abs(std::floor(POS.x) - LOGICALPOS.x) > 2 || abs(std::floor(POS.y) - LOGICALPOS.y) > 2 || abs(std::floor(SIZ.x) - LOGICALGEOSIZE.x) > 2 ||
388389
abs(std::floor(SIZ.y) - LOGICALGEOSIZE.y) > 2) {
389-
@@ -2893,7 +2934,10 @@ std::optional<Vector2D> CWindow::minSize() {
390+
@@ -2893,7 +2935,10 @@ std::optional<Vector2D> CWindow::minSize() {
390391
if ((m_isX11 && !hasSizeHints) || (!m_isX11 && !hasTopLevel))
391392
return std::nullopt;
392393

@@ -398,7 +399,7 @@ index 8836f73..0d2a37b 100644
398399

399400
minSize = minSize.clamp({1, 1});
400401

401-
@@ -2913,10 +2957,11 @@ std::optional<Vector2D> CWindow::maxSize() {
402+
@@ -2913,10 +2958,11 @@ std::optional<Vector2D> CWindow::maxSize() {
402403

403404
Vector2D maxSize = m_isX11 ? Vector2D(m_xwaylandSurface->m_sizeHints->max_width, m_xwaylandSurface->m_sizeHints->max_height) : m_xdgSurface->m_toplevel->layoutMaxSize();
404405

@@ -723,21 +724,23 @@ index f139af4..5e81959 100644
723724
if (m_resource->version() < OUTPUT_DONE_DEPRECATED_SINCE_VERSION)
724725
m_resource->sendDone();
725726
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
726-
index 249f084..28ad1b7 100644
727+
index 249f084..60760d7 100644
727728
--- a/src/render/Renderer.cpp
728729
+++ b/src/render/Renderer.cpp
729-
@@ -671,7 +671,14 @@ void IHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T
730+
@@ -671,7 +671,16 @@ void IHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, const T
730731
}
731732

732733
static auto PXWLUSENN = CConfigValue<Config::INTEGER>("xwayland:use_nearest_neighbor");
733734
- if ((pWindow->m_isX11 && *PXWLUSENN) || pWindow->m_ruleApplicator->nearestNeighbor().valueOrDefault())
734-
+ // an X11 window drawn at another scale than the monitor's is filtered linearly unless each
735-
+ // of its pixels becomes a whole number of the monitor's: nearest neighbour would drop whole
736-
+ // rows of a window drawn at a higher scale (the one X11 scale for every monitor), and
737-
+ // double some rows and not others of one enlarged by 1.6 (an unscaled window)
735+
+ static auto PXWLSCALE = CConfigValue<Config::FLOAT>("xwayland:scale");
736+
+ // with xwayland:scale, an X11 window drawn at another scale than the monitor's is filtered
737+
+ // linearly unless each of its pixels becomes a whole number of the monitor's: nearest
738+
+ // neighbour would drop whole rows of a window drawn at a higher scale (the one X11 scale for
739+
+ // every monitor), and double some rows and not others of one enlarged by 1.6 (an unscaled
740+
+ // window). Without it, X11 is filtered as it always was.
738741
+ const float XWLBUFFERSCALE = pWindow->m_isX11 ? pWindow->x11PixelScale() : 1.F;
739742
+ const float XWLRATIO = pMonitor->m_scale / XWLBUFFERSCALE;
740-
+ const bool XWLRESAMPLED = pWindow->m_isX11 && (XWLRATIO < 0.999F || std::abs(XWLRATIO - std::round(XWLRATIO)) > 0.001F);
743+
+ const bool XWLRESAMPLED = pWindow->m_isX11 && *PXWLSCALE != 0.F && (XWLRATIO < 0.999F || std::abs(XWLRATIO - std::round(XWLRATIO)) > 0.001F);
741744
+ if ((pWindow->m_isX11 && *PXWLUSENN && !XWLRESAMPLED) || pWindow->m_ruleApplicator->nearestNeighbor().valueOrDefault())
742745
renderdata.useNearestNeighbor = true;
743746

0 commit comments

Comments
 (0)