Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ RDP scale wire format (`Services/RdpDpiScale.cs`, `native/CxRdpBridge/cxrdp_brid

RDP clipboard (CLIPRDR): the managed side (`Services/RdpBridgeClient.cs`, `Services/RdpClipboardImageHelper.cs`) talks through `cxrdp_set_clipboard_text` / `_rich_text` / `_image` / `_files` and receives remote content through the text, image and files callbacks. Every one of those entry points is gated on `cxrdp_get_api_version() >= 14` PLUS its own capability bit (`CX_RDP_CAPABILITY_CLIPBOARD_IMAGE/FILES/RICH_TEXT/LOCK`), because older bridges declared the prototypes in `cxrdp_bridge.h` without defining them — calling an unimplemented symbol throws `EntryPointNotFoundException`, so never add a `DllImport` call that is not behind a capability check. Format ids beyond the CF_* range are local conventions (`CX_CLIPRDR_FORMAT_PNG 0xC001`, `FILE_GROUP_DESCRIPTOR_W 0xC002`, `HTML 0xC003`, `RTF 0xC004`, `FILE_CONTENTS 0xC005`, `PREFERRED_DROP_EFFECT 0xC006`) and the bridge advertises them by name (`PNG`, `FileGroupDescriptorW`, `FileContents`, `Preferred DropEffect`, `HTML Format`, `Rich Text Format`), so remote format matching keys off `formatName` and falls back to the numeric `formatId`. Files copied on the RDP side are staged into `%TEMP%/CxShell-RdpClip/<stamp>` in 64 KiB stream chunks before the paths are handed to the host, and a local copy is enumerated recursively (directories become a leading entry plus `root\relative` names) so pasting a folder recreates the tree. Capabilities advertise `CB_STREAM_FILECLIP_ENABLED`, `CB_FILECLIP_NO_FILE_PATHS`, `CB_HUGE_FILE_SUPPORT_ENABLED` and, when `SessionInfo.RdpEnableClipboardLock` is on, `CB_CAN_LOCK_CLIPDATA`; a lock request snapshots the offered text/files under its `clipDataId` so a later local copy cannot abort an in-flight transfer. `RdpClipboardImageHelper` opens the Windows clipboard with the session window's HWND as owner — passing `IntPtr.Zero` made the data disappear when another app polled the clipboard. Local clipboard content is one of three mutually exclusive kinds (text/rich text, image, files); switching kind bumps `local_clipboard_revision` and only the matching format list is offered.

RDP keyboard scancodes (`Views/RdpView.axaml.cs`, `Services/RdpKeyboardScancodes.cs`): the numeric keypad's PS/2 set-1 scancodes are a physical grid, NOT a linear range - only NumPad0 sits at 0x52 while digits 1-9 occupy 0x47-0x51 (they share their codes with the non-extended navigation keys: 7=Home 0x47, 8=Up 0x48, 9=PgUp 0x49, 4=Left 0x4B, 6=Right 0x4D, 1=End 0x4F, 2=Down 0x50, 3=PgDn 0x51). Never derive them from the Key enum order (`0x52 + digit` sent NumPad1 as the keypad decimal 0x53 and NumPad5/NumPad6 as F11/F12, which made the numpad unusable in RDP); always go through `RdpKeyboardScancodes.NumPadDigitScancode`. The remote decides digits versus navigation from its own NumLock state, so `RdpView` re-asserts the local toggle state through a synchronize event (`SyncLocalLockKeysToRemote`) at connect, on focus and after each NumLock/CapsLock/ScrollLock key-up to keep both sides aligned.

RDP connect latency: the bridge tries security profiles in the order `negotiate` (standard X.224 negotiation, what modern servers want) then `nla`, `tls`, `rdp`. Never put the single-layer profiles first — each one costs a complete failed TCP/TLS handshake. `RdpBridgeClient` persists the winning profile per `host:port` in `Services/RdpSecurityProfileCache.cs` (`%LOCALAPPDATA%/CxShell/rdp-security-profiles.json`) after the bridge reports `RDP security profile selected mode=...`, and passes it back through `cxrdp_set_security_profile` (API 7 / `CX_RDP_CAPABILITY_FAST_CONNECT`). A clipboard-triggered retry re-runs only the profile that already worked. Credential/account errors (`ERRCONNECT_LOGON_FAILURE`, `ERRCONNECT_ACCOUNT_LOCKED_OUT`, ...) stop the fallback loop immediately so retries cannot lock an account. `FreeRDP_TcpConnectTimeout`/`TcpAckTimeout` bound each handshake, `cx_retry_dialog` returns -1 during the initial connect (only ARC gets a backoff), and `RdpViewModel` adds a 45 s connect watchdog (`CXSHELL_RDP_CONNECT_TIMEOUT_SECONDS`, 0 disables). Per-profile failures, queued display updates and clipboard retries are classified as transient by `ViewModels/RdpReconnectStatus.cs` — the UI must not treat them as a disconnect; the bridge emits one terminal `RDP connection failed.` line when the loop is exhausted. `SessionInfo.RdpClipboardEnabled` (session edit dialog, default true) maps to `cxrdp_set_clipboard_channel`; `CXSHELL_RDP_CLIPBOARD_CHANNEL=0` remains a global kill switch. Session throughput uses `FreeRDP_CompressionEnabled`, `BitmapCacheEnabled`, `NetworkAutoDetect`, `CONNECTION_TYPE_AUTODETECT` and font smoothing; `SoftwareGdi=TRUE` is required by the GDI frame callback; EGFX (see frame presentation below) is its front end, not an alternative. `SessionInfo.RdpDisableWallpaper` (session edit dialog, default true) maps to `cxrdp_set_disable_wallpaper` (API 9 / `CX_RDP_CAPABILITY_PERFORMANCE_FLAGS`): the bridge sets `FreeRDP_DisableWallpaper` and calls `freerdp_performance_flags_make` so `PERF_DISABLE_WALLPAPER` is folded into `FreeRDP_PerformanceFlags` before the client core data is sent; older bridges lack the bit and the managed side skips the call. The worker keeps a resize queued for 2 s after connect so the `disp` channel can negotiate before a layout is sent; `RdpViewModel` retries an in-place resize once after 1200 ms before falling back to a full reconnect.

RDP H.264 / AVC444 and dirty-rect copies (merged from PR #6 on 2026-11-28): `SessionInfo.RdpH264Enabled` (session edit dialog, default off, checkbox disabled while EGFX is off) maps to `cxrdp_set_h264_enabled` (capability `CX_RDP_CAPABILITY_GFX_H264` = 0x00080000). The bridge only honours it when `FreeRDP_SupportGraphicsPipeline` is on: it then sets `FreeRDP_GfxH264`, `FreeRDP_GfxAVC444` and `FreeRDP_GfxAVC444v2`, and forces all three off when the graphics pipeline is disabled or failed. A missing decoder or server-side codec costs a dropped codec, not the session. Partial frame copies live in `Services/RdpBridgeClient.cs`: when `cxrdp_get_frame_dirty_rect` reports a rect and the frame did not resize, `OnFrame` copies only that rect out of the native buffer into `_frameBuffer`/`_previousFrameBuffer`, and `TryPresentFrame` copies only that rect — unioned with the previously presented rect — into the pooled snapshot, which `RdpViewModel.OnFramebufferUpdated` blits into the locked target bitmap. The union with the last presented rect is REQUIRED: the host alternates two persistent bitmaps, so a region must be published twice before both bitmaps are current; dropping the union shows stale regions on the back buffer. Any full copy (resize, wave classification, no dirty rect) resets `_pendingFullFrameCopy` and re-copies the whole surface.
Expand All @@ -81,7 +83,7 @@ RDP frame presentation latency (regression fix, 2026-11-23): pure repaint-wave d

## Full Screen Connection Bar

`Views/FullScreenConnectionBar.axaml(.cs)` is the mstsc-style floating bar shown at the top centre of a full screen window. It is hosted by `Views/MainWindow.axaml` (bound to `MainWindowViewModel.IsTerminalFullScreen`, endpoint `SelectedTab.Session.Host`, quality `SelectedTab.Rdp.LinkQualityLevel`, `IsQualityVisible=SelectedTab.IsRdpSession`), `Views/DetachedTabWindow.axaml` (bound to the tab view model), and `Views/RdpMonitorWindow.axaml`. Hosts wire `MinimizeRequested` / `RestoreRequested` / `CloseRequested` / `PinnedChanged` (and workspace/multi-monitor events where applicable).
`Views/FullScreenConnectionBar.axaml(.cs)` is the mstsc-style floating bar shown at the top centre of a full screen window. It is hosted by `Views/MainWindow.axaml` (bound to `MainWindowViewModel.IsTerminalFullScreen`, endpoint `SelectedTab.Session.Host`, quality `SelectedTab.Rdp.LinkQualityLevel`, `IsQualityVisible=SelectedTab.IsRdpSession`), `Views/DetachedTabWindow.axaml` (bound to the tab view model), `Views/RdpWorkspaceWindow.axaml`, and `Views/RdpMonitorWindow.axaml`. Hosts wire `MinimizeRequested` / `RestoreRequested` / `CloseRequested` / `PinnedChanged` (and workspace/multi-monitor events where applicable).

Behaviour that must not regress:

Expand All @@ -92,7 +94,7 @@ Behaviour that must not regress:
- The quality bars are an estimate, not an RDP capability: `RdpViewModel` times a bare TCP connect to the session endpoint every 10 s while connected and maps ≤50 ms/≤100 ms/≤200 ms/longer to 4/3/2/1 bars (`LinkQualityLevel`); 0 means unknown/disconnected. RDP exposes no signal strength, and a full reconnect probe must never be used.
- Minimize from the bar leaves the full screen presentation, so the host must restore it when the window comes back: `MainWindow` uses `_restoreFullScreenAfterMinimize` plus `OnMainWindowPropertyChanged`; `DetachedTabWindow` needs `_restoreFullScreenAfterMinimize` / `_restoreKeepTaskbarAfterMinimize` and the `_suppressPresentationRestore` guard, because leaving the taskbar-visible mode changes `WindowState` and would otherwise look like a user restore. Close maps to `CloseTab(SelectedTab)` in the main window and `Close()` in a detached window - never to shutting down the application.
- **Both full screen modes must hide the drawn chrome, not just the title bar.** `WindowState.FullScreen` only drops the native frame; AtomUI draws its title bar (`IsTitleBarVisible`) inside the client area. `Views/KeepTaskbarFullScreen.cs` owns that: `Enter()` hides the title bar before maximizing, the immersive path calls `HideTitleBar()`.
- **AtomUI 6.3.0's built-in full-screen title bar must stay disabled via `FullScreenTitleBarMode="Hidden"`.** AtomUI 6.3.0 removed `FullscreenHeaderFrame` from `WindowDrawnDecorationsTheme` and introduced `Window.FullScreenTitleBarMode` (default `AutoHide`) inside `WindowChromeLayer`. Every window hosting `FullScreenConnectionBar` (`MainWindow.axaml`, `DetachedTabWindow.axaml`, `RdpMonitorWindow.axaml`) must set `FullScreenTitleBarMode="Hidden"` so AtomUI never activates its built-in full-screen bar or moves `TitleBar` between `NormalSlotTitleBar` and `FullScreenSlotContent`.
- **AtomUI 6.3.0's built-in full-screen title bar must stay disabled via `FullScreenTitleBarMode="Hidden"`.** AtomUI 6.3.0 removed `FullscreenHeaderFrame` from `WindowDrawnDecorationsTheme` and introduced `Window.FullScreenTitleBarMode` (default `AutoHide`) inside `WindowChromeLayer`. Every window hosting `FullScreenConnectionBar` (`MainWindow.axaml`, `DetachedTabWindow.axaml`, `RdpWorkspaceWindow.axaml`, `RdpMonitorWindow.axaml`) must set `FullScreenTitleBarMode="Hidden"` so AtomUI never activates its built-in full-screen bar or moves `TitleBar` between `NormalSlotTitleBar` and `FullScreenSlotContent`.
- **Keep `FullScreenConnectionBar` as a dedicated control rather than replacing it with `Window.FullScreenTitleBar`.** `Window.FullScreenTitleBar` only activates for `WindowState.FullScreen`, whereas CxShell needs the same bar in taskbar-visible maximized mode (`KeepTaskbarFullScreen`) and `RdpMonitorWindow` borderless mode, with the centred 8 px / 500 ms mstsc hot-zone, RDP link quality, pin persistence, multi-monitor popup lock, workspace tab switching, and drag-restore.
- `KeepTaskbarFullScreen` owns `HideTitleBar`/`RestoreTitleBar` and `HideDecorations`/`RestoreDecorations` (`Window.WindowDecorations = None`, previous values saved once). Both helpers are idempotent so switching between "keep taskbar" and immersive full screen never loses the original state. Restore them on every exit path (after leaving full screen, never before), including an external takeover (window manager shortcut, native caption button): `MainWindow.OnMainWindowPropertyChanged` and `DetachedTabWindow.OnWindowPropertyChanged` restore the chrome whenever the window ends up outside full screen without `_keepTaskbarFullScreen.IsActive`. Never bind `IsTitleBarVisible` or `WindowDecorations` from XAML.

Expand Down
72 changes: 72 additions & 0 deletions CxShell.Tests/RdpKeyboardScancodesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Avalonia.Input;
using CxShell.Services;

namespace CxShell.Tests;

public sealed class RdpKeyboardScancodesTests
{
[Theory]
[InlineData(Key.NumPad0, 0x52)]
[InlineData(Key.NumPad1, 0x4F)]
[InlineData(Key.NumPad2, 0x50)]
[InlineData(Key.NumPad3, 0x51)]
[InlineData(Key.NumPad4, 0x4B)]
[InlineData(Key.NumPad5, 0x4C)]
[InlineData(Key.NumPad6, 0x4D)]
[InlineData(Key.NumPad7, 0x47)]
[InlineData(Key.NumPad8, 0x48)]
[InlineData(Key.NumPad9, 0x49)]
public void NumPadDigitScancode_MatchesPs2KeypadGrid(Key key, uint expected)
{
Assert.Equal(expected, RdpKeyboardScancodes.NumPadDigitScancode(key));
}

[Fact]
public void NumPadDigitScancode_ReturnsZeroOutsideTheKeypad()
{
Assert.Equal(0u, RdpKeyboardScancodes.NumPadDigitScancode(Key.D1));
Assert.Equal(0u, RdpKeyboardScancodes.NumPadDigitScancode(Key.Decimal));
Assert.Equal(0u, RdpKeyboardScancodes.NumPadDigitScancode(Key.Add));
Assert.Equal(0u, RdpKeyboardScancodes.NumPadDigitScancode(Key.None));
}

[Fact]
public void NumPadDigits_DoNotCollideWithKeypadDecimalOrFunctionKeys()
{
// The old 0x52 + digit arithmetic sent NumPad1 as the keypad decimal
// (0x53) and NumPad5/NumPad6 as F11/F12 (0x57/0x58), which is why the
// numeric keypad typed garbage or nothing in RDP sessions.
var scancodes = new HashSet<uint>();
for (var key = Key.NumPad0; key <= Key.NumPad9; key++)
scancodes.Add(RdpKeyboardScancodes.NumPadDigitScancode(key));

Assert.Equal(10, scancodes.Count);
Assert.DoesNotContain(0x53u, scancodes); // keypad .
Assert.DoesNotContain(0x57u, scancodes); // F11
Assert.DoesNotContain(0x58u, scancodes); // F12
}

[Fact]
public void NumPadDigits_MatchTheNonExtendedNavigationScancodes()
{
// The keypad shares its scancodes with the navigation block: NumPad7
// is the non-extended Home, NumPad8 the non-extended Up, and so on.
// The remote side decides digits versus navigation from its own
// NumLock state, exactly like a physical keyboard plugged into it.
Assert.Equal(0x0100 | 0x47u, RdpKeyboardScancodes.NumPadDigitScancode(Key.NumPad7) | 0x0100);
Assert.Equal(0x0100 | 0x48u, RdpKeyboardScancodes.NumPadDigitScancode(Key.NumPad8) | 0x0100);
Assert.Equal(0x0100 | 0x4Du, RdpKeyboardScancodes.NumPadDigitScancode(Key.NumPad6) | 0x0100);
Assert.Equal(0x0100 | 0x50u, RdpKeyboardScancodes.NumPadDigitScancode(Key.NumPad2) | 0x0100);
}

[Fact]
public void IsLockKey_MatchesTheToggleKeys()
{
Assert.True(RdpKeyboardScancodes.IsLockKey(Key.NumLock));
Assert.True(RdpKeyboardScancodes.IsLockKey(Key.CapsLock));
Assert.True(RdpKeyboardScancodes.IsLockKey(Key.Scroll));
Assert.False(RdpKeyboardScancodes.IsLockKey(Key.NumPad1));
Assert.False(RdpKeyboardScancodes.IsLockKey(Key.F5));
Assert.False(RdpKeyboardScancodes.IsLockKey(Key.None));
}
}
14 changes: 14 additions & 0 deletions Models/SessionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,20 @@ public int SshMonitorRefreshIntervalSeconds
public string RdpColorQuality { get; set; } = "32";
/// <summary>Preferred RDP security mode: Auto, Negotiate, NLA, TLS or RDP.</summary>
public string RdpSecurityMode { get; set; } = "Auto";
/// <summary>RDP window mode: Default (main window tab), MultiTab (standalone multi-tab RDP window), or Standalone (detached single-session window with multi-monitor support).</summary>
public string RdpWindowMode { get; set; } = "Default";
public bool RdpOpenInStandaloneWindow { get; set; }

public string ResolveEffectiveRdpWindowMode()
{
if (string.Equals(RdpWindowMode, "MultiTab", StringComparison.OrdinalIgnoreCase))
return "MultiTab";
if (string.Equals(RdpWindowMode, "Standalone", StringComparison.OrdinalIgnoreCase))
return "Standalone";
if (string.Equals(RdpWindowMode, "Default", StringComparison.OrdinalIgnoreCase) && RdpOpenInStandaloneWindow)
return "MultiTab";
return RdpOpenInStandaloneWindow ? "MultiTab" : "Default";
}
public bool RdpApplyKeyCombinations { get; set; } = true;
public bool RdpSyncLockKeys { get; set; } = true;
public bool RdpEnableClipboardLock { get; set; } = true;
Expand Down
Loading
Loading