Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8359899

Stage.isFocused() returns invalid value when Stage fails to receive focus

XMLWordPrintable

    • generic
    • windows

      Follow-up issue to https://github.com/openjdk/jfx/pull/1804#discussion_r2153809248

      On Windows, Stage can sometimes not receive focus due to Windows' anti-focus-stealing mechanisms, SetForegroundWindow() API will then fail and return FALSE. JavaFX never observes if SetForegroundWindow() actually succeeded (return value is ignored) - it assumes the call was successful and the Stage received focus, despite Windows refusing to do so, which causes a state mismatch. See native-glass/win/GlassWindow.cpp @ 1644

      This was observed on Windows when running system tests via Gradle daemon (with --daemon flag or its default behavior). Not sure if other platforms also have this behavior, or have a way of triggering it.

      Also worth noting, some tests do rely on Stage being focused after calling show(). These tests do not check whether Stage is actually focused before executing, so it might be a good idea to add assertions to those tests to prevent any spurious inputs being sent to other programs:
      - MenuDoubleShortcutTest
      - TextAreaBehaviorRobotTest
      And others that might require it (check by running system tests with --daemon flag)

            lkostyra Lukasz Kostyra
            lkostyra Lukasz Kostyra
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: