🐛 Use virtual display bounds for x86 cursor crossings

IOFramebuffer exposes physical and virtual desktop rectangles. Passing
the physical rectangle to IOHIDSystem misplaced the cursor when a HiDPI
mode changed the desktop geometry without changing the scanout.

Use the virtual rectangle for pointer warps and DISPLAY_BOUNDS. Cover
mixed-scale crossings in both directions and bounds updates on a mode
switch.

Regenerate both guest prebuilt sets with Xcode 27.2 so the shipped
drivers and source records match this change.
This commit is contained in:
porcelain horse committed 2026-11-25 02:18:59 +03:00
1 parent f1c518d312
commit 4c6acb5e04
11 files changed
+65 -32

No files matched your search

+6 -6
View File
@@ -23,9 +23,9 @@
* moved the cursor yet: the latest is where the host's pointer is.
*
* Where the point lies, and the rectangles the host is told:
* - on x86-64, each framebuffer holds its display's rectangle as WindowServer placed it
* (getBoundingRect), and a move of the cursor on any display tells the host each display's
* that changed (tellBounds);
* - on x86-64, each framebuffer holds its display's virtual desktop rectangle as WindowServer
* placed it (getBoundingRect), and a move of the cursor on any display tells the host each
* virtual rectangle that changed (tellBounds);
* - on arm64, WindowServer tells the displays nothing of where it placed them, so the kext
* learns it from its own posts: a crossing posts at the display's pixel of the rectangle held
* for it, and again beside the other displays where the cursor did not reach it, at most
@@ -185,7 +185,7 @@ void ReimsGraphics::movePointer(thread_call_param_t self, thread_call_param_t)
IOSimpleLockUnlock(me->interruptLock);
if (!me->hasStarted())
return;
// The display's mode and its rectangle in the global space.
// The display's scanout size and its virtual desktop rectangle.
ReimsGraphics *fb = me->copyDisplay(me->drivenIndex(at.display));
if (!fb)
return;
@@ -221,7 +221,7 @@ void ReimsGraphics::movePointer(thread_call_param_t self, thread_call_param_t)
move == RgfxPointerMove::moved ? "moves" : "is dragged", globalX, globalY, posted);
}
// Each framebuffer holds its display's rectangle as WindowServer placed it (getBoundingRect).
// The virtual rectangles used for both IOHIDSystem posts and DISPLAY_BOUNDS.
void ReimsGraphics::displayPlaces(RgfxGlobalRect *rects, bool *placed)
{
ReimsGraphics *fbs[RGFX_DISPLAYS_MAX];
@@ -232,7 +232,7 @@ void ReimsGraphics::displayPlaces(RgfxGlobalRect *rects, bool *placed)
fbs[i]->getBoundingRect(&bounds);
if (!bounds || display >= RGFX_DISPLAYS_MAX)
continue;
rects[display] = {bounds->minx, bounds->miny, bounds->maxx, bounds->maxy};
rects[display] = rgfxFramebufferDesktopBounds(bounds);
placed[display] = true;
}
releaseDisplays(fbs, n);
+11 -2
View File
@@ -1,7 +1,7 @@
// RgfxDisplayBounds: which displays' rectangles the kext tells the host in DISPLAY_BOUNDS
// (design.md, "Multiple displays", "A drag across displays"). On x86-64 each framebuffer holds its
// display's rectangle in WindowServer's global space as WindowServer placed it (IOFBSetBounds,
// which IOFramebuffer::getBoundingRect reads; RgfxPointerOver.hpp), and on arm64 the kext holds
// display's virtual desktop rectangle as WindowServer placed it (IOFBSetBounds, which
// IOFramebuffer::getBoundingRect reads; RgfxPointerOver.hpp), and on arm64 the kext holds
// each one a landing of its own moves of the cursor confirmed (RgfxDisplayPlaces.hpp); the host
// carries its captured pointer past one display's edge onto the display whose rectangle meets it
// there. Each move of the cursor, on any display, tells the host every display's rectangle that
@@ -21,6 +21,15 @@
#include "RgfxPointerOver.hpp"
#include "reims_graphics_wire.h"
// IOFramebuffer's getBoundingRect returns its physical and virtual rectangles in order.
// IOFBSetBounds supplies both, or IOFramebuffer uses the sole rectangle for both.
template <class Bounds>
inline RgfxGlobalRect rgfxFramebufferDesktopBounds(const Bounds *bounds)
{
const Bounds &rect = bounds[1];
return {rect.minx, rect.miny, rect.maxx, rect.maxy};
}
// The rectangle the host was last told of each display, by id, where it was told one.
struct RgfxBoundsTold {
RgfxGlobalRect rects[RGFX_DISPLAYS_MAX];
+6 -10
View File
@@ -4,16 +4,12 @@
// the display its cursor is on, so the kext moves the cursor onto that display, at that point,
// before the tablet's next position comes (ReimsGraphicsPointer.cpp).
//
// The point is in WindowServer's global space, in which it placed each display: on x86-64 each
// framebuffer holds its display's rectangle there as WindowServer gave it (IOFBSetBounds, which
// IOFramebuffer::getBoundingRect reads), the space the cursor's moves arrive in
// (IOFramebuffer::extSetCursorPosition); on arm64 the kext learns each one from its own moves
// (RgfxDisplayPlaces.hpp). The display's pixel lies in that rectangle as the pixel
// lies in the display's mode, scaled from the mode's pixels to the rectangle's size. Measured on
// x86-64 macOS 11.7.11, 15.8.2 and 26.7.2 with two 1920 x 1080 displays side by side: each
// framebuffer's rectangle is the display's CGDisplayBounds, and IOHIDSystem's mouse-moved posted
// at a point of display 1's rectangle puts the cursor there (lane ptrcross, potluck jobs
// m3-max-34583 to 34585).
// IOHIDSystem's post takes a point in WindowServer's virtual desktop. On x86-64 the framebuffer
// holds the virtual rectangle WindowServer gave it (IOFBSetBounds); on arm64 the kext learns
// each rectangle from its own moves (RgfxDisplayPlaces.hpp). Scale the scanout pixels into that
// rectangle. Measured on x86-64 macOS 11.7.11, 15.8.2 and 26.7.2 with two 1920 x 1080 displays
// side by side: a mouse-moved posted at a point in display 1's CGDisplayBounds puts the cursor
// there (lane ptrcross, potluck jobs m3-max-34583 to 34585).
//
// The move is a mouse-moved where no button is held, and the drag of the button held where one is,
// as IOHIDSystem's own moves are (the left button's before the right's, the right's before any
+28
View File
@@ -19,10 +19,38 @@ void check(bool ok, const char *what)
std::exit(1);
}
}
void mixedScaleDesktop()
{
// IOFramebuffer keeps the physical and virtual desktop rectangles, in that order.
const RgfxGlobalRect framebuffers[2][2] = {
{{0, 0, 3840, 2160}, {0, 0, 1920, 1080}},
{{3840, 0, 6400, 1440}, {1920, 0, 4480, 1440}},
};
const RgfxGlobalRect left = rgfxFramebufferDesktopBounds(framebuffers[0]);
const RgfxGlobalRect right = rgfxFramebufferDesktopBounds(framebuffers[1]);
int32_t x = 0, y = 0;
check(rgfxPointerGlobal(right, 2560, 1440, 2, 653, &x, &y) && x == 1922 && y == 653,
"crossing onto the native display uses its virtual origin");
check(rgfxPointerGlobal(left, 3840, 2160, 3834, 943, &x, &y) && x == 1917 && y == 471,
"crossing back scales scanout pixels into the HiDPI desktop rectangle");
// Both displays were native before the switch. Their physical rectangles stay the same.
RgfxBoundsTold told = {};
rgfxBoundsWereTold(&told, 0, framebuffers[0][0]);
rgfxBoundsWereTold(&told, 1, framebuffers[1][0]);
check(rgfxBoundsToTell(told, 0, left) && rgfxBoundsToTell(told, 1, right),
"a HiDPI switch reports the resized display and the moved neighbor");
const RgfxDisplayBounds command = rgfxBoundsCommand(1, right);
check(command.min_x == 1920 && command.max_x == 4480 && command.max_y == 1440,
"DISPLAY_BOUNDS uses the same desktop rectangle as the pointer post");
}
} // namespace
int main()
{
mixedScaleDesktop();
// The wire's command: 40 bytes, the display then the rectangle past the 16-byte header.
check(sizeof(RgfxDisplayBounds) == 40 && RGFX_CMD_DISPLAY_BOUNDS == 9, "the wire's");
check(offsetof(RgfxDisplayBounds, display) == 16 && offsetof(RgfxDisplayBounds, min_x) == 20 &&
+1 -1
View File
@@ -34,4 +34,4 @@ Arch = "arm64e"
MinKernel = "23.0.0"
MaxKernel = ""
Comment = "Installs the reims-graphics Metal bundle and admits it"
sha256 = "45b05e7f2b33b5a29bdb90a8268888bf999cab9334572ccddf306a9cdcb75d9a"
sha256 = "f2183a5806e84c4c6a4924b138d41f37246d0c0611e51b9f126d4f7718070bf6"
+5 -5
View File
@@ -331,7 +331,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"guest/kext/src/ReimsGraphics.cpp" = "96a3ec262adf88d73d33ebcb16f9750c5c413d7de6149cfd4e5b5573ce9796d5"
"guest/kext/src/ReimsGraphics.hpp" = "48fed412033d1314c46aa685aae9b79888630d3755311d57a4198aba8847f506"
"guest/kext/src/ReimsGraphicsMobile.cpp" = "b73a2e5f5b061453817c5d0b18211a2d0782f5971f02d90b0fb7f930365086de"
"guest/kext/src/ReimsGraphicsPointer.cpp" = "255f049c3a5244a148d80fd25ef3388001ba180c58901e3620451c3158908f0e"
"guest/kext/src/ReimsGraphicsPointer.cpp" = "7b3482545b8e5e459327ab31648e32d83fd8317587b453b4133a5974fa44e35d"
"guest/kext/src/RgfxAccelTypes.hpp" = "c65e032a617cda503b2534c68bec87947d7856accda676f35a1affa145998259"
"guest/kext/src/RgfxAccelerator.cpp" = "3f5e8b8805d8fcdf08bc64c4ba2c2033d0f625b020be73f4a2b989180204974c"
"guest/kext/src/RgfxAccelerator.hpp" = "a5f4de989cdbbbe36769a836cd71a64f2f94d33701f4bf973fcf763baaff00ca"
@@ -359,7 +359,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"guest/kext/src/RgfxDeviceControl.cpp" = "53c7c6a722ef4d7edeb5756eb04091d4a56f397dc5aef83c3637b1c0f129b934"
"guest/kext/src/RgfxDeviceControl.hpp" = "c1357b80ee2141e1e2fd57213f3c9361cb497b8c6490a0b6aff8c64649be48c6"
"guest/kext/src/RgfxDeviceName.hpp" = "b242e0ccdce31c3c454bc3a4d64b13c30e574b25379a0833973dcecbbb1146d3"
"guest/kext/src/RgfxDisplayBounds.hpp" = "c1e8fe52f89bcb25ee178f4e0ea4ac53396109fd934348408692d21d1931ecf7"
"guest/kext/src/RgfxDisplayBounds.hpp" = "7aafbc6d1c2bb28e50c973f77d21c1aa00b322fb5fc934d4b1238b50f3aa89db"
"guest/kext/src/RgfxDisplayIdentity.hpp" = "ce4328b8e255f942aea0f0dc097e2e80eb4a8d7e126ea0f342fd116252357731"
"guest/kext/src/RgfxDisplayModes.hpp" = "62026ac6fa3febe5ce403fbfe026760f0434b70cc47e5d74c191fa5509ae12cd"
"guest/kext/src/RgfxDisplayPipeUserClient.cpp" = "460c7d61a305d7d145b3318bb4fbe940c0d2d48d63afbbfeb6f273cd929aa3af"
@@ -397,7 +397,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"guest/kext/src/RgfxPointerDevice.cpp" = "fa1d13465df9d9b8da4a20d9ba755fd2fa88358a4b677544ca0fd5e4a70b7378"
"guest/kext/src/RgfxPointerDevice.hpp" = "0d269566fd26cf30590c9c6ec8f38aa41201b13b2891eb3aaf314945ca29218e"
"guest/kext/src/RgfxPointerMotion.hpp" = "02fba3e9043f8d0c2f9c4038917ffc1df514b347a1b1c0a92b24b5ee67d81f78"
"guest/kext/src/RgfxPointerOver.hpp" = "c2c38dbd101b1f59400bb159bd8cb44ed8c937bf25b93e9d62a03d6c2fd9ae50"
"guest/kext/src/RgfxPointerOver.hpp" = "757946b2332ba278201f4c2f44ec1ee2bb21ca10b017a7c7933f696d8ee8f10c"
"guest/kext/src/RgfxPointerReporting.cpp" = "c9f33023f3acea2e638353e8943c65f28f8befa984989ae88e7abc24858b961e"
"guest/kext/src/RgfxPoolBlocks.hpp" = "a657b67922b04b75ccef6f12e10d775867f4037e50b89a8cf0d4972af43747fe"
"guest/kext/src/RgfxQueueLimits.hpp" = "13f8ecd60e8d19f438b8ddc1cf3a0273fba1028bc049110776b637fa2097173c"
@@ -465,5 +465,5 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"ReimsGraphics.kext/Contents/Info.plist" = "9683153587659c4bd4d5c52167eff1f3d2ae51dae575f60c15a27d89240f46c5"
"ReimsGraphics.kext/Contents/MacOS/ReimsGraphics" = "2f7a4f8a307d3655e65a37bc0a479fffed3dece132f0d7abb41addddf9554863"
"RgfxGate.kext/Contents/Info.plist" = "7b78d915fab4d36e6cdb3f40aa2a6c1e7224f30158ee879af23451d2e6969992"
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "45b05e7f2b33b5a29bdb90a8268888bf999cab9334572ccddf306a9cdcb75d9a"
"set.toml" = "1524bc0887c03c3f9727725b68b0d79090ba41a9815cdec5e3d0c80b6cf0c557"
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "f2183a5806e84c4c6a4924b138d41f37246d0c0611e51b9f126d4f7718070bf6"
"set.toml" = "9d26ef1c7e0906cb13c46e4579262fbbd763d1a160ffabfb1532025f392b9d52"
Binary file not shown.
+2 -2
View File
@@ -24,7 +24,7 @@ Arch = "x86_64"
MinKernel = "20.0.0"
MaxKernel = ""
Comment = "The reims-graphics display, accelerator and device control"
sha256 = "fe258ae0845ebf7e4ab0834254c692c70ee8931f92c9f4217473d676243b48b4"
sha256 = "9b5f2f32fe27fce248c65dada6ffbc5efa6c7c4bde861bc1bb667997a2286b15"
[[kext]]
BundlePath = "RgfxGate.kext"
@@ -34,4 +34,4 @@ Arch = "x86_64"
MinKernel = "20.0.0"
MaxKernel = ""
Comment = "Installs the reims-graphics Metal bundle and admits it"
sha256 = "532c1d6893e6a466437126481670d8080c7fe70bc42543fd10c49ca8d23c8992"
sha256 = "a88984abbc52afd247993fb0991ae1c8d95f05df87454191a64a0867b25ad7b5"
+6 -6
View File
@@ -331,7 +331,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"guest/kext/src/ReimsGraphics.cpp" = "96a3ec262adf88d73d33ebcb16f9750c5c413d7de6149cfd4e5b5573ce9796d5"
"guest/kext/src/ReimsGraphics.hpp" = "48fed412033d1314c46aa685aae9b79888630d3755311d57a4198aba8847f506"
"guest/kext/src/ReimsGraphicsMobile.cpp" = "b73a2e5f5b061453817c5d0b18211a2d0782f5971f02d90b0fb7f930365086de"
"guest/kext/src/ReimsGraphicsPointer.cpp" = "255f049c3a5244a148d80fd25ef3388001ba180c58901e3620451c3158908f0e"
"guest/kext/src/ReimsGraphicsPointer.cpp" = "7b3482545b8e5e459327ab31648e32d83fd8317587b453b4133a5974fa44e35d"
"guest/kext/src/RgfxAccelTypes.hpp" = "c65e032a617cda503b2534c68bec87947d7856accda676f35a1affa145998259"
"guest/kext/src/RgfxAccelerator.cpp" = "3f5e8b8805d8fcdf08bc64c4ba2c2033d0f625b020be73f4a2b989180204974c"
"guest/kext/src/RgfxAccelerator.hpp" = "a5f4de989cdbbbe36769a836cd71a64f2f94d33701f4bf973fcf763baaff00ca"
@@ -359,7 +359,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"guest/kext/src/RgfxDeviceControl.cpp" = "53c7c6a722ef4d7edeb5756eb04091d4a56f397dc5aef83c3637b1c0f129b934"
"guest/kext/src/RgfxDeviceControl.hpp" = "c1357b80ee2141e1e2fd57213f3c9361cb497b8c6490a0b6aff8c64649be48c6"
"guest/kext/src/RgfxDeviceName.hpp" = "b242e0ccdce31c3c454bc3a4d64b13c30e574b25379a0833973dcecbbb1146d3"
"guest/kext/src/RgfxDisplayBounds.hpp" = "c1e8fe52f89bcb25ee178f4e0ea4ac53396109fd934348408692d21d1931ecf7"
"guest/kext/src/RgfxDisplayBounds.hpp" = "7aafbc6d1c2bb28e50c973f77d21c1aa00b322fb5fc934d4b1238b50f3aa89db"
"guest/kext/src/RgfxDisplayIdentity.hpp" = "ce4328b8e255f942aea0f0dc097e2e80eb4a8d7e126ea0f342fd116252357731"
"guest/kext/src/RgfxDisplayModes.hpp" = "62026ac6fa3febe5ce403fbfe026760f0434b70cc47e5d74c191fa5509ae12cd"
"guest/kext/src/RgfxDisplayPipeUserClient.cpp" = "460c7d61a305d7d145b3318bb4fbe940c0d2d48d63afbbfeb6f273cd929aa3af"
@@ -397,7 +397,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"guest/kext/src/RgfxPointerDevice.cpp" = "fa1d13465df9d9b8da4a20d9ba755fd2fa88358a4b677544ca0fd5e4a70b7378"
"guest/kext/src/RgfxPointerDevice.hpp" = "0d269566fd26cf30590c9c6ec8f38aa41201b13b2891eb3aaf314945ca29218e"
"guest/kext/src/RgfxPointerMotion.hpp" = "02fba3e9043f8d0c2f9c4038917ffc1df514b347a1b1c0a92b24b5ee67d81f78"
"guest/kext/src/RgfxPointerOver.hpp" = "c2c38dbd101b1f59400bb159bd8cb44ed8c937bf25b93e9d62a03d6c2fd9ae50"
"guest/kext/src/RgfxPointerOver.hpp" = "757946b2332ba278201f4c2f44ec1ee2bb21ca10b017a7c7933f696d8ee8f10c"
"guest/kext/src/RgfxPointerReporting.cpp" = "c9f33023f3acea2e638353e8943c65f28f8befa984989ae88e7abc24858b961e"
"guest/kext/src/RgfxPoolBlocks.hpp" = "a657b67922b04b75ccef6f12e10d775867f4037e50b89a8cf0d4972af43747fe"
"guest/kext/src/RgfxQueueLimits.hpp" = "13f8ecd60e8d19f438b8ddc1cf3a0273fba1028bc049110776b637fa2097173c"
@@ -463,7 +463,7 @@ clang = "Apple clang version 21.0.0 (clang-2100.4.1.1)"
"Graft.kext/Contents/Info.plist" = "fa8533d5ec06430f3ede502e6f9e739e9c8c3f6b6909c46d854effe6028cbc7f"
"Graft.kext/Contents/MacOS/Graft" = "04a1d44c0c80c20a71f3a662c46b56a1732b8134f095fb2ac57ec790f72baf72"
"ReimsGraphics.kext/Contents/Info.plist" = "ae0dafd3b6c36c24d1c92467d8203d76360eb6e4f6ad5c496167a21033b2c209"
"ReimsGraphics.kext/Contents/MacOS/ReimsGraphics" = "fe258ae0845ebf7e4ab0834254c692c70ee8931f92c9f4217473d676243b48b4"
"ReimsGraphics.kext/Contents/MacOS/ReimsGraphics" = "9b5f2f32fe27fce248c65dada6ffbc5efa6c7c4bde861bc1bb667997a2286b15"
"RgfxGate.kext/Contents/Info.plist" = "7b78d915fab4d36e6cdb3f40aa2a6c1e7224f30158ee879af23451d2e6969992"
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "532c1d6893e6a466437126481670d8080c7fe70bc42543fd10c49ca8d23c8992"
"set.toml" = "055e2653b27ff3a596e904a2bca0cc6df7d1029383bb17c09599175c8d0aa0bf"
"RgfxGate.kext/Contents/MacOS/RgfxGate" = "a88984abbc52afd247993fb0991ae1c8d95f05df87454191a64a0867b25ad7b5"
"set.toml" = "bb9796c599a2ef0a01727c0ba22734fb75d84cc0fc3bfc2ec20b28f946378396"