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: Accept first mouse events on FloatingForm when active #2234

Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions src/Eto.Mac/Forms/Controls/DrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public override void DrawRect(CGRect dirtyRect)

public override bool AcceptsFirstResponder() => CanFocus;

public override bool AcceptsFirstMouse(NSEvent theEvent) => CanFocus || base.AcceptsFirstMouse(theEvent);

public override NSView HitTest(CGPoint aPoint)
{
var view = base.HitTest(aPoint);
Expand Down Expand Up @@ -130,5 +128,12 @@ public void Update(Rectangle rect)
{
Control.DisplayRect(rect.ToNS());
}

protected override bool OnAcceptsFirstMouse(NSEvent theEvent)
{
if (CanFocus)
return true;
return base.OnAcceptsFirstMouse(theEvent);
}
}
}
5 changes: 5 additions & 0 deletions src/Eto.Mac/Forms/Controls/SplitterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ public override void Layout()
if (!MacView.NewLayout)
base.Layout();
}

public override bool AcceptsFirstMouse(NSEvent theEvent)
{
return Handler != null ? Handler.OnAcceptsFirstMouse(theEvent) : base.AcceptsFirstMouse(theEvent);
}
}

bool changeStarted;
Expand Down
15 changes: 8 additions & 7 deletions src/Eto.Mac/Forms/MacView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,21 +1419,22 @@ public event EventHandler<MouseEventArgs> AcceptsFirstMouse
remove => Widget.Properties.RemoveEvent(MacView.AcceptsFirstMouse_Key, value);
}

protected virtual void OnAcceptsFirstMouse(MouseEventArgs e)
{
Widget?.Properties.TriggerEvent(MacView.AcceptsFirstMouse_Key, this, e);
}

bool IMacViewHandler.OnAcceptsFirstMouse(NSEvent theEvent)
protected virtual bool OnAcceptsFirstMouse(NSEvent theEvent)
{
if (!Widget.Properties.ContainsKey(MacView.AcceptsFirstMouse_Key))
{
if (ContainerControl.Window is NSPanel)
return Application.Instance.IsActive;
return false;
}

var args = MacConversions.GetMouseEvent(this, theEvent, false);
OnAcceptsFirstMouse(args);
Widget.Properties.TriggerEvent(MacView.AcceptsFirstMouse_Key, this, args);
return args.Handled;
}

bool IMacViewHandler.OnAcceptsFirstMouse(NSEvent theEvent) => OnAcceptsFirstMouse(theEvent);

public virtual MouseEventArgs TriggerMouseDown(NSObject obj, IntPtr sel, NSEvent theEvent)
{
// Flag that we are going to use a mouse tracking loop
Expand Down