-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2119 from cwensley/curtis/window-frompoint
Add Window.FromPoint API
- Loading branch information
Showing
11 changed files
with
193 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using System.Linq; | ||
|
||
namespace Eto.GtkSharp.Forms | ||
{ | ||
public class WindowHandler : Window.IWindowHandler | ||
{ | ||
public Window FromPoint(PointF point) | ||
{ | ||
var screenWindowStackWorks = false; | ||
var windowStack = Gdk.Screen.Default.WindowStack; | ||
if (windowStack != null) | ||
{ | ||
// doesn't work on Mac or Windows.. 🤔 | ||
foreach (var gdkWindow in windowStack.Reverse()) | ||
{ | ||
screenWindowStackWorks = true; | ||
if (!gdkWindow.FrameExtents.Contains((int)point.X, (int)point.Y)) | ||
continue; | ||
|
||
foreach (var window in Application.Instance.Windows) | ||
{ | ||
if (window.Handler is IGtkWindow handler && handler.Control.GetWindow()?.Handle == gdkWindow.Handle) | ||
{ | ||
return window; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (!screenWindowStackWorks) | ||
{ | ||
// fallback to looking at all windows in no particular order. | ||
// TODO: this needs a proper implementation for Mac and Windows since Screen.WindowStack doesn't actually work | ||
var pt = Point.Round(point); | ||
foreach (var window in Application.Instance.Windows) | ||
{ | ||
if (window.Bounds.Contains(pt)) | ||
{ | ||
return window; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using System.Linq; | ||
#if XAMMAC2 | ||
using AppKit; | ||
using Foundation; | ||
using CoreGraphics; | ||
using ObjCRuntime; | ||
using CoreAnimation; | ||
#else | ||
using MonoMac.AppKit; | ||
using MonoMac.Foundation; | ||
using MonoMac.CoreGraphics; | ||
using MonoMac.ObjCRuntime; | ||
using MonoMac.CoreAnimation; | ||
#endif | ||
|
||
namespace Eto.Mac.Forms | ||
{ | ||
public class WindowHandler : Window.IWindowHandler | ||
{ | ||
public Window FromPoint(PointF point) | ||
{ | ||
var mainFrame = NSScreen.Screens[0].Frame; | ||
var nspoint = new CGPoint(point.X, mainFrame.Height - point.Y); | ||
var windowNumber = NSWindow.WindowNumberAtPoint(nspoint, 0); | ||
foreach (var window in Application.Instance.Windows) | ||
{ | ||
if (window.Handler is IMacWindow handler && handler.Control.WindowNumber == windowNumber) | ||
{ | ||
return window; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
|
||
namespace Eto.Wpf.Forms | ||
{ | ||
|
||
public class WindowHandler : Window.IWindowHandler | ||
{ | ||
internal static readonly object MovableByWindowBackground_Key = new object(); | ||
|
||
public Window FromPoint(PointF point) | ||
{ | ||
var screenPoint = point.LogicalToScreen(); | ||
var windowHandle = Win32.WindowFromPoint(new Win32.POINT(screenPoint.X, screenPoint.Y)); | ||
if (windowHandle == IntPtr.Zero) | ||
return null; | ||
windowHandle = Win32.GetAncestor(windowHandle, Win32.GA.GA_ROOT); | ||
|
||
foreach (var window in Application.Instance.Windows) | ||
{ | ||
if (window.NativeHandle == windowHandle) | ||
{ | ||
return window; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
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