This repository was archived by the owner on Jun 10, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 } ) ;
Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 -->
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments