Skip to content

Commit

Permalink
Fixed hiding capture rect and main window timing issue on capturing s…
Browse files Browse the repository at this point in the history
…ingle image
  • Loading branch information
mvmn committed Oct 9, 2020
1 parent d965c67 commit dd65520
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/main/java/x/mvmn/jscrcap/gui/swing/ControlWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,27 +453,17 @@ public void windowDeactivated(WindowEvent e) {}

private void doCapture(Rectangle captureRect) {
boolean captureRectWasVisible = captureRectFrame.isVisible();
captureRectFrame.setSize(0, 0);
this.setVisible(false);
if (captureRectWasVisible) {
captureRectFrame.setVisible(false);
try {
// TODO: Dirty workaround for OS X - investigate
// alternatives
Thread.sleep(50);
} catch (InterruptedException e) {}
}
BufferedImage screenshot = SwingUtil.getRobot().createScreenCapture(captureRect);
capturesTableModel.addImage(new CapturedImage(screenshot));
captureRectFrame.setSize(captureRect.width, captureRect.height);
if (captureRectWasVisible) {
try {
// TODO: Dirty workaround for OS X - investigate
// alternatives
Thread.sleep(15);
} catch (InterruptedException e) {}
captureRectFrame.setVisible(true);
}
this.setVisible(true);
SwingUtilities.invokeLater(() -> {
BufferedImage screenshot = SwingUtil.getRobot().createScreenCapture(captureRect);
capturesTableModel.addImage(new CapturedImage(screenshot));
if (captureRectWasVisible) {
captureRectFrame.setVisible(true);
}
this.setVisible(true);
});
}
}

0 comments on commit dd65520

Please sign in to comment.