Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

Commit 32ace99

Browse files
authored
Merge pull request #18 from Redth/element-screenshots
Fix GTK modal screenshots and update Linux GTK packages to 0.5.0
2 parents 090601c + 303af0b commit 32ace99

5 files changed

Lines changed: 48 additions & 7 deletions

File tree

src/MauiDevFlow.Agent.Core/DevFlowAgentService.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,37 @@ protected virtual async Task<HttpResponse> HandleScreenshot(HttpRequest request)
342342
var pngData = await DispatchAsync(async () =>
343343
{
344344
var window = GetWindow(windowIndex);
345-
if (window?.Page is not VisualElement rootElement) return null;
345+
if (window == null) return null;
346+
347+
// If a modal page is displayed, capture it instead of the underlying page
348+
VisualElement? topModal = null;
349+
try
350+
{
351+
var modalStack = window.Page?.Navigation?.ModalStack;
352+
if (modalStack?.Count > 0 && modalStack[^1] is VisualElement ms)
353+
topModal = ms;
354+
}
355+
catch { }
356+
357+
// Fallback: check Window's visual children for modal pages
358+
// (on some platforms like GTK, modals appear as direct children of the Window)
359+
if (topModal == null && window is IVisualTreeElement windowVte)
360+
{
361+
var children = windowVte.GetVisualChildren();
362+
for (int i = children.Count - 1; i >= 0; i--)
363+
{
364+
if (children[i] is Page page && page != window.Page)
365+
{
366+
topModal = page;
367+
break;
368+
}
369+
}
370+
}
371+
372+
if (topModal != null)
373+
return await CaptureScreenshotAsync(topModal);
374+
375+
if (window.Page is not VisualElement rootElement) return null;
346376

347377
return await CaptureScreenshotAsync(rootElement);
348378
});

src/MauiDevFlow.Agent.Gtk/GtkAgentService.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,18 @@ protected override bool TryNativeTap(VisualElement ve)
106106
}
107107
catch { }
108108

109-
// GTK4-specific fallback: capture via Gtk.WidgetPaintable
109+
// GTK4-specific fallback: capture the rootElement's native widget directly
110+
try
111+
{
112+
if (rootElement.Handler?.PlatformView is global::Gtk.Widget widget)
113+
{
114+
var pngBytes = CaptureGtkWidget(widget);
115+
if (pngBytes != null) return pngBytes;
116+
}
117+
}
118+
catch { }
119+
120+
// Final fallback: capture the main GTK window
110121
try
111122
{
112123
var window = Application.Current?.Windows.FirstOrDefault();

src/MauiDevFlow.Agent.Gtk/MauiDevFlow.Agent.Gtk.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.2.3" />
16+
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.5.0" />
1717
</ItemGroup>
1818

1919
</Project>

src/MauiDevFlow.Blazor.Gtk/MauiDevFlow.Blazor.Gtk.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.2.3" />
17+
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.5.0" />
1818
</ItemGroup>
1919

2020
<!-- Embed JS scripts as resources -->

src/SampleMauiApp.Linux/SampleMauiApp.Linux.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.2.3" />
13-
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.2.3" />
14-
<PackageReference Include="Platform.Maui.Linux.Gtk4.Essentials" Version="0.2.3" />
12+
<PackageReference Include="Platform.Maui.Linux.Gtk4" Version="0.5.0" />
13+
<PackageReference Include="Platform.Maui.Linux.Gtk4.BlazorWebView" Version="0.5.0" />
14+
<PackageReference Include="Platform.Maui.Linux.Gtk4.Essentials" Version="0.5.0" />
1515
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
1616
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
1717
</ItemGroup>

0 commit comments

Comments
 (0)