Skip to content

feat(kvm): start Windows remote-desktop sessions on the primary monitor - #177

Merged
mikhailm-coder merged 1 commit into
masterfrom
hotfix/win-kvm-primary-monitor
Oct 13, 2026
Merged

mikhailm-coder merged 1 commit into
masterfrom
hotfix/win-kvm-primary-monitor

Conversation

@mikhailm-coder

@mikhailm-coder mikhailm-coder commented Oct 12, 2026 •

Copy link
Copy Markdown

Description

The Windows KVM started every remote-desktop session on all monitors combined (SCREEN_SEL / SCREEN_SEL_TARGET = 0). The console switched to one display only after the display list arrived, so the first frames of every session and every recording showed the whole virtual desktop.

A new KVM (fresh child process: new session, or re-spawn after a desktop switch) now selects the primary monitor (MONITORINFOF_PRIMARY) on its first look at the displays, numbered like the display-location message (cmd 82) that the console reads. The first display list already reports it as selected, so the console has nothing to switch.

Behaviour kept:

  • Single-monitor machines stream "all" exactly as before (count 0 / selected 0).
  • "All" (0xFFFF in MNG_KVM_SET_DISPLAY) still works; the UI does not offer it.
  • The selection stays global to the capture, so every viewer and the recording see the same monitor.

New fallback: a selected display that no longer exists (unplugged, or an unknown id) now falls back to the primary instead of capturing the stale rectangle of the vanished monitor.

Improvements

  • kvm_default_display(): primary display index with several monitors (the first one if none is flagged), 0 with one.
  • CheckDesktopSwitch: on the first display count of a KVM process, start on that display; when the enumerator cannot find the selected display, fall back to it.

Safety / compatibility:

  • Frontend (main): identifies the primary as the cmd-82 display at 0,0 and only switches when the agent is not on its target, so with this agent the start-of-session PAUSE / SET_DISPLAY / REFRESH round trip disappears; a technician's own pick is still re-applied after a reconnect or desktop switch. Older frontends see the primary selected and do not switch either.
  • Mesh server: the desktop multiplexer only caches and forwards cmd 11 / 82 / 12; nothing assumes "all".
  • Backend: no monitor state.
  • The fleet runs mixed agent versions; the frontend keeps its auto-select of the primary as the fallback.

Testing:

  • MinGW -fsyntax-only of kvm.c: same diagnostics as master (MSVC-only __try).
  • Mock harness that runs the extracted display-selection code of kvm.c against fake monitor layouts: 3 monitors with the primary enumerated second, switching, "all", unplug of the selected monitor, unknown id, unplug down to one monitor, single monitor, no primary flagged, input thread first, hot-plug. All pass on the branch; on master the start, fallback and no-primary cases fail. 7 mutations of the change are all caught.
  • Not yet run on a real 2- or 3-monitor Windows machine.

Known limits (unchanged from before):

  • DisplayInfoEnumProc (which applies a selection) counts only monitors named \\.\DISPLAY<n>, while cmd 82 and the new default count every monitor. On a machine with an oddly named display enumerated before the primary, the two numberings differ; explicit picks from the console already behave this way today.
  • Console mode (run / connect, testing only) runs the KVM as a thread that keeps its state, so only the first session of that process starts on the primary. OpenFrame installs the agent as a service (-install), where every session gets a fresh KVM process.

Rollout: release a new meshagent version and bump meshcentral.client.tag (0.0.29 on every environment today). The next release also carries #172.

Task

ClickUp task: CU-17tkuw5v5zr [Mesh Agent] Windows: start every remote-screen session on the primary monitor

Change-Set: hotfix-win-kvm-primary-monitor

Change set flamingo-stack/hotfix-win-kvm-primary-monitor: this pull request is the only one in it so far. Another pull request joins by naming this one in a Depends-On line, or by carrying the same Change-Set line.

Linked work

Linked by the Depends-On / Change-Set lines in these descriptions; this block is maintained by the hub.

The Windows KVM started every session on all monitors combined, so the
first frames of each session and recording showed the whole virtual
desktop until the console switched to one display.

A new KVM now selects the primary monitor (numbered like the display
location message) when the machine has more than one; single-monitor
machines keep streaming "all" as before. A selection that no longer
exists (unplugged monitor, unknown id) falls back to the same default
instead of capturing a stale rectangle. "All" (0xFFFF) stays supported.
@github-actions

Copy link
Copy Markdown

🦩 Flamingo Code Review

Not reviewed yet. Reviews start when you ask, so the reviewer reads this pull request when it is ready, not when it is opened.

When it is ready:

  • Review this pull request

Or comment @flamingo-review. Add the flamingo-review-always label to review every push.

Updated 2026-10-12 21:15 UTC · workflow run

@mikhailm-coder
mikhailm-coder merged commit c07a160 into master Oct 13, 2026
14 checks passed
@mikhailm-coder
mikhailm-coder deleted the hotfix/win-kvm-primary-monitor branch October 13, 2026 14:06
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.

2 participants