Skip to content

Commit fb6f473

Browse files
committed
Refactor dialog positioning and streamline offset calculation
- Removed redundant `SideEffect` for dialog positioning. - Optimized offset handling with direction-aware logic for better window positioning. - Improved code readability by introducing `isTop` and `isRight` flags.
1 parent db65094 commit fb6f473

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,6 @@ private fun ApplicationScope.TrayAppImplLinux(
741741
}
742742

743743
val dialogState = rememberDialogState(position = initialPositionForFirstFrame, size = currentWindowSize)
744-
SideEffect { dialogState.position = initialPositionForFirstFrame }
745744
LaunchedEffect(currentWindowSize) { dialogState.size = currentWindowSize }
746745

747746
// Visibility controller for exit-finish detection; content will NOT be disposed.

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,30 @@ private fun calculateWindowPositionFromClick(
328328
horizontalOffset: Int,
329329
verticalOffset: Int
330330
): WindowPosition {
331+
val isTop = trayPosition == TrayPosition.TOP_LEFT || trayPosition == TrayPosition.TOP_RIGHT
332+
val isRight = trayPosition == TrayPosition.TOP_RIGHT || trayPosition == TrayPosition.BOTTOM_RIGHT
333+
331334
var x = clickX - (windowWidth / 2)
332-
var y = if (trayPosition == TrayPosition.TOP_LEFT || trayPosition == TrayPosition.TOP_RIGHT) {
335+
var y = if (isTop) {
336+
// Anchor below the top bar
333337
clickY
334338
} else {
339+
// Anchor above the bottom bar
335340
clickY - windowHeight
336341
}
337342

338-
// Offsets utilisateur
339-
x += horizontalOffset
340-
y += verticalOffset
343+
// Direction-aware offsets: always push AWAY from the bar/edge.
344+
x += if (isRight) -horizontalOffset else horizontalOffset
345+
y += if (isTop) verticalOffset else -verticalOffset
341346

342-
// Clamp écran
347+
// Clamp to screen
343348
if (x < 0) x = 0 else if (x + windowWidth > screenWidth) x = screenWidth - windowWidth
344349
if (y < 0) y = 0 else if (y + windowHeight > screenHeight) y = screenHeight - windowHeight
345350

346351
return WindowPosition(x = x.dp, y = y.dp)
347352
}
348353

354+
349355
/** Position de repli coin + offsets */
350356
private fun fallbackCornerPosition(
351357
w: Int, h: Int,

0 commit comments

Comments
 (0)