Skip to content

Add DesktopSize / ExtendedDesktopSize pseudo-encoding support#12

Open
rsp2k wants to merge 1 commit into
andrews239:mainfrom
rsp2k:add-desktop-size
Open

Add DesktopSize / ExtendedDesktopSize pseudo-encoding support#12
rsp2k wants to merge 1 commit into
andrews239:mainfrom
rsp2k:add-desktop-size

Conversation

@rsp2k

@rsp2k rsp2k commented Jun 14, 2026

Copy link
Copy Markdown

The RFB pseudo-encodings -223 (DesktopSize) and -308 (ExtendedDesktopSize) carry server-side geometry change notifications. asyncvnc2 currently has no parser for them, so when a server pushes one (TigerVNC does this on every xrandr resize, for example), Enc(...) raises ValueError and the connection drops on the next byte read.

What changed

  • Enc gains DESKTOP_SIZE = -223 and EXTENDED_DESKTOP_SIZE = -308.
  • The SetEncodings writer uses signed=True so negative pseudo-encodings serialize correctly when callers opt them in via EncList.
  • Video.read converts the unsigned wire integer back to signed before the Enc(...) lookup. Existing raise-on-unknown-encoding behavior is preserved (silently skipping an unknown rect would desync the stream).
  • Two new dispatch branches drain the pseudo-encoding payload and update Video.width/height through a small _handle_desktop_resize helper that only invalidates the framebuffer when the size actually changes (servers commonly echo the current size on connect).
  • Client.screenshot re-requests on incomplete updates so callers don't deadlock when an unsolicited pseudo-encoding rect arrives mid-screenshot.
  • Enc.default() now excludes pseudo-encodings (filter value > 0) with a docstring explaining the TigerVNC subscription quirk — see below.
  • tests/test_desktop_size.py adds 5 unit tests covering _handle_desktop_resize no-op vs invalidate semantics and Video.read parsing of DESKTOP_SIZE plus EDS rects (including multi-screen payloads).

TigerVNC subscription quirk

If you advertise ExtendedDesktopSize in SetEncodings, the TigerVNC build in accetto/ubuntu-vnc-xfce-g3 returns EDS-only FramebufferUpdate responses (cnt=1, no pixel data) to every FramebufferUpdateRequest, even with incremental=False. This effectively starves the screenshot path. The docstring on Enc.default() warns about this so users who want subscription-style resize notifications opt in deliberately: EncList() + Enc.EXTENDED_DESKTOP_SIZE.

Verification

Tested against accetto/ubuntu-vnc-xfce-g3 and the existing pytest suite. Default-behavior screenshots and the new resize handling both work; the test suite passes unchanged.

The RFB pseudo-encodings -223 (DesktopSize) and -308
(ExtendedDesktopSize) carry server-side geometry change
notifications. asyncvnc2 currently has no parser for them, so when
a server pushes one (TigerVNC does this on every xrandr resize, for
example), Enc(...) raises ValueError and the connection drops on
the next byte read.

- Add DESKTOP_SIZE and EXTENDED_DESKTOP_SIZE to Enc with the proper
  negative wire values
- SetEncodings writer uses signed=True so negative pseudo-encodings
  serialize correctly when callers opt them in via EncList
- Video.read converts the unsigned wire integer back to signed for
  pseudo-encodings (existing raise-on-unknown behavior preserved)
- Two new dispatch branches drain the pseudo-encoding payload and
  update Video.width/height through a small _handle_desktop_resize
  helper. The helper only invalidates the framebuffer on actual size
  changes -- servers commonly echo the current size on connect, and
  invalidating on echo would deadlock the screenshot loop
- Client.screenshot re-requests on incomplete updates so callers
  don't deadlock when an unsolicited pseudo-encoding rect arrives
  mid-screenshot
- Enc.default() now excludes pseudo-encodings (filter value > 0) with
  a docstring warning about TigerVNC: that build treats EDS in
  SetEncodings as a subscription, returning EDS-only FBU responses
  that starve the screenshot path. Callers wanting subscription-style
  resize notifications opt in deliberately via EncList + EDS

Tests in tests/test_desktop_size.py cover _handle_desktop_resize
no-op vs invalidate semantics and Video.read parsing of DESKTOP_SIZE
plus EDS rects (including multi-screen payloads).
@rsp2k
rsp2k marked this pull request as ready for review June 14, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant