Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions core/src/processing/awt/PSurfaceAWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,11 @@ public void placeWindow(int[] location, int[] editorLocation) {

if (sketch.sketchFullScreen()) {
setFullFrame();
}

// Ignore placement of previous window and editor when full screen
if (!sketch.sketchFullScreen()) {
} else if (sketch.sketchMaximize()) {
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
} else {
// Ignore placement of previous window and editor when full screen/
// maximized.
if (location != null) {
// a specific location was received from the Runner
// (applet has been run more than once, user placed window)
Expand Down Expand Up @@ -1105,6 +1106,11 @@ public void windowStateChanged(WindowEvent e) {
// This seems to be firing when dragging the window on OS X
// https://github.com/processing/processing/issues/3092
if (Frame.MAXIMIZED_BOTH == e.getNewState()) {
if (sketch.sketchMaximize()) {
// If maximizing, mustn't start the animation thread until the window
// really has maximized.
sketch.doneMaximizing();
}
// Supposedly, sending the frame to back and then front is a
// workaround for this bug:
// http://stackoverflow.com/a/23897602
Expand All @@ -1127,7 +1133,7 @@ public void componentResized(ComponentEvent e) {
// http://dev.processing.org/bugs/show_bug.cgi?id=341
// This should also fix the blank screen on Linux bug
// http://dev.processing.org/bugs/show_bug.cgi?id=282
if (frame.isResizable()) {
if (frame.isResizable() || sketch.sketchMaximize()) {
// might be multiple resize calls before visible (i.e. first
// when pack() is called, then when it's resized for use).
// ignore them because it's not the user resizing things.
Expand Down
65 changes: 65 additions & 0 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.util.zip.*;

Expand Down Expand Up @@ -897,6 +898,7 @@ public PSurface getSurface() {
int smooth = 1; // default smoothing (whatever that means for the renderer)

boolean fullScreen;
boolean maximize; // True if sketch should be created maximized.
int display = -1; // use default
GraphicsDevice[] displayDevices;
// Unlike the others above, needs to be public to support
Expand Down Expand Up @@ -1066,6 +1068,15 @@ final public boolean sketchFullScreen() {
}


/**
* Returns whether the sketch was/should be created maximized, not whether
* it is now.
*/
final public boolean sketchMaximize() {
return maximize;
}


// // Could be named 'screen' instead of display since it's the people using
// // full screen who will be looking for it. On the other hand, screenX/Y/Z
// // makes things confusing, and if 'displayIndex' exists...
Expand Down Expand Up @@ -1830,6 +1841,7 @@ public void fullScreen() {
if (!fullScreen) {
if (insideSettings("fullScreen")) {
this.fullScreen = true;
this.maximize = false;
}
}
}
Expand All @@ -1839,6 +1851,7 @@ public void fullScreen(int display) {
if (!fullScreen || display != this.display) {
if (insideSettings("fullScreen", display)) {
this.fullScreen = true;
this.maximize = false;
this.display = display;
}
}
Expand All @@ -1863,6 +1876,7 @@ public void fullScreen(String renderer) {
!renderer.equals(this.renderer)) {
if (insideSettings("fullScreen", renderer)) {
this.fullScreen = true;
this.maximize = false;
this.renderer = renderer;
}
}
Expand All @@ -1879,13 +1893,58 @@ public void fullScreen(String renderer, int display) {
display != this.display) {
if (insideSettings("fullScreen", renderer, display)) {
this.fullScreen = true;
this.maximize = false;
this.renderer = renderer;
this.display = display;
}
}
}


/**
* ( begin auto-generated from maximize.xml )
*
* Create this sketch maximized.
* Description to come...
*
* ( end auto-generated )
* @webref environment
* @param renderer the renderer to use, e.g. P2D, P3D, JAVA2D (default)
* @see PApplet#settings()
* @see PApplet#setup()
* @see PApplet#size()
*/
public void maximize(String renderer) {
if (!maximize && insideSettings("maximize")) {
this.maximize = true;
this.fullScreen = false;
this.renderer = renderer;
}
}


/**
* @see PApplet#maximize(String)
*/
public void maximize() {
if (!maximize && insideSettings("maximize")) {
this.maximize = true;
this.fullScreen = false;
}
}


private CountDownLatch maximizeSignal = new CountDownLatch(1);


/**
* Called by a PSurface to indicate that the window has maximized.
*/
public void doneMaximizing() {
maximizeSignal.countDown();
}


/**
* ( begin auto-generated from size.xml )
*
Expand Down Expand Up @@ -10320,6 +10379,12 @@ static public void runSketch(final String[] args,
}

sketch.showSurface();

if (sketch.sketchMaximize()) try {
if (!sketch.maximizeSignal.await(2500, TimeUnit.MILLISECONDS)) {
System.err.format("maximize() failed for %s.%n", sketch.renderer);
}
} catch (InterruptedException e) {}
sketch.startSurface();
/*
if (sketch.getGraphics().displayable()) {
Expand Down
11 changes: 11 additions & 0 deletions core/src/processing/javafx/PSurfaceFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public void changed(ObservableValue<? extends Number> value,
sketch.setSize(newWidth.intValue(), sketch.height);
// draw();
fx.setSize(sketch.width, sketch.height);
// On Linux, there are three resize events to get the right size.
// 100 → 1, 1 → 100, 100 → correct value; not tried other platforms.
// There isn't an event to say the window's maximized.
// So I'm just waiting until the sketch is at least 90% screen width.
if (sketch.sketchMaximize()
&& stage != null && stage.isMaximized()
&& newWidth.floatValue() > sketch.displayWidth * 0.9f) {
sketch.doneMaximizing();
}
}
});
heightProperty().addListener(new ChangeListener<Number>() {
Expand Down Expand Up @@ -304,6 +313,8 @@ public void start(final Stage stage) {
stage.setY(screenRect.getMinY());
stage.setWidth(screenRect.getWidth());
stage.setHeight(screenRect.getHeight());
} else if (sketch.sketchMaximize()) {
stage.setMaximized(true);
}

Canvas canvas = surface.canvas;
Expand Down
11 changes: 9 additions & 2 deletions core/src/processing/opengl/PSurfaceJOGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,13 @@ protected void initWindow() {
ScalableSurface.IDENTITY_PIXELSCALE };
}
window.setSurfaceScale(reqSurfacePixelScale);
window.setSize(sketchWidth, sketchHeight);
if (sketch.sketchMaximize()) {
window.setMaximized(true, true);
} else {
window.setSize(sketchWidth, sketchHeight);
setSize(sketchWidth, sketchHeight);
}
window.setResizable(false);
setSize(sketchWidth, sketchHeight);
sketchX = displayDevice.getViewportInWindowUnits().getX();
sketchY = displayDevice.getViewportInWindowUnits().getY();
if (fullScreen) {
Expand Down Expand Up @@ -908,6 +912,9 @@ public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
// nativeSurfacePixelScale[0]+"x"+nativeSurfacePixelScale[1]+" (native)");


if (window.isMaximizedHorz() && window.isMaximizedVert()) {
sketch.doneMaximizing();
}


// System.out.println("reshape: " + w + ", " + h);
Expand Down
26 changes: 21 additions & 5 deletions java/src/processing/mode/java/preproc/PdePreprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,12 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings

String[] sizeContents = matchMethod("size", searchArea);
String[] fullContents = matchMethod("fullScreen", searchArea);
// First check and make sure they aren't both being used, otherwise it'll
// throw a confusing state exception error that one "can't be used here".
if (sizeContents != null && fullContents != null) {
throw new SketchException("size() and fullScreen() cannot be used in the same sketch", false);
String[] maxiContents = matchMethod("maximize", searchArea);
// First check and make sure there isn't more than one being used, otherwise
// it'll throw a confusing state exception error that one "can't be used here".
if ((sizeContents != null) == (fullContents != null)
? (sizeContents != null) : (maxiContents != null)) {
throw new SketchException("Use only one of size(), maximize() and fullScreen() in the same sketch.", false);
}

// Get everything inside the parens for the size() method
Expand Down Expand Up @@ -425,6 +427,20 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings
return info;
}

if (maxiContents != null) {
SurfaceInfo info = new SurfaceInfo();
info.addStatement(maxiContents[0]);
StringList args = breakCommas(maxiContents[1]);
if (args.size() == 1) {
info.renderer = args.get(0).trim();
} else if (args.size() > 1) {
throw new SketchException("That's too many parameters for maximize().");
}
info.addStatements(extraStatements);
info.checkEmpty();
return info;
}

// Made it this far, but no size() or fullScreen(), and still
// need to pull out the noSmooth() and smooth(N) methods.
if (extraStatements.size() != 0) {
Expand Down Expand Up @@ -1472,4 +1488,4 @@ private String debugHiddenTokens(antlr.CommonHiddenStreamToken t) {
}
return sb.toString();
}
}
}