Skip to content

Commit b0cd253

Browse files
committed
fix a pixelDensity() issue w/ default display
1 parent f681ae3 commit b0cd253

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

core/src/processing/awt/ShimAWT.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,34 @@ private int displayDensityImpl() {
129129

130130

131131
private int displayDensityImpl(int display) {
132-
if (display > 0 && display <= displayDevices.length) {
133-
GraphicsConfiguration graphicsConfig =
134-
displayDevices[display - 1].getDefaultConfiguration();
132+
GraphicsConfiguration graphicsConfig = null;
133+
134+
if (display == -1) { // the default display
135+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
136+
graphicsConfig = ge.getDefaultScreenDevice().getDefaultConfiguration();
137+
138+
} else if (display == SPAN) {
139+
// walk through all displays, go with lowest common denominator
140+
for (int i = 0; i < displayDevices.length; i++) {
141+
if (displayDensityImpl(i) == 1) {
142+
return 1;
143+
}
144+
}
145+
return 2; // everyone is density 2
146+
147+
} else if (display <= displayDevices.length) {
148+
graphicsConfig = displayDevices[display - 1].getDefaultConfiguration();
149+
}
150+
151+
if (graphicsConfig == null) {
152+
System.err.println("Display " + display + " does not exist, " +
153+
"returning 1 for displayDensity(" + display + ")");
154+
return 1; // not the end of the world, so don't throw a RuntimeException
155+
156+
} else {
135157
AffineTransform tx = graphicsConfig.getDefaultTransform();
136158
return (int) Math.round(tx.getScaleX());
137159
}
138-
139-
System.err.println("Display " + display + " does not exist, " +
140-
"returning 1 for displayDensity(" + display + ")");
141-
return 1; // not the end of the world, so don't throw a RuntimeException
142160
}
143161

144162

core/todo.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ X Updating PApplet to use Java 17 (switch statements, etc)
33
X XxxList bug with random() if there are zero elements in the array
44
X now throws ArrayIndexOutOfBoundsException
55
X kinda want to return null, but later getting an NPE is more confusing
6+
X can't do pixelDensity 2 with fullScreen and Java2D
7+
X when using fullScreen(), shows error:
8+
X "Display -1 does not exist, returning 1 for displayDensity(-1)"
9+
X maybe https://github.com/processing/processing4/issues/487
610

711

12+
_ need alphabetical ordering for json serialization
13+
_ use choice() instead of random() for list classes
14+
_ add choice() as a PApplet method for int values of random()?
15+
816
_ concurrent StringDict et al
917
_ why no concurrent TreemMap? https://stackoverflow.com/a/17656453
1018
_ https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListMap.html

0 commit comments

Comments
 (0)