public static @Nullable Window findOwner(@Nullable Component parent) {
    if (parent == null) {
      parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
      if (parent == null) {
        parent = Window.getWindows()[0];
      }
    }

    var owner = parent instanceof Window ? (Window)parent : SwingUtilities.getWindowAncestor(parent);

    if (IdeEventQueue.getInstance().getPopupManager().isPopupWindow(owner)) {
      if (!owner.isFocused() || !SystemInfo.isJetBrainsJvm) {
        do {
          owner = owner.getOwner();
        }
        while (UIUtil.isSimpleWindow(owner));
      }
    }

    if (owner instanceof Dialog ownerDialog && !ownerDialog.isModal() && !UIUtil.isPossibleOwner(ownerDialog)) {
      while (owner instanceof Dialog ownerDialog2 && !ownerDialog2.isModal()) {
        owner = owner.getOwner();
      }
    }

    while (owner != null && !owner.isShowing()) {
      owner = owner.getOwner();
    }

    // `Window` cannot be a parent of `JDialog`
    if (UIUtil.isSimpleWindow(owner)) {
      owner = null;
    }
    return owner;
  }
public static @Nullable Window findOwner(@Nullable Component parent)