Skip to content

Conversation

@onesounds
Copy link

What's the PR

Cause

  • There was a unit mismatch in coordinate calculations.
  • Win32 API (GetCursorPos): Returns coordinates in Physical Pixels (monitor actual pixels).
  • WPF (ActualWidth): Returns dimensions in Logical Pixels (DPI-independent units).

Conflict: Comparing physical coordinates (e.g., 1250px) directly with logical dimensions (e.g., 1000px) caused the application to wrongly detect that the mouse had left the window boundaries.

Solution

  • Updated app.manifest (OS Configuration) We added/configured the app.manifest file to explicitly declare the application as DPI-Aware.

Setting: <dpiAwareness>PerMonitorV2</dpiAwareness>

Effect: This prevents the OS from applying bitmap stretching and tells Windows that the application will handle DPI scaling natively for each monitor.

Modified Window_MouseMove Logic (Code Correction)

  • Updated the boundary check logic to convert WPF's Logical Size into Physical Size before comparing it with the cursor position.

Before

  • Compared Cursor Position vs. ActualWidth.

After

  • Multiplies ActualWidth by the _windowsScalingFactor to match the physical pixel units of the cursor.
// Window_MouseMove
double scale = _windowsScalingFactor > 0 ? _windowsScalingFactor : 1.0;

// Convert Logical Size to Physical Size (e.g., 1000px * 1.25 = 1250px)
var physicalWidth = this.ActualWidth * scale;
var physicalHeight = this.ActualHeight * scale;

// Perform boundary checks using the converted physical dimensions
if (cursorPos.X ... > windowPos.X + physicalWidth) { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - Issue with icon background hover color

1 participant