diff --git a/docs/capture-protocol.md b/docs/capture-protocol.md index 3c98162..16e8ef5 100644 --- a/docs/capture-protocol.md +++ b/docs/capture-protocol.md @@ -50,6 +50,13 @@ the managed prefix configuration. It is never a global shared-memory name. ## Geometry and session changes +An exact Wine monitor rectangle maps onto the entire selected frame when their +aspect ratios match. Pixel dimensions may differ under fractional scaling, where +Xwayland's render size can exceed the portal's native frame size. Partial regions +and whole-virtual-desktop requests retain the existing virtual-desktop mapping. +This does not establish monitor identity between Wine and the portal; selecting +a non-primary monitor still requires consistent client/input coordinates. + Each transport inode has immutable geometry. A negotiated size change creates a new mode-0600 file, initializes its header and slots, then atomically replaces the transport path. The previous mapping remains valid for existing readers; diff --git a/hook/uur-hook.c b/hook/uur-hook.c index b2d26d2..1d4a570 100644 --- a/hook/uur-hook.c +++ b/hook/uur-hook.c @@ -492,10 +492,48 @@ static BOOL feed_capture_frame_locked(HDC hdc_dest, int x, int y, int width, screen_width = (int)fw; if (screen_height < 1) screen_height = (int)fh; - int sx = (int)((int64_t)source_x * fw / screen_width); - int sy = (int)((int64_t)source_y * fh / screen_height); - int sw = (int)((int64_t)source_width * fw / screen_width); - int sh = (int)((int64_t)source_height * fh / screen_height); + /* The frame holds exactly one monitor, but the client may ask + * for that monitor's whole rectangle. Wine reports the + * compositor's monitors in its own order, so the virtual desktop + * is only the right basis for a partial request; a complete + * monitor request must map onto the whole frame. Fractional + * scaling can give Xwayland and the portal different pixel + * sizes, so compare aspect ratios rather than resolutions. */ + int sx = 0; + int sy = 0; + int sw = 0; + int sh = 0; + RECT requested; + requested.left = (LONG)source_x; + requested.top = (LONG)source_y; + requested.right = (LONG)source_x + (LONG)source_width; + requested.bottom = (LONG)source_y + (LONG)source_height; + HMONITOR monitor = (source_width > 0 && source_height > 0) + ? MonitorFromRect(&requested, MONITOR_DEFAULTTONULL) + : NULL; + MONITORINFO info; + info.cbSize = sizeof(info); + BOOL whole_monitor = FALSE; + if (monitor != NULL && GetMonitorInfoA(monitor, &info)) { + whole_monitor = + info.rcMonitor.left == requested.left && + info.rcMonitor.top == requested.top && + info.rcMonitor.right == requested.right && + info.rcMonitor.bottom == requested.bottom && + (int64_t)(info.rcMonitor.right - info.rcMonitor.left) * fh == + (int64_t)(info.rcMonitor.bottom - info.rcMonitor.top) * fw; + } + if (whole_monitor) { + sx = 0; + sy = 0; + sw = (int)fw; + sh = (int)fh; + } else { + sx = (int)((int64_t)source_x * fw / screen_width); + sy = (int)((int64_t)source_y * fh / screen_height); + sw = (int)((int64_t)source_width * fw / screen_width); + sh = (int)((int64_t)source_height * fh / screen_height); + } if (sw < 1) sw = (int)fw; if (sh < 1)