diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index 1be2595ebe..60b6b9e947 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -24,7 +24,7 @@ namespace Avalonia.Input public static readonly RoutedEvent ScrollGestureEvent = RoutedEvent.Register( "ScrollGesture", RoutingStrategies.Bubble, typeof(Gestures)); - + public static readonly RoutedEvent ScrollGestureEndedEvent = RoutedEvent.Register( "ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures)); @@ -89,7 +89,7 @@ namespace Avalonia.Input { if (s_lastPress.TryGetTarget(out var target) && target == e.Source) { - e.Source.RaiseEvent(new RoutedEventArgs(DoubleTappedEvent)); + e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e)); } } } @@ -105,8 +105,14 @@ namespace Avalonia.Input { if (e.InitialPressMouseButton == MouseButton.Left || e.InitialPressMouseButton == MouseButton.Right) { - var et = e.InitialPressMouseButton != MouseButton.Right ? TappedEvent : RightTappedEvent; - e.Source.RaiseEvent(new RoutedEventArgs(et)); + if (e.InitialPressMouseButton == MouseButton.Right) + { + e.Source.RaiseEvent(new TappedEventArgs(RightTappedEvent, e)); + } + else + { + e.Source.RaiseEvent(new TappedEventArgs(TappedEvent, e)); + } } } } diff --git a/src/Avalonia.Input/PointerEventArgs.cs b/src/Avalonia.Input/PointerEventArgs.cs index 451f80b1df..ba39f7ca8e 100644 --- a/src/Avalonia.Input/PointerEventArgs.cs +++ b/src/Avalonia.Input/PointerEventArgs.cs @@ -107,7 +107,9 @@ namespace Avalonia.Input None, Left, Right, - Middle + Middle, + XButton1, + XButton2 } public class PointerPressedEventArgs : PointerEventArgs diff --git a/src/Avalonia.Input/PointerPoint.cs b/src/Avalonia.Input/PointerPoint.cs index a316e0d964..ebc64fa2f9 100644 --- a/src/Avalonia.Input/PointerPoint.cs +++ b/src/Avalonia.Input/PointerPoint.cs @@ -90,6 +90,10 @@ namespace Avalonia.Input return MouseButton.Middle; if (kind == PointerUpdateKind.RightButtonPressed || kind == PointerUpdateKind.RightButtonReleased) return MouseButton.Right; + if (kind == PointerUpdateKind.XButton1Pressed || kind == PointerUpdateKind.XButton1Released) + return MouseButton.XButton1; + if (kind == PointerUpdateKind.XButton2Pressed || kind == PointerUpdateKind.XButton2Released) + return MouseButton.XButton2; return MouseButton.None; } } diff --git a/src/Avalonia.Input/TappedEventArgs.cs b/src/Avalonia.Input/TappedEventArgs.cs new file mode 100644 index 0000000000..02add509cd --- /dev/null +++ b/src/Avalonia.Input/TappedEventArgs.cs @@ -0,0 +1,18 @@ +using Avalonia.Interactivity; +using Avalonia.VisualTree; + +namespace Avalonia.Input +{ + public class TappedEventArgs : RoutedEventArgs + { + private readonly PointerEventArgs lastPointerEventArgs; + + public TappedEventArgs(RoutedEvent routedEvent, PointerEventArgs lastPointerEventArgs) + : base(routedEvent) + { + this.lastPointerEventArgs = lastPointerEventArgs; + } + + public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); + } +} diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index a42dd5fc07..f3f8618cc9 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -85,6 +85,7 @@ namespace Avalonia.Win32 private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; private bool _isCloseRequested; private bool _shown; + private bool _hiddenWindowIsParent; public WindowImpl() { @@ -483,8 +484,8 @@ namespace Avalonia.Win32 IntPtr.Zero, 0, 0, - requestedClientWidth + (windowRect.Width - clientRect.Width), - requestedClientHeight + (windowRect.Height - clientRect.Height), + requestedClientWidth + (_isClientAreaExtended ? 0 : windowRect.Width - clientRect.Width), + requestedClientHeight + (_isClientAreaExtended ? 0 : windowRect.Height - clientRect.Height), SetWindowPosFlags.SWP_RESIZE); } } @@ -571,8 +572,7 @@ namespace Avalonia.Win32 public virtual void Show(bool activate) { - SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent != null ? _parent._hwnd : IntPtr.Zero); - + SetParent(_parent); ShowWindow(_showWindowState, activate); } @@ -580,8 +580,15 @@ namespace Avalonia.Win32 public void SetParent(IWindowImpl parent) { - _parent = (WindowImpl)parent; - SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, _parent._hwnd); + var parentHwnd = ((WindowImpl)parent)?._hwnd ?? IntPtr.Zero; + + if (parentHwnd == IntPtr.Zero && !_windowProperties.ShowInTaskbar) + { + parentHwnd = OffscreenParentWindow.Handle; + _hiddenWindowIsParent = true; + } + + SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, parentHwnd); } public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable); @@ -883,20 +890,19 @@ namespace Avalonia.Win32 _isClientAreaExtended = false; return; } - - GetWindowRect(_hwnd, out var rcClient); + GetClientRect(_hwnd, out var rcClient); + GetWindowRect(_hwnd, out var rcWindow); // Inform the application of the frame change. SetWindowPos(_hwnd, - IntPtr.Zero, - rcClient.left, rcClient.top, - rcClient.Width, rcClient.Height, - SetWindowPosFlags.SWP_FRAMECHANGED); + IntPtr.Zero, + rcWindow.left, rcWindow.top, + rcClient.Width, rcClient.Height, + SetWindowPosFlags.SWP_FRAMECHANGED); if (_isClientAreaExtended && WindowState != WindowState.FullScreen) { var margins = UpdateExtendMargins(); - DwmExtendFrameIntoClientArea(_hwnd, ref margins); } else @@ -906,6 +912,8 @@ namespace Avalonia.Win32 _offScreenMargin = new Thickness(); _extendedMargins = new Thickness(); + + Resize(new Size(rcWindow.Width/ RenderScaling, rcWindow.Height / RenderScaling)); } if(!_isClientAreaExtended || (_extendChromeHints.HasFlagCustom(ExtendClientAreaChromeHints.SystemChrome) && @@ -1094,16 +1102,38 @@ namespace Avalonia.Win32 if (newProperties.ShowInTaskbar) { exStyle |= WindowStyles.WS_EX_APPWINDOW; + + if (_hiddenWindowIsParent) + { + // Can't enable the taskbar icon by clearing the parent window unless the window + // is hidden. Hide the window and show it again with the same activation state + // when we've finished. Interestingly it seems to work fine the other way. + var shown = IsWindowVisible(_hwnd); + var activated = GetActiveWindow() == _hwnd; + + if (shown) + Hide(); + + _hiddenWindowIsParent = false; + SetParent(null); + + if (shown) + Show(activated); + } } else { + // To hide a non-owned window's taskbar icon we need to parent it to a hidden window. + if (_parent is null) + { + SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, OffscreenParentWindow.Handle); + _hiddenWindowIsParent = true; + } + exStyle &= ~WindowStyles.WS_EX_APPWINDOW; } SetExtendedStyle(exStyle); - - // TODO: To hide non-owned window from taskbar we need to parent it to a hidden window. - // Otherwise it will still show in the taskbar. } WindowStyles style;