1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-23 12:15:48 +02:00

Fix video player showing controls when cursor is above a different window

Closes 
This commit is contained in:
chylex 2023-03-18 13:46:39 +01:00
parent 9a6394d079
commit 23ebd58da0
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
2 changed files with 14 additions and 1 deletions
windows/TweetDuck.Video

View File

@ -237,7 +237,7 @@ private void timerSync_Tick(object? sender, EventArgs e) {
int maxWidth = Math.Min(DpiScaled(media.imageSourceWidth), ownerWidth * 3 / 4);
int maxHeight = Math.Min(DpiScaled(media.imageSourceHeight), ownerHeight * 3 / 4);
bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position));
bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position)) && Handle == NativeMethods.GetFormHandleAt(Cursor.Position);
Size newSize = new Size(Math.Max(minWidth + 2, maxWidth), Math.Max(minHeight + 2, maxHeight));
Point newLocation = new Point(ownerLeft + (ownerWidth - newSize.Width) / 2, ownerTop + (ownerHeight - newSize.Height + SystemInformation.CaptionHeight) / 2);

View File

@ -1,11 +1,13 @@
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Runtime.InteropServices;
namespace TweetDuck.Video {
[SuppressMessage("ReSharper", "InconsistentNaming")]
static class NativeMethods {
private const int GA_ROOT = 2;
private const int GWL_HWNDPARENT = -8;
[DllImport("user32.dll")]
@ -24,6 +26,12 @@ static class NativeMethods {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern IntPtr WindowFromPoint(Point point);
[DllImport("user32.dll")]
private static extern IntPtr GetAncestor(IntPtr hwnd, int flags);
[DllImport("user32.dll")]
public static extern bool SetProcessDPIAware();
@ -49,5 +57,10 @@ public static void SetWindowOwner(IntPtr child, IntPtr owner) {
* ...so technically, this is following the documentation to the word.
*/
}
public static IntPtr GetFormHandleAt(Point point) {
IntPtr window = WindowFromPoint(point);
return window == IntPtr.Zero ? IntPtr.Zero : GetAncestor(window, GA_ROOT);
}
}
}