Skip to content

Commit

Permalink
workaround for issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalazscs committed Sep 28, 2018
1 parent 3a43f2a commit 8bc7e13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 19 additions & 2 deletions src/main/java/pixelitor/gui/utils/GUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.awt.GraphicsEnvironment;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand All @@ -58,8 +59,7 @@ private GUIUtils() {
}

public static void centerOnScreen(Component component) {
Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getMaximumWindowBounds();
Dimension screen = getMaxWindowSize();
Dimension window = component.getSize();

if (window.height > screen.height) {
Expand All @@ -78,6 +78,23 @@ public static void centerOnScreen(Component component) {
component.setSize(window);
}

public static Dimension getMaxWindowSize() {
Rectangle bounds;
try {
// use this because it takes into account areas
// like the taskbar, but it can throw
// a "Window must not be zero" if there are 3 monitors
// on Linux with some newer Java versions, see
// https://github.com/lbalazscs/Pixelitor/issues/15
bounds = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getMaximumWindowBounds();
} catch (Exception e) {
return Toolkit.getDefaultToolkit().getScreenSize();
}

return new Dimension(bounds.width, bounds.height);
}

/**
* @return true if any app window has focus
*/
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/pixelitor/utils/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pixelitor.TipsOfTheDay;
import pixelitor.gui.ImageArea;
import pixelitor.gui.PixelitorWindow;
import pixelitor.gui.utils.GUIUtils;
import pixelitor.history.History;
import pixelitor.io.Dirs;
import pixelitor.layers.LayerButtonLayout;
Expand All @@ -35,9 +36,7 @@
import javax.swing.filechooser.FileSystemView;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
import java.io.File;
import java.util.prefs.Preferences;
Expand Down Expand Up @@ -129,8 +128,7 @@ public static void loadFramePosition(Window window) {
int width = mainNode.getInt(FRAME_WIDTH_KEY, 0);
int height = mainNode.getInt(FRAME_HEIGHT_KEY, 0);

Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getMaximumWindowBounds();
Dimension screen = GUIUtils.getMaxWindowSize();

if ((width <= 0) || (height <= 0)) {
width = screen.width;
Expand Down

0 comments on commit 8bc7e13

Please sign in to comment.