Skip to content

Commit fce1f4b

Browse files
committed
Improve GNOME-specific dialog positioning and snap logic
- Adjust `defaultVerticalOffset` for GNOME environment to 10 for better alignment. - Update vertical positioning logic to snap dialogs consistently to the bar edge. - Introduce `panelGuessPx` heuristic for handling GNOME UI scaling effectively. - Refine direction-aware offset adjustments and ensure bounds clamping remains intact.
1 parent fb6f473 commit fce1f4b

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/commonMain/kotlin/com/kdroid/composetray/tray/api/TrayApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private val defaultVerticalOffset = when (getOperatingSystem()) {
7070
WINDOWS -> -10
7171
MACOS -> 30
7272
else -> when (detectLinuxDesktopEnvironment()) {
73-
LinuxDesktopEnvironment.GNOME -> 25
73+
LinuxDesktopEnvironment.GNOME -> 10
7474
else -> 0
7575
}
7676
}

src/commonMain/kotlin/com/kdroid/composetray/utils/TrayPosition.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,23 +328,26 @@ private fun calculateWindowPositionFromClick(
328328
horizontalOffset: Int,
329329
verticalOffset: Int
330330
): WindowPosition {
331+
// Snap to the bar edge instead of using the raw clickY.
332+
// This removes the "top vs bottom of icon" discrepancy on GNOME.
331333
val isTop = trayPosition == TrayPosition.TOP_LEFT || trayPosition == TrayPosition.TOP_RIGHT
332334
val isRight = trayPosition == TrayPosition.TOP_RIGHT || trayPosition == TrayPosition.BOTTOM_RIGHT
333335

336+
// Heuristic bar thickness in pixels (kept conservative; scaling-safe enough in practice)
337+
val panelGuessPx = 28
338+
339+
// Horizontal: center on clickX, then apply direction-aware offset
334340
var x = clickX - (windowWidth / 2)
335-
var y = if (isTop) {
336-
// Anchor below the top bar
337-
clickY
338-
} else {
339-
// Anchor above the bottom bar
340-
clickY - windowHeight
341-
}
342341

343-
// Direction-aware offsets: always push AWAY from the bar/edge.
342+
// Vertical: snap to the bar edge; ignore clickY height within the icon
343+
val anchorY = if (isTop) panelGuessPx else screenHeight - panelGuessPx
344+
var y = if (isTop) anchorY else anchorY - windowHeight
345+
346+
// Direction-aware offsets: push away from the bar/edge for a consistent "gap".
344347
x += if (isRight) -horizontalOffset else horizontalOffset
345348
y += if (isTop) verticalOffset else -verticalOffset
346349

347-
// Clamp to screen
350+
// Clamp to screen bounds
348351
if (x < 0) x = 0 else if (x + windowWidth > screenWidth) x = screenWidth - windowWidth
349352
if (y < 0) y = 0 else if (y + windowHeight > screenHeight) y = screenHeight - windowHeight
350353

0 commit comments

Comments
 (0)