diff --git a/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs b/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs index 52c592f45b02..94660cf559ff 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.cs @@ -51,13 +51,6 @@ public GLRenderSurfaceBase() { _displayInformation = DisplayInformation.GetForCurrentView(); _displayInformation.DpiChanged += OnDpiChanged; - WUX.Window.InvalidateRender - += () => - { - // TODO Uno: Make this invalidation less often if possible. - InvalidateOverlays(); - QueueRender(); - }; // Set some event handlers Render += UnoGLDrawingArea_Render; @@ -68,6 +61,13 @@ public GLRenderSurfaceBase() AutoRender = true; } + public void InvalidateRender() + { + // TODO Uno: Make this invalidation less often if possible. + InvalidateOverlays(); + QueueRender(); + } + private void GLRenderSurface_Realized(object? sender, EventArgs e) { Context.MakeCurrent(); diff --git a/src/Uno.UI.Runtime.Skia.Gtk/GtkCoreWindowExtension.cs b/src/Uno.UI.Runtime.Skia.Gtk/GtkCoreWindowExtension.cs index 7db2c08f03aa..ce73b390fbe4 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/GtkCoreWindowExtension.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/GtkCoreWindowExtension.cs @@ -14,6 +14,8 @@ using Device = Gtk.Device; using Exception = System.Exception; using Uno.Foundation.Logging; +using Windows.UI.Xaml; +using Uno.UI.Xaml.Core; namespace Uno.UI.Runtime.Skia { @@ -104,7 +106,7 @@ private void OnWindowEnterEvent(object o, EnterNotifyEventArgs args) { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerEntered(ptArgs); + RaisePointerEntered(ptArgs); } } catch (Exception e) @@ -125,7 +127,7 @@ private void OnWindowLeaveEvent(object o, LeaveNotifyEventArgs args) { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerExited(ptArgs); + RaisePointerExited(ptArgs); } } } @@ -141,7 +143,7 @@ private void OnWindowButtonPressEvent(object o, ButtonPressEventArgs args) { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerPressed(ptArgs); + RaisePointerPressed(ptArgs); } } catch (Exception e) @@ -156,7 +158,7 @@ private void OnWindowButtonReleaseEvent(object o, ButtonReleaseEventArgs args) { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerReleased(ptArgs); + RaisePointerReleased(ptArgs); } } catch (Exception e) @@ -171,7 +173,7 @@ private void OnWindowMotionEvent(object o, MotionNotifyEventArgs args) // a.k.a. { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerMoved(ptArgs); + RaisePointerMoved(ptArgs); } } catch (Exception e) @@ -186,7 +188,7 @@ private void OnWindowScrollEvent(object o, ScrollEventArgs args) { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerWheelChanged(ptArgs); + RaisePointerWheelChanged(ptArgs); } } catch (Exception e) @@ -206,21 +208,21 @@ private void OnWindowTouchEvent(object o, TouchEventArgs args) switch (evt.Type) { case EventType.TouchBegin: - _ownerEvents.RaisePointerEntered(ptArgs); - _ownerEvents.RaisePointerPressed(ptArgs); + RaisePointerEntered(ptArgs); + RaisePointerPressed(ptArgs); break; case EventType.TouchEnd: - _ownerEvents.RaisePointerReleased(ptArgs); - _ownerEvents.RaisePointerExited(ptArgs); + RaisePointerReleased(ptArgs); + RaisePointerExited(ptArgs); break; case EventType.TouchCancel: - _ownerEvents.RaisePointerMoved(ptArgs); + RaisePointerMoved(ptArgs); break; } - _ownerEvents.RaisePointerMoved(ptArgs); + RaisePointerMoved(ptArgs); } } catch (Exception e) @@ -235,7 +237,7 @@ private void OnWindowProximityOutEvent(object o, ProximityOutEventArgs args) { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerExited(ptArgs); + RaisePointerExited(ptArgs); } } catch (Exception e) @@ -250,7 +252,7 @@ private void OnWindowProximityInEvent(object o, ProximityInEventArgs args) { if (AsPointerArgs(args.Event) is { } ptArgs) { - _ownerEvents.RaisePointerEntered(ptArgs); + RaisePointerEntered(ptArgs); } } catch (Exception e) @@ -448,5 +450,49 @@ private static PointerDevice ToPointerDevice(Gdk.Device sourceDevice) private static bool IsPressed(ModifierType state, ModifierType mask, PointerUpdateKind update, PointerUpdateKind pressed, PointerUpdateKind released) => update == pressed || (state.HasFlag(mask) && update != released); + + private void RaisePointerExited(PointerEventArgs ptArgs) + { + _ownerEvents.RaisePointerExited(ptArgs); + InputManager?.RaisePointerExited(ptArgs); + } + + private void RaisePointerPressed(PointerEventArgs ptArgs) + { + _ownerEvents.RaisePointerPressed(ptArgs); + InputManager?.RaisePointerPressed(ptArgs); + } + + private void RaisePointerReleased(PointerEventArgs ptArgs) + { + _ownerEvents.RaisePointerReleased(ptArgs); + InputManager?.RaisePointerReleased(ptArgs); + } + + private void RaisePointerMoved(PointerEventArgs ptArgs) + { + _ownerEvents.RaisePointerMoved(ptArgs); + InputManager?.RaisePointerMoved(ptArgs); + } + + private void RaisePointerWheelChanged(PointerEventArgs ptArgs) + { + _ownerEvents.RaisePointerWheelChanged(ptArgs); + InputManager?.RaisePointerWheelChanged(ptArgs); + } + + private void RaisePointerEntered(PointerEventArgs ptArgs) + { + _ownerEvents.RaisePointerEntered(ptArgs); + InputManager?.RaisePointerEntered(ptArgs); + } + + + + internal InputManager InputManager => + CoreServices.Instance + .ContentRootCoordinator? + .CoreWindowContentRoot? + .InputManager; } } diff --git a/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs b/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs index 7c8f612de390..e50120f423b5 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/GtkHost.cs @@ -31,6 +31,8 @@ using Uno.UI.Runtime.Skia.Helpers; using Uno.UI.Runtime.Skia.Helpers.Dpi; using System.Runtime.InteropServices; +using Uno.UI.Xaml.Core; +using Windows.UI.Core; namespace Uno.UI.Runtime.Skia { @@ -42,6 +44,7 @@ public class GtkHost : ISkiaHost private static bool _isDispatcherThread = false; private readonly Func _appBuilder; + private IRenderSurface _renderSurface; private static Gtk.Window _window; private static Gtk.EventBox _eventBox; private Widget _area; @@ -147,7 +150,9 @@ void Dispatch(System.Action d) var overlay = new Overlay(); _eventBox = new EventBox(); - _area = BuildRenderSurfaceType(); + + _renderSurface = BuildRenderSurfaceType(); + _area = (Widget)_renderSurface; _fix = new Fixed(); overlay.Add(_area); overlay.AddOverlay(_fix); @@ -182,11 +187,32 @@ void CreateApp(ApplicationInitializationCallbackParams _) WUX.Application.StartWithArguments(CreateApp); + WUX.Window.Current.Activated += Current_Activated; + UpdateWindowPropertiesFromPackage(); Gtk.Application.Run(); } + private void Current_Activated(object sender, WindowActivatedEventArgs e) + { + var xamlRoot = CoreServices.Instance + .ContentRootCoordinator? + .CoreWindowContentRoot? + .XamlRoot; + + if (xamlRoot is null) + { + throw new InvalidOperationException("XamlRoot was not properly initialized"); + } + + xamlRoot.InvalidateRender += _renderSurface.InvalidateRender; + + // Force initial render + _renderSurface.InvalidateRender(); + WUX.Window.Current.Activated -= Current_Activated; + } + private void WindowClosing(object sender, DeleteEventArgs args) { var manager = SystemNavigationManagerPreview.GetForCurrentView(); diff --git a/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs b/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs index d3519672bb58..21ea4f91a9a8 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/IRenderSurface.cs @@ -3,5 +3,7 @@ internal interface IRenderSurface { void TakeScreenshot(string filePath); + + void InvalidateRender(); } } diff --git a/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs b/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs index 5a20f7231583..d73e6b50371d 100644 --- a/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs +++ b/src/Uno.UI.Runtime.Skia.Gtk/SoftwareRenderSurface.cs @@ -36,6 +36,14 @@ public SoftwareRenderSurface() { _displayInformation = DisplayInformation.GetForCurrentView(); _displayInformation.DpiChanged += OnDpiChanged; + } + + public void InvalidateRender() + { + //TODO:MZ: Fix below conflict! + // TODO Uno: Make this invalidation less often if possible. + InvalidateOverlays(); + Invalidate(); WUX.Window.InvalidateRender += () => { diff --git a/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs b/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs index 88a0b5336733..4b99f97d1392 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs @@ -19,17 +19,20 @@ using Uno.UI.Core.Preview; using Uno.UI.Runtime.Skia.Wpf; using Uno.UI.Runtime.Skia.Wpf.Extensions.UI.Xaml.Input; +using Uno.UI.Runtime.Skia.Wpf.Hosting; using Uno.UI.Runtime.Skia.Wpf.WPF.Extensions.Helper.Theming; using Uno.UI.Runtime.Skia.WPF.Extensions.UI.Xaml.Controls; using Uno.UI.Xaml; using Uno.UI.Xaml.Controls.Extensions; using Uno.UI.Xaml.Core; using Uno.UI.Xaml.Input; +using Uno.UI.XamlHost.Skia.Wpf; using Windows.Devices.Input; using Windows.Graphics.Display; using Windows.Networking.Connectivity; using Windows.Storage.Pickers; using Windows.System.Profile.Internal; +using Windows.UI.Core; using Windows.UI.Core.Preview; using Windows.UI.ViewManagement; using Windows.UI.Xaml.Controls; @@ -68,6 +71,7 @@ static WpfHost() } private static bool _extensionsRegistered; + private HostPointerHandler _hostPointerHandler; internal static void RegisterExtensions() { @@ -126,12 +130,8 @@ void CreateApp(WinUI.ApplicationInitializationCallbackParams _) WinUI.Application.StartWithArguments(CreateApp); - //TODO:MZ: - //WinUI.Window.InvalidateRender += () => - //{ - // InvalidateOverlays(); - // InvalidateVisual(); - //}; + _hostPointerHandler = new HostPointerHandler(this); + WinUI.Window.Current.Activated += Current_Activated; WpfApplication.Current.Activated += Current_Activated; WpfApplication.Current.Deactivated += Current_Deactivated; @@ -149,6 +149,32 @@ void CreateApp(WinUI.ApplicationInitializationCallbackParams _) Loaded += WpfHost_Loaded; } + private void Current_Activated(object sender, WindowActivatedEventArgs e) + { + var xamlRoot = CoreServices.Instance + .ContentRootCoordinator? + .CoreWindowContentRoot? + .XamlRoot; + + if (xamlRoot is null) + { + throw new InvalidOperationException("XamlRoot was not properly initialized"); + } + + xamlRoot.InvalidateRender += InvalidateRender; + XamlRootMap.Register(xamlRoot, this); + + // Force initial render + InvalidateRender(); + WinUI.Window.Current.Activated -= Current_Activated; + } + + private void InvalidateRender() + { + InvalidateOverlays(); + InvalidateVisual(); + } + private void MainWindow_Closing(object sender, CancelEventArgs e) { var manager = SystemNavigationManagerPreview.GetForCurrentView();