Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Suppress MouseUp when there is no MouseDown #2538

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Eto.Mac/Forms/MacView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ static partial class MacView
public static readonly bool supportsCanDrawSubviewsIntoLayer = ObjCExtensions.InstancesRespondToSelector<NSView>("setCanDrawSubviewsIntoLayer:");
public static readonly object UseAlignmentFrame_Key = new object();
public static readonly object SuppressMouseEvents_Key = new object();
public static readonly object SuppressMouseUp_Key = new object();
public static readonly object UseMouseTrackingLoop_Key = new object();
public static readonly object MouseTrackingRunLoopMode_Key = new object();
public static readonly object UseNSBoxBackgroundColor_Key = new object();
Expand Down Expand Up @@ -1428,6 +1429,12 @@ public int SuppressMouseEvents
set => Widget.Properties.Set<int>(MacView.SuppressMouseEvents_Key, value);
}

bool SuppressMouseUp
{
get => Widget.Properties.Get<bool>(MacView.SuppressMouseUp_Key);
set => Widget.Properties.Set<bool>(MacView.SuppressMouseUp_Key, value);
}

public static bool SuppressMouseTriggerCallback { get; set; }

/// <summary>
Expand Down Expand Up @@ -1543,9 +1550,16 @@ public virtual MouseEventArgs TriggerMouseDown(NSObject obj, IntPtr sel, NSEvent

var args = MacConversions.GetMouseEvent(this, theEvent, false);

// ensure we're actually in the control's bounds
// Ensure we're actually in the control's bounds
if (!new RectangleF(Size).Contains(args.Location))
{
// This can happen e.g. when double clicking outside of the control after a ContextMenu is shown during MouseUp.
Messaging.void_objc_msgSendSuper_IntPtr(obj.SuperHandle, sel, theEvent.Handle);
SuppressMouseUp = true;
return null;
}

SuppressMouseUp = false; // MouseDown is called, so we are expecting a MouseUp

// Flag that we are going to use a mouse tracking loop
// if this is set to false during the OnMouseDown/OnMouseDoubleClick, then we won't
Expand Down Expand Up @@ -1613,7 +1627,12 @@ public virtual MouseEventArgs TriggerMouseDown(NSObject obj, IntPtr sel, NSEvent
public virtual MouseEventArgs TriggerMouseUp(NSObject obj, IntPtr sel, NSEvent theEvent)
{
var args = MacConversions.GetMouseEvent(this, theEvent, false);
Callback.OnMouseUp(Widget, args);
if (!SuppressMouseUp)
{
Callback.OnMouseUp(Widget, args);
SuppressMouseUp = false;
}

if (!args.Handled)
{
Messaging.void_objc_msgSendSuper_IntPtr(obj.SuperHandle, sel, theEvent.Handle);
Expand Down
Loading