diff --git a/CHANGELOG.md b/CHANGELOG.md index a9f0712d..dbdc344b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Version numbers follow `MAJOR.MINOR.PATCH`; the 0.x series is under active development. Release tags and downloadable archives use the same version. +## 0.12.4 — 2026-11-13 + +- Clicking a World tree row button after switching back to zStudio keeps the tree at its current scroll position. +- Maximized zStudio leaves the reveal edge available for an automatically hidden Windows taskbar. + ## 0.12.3 — 2026-11-12 - The Blender extension now installs on Blender 5.3 and newer, retaining the 5.2 minimum without an upper version cutoff. diff --git a/Directory.Build.props b/Directory.Build.props index 08c216de..8a5297d6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -18,6 +18,6 @@ Advanced viewer and editor for Zipper Interactive's ZBD files https://github.com/Vorta/zStudio git - 0.12.3 + 0.12.4 diff --git a/README.md b/README.md index 60248573..788c811a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ zStudio is a Windows desktop application. It unpacks RECOIL's retail game files once into an editable source project (the developers' original `data\` and `gamegen\` tree: text resources, glTF models, PNG textures, WAV sounds and build scripts), lets you edit the maps in zStudio or in Blender, and exports new game files from the sources. AI agents can work in the same workspace through local MCP. -Download **[zStudio v0.12.3](https://github.com/Vorta/zStudio/releases/tag/v0.12.3)** for Windows x64. +Download **[zStudio v0.12.4](https://github.com/Vorta/zStudio/releases/tag/v0.12.4)** for Windows x64. zStudio tells you when a newer release is out: **Update available** appears in the status bar; click it for the release page. zStudio asks GitHub's public release API at most once a day and sends nothing but its version; **Help → Check for updates** asks now, and **Help → Check for updates automatically** turns the daily check off. Running zStudio 0.9.6 or older on the same Windows account turns the daily check back on, because older versions drop settings they don't know. diff --git a/blender/zstudio_recoil/blender_manifest.toml b/blender/zstudio_recoil/blender_manifest.toml index 68699756..b6858644 100644 --- a/blender/zstudio_recoil/blender_manifest.toml +++ b/blender/zstudio_recoil/blender_manifest.toml @@ -1,6 +1,6 @@ schema_version = "1.0.0" id = "zstudio_recoil" -version = "0.12.3" +version = "0.12.4" name = "zStudio RECOIL" tagline = "Edit RECOIL glTF models, linked worlds, flags and zones" maintainer = "Vorta" diff --git a/src/zStudio.Desktop/MainWindow.Chrome.cs b/src/zStudio.Desktop/MainWindow.Chrome.cs index 322cf94b..ffe8f6e9 100644 --- a/src/zStudio.Desktop/MainWindow.Chrome.cs +++ b/src/zStudio.Desktop/MainWindow.Chrome.cs @@ -12,6 +12,11 @@ namespace zStudio.Desktop; public partial class MainWindow { private bool captionMaximizePressed; + private bool maximizedFrameQueued; + private CaptionBounds? maximizedClientBounds; + private static readonly int taskbarCreatedMessage = (int)RegisterWindowMessage("TaskbarCreated"); + // A private desktop has no Explorer taskbar. Tests supply its reported edges without changing shell settings. + internal Func? AutoHideTaskbarEdgesForTest { get; set; } private void InitializeChrome() { WindowChrome.SetWindowChrome(this, new WindowChrome @@ -27,7 +32,7 @@ private void InitializeChrome() SourceInitialized += (_, _) => { nint handle = new WindowInteropHelper(this).Handle; - HwndSource.FromHwnd(handle)?.AddHook(ChromeMessage); + InstallChromeHook(handle); ApplyCornerPreference(handle); UpdateCaptionBounds(); }; @@ -49,6 +54,13 @@ private void InitializeChrome() } private nint ChromeMessage(nint hwnd, int message, nint wParam, nint lParam, ref bool handled) { + if (message == 0x0083 && lParam != 0 && TryMaximizedClientBounds(hwnd, out var client, Marshal.PtrToStructure(lParam))) + { + // Both NCCALCSIZE_PARAMS and the wParam=FALSE form begin with a RECT. Correct the native client, not just XAML. + Marshal.StructureToPtr(client, lParam, false); + maximizedClientBounds = client; + handled = true; return 0; + } if (presentationFullscreen && message == 0x0112 && ((long)wParam & 0xFFF0) == 0xF030) { handled = true; return 0; } // SC_MAXIMIZE: fullscreen exits only through its own command. // Windows 11 discovers Snap Layouts from the real maximize hit region, even @@ -70,9 +82,65 @@ private nint ChromeMessage(nint hwnd, int message, nint wParam, nint lParam, ref } if (message is 0x031A or 0x031E) ApplyCornerPreference(hwnd); if (message is 0x02E0 or 0x007E or 0x001A) QueueFullscreenBounds(); + if (message is 0x02E0 or 0x007E or 0x001A or 0x0047 || message == taskbarCreatedMessage) QueueMaximizedFrame(); if (message is 0x02E0 or 0x031A or 0x031E or 0x001A or 0x0047) Dispatcher.BeginInvoke(DispatcherPriority.Loaded, UpdateCaptionBounds); return 0; } + private void InstallChromeHook(nint handle) + { + // Hooks run newest first. WindowChrome installs a new hook when F11 restores the ordinary frame. + var source = HwndSource.FromHwnd(handle); + source?.RemoveHook(ChromeMessage); + source?.AddHook(ChromeMessage); + } + private static void RefreshChromeFrame(nint handle) => RequireNative(SetWindowPos(handle, 0, 0, 0, 0, 0, + 0x0001 | 0x0002 | 0x0004 | 0x0010 | 0x0020 | 0x0200)); // frame only, no size/position/activation/Z-order changes + + private void QueueMaximizedFrame() + { + if (maximizedFrameQueued || presentationFullscreen) return; + maximizedFrameQueued = true; + Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () => + { + maximizedFrameQueued = false; + if (shutdownToken.IsCancellationRequested || !IsVisible) return; + nint handle = new WindowInteropHelper(this).Handle; + if (!TryMaximizedClientBounds(handle, out var bounds) || maximizedClientBounds is { } applied && applied.Equals(bounds)) return; + try { RefreshChromeFrame(handle); } + catch (System.ComponentModel.Win32Exception ex) { ViewModel.Status = "Maximized window bounds could not be updated: " + ex.Message; } + }); + } + private bool TryMaximizedClientBounds(nint handle, out CaptionBounds client, CaptionBounds? proposed = null) + { + client = default; + if (presentationFullscreen || handle == 0 || !IsZoomed(handle)) return false; + var rect = proposed.GetValueOrDefault(); + nint monitorHandle = proposed.HasValue ? MonitorFromRect(ref rect, 2) : MonitorFromWindow(handle, 2); + var monitor = new MonitorBounds { Size = Marshal.SizeOf() }; + if (!GetMonitorInfo(monitorHandle, ref monitor)) return false; + uint edges = AutoHideTaskbarEdgesForTest?.Invoke() ?? AutoHideTaskbarEdges(monitor.Monitor); + client = MaximizedClientArea(monitor.Monitor, monitor.Work, edges); + return true; + } + private static uint AutoHideTaskbarEdges(CaptionBounds monitor) + { + uint edges = 0; + for (uint edge = 0; edge < 4; edge++) + { + var data = new AppBarData { Size = (uint)Marshal.SizeOf(), Edge = edge, Bounds = monitor }; + if (SHAppBarMessage(0x0000000B, ref data) != 0) edges |= 1u << (int)edge; // ABM_GETAUTOHIDEBAREX + } + return edges; + } + internal static CaptionBounds MaximizedClientArea(CaptionBounds monitor, CaptionBounds work, uint autoHideEdges) + { + // Two physical pixels, as in Windows Terminal's custom chrome. Do not scale by DPI or reserve an occupied edge twice. + if ((autoHideEdges & 1) != 0) work.Left = Math.Max(work.Left, monitor.Left + 2); + if ((autoHideEdges & 2) != 0) work.Top = Math.Max(work.Top, monitor.Top + 2); + if ((autoHideEdges & 4) != 0) work.Right = Math.Min(work.Right, monitor.Right - 2); + if ((autoHideEdges & 8) != 0) work.Bottom = Math.Min(work.Bottom, monitor.Bottom - 2); + return work; + } private void ApplyCornerPreference(nint handle) { if (handle == 0 || !OperatingSystem.IsWindowsVersionAtLeast(10,0,22000)) return; @@ -135,10 +203,15 @@ internal static Size DialogWorkArea(Window owner) } return SystemParameters.WorkArea.Size; } - [StructLayout(LayoutKind.Sequential)] private struct CaptionBounds { public int Left,Top,Right,Bottom; } + [StructLayout(LayoutKind.Sequential)] internal struct CaptionBounds { public int Left,Top,Right,Bottom; } [StructLayout(LayoutKind.Sequential)] private struct ScreenPoint { public int X,Y; } [StructLayout(LayoutKind.Sequential)] private struct MonitorBounds { public int Size; public CaptionBounds Monitor,Work; public uint Flags; } [StructLayout(LayoutKind.Sequential)] private struct MouseTracking { public int Size; public uint Flags; public nint Window; public uint HoverTime; } + [StructLayout(LayoutKind.Sequential)] private struct AppBarData { public uint Size; public nint Window; public uint Callback, Edge; public CaptionBounds Bounds; public nint Param; } + [DllImport("shell32.dll")] private static extern nuint SHAppBarMessage(uint message, ref AppBarData data); + [DllImport("user32.dll", EntryPoint = "RegisterWindowMessageW", CharSet = CharSet.Unicode)] private static extern uint RegisterWindowMessage(string message); + [DllImport("user32.dll")] private static extern bool IsZoomed(nint handle); + [DllImport("user32.dll")] private static extern nint MonitorFromRect(ref CaptionBounds rect, uint flags); [DllImport("user32.dll")] private static extern bool TrackMouseEvent(ref MouseTracking tracking); [DllImport("user32.dll")] private static extern nint MonitorFromWindow(nint hwnd,uint flags); [DllImport("user32.dll",CharSet=CharSet.Auto,SetLastError=true)] private static extern bool GetMonitorInfo(nint monitor,ref MonitorBounds info); diff --git a/src/zStudio.Desktop/MainWindow.OutlinerKeyboard.cs b/src/zStudio.Desktop/MainWindow.OutlinerKeyboard.cs index 72b604a2..7534b634 100644 --- a/src/zStudio.Desktop/MainWindow.OutlinerKeyboard.cs +++ b/src/zStudio.Desktop/MainWindow.OutlinerKeyboard.cs @@ -3,6 +3,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Threading; namespace zStudio.Desktop; @@ -19,11 +20,51 @@ public partial class MainWindow /// Set while a rebuild disables the tree that had keyboard focus: the rebuilt tree gives it back to the selection. private bool outlinerFocusPending; + private bool suppressOutlinerFocusScroll; + private int outlinerFocusScrollGeneration; + + private void InitializeOutlinerFocusScroll() + { + Activated += (_, _) => GuardOutlinerFocusScroll(); + DocumentSceneTree.AddHandler(Mouse.PreviewMouseDownEvent, + new MouseButtonEventHandler((_, _) => GuardOutlinerFocusScroll()), handledEventsToo: true); + DocumentSceneTree.IsVisibleChanged += (_, _) => { if (!DocumentSceneTree.IsVisible) ClearOutlinerFocusScroll(); }; + } + + /// + /// WPF restores the old focused row on activation, and on mouse-down even when a non-focusable row button handles it. + /// Let focus return without scrolling away from the row being clicked. Deliberate navigation clears this guard. + /// + private void GuardOutlinerFocusScroll() + { + if (!sourceChromeActive || sceneTree?.Projection == null || !DocumentSceneTree.IsVisible) return; + suppressOutlinerFocusScroll = true; + int generation = ++outlinerFocusScrollGeneration; + Dispatcher.BeginInvoke(DispatcherPriority.Input, () => + { + if (generation == outlinerFocusScrollGeneration) ClearOutlinerFocusScroll(); + }); + } + + private void ClearOutlinerFocusScroll() + { + suppressOutlinerFocusScroll = false; + ++outlinerFocusScrollGeneration; + } + + private void OutlinerBringIntoView(object sender, RequestBringIntoViewEventArgs e) + { + // This handler belongs on each item, below the internal ScrollViewer. WPF redirects an item's request to its header. + if (suppressOutlinerFocusScroll && sender is TreeViewItem { DataContext: SceneTreeItem row } && row.Owner == sceneTree) + e.Handled = true; + } + private void OutlinerKeyDown(object sender, KeyEventArgs e) { if (!sourceChromeActive || sceneTree is not { Projection: not null } model || System.Windows.Input.Keyboard.Modifiers != ModifierKeys.None) return; // The tree's context menu routes its keys through the tree: they are the menu's. if (e.OriginalSource is not Visual source || !DocumentSceneTree.IsAncestorOf(source)) return; + ClearOutlinerFocusScroll(); var focused = System.Windows.Input.Keyboard.FocusedElement as DependencyObject; var item = focused == null ? null : RowContainer(focused); var row = item?.DataContext as SceneTreeItem; @@ -98,6 +139,7 @@ private static void FocusRow(TreeViewItem item) /// The row's container, created (and scrolled to) when the tree has not made it yet. private TreeViewItem? RealizeRow(SceneTreeItem row) { + ClearOutlinerFocusScroll(); Stack path = new(); for (var at = row; at != null; at = at.Parent) path.Push(at); ItemsControl parent = DocumentSceneTree; TreeViewItem? container = null; diff --git a/src/zStudio.Desktop/MainWindow.Presentation.cs b/src/zStudio.Desktop/MainWindow.Presentation.cs index 0d6a463e..aafb74c6 100644 --- a/src/zStudio.Desktop/MainWindow.Presentation.cs +++ b/src/zStudio.Desktop/MainWindow.Presentation.cs @@ -220,8 +220,10 @@ private void RestoreOrdinaryWindow(nint handle, WindowPresentation saved) WindowStyle = saved.Style; ResizeMode = saved.Resize; MinWidth = saved.MinWidth; MinHeight = saved.MinHeight; MaxWidth = saved.MaxWidth; MaxHeight = saved.MaxHeight; WindowChrome.SetWindowChrome(this, saved.Chrome); + InstallChromeHook(handle); var placement = saved.Placement; RequireNative(SetWindowPlacement(handle, ref placement)); + RefreshChromeFrame(handle); ApplyCornerPreference(handle); UpdateCaptionBounds(); } diff --git a/src/zStudio.Desktop/MainWindow.SceneTree.cs b/src/zStudio.Desktop/MainWindow.SceneTree.cs index 641ae056..4ed78580 100644 --- a/src/zStudio.Desktop/MainWindow.SceneTree.cs +++ b/src/zStudio.Desktop/MainWindow.SceneTree.cs @@ -52,6 +52,7 @@ private void RefreshSceneTree() if (outlinerFocusPending) { if (sceneTree?.Selected == null) outlinerFocusPending = false; else ScheduleSceneTreeReveal(); } return; } + ClearOutlinerFocusScroll(); changingSceneTree = true; try { @@ -281,6 +282,7 @@ private void ScheduleSceneTreeReveal(SceneTreeItem? reveal = null) { if (sceneTree != model || generation != sceneTreeRevealGeneration) return; if (!DocumentSceneTree.IsVisible) { outlinerFocusPending = false; return; } + ClearOutlinerFocusScroll(); // An explicit reveal (including rebuild restoration) may scroll its intended row. changingSceneTree = true; try { diff --git a/src/zStudio.Desktop/MainWindow.xaml b/src/zStudio.Desktop/MainWindow.xaml index 5aead9d2..a627d356 100644 --- a/src/zStudio.Desktop/MainWindow.xaml +++ b/src/zStudio.Desktop/MainWindow.xaml @@ -324,7 +324,7 @@ - + diff --git a/src/zStudio.Desktop/MainWindow.xaml.cs b/src/zStudio.Desktop/MainWindow.xaml.cs index 4fe387d1..278e381c 100644 --- a/src/zStudio.Desktop/MainWindow.xaml.cs +++ b/src/zStudio.Desktop/MainWindow.xaml.cs @@ -60,6 +60,7 @@ public MainWindow() shutdownToken = shutdown.Token; preview = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken); InitializeComponent(); DataContext = ViewModel; + InitializeOutlinerFocusScroll(); // The Animations rows' target text and Frame follow the World tree pane's width (narrow below 260 DIP, wide from 400). SourceOutlinerPane.SizeChanged += (_, e) => sceneTree?.SetPaneWidth(e.NewSize.Width); WorldDifficulty.ItemsSource = MainViewModel.DifficultyChoices; diff --git a/src/zStudio.Desktop/packages.lock.json b/src/zStudio.Desktop/packages.lock.json index ba9f4e65..430e0457 100644 --- a/src/zStudio.Desktop/packages.lock.json +++ b/src/zStudio.Desktop/packages.lock.json @@ -77,7 +77,7 @@ "type": "Project", "dependencies": { "ModelContextProtocol.Core": "[2.4.0, )", - "zStudio.Application": "[0.12.3, )" + "zStudio.Application": "[0.12.4, )" } }, "zstudio.rendering": { @@ -87,7 +87,7 @@ "Vortice.DXGI": "[3.8.3, )", "Vortice.Direct3D11": "[3.8.3, )", "Vortice.Direct3D9": "[3.8.3, )", - "zStudio.Core": "[0.12.3, )" + "zStudio.Core": "[0.12.4, )" } }, "Clipper2": { diff --git a/tests/zStudio.Desktop.Tests/PresentationMcpChecks.cs b/tests/zStudio.Desktop.Tests/PresentationMcpChecks.cs index 95f11513..0f9d26d3 100644 --- a/tests/zStudio.Desktop.Tests/PresentationMcpChecks.cs +++ b/tests/zStudio.Desktop.Tests/PresentationMcpChecks.cs @@ -24,6 +24,7 @@ internal static class PresentationMcpChecks internal static async Task Run(Application app) { + CheckMaximizedClientGeometry(); PresentationRendererChecks.Run(); string folder = Directory.CreateTempSubdirectory("zstudio-presentation-").FullName; using var deadline = new CancellationTokenSource(TimeSpan.FromSeconds(45)); var token = deadline.Token; @@ -60,10 +61,25 @@ internal static async Task Run(Application app) var ordinaryChrome = WindowChrome.GetWindowChrome(main); var ordinaryStyle = main.WindowStyle; var ordinaryResize = main.ResizeMode; + // A custom maximized client must leave the auto-hide reveal edge outside its HWND client area. + // A private desktop has no taskbar, so simulate only the shell's query result, never change OS settings. + uint taskbarEdges = 8; + main.AutoHideTaskbarEdgesForTest = () => taskbarEdges; + main.WindowState = WindowState.Maximized; await Idle(); AssertMaximizedClient(); + taskbarEdges = 0; + SendMessage(hwnd, 0x001A, 0, 0); await Idle(); AssertMaximizedClient(); + taskbarEdges = 8; + SendMessage(hwnd, 0x001A, 0, 0); await Idle(); AssertMaximizedClient(); + var maximizedPlacement = Placement(hwnd); + await Command("window", new() { ["action"] = "minimize" }); await Idle(); + SendMessage(hwnd, 0x0112, 0xF120, 0); await Idle(); // native SC_RESTORE retains the maximized placement + AssertMaximizedClient(); Assert.Equal(maximizedPlacement.Normal, Placement(hwnd).Normal); + // Both show states restore the native normal rectangle, not a work-area/screen-coordinate mix. foreach (var mode in new[] { WindowState.Normal, WindowState.Maximized }) { main.WindowState = mode; await Idle(); + if (mode == WindowState.Maximized) AssertMaximizedClient(); var placement = Placement(hwnd); Send(main, Key.F11); await Idle(); var shown = await Present(); @@ -80,6 +96,7 @@ internal static async Task Run(Application app) Assert.Equal(placement.Normal, Placement(hwnd).Normal); Assert.Equal(placement.Show, Placement(hwnd).Show); Assert.Equal(mode, main.WindowState); + if (mode == WindowState.Maximized) AssertMaximizedClient(); Assert.Same(ordinaryChrome, WindowChrome.GetWindowChrome(main)); Assert.Equal(ordinaryStyle, main.WindowStyle); Assert.Equal(ordinaryResize, main.ResizeMode); Assert.Same(viewport, ((ContentControl)main.FindName("SceneHost")).Content); @@ -138,6 +155,18 @@ void AssertFullscreen() Assert.True(GetWindowRect(hwnd, out var actual)); Assert.Equal(monitor.Monitor, actual); Assert.Equal(0, GetWindowLongPtr(hwnd, -20).ToInt64() & 8); // WS_EX_TOPMOST } + void AssertMaximizedClient() + { + Assert.Equal(WindowState.Maximized, main.WindowState); + var monitor = new MonitorInfo { Size = Marshal.SizeOf() }; + Assert.True(GetMonitorInfo(MonitorFromWindow(hwnd, 2), ref monitor)); + var expected = MainWindow.MaximizedClientArea(ToBounds(monitor.Monitor), ToBounds(monitor.Work), taskbarEdges); + Assert.True(GetClientRect(hwnd, out var actual)); + var origin = new NativePoint(); Assert.True(ClientToScreen(hwnd, ref origin)); + Assert.Equal(expected.Left, origin.X); Assert.Equal(expected.Top, origin.Y); + Assert.Equal(expected.Right, origin.X + actual.Right); Assert.Equal(expected.Bottom, origin.Y + actual.Bottom); + Assert.Equal(0, GetWindowLongPtr(hwnd, -20).ToInt64() & 8); + } } finally { @@ -151,6 +180,24 @@ void AssertFullscreen() Assert.DoesNotContain(app.Windows.Cast(), w => w.Title is "Resolve property input" or "Unsaved changes"); } + private static MainWindow.CaptionBounds ToBounds(NativeRect rect) => new() { Left = rect.Left, Top = rect.Top, Right = rect.Right, Bottom = rect.Bottom }; + private static void CheckMaximizedClientGeometry() + { + // Screen pixels stay pixels at fractional DPI; negative secondary-monitor coordinates are not work-area offsets. + foreach (var monitor in new[] { new MainWindow.CaptionBounds { Right = 3840, Bottom = 2160 }, new MainWindow.CaptionBounds { Left = -1920, Top = -200, Bottom = 880 } }) + { + Assert.Equal(monitor, MainWindow.MaximizedClientArea(monitor, monitor, 0)); + for (int edge = 0; edge < 4; edge++) + { + var expected = monitor; + switch (edge) { case 0: expected.Left += 2; break; case 1: expected.Top += 2; break; case 2: expected.Right -= 2; break; case 3: expected.Bottom -= 2; break; } + Assert.Equal(expected, MainWindow.MaximizedClientArea(monitor, monitor, 1u << edge)); + } + var occupied = monitor; occupied.Bottom -= 60; + Assert.Equal(occupied, MainWindow.MaximizedClientArea(monitor, occupied, 8)); + } + } + private static void State(JsonNode state, bool fullscreen, bool available, bool hidden = false) { Assert.Equal(fullscreen, state["fullscreen"]!.GetValue()); Assert.Equal(hidden, state["uiHidden"]!.GetValue()); Assert.Equal(available, state["available"]!.GetValue()); } private static async Task Idle() { await Dispatcher.Yield(DispatcherPriority.ApplicationIdle); await Task.Delay(20); } @@ -185,6 +232,9 @@ private static NativePlacement Placement(nint handle) [StructLayout(LayoutKind.Sequential)] private struct MonitorInfo { public int Size; public NativeRect Monitor, Work; public uint Flags; } [DllImport("user32.dll", SetLastError = true)] private static extern bool GetWindowPlacement(nint handle, ref NativePlacement placement); [DllImport("user32.dll", SetLastError = true)] private static extern bool GetWindowRect(nint handle, out NativeRect rect); + [DllImport("user32.dll")] private static extern bool GetClientRect(nint handle, out NativeRect rect); + [DllImport("user32.dll")] private static extern bool ClientToScreen(nint handle, ref NativePoint point); + [DllImport("user32.dll", EntryPoint = "SendMessageW")] private static extern nint SendMessage(nint handle, uint message, nint wparam, nint lparam); [DllImport("user32.dll")] private static extern nint MonitorFromWindow(nint handle, uint flags); [DllImport("user32.dll", EntryPoint = "GetMonitorInfoW", SetLastError = true)] private static extern bool GetMonitorInfo(nint handle, ref MonitorInfo monitor); [DllImport("user32.dll", EntryPoint = "GetWindowLongPtrW")] private static extern nint GetWindowLongPtr(nint handle, int index); diff --git a/tests/zStudio.Desktop.Tests/SourceWorldTreeChecks.cs b/tests/zStudio.Desktop.Tests/SourceWorldTreeChecks.cs index d250c195..49748488 100644 --- a/tests/zStudio.Desktop.Tests/SourceWorldTreeChecks.cs +++ b/tests/zStudio.Desktop.Tests/SourceWorldTreeChecks.cs @@ -2,8 +2,10 @@ using System.IO.Pipes; using System.Reflection; using System.Text.Json.Nodes; +using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; +using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; using ModelContextProtocol.Client; @@ -100,6 +102,60 @@ internal static async Task Run() await ClickEye(eye); await CheckScroll(); Assert.Same(eye, System.Windows.Input.Keyboard.FocusedElement); await ClickEye(eye); await CheckScroll(); + // A real tree mouse-down restores the selected row's focus even when a row button handles it. Raising Click + // alone missed the regression where that restoration scrolls away before the intended action is delivered. + var healthyContainer = Assert.IsType(eyeRow); + var wreckRow = TreeModel().CreatedRows.Single(r => r.Index == Node("wreck")); + var wreckContainer = (TreeViewItem)typeof(MainWindow).GetMethod("RealizeRow", BindingFlags.Instance | BindingFlags.NonPublic)!.Invoke(main, [wreckRow])!; + var wreckEye = Descendants(wreckContainer).OfType