Skip to content

Commit

Permalink
Merge pull request #2538 from cwensley/curtis/mac-suppress-mouse-up-w…
Browse files Browse the repository at this point in the history
…hen-there-is-no-mousedown

Mac: Suppress MouseUp when there is no MouseDown
  • Loading branch information
cwensley authored Aug 1, 2023
2 parents 88fec23 + f7e5ae1 commit 02ad389
Showing 1 changed file with 21 additions and 2 deletions.
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

0 comments on commit 02ad389

Please sign in to comment.