@@ -177,22 +177,31 @@ private void DrawingArea_InitializeGraphicsBackend(object? sender, EventArgs e)
177177 Console . WriteLine ( "[DEBUG] Ensured native window for DrawingArea" ) ;
178178 }
179179
180- // For Wayland, we need to ensure the window is properly mapped before initializing
180+ // Ensure the widget is shown - this is critical for Wayland
181+ if ( drawingArea != null && ! drawingArea . Visible )
182+ {
183+ Console . WriteLine ( "[DEBUG] Making DrawingArea visible" ) ;
184+ drawingArea . ShowAll ( ) ;
185+ }
186+
187+ // For Wayland, wait a bit for the surface to be committed by the compositor
181188 var gdkDisplay = drawingArea ! . Display . Handle ;
182189 bool isWayland = X11Interop . IsWaylandDisplay ( gdkDisplay ) ;
183190
184- if ( isWayland && ! drawingArea . Window . IsVisible )
191+ if ( isWayland )
185192 {
186- Console . WriteLine ( "[DEBUG] Wayland window not visible yet, deferring initialization" ) ;
187- // Defer initialization until window is visible
188- drawingArea . Shown += ( s , args ) => {
189- Console . WriteLine ( "[DEBUG] Wayland window shown, initializing backend" ) ;
190- Callback . OnInitializeBackend ( Widget , new InitializeEventArgs ( RenderSize ) ) ;
191- } ;
192- return ;
193+ Console . WriteLine ( "[DEBUG] Wayland detected, processing events before initialization" ) ;
194+ // Process pending events to ensure surface is ready
195+ while ( global ::Gtk . Application . EventsPending ( ) )
196+ {
197+ global ::Gtk . Application . RunIteration ( ) ;
198+ }
199+
200+ // Small delay to ensure compositor has committed the surface
201+ System . Threading . Thread . Sleep ( 50 ) ;
193202 }
194203
195- // Initialize immediately for X11 or when Wayland window is ready
204+ // Initialize graphics backend
196205 Console . WriteLine ( "[DEBUG] Initializing graphics backend" ) ;
197206 Callback . OnInitializeBackend ( Widget , new InitializeEventArgs ( RenderSize ) ) ;
198207 }
@@ -336,6 +345,9 @@ void Forms.Control.IHandler.Invalidate(bool invalidateChildren)
336345 // This is critical for Wayland support
337346 drawingArea . AppPaintable = true ;
338347
348+ // Make sure the widget is visible
349+ drawingArea . Visible = true ;
350+
339351 // Use Realized event for initialization
340352 drawingArea . Realized += DrawingArea_InitializeGraphicsBackend ;
341353
0 commit comments