Browse Source

Merge pull request #5110 from AvaloniaUI/fixes/osx-extended-titlebar-double-click

OSX extended Window Frame - detecting chrome double click.
pull/5112/head
Dan Walmsley 6 years ago
committed by GitHub
parent
commit
2b47ba08c9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/Avalonia.Native/DoubleClickHelper.cs
  2. 22
      src/Avalonia.Native/WindowImpl.cs

31
src/Avalonia.Native/DoubleClickHelper.cs

@ -0,0 +1,31 @@
using Avalonia.Platform;
namespace Avalonia.Native
{
internal class DoubleClickHelper
{
private int _clickCount;
private Rect _lastClickRect;
private ulong _lastClickTime;
public bool IsDoubleClick(
ulong timestamp,
Point p)
{
var settings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds;
if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
{
_clickCount = 0;
}
++_clickCount;
_lastClickTime = timestamp;
_lastClickRect = new Rect(p, new Size())
.Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2));
return _clickCount == 2;
}
}
}

22
src/Avalonia.Native/WindowImpl.cs

@ -1,4 +1,5 @@
using System; using System;
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Platform; using Avalonia.Controls.Platform;
using Avalonia.Input; using Avalonia.Input;
@ -17,6 +18,8 @@ namespace Avalonia.Native
private readonly AvaloniaNativePlatformOpenGlInterface _glFeature; private readonly AvaloniaNativePlatformOpenGlInterface _glFeature;
IAvnWindow _native; IAvnWindow _native;
private double _extendTitleBarHeight = -1; private double _extendTitleBarHeight = -1;
private DoubleClickHelper _doubleClickHelper;
internal WindowImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts, internal WindowImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts,
AvaloniaNativePlatformOpenGlInterface glFeature) : base(opts, glFeature) AvaloniaNativePlatformOpenGlInterface glFeature) : base(opts, glFeature)
@ -24,6 +27,8 @@ namespace Avalonia.Native
_factory = factory; _factory = factory;
_opts = opts; _opts = opts;
_glFeature = glFeature; _glFeature = glFeature;
_doubleClickHelper = new DoubleClickHelper();
using (var e = new WindowEvents(this)) using (var e = new WindowEvents(this))
{ {
var context = _opts.UseGpu ? glFeature?.MainContext : null; var context = _opts.UseGpu ? glFeature?.MainContext : null;
@ -118,7 +123,22 @@ namespace Avalonia.Native
if(visual == null) if(visual == null)
{ {
_native.BeginMoveDrag(); if (_doubleClickHelper.IsDoubleClick(e.Timestamp, e.Position))
{
// TOGGLE WINDOW STATE.
if (WindowState == WindowState.Maximized || WindowState == WindowState.FullScreen)
{
WindowState = WindowState.Normal;
}
else
{
WindowState = WindowState.Maximized;
}
}
else
{
_native.BeginMoveDrag();
}
} }
} }
} }

Loading…
Cancel
Save