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

TitleBar Buttons not working in some cases #1373

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,39 @@
),
};
}

PresentationSource presentationSource = null;

Check warning on line 236 in src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

protected bool IsMouseOverElement(nint lParam)

Check warning on line 238 in src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs

View workflow job for this annotation

GitHub Actions / build

{

Check warning on line 239 in src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs

View workflow job for this annotation

GitHub Actions / build

System.Drawing.Point winPoint;

Check warning on line 240 in src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs

View workflow job for this annotation

GitHub Actions / build

bool gotCursorPos = User32.GetCursorPos(out winPoint);

Check warning on line 241 in src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs

View workflow job for this annotation

GitHub Actions / build


if (!gotCursorPos)

Check warning on line 243 in src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs

View workflow job for this annotation

GitHub Actions / build

{

Check warning on line 244 in src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs

View workflow job for this annotation

GitHub Actions / build

int fallbackX = unchecked((short)((long)lParam & 0xFFFF));
int fallbackY = unchecked((short)(((long)lParam >> 16) & 0xFFFF));
winPoint = new System.Drawing.Point(fallbackX, fallbackY);
}

var screenPoint = new System.Windows.Point(winPoint.X, winPoint.Y);

presentationSource ??= PresentationSource.FromVisual(this);

if (presentationSource?.CompositionTarget != null)
{
screenPoint = presentationSource.CompositionTarget.TransformFromDevice.Transform(screenPoint);
}

var localPoint = this.PointFromScreen(screenPoint);

var hitTestRect =
new System.Windows.Rect(
0,
0,
this.ActualWidth,
this.ActualHeight);

return hitTestRect.Contains(localPoint);
}
}
3 changes: 3 additions & 0 deletions src/Wpf.Ui/Interop/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,9 @@
[DllImport(Libraries.User32, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos([Out] out WinDef.POINT lpPoint);
[DllImport(Libraries.User32, SetLastError = true)]

Check warning on line 1453 in src/Wpf.Ui/Interop/User32.cs

View workflow job for this annotation

GitHub Actions / build

public static extern bool GetCursorPos(out System.Drawing.Point lpPoint);

Check warning on line 1454 in src/Wpf.Ui/Interop/User32.cs

View workflow job for this annotation

GitHub Actions / build



[DllImport(Libraries.User32)]
public static extern bool UnionRect(out WinDef.RECT rcDst, ref WinDef.RECT rc1, ref WinDef.RECT rc2);
Expand Down
Loading