Skip to content

Commit 0850533

Browse files
committed
fix(win): Adjust outside click detection for DPI scaling
1 parent 688e69e commit 0850533

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/commonMain/kotlin/com/kdroid/composetray/lib/windows/WindowsOutsideClickWatcher.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ class WindowsOutsideClickWatcher(
6262
if (win != null && win.isShowing) {
6363
val winLoc = try { win.locationOnScreen } catch (_: Throwable) { null }
6464
if (winLoc != null) {
65-
val wx = winLoc.x
66-
val wy = winLoc.y
67-
val ww = win.width
68-
val wh = win.height
65+
// Get the graphics configuration to determine the DPI scale
66+
val scale = try {
67+
win.graphicsConfiguration?.defaultTransform?.scaleX ?: 1.0
68+
} catch (_: Throwable) { 1.0 }
69+
70+
// Convert window bounds from logical to physical pixels
71+
val wx = (winLoc.x * scale).toInt()
72+
val wy = (winLoc.y * scale).toInt()
73+
val ww = (win.width * scale).toInt()
74+
val wh = (win.height * scale).toInt()
6975

7076
val insideWindow = px in wx until (wx + ww) && py in wy until (wy + wh)
7177
val ignored = ignorePointPredicate?.invoke(px, py) == true

0 commit comments

Comments
 (0)