public static @Nullable Pair<@NotNull Rectangle, @Nullable GraphicsDevice> convertFromDeviceSpaceAndFitToScreen(@NotNull Rectangle bounds) {
    int tolerance = Registry.intValue("ide.project.frame.screen.bounds.tolerance", 10);
    Rectangle b = bounds.getBounds();
    // Protect against incorrectly saved meaningless values.
    if (b.width < MIN_WIDTH) b.width = MIN_WIDTH;
    if (b.height < MIN_HEIGHT) b.height = MIN_HEIGHT;
    int centerX = b.x + b.width / 2;
    int centerY = b.y + b.height / 2;
    boolean scaleNeeded = shouldConvert();
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
      GraphicsConfiguration gc = gd.getDefaultConfiguration();
      Rectangle devBounds = gc.getBounds(); // in user space
      if (scaleNeeded) {
        scaleUp(devBounds, gc); // to device space if needed
      }
      if (devBounds.contains(centerX, centerY)) {
        if (scaleNeeded) {
          scaleDown(b, gc); // to user space if needed
        }
        // do not return bounds bigger than the corresponding screen rectangle
        Rectangle screen = ScreenUtil.getScreenRectangle(gc);
        // but allow for the invisible parts of the frame (border drag zones) to be placed slightly outside
        screen.x -= tolerance;
        screen.y -= tolerance;
        screen.width += tolerance;
        screen.height += tolerance;
        if (b.x < screen.x) {
          b.x = screen.x;
        }
        if (b.y < screen.y) {
          b.y = screen.y;
        }
        if (b.width > screen.width) {
          b.width = screen.width;
        }
        if (b.height > screen.height) {
          b.height = screen.height;
        }
        if (IDE_FRAME_EVENT_LOG.isDebugEnabled()) { // avoid unnecessary concatenation
          IDE_FRAME_EVENT_LOG.debug("Found the screen " + screen + " for the loaded bounds " + bounds);
        }
        return new Pair<>(b, gd);
      }
    }

    if (IDE_FRAME_EVENT_LOG.isDebugEnabled()) { // avoid unnecessary concatenation
      IDE_FRAME_EVENT_LOG.debug("Found no screen for the loaded bounds " + bounds);
    }
    // We didn't find a proper device at all. Probably it was an external screen that is unavailable now. We cannot use specified bounds.
    return null;
  }
public static @Nullable Pair<@NotNull Rectangle, @Nullable GraphicsDevice> convertFromDeviceSpaceAndFitToScreen(@NotNull Rectangle bounds)