Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 25, 2025

When a floating window's content is hidden or resized (causing view size changes), the remaining content would incorrectly position at the top-left corner instead of respecting the configured FxGravity setting.

Problem

The issue occurred in the onSizeChanged method of FxViewLocationHelper.kt. When needUpdateLocation was false, the code would only apply safe coordinate bounds to the current position without recalculating based on gravity:

// Previous behavior - only ensured coordinates were within safe bounds
basicView?.internalMoveToXY(safeX(x), safeY(y))

This meant that when a floating window with FxGravity.RIGHT_OR_BOTTOM had its content hidden (reducing view size), the button would appear at the top-left of the original floating window area instead of repositioning to the right-bottom corner.

Solution

The fix detects when the view size actually changes and recalculates position based on the configured gravity:

override fun onSizeChanged(w: Int, h: Int, oldW: Int, oldH: Int) {
    val sizeChanged = updateViewSize()
    if (isInitLocation) return
    if (needUpdateLocation) {
        checkOrRestoreLocation()
    } else if (sizeChanged && !config.gravity.isDefault()) {
        // Recalculate position based on gravity when view size changes
        val (newX, newY) = recalculatePositionByGravity()
        basicView?.internalMoveToXY(newX, newY)
    } else {
        basicView?.internalMoveToXY(safeX(x), safeY(y))
    }
}

Key Changes

  1. Modified updateViewSize() to return a boolean indicating if the view size actually changed
  2. Added recalculatePositionByGravity() method that reuses existing gravity calculation logic
  3. Enhanced onSizeChanged() to detect size changes and apply gravity-based repositioning when appropriate

Behavior

  • Before: Floating window with FxGravity.RIGHT_OR_BOTTOM would move to top-left when content was hidden
  • After: Floating window correctly repositions to right-bottom corner based on new view size
  • Preserved: All existing behavior for initialization, full updates, and default gravity cases

The fix only applies when:

  • View size actually changes (not just method calls)
  • Gravity is set to non-default values (excludes DEFAULT and LEFT_OR_TOP)
  • No full location update is in progress

Fixes #206.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/gradle-daemon-main-8.14.3.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/agents/gradle-instrumentation-agent-8.14.3.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.14.3 (dns block)
  • jitpack.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/gradle-daemon-main-8.14.3.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.14.3-all/8fdzzxam9lo77uruaibtsldo0/gradle-8.14.3/lib/agents/gradle-instrumentation-agent-8.14.3.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.14.3 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits August 25, 2025 03:22
…ettings

Co-authored-by: Petterpx <41142188+Petterpx@users.noreply.github.com>
Co-authored-by: Petterpx <41142188+Petterpx@users.noreply.github.com>
Copilot AI changed the title [WIP] 悬浮窗部分内容隐藏后, 悬浮窗如何靠边 Fix floating window positioning when view size changes with gravity settings Aug 25, 2025
Copilot AI requested a review from Petterpx August 25, 2025 03:26
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.

悬浮窗部分内容隐藏后, 悬浮窗如何靠边

2 participants