-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Ctrl+Click support for opening context menu on mac
- Loading branch information
1 parent
2cb40ac
commit d907e96
Showing
14 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Avalonia.Base/Input/Platform/PlatformPointerConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using Avalonia.Metadata; | ||
|
||
namespace Avalonia.Input.Platform; | ||
|
||
public sealed class PlatformPointerConfiguration | ||
{ | ||
public List<PointerGesture> OpenContextMenu { get; set; } | ||
|
||
[PrivateApi] | ||
public PlatformPointerConfiguration() | ||
{ | ||
OpenContextMenu = new List<PointerGesture> | ||
{ | ||
new PointerGesture(MouseButton.Right, KeyModifiers.None) | ||
}; | ||
} | ||
|
||
[PrivateApi] | ||
public PlatformPointerConfiguration(params PointerGesture[] additionalContextGestures) : this() | ||
{ | ||
OpenContextMenu.AddRange(additionalContextGestures); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Text; | ||
using Avalonia.VisualTree; | ||
|
||
namespace Avalonia.Input; | ||
|
||
public class PointerGesture : IEquatable<PointerGesture> | ||
{ | ||
public PointerGesture(MouseButton button, KeyModifiers modifiers = KeyModifiers.None) | ||
{ | ||
Button = button; | ||
KeyModifiers = modifiers; | ||
} | ||
|
||
public bool Equals(PointerGesture? other) | ||
{ | ||
if (ReferenceEquals(null, other)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
|
||
return Button == other.Button && KeyModifiers == other.KeyModifiers; | ||
} | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
|
||
return obj is KeyGesture gesture && Equals(gesture); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return ((int)Button * 397) ^ (int)KeyModifiers; | ||
} | ||
} | ||
|
||
public static bool operator ==(PointerGesture? left, PointerGesture? right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(PointerGesture? left, PointerGesture? right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
|
||
public MouseButton Button { get; } | ||
|
||
public KeyModifiers KeyModifiers { get; } | ||
|
||
public override string ToString() | ||
{ | ||
var s = new StringBuilder(); | ||
|
||
static void Plus(StringBuilder s) | ||
{ | ||
if (s.Length > 0) | ||
{ | ||
s.Append("+"); | ||
} | ||
} | ||
|
||
if (KeyModifiers.HasAllFlags(KeyModifiers.Control)) | ||
{ | ||
s.Append("Ctrl"); | ||
} | ||
|
||
if (KeyModifiers.HasAllFlags(KeyModifiers.Shift)) | ||
{ | ||
Plus(s); | ||
s.Append("Shift"); | ||
} | ||
|
||
if (KeyModifiers.HasAllFlags(KeyModifiers.Alt)) | ||
{ | ||
Plus(s); | ||
s.Append("Alt"); | ||
} | ||
|
||
if (KeyModifiers.HasAllFlags(KeyModifiers.Meta)) | ||
{ | ||
Plus(s); | ||
s.Append("Cmd"); | ||
} | ||
|
||
Plus(s); | ||
s.Append(Button); | ||
|
||
return s.ToString(); | ||
} | ||
|
||
public bool Matches(PointerEventArgs pointerEvent) => | ||
pointerEvent != null && | ||
pointerEvent.KeyModifiers == KeyModifiers && | ||
pointerEvent.GetCurrentPoint(pointerEvent.Source as Visual).Properties.PointerUpdateKind.GetMouseButton() == Button; | ||
|
||
public bool Matches(PointerReleasedEventArgs pointerEvent) => | ||
pointerEvent != null && | ||
pointerEvent.KeyModifiers == KeyModifiers && | ||
pointerEvent.InitialPressMouseButton == Button; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters