diff --git a/core/examples/src/main/java/Issue1003.java b/core/examples/src/main/java/Issue1003.java new file mode 100644 index 000000000..52dacf860 --- /dev/null +++ b/core/examples/src/main/java/Issue1003.java @@ -0,0 +1,33 @@ +import processing.core.PApplet; +import processing.awt.PSurfaceAWT; + +// Reproduction of issue #1003 +// Resizeable causes crash on linux mint +public class Issue1003 extends PApplet { + + public void settings(){ + size(200, 200); + } + + public void setup() { + surface.setTitle("Hello resize!"); + surface.setResizable(true); + surface.setLocation(100, 100); + } + + public void draw(){ + background(frameCount % 255); + line(0, 0, width, height); + line(width, 0, 0, height); + } + + public static void main(String[] passedArgs) { + String[] appletArgs = new String[]{ Issue1003.class.getName()}; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + + } +} diff --git a/core/src/processing/awt/PSurfaceAWT.java b/core/src/processing/awt/PSurfaceAWT.java index 57649d6ba..ddc4cd90b 100644 --- a/core/src/processing/awt/PSurfaceAWT.java +++ b/core/src/processing/awt/PSurfaceAWT.java @@ -442,7 +442,10 @@ public void initFrame(final PApplet sketch) {/*, int backgroundColor, // disabling resize has to happen after pack() to avoid apparent Apple bug // https://github.com/processing/processing/issues/506 - frame.setResizable(false); +// setResizable(this.resizable); + // disabling resize has been moved again because of a bug on linux mint + // it can now be found in PSurfaceAWT.setVisible() + // https://github.com/processing/processing4/issues/1003 frame.addWindowListener(new WindowAdapter() { @Override @@ -484,10 +487,25 @@ public void setTitle(String title) { /** Set true if we want to resize things (default is not resizable) */ @Override public void setResizable(boolean resizable) { - //this.resizable = resizable; // really only used for canvas + //this.resizable = resizable; // really only used for canvas if (frame != null) { + boolean frameValidBefore = frame.isValid(); frame.setResizable(resizable); + + if (PApplet.platform == PConstants.LINUX) { + // Because of a bug on linux mint where the window manager does not fully accept a change to + // frame.setResizable() we are forced to recreate the frame. + // To avoid extra overhead we skip this on other platforms. + // https://github.com/processing/processing4/issues/1003 + frame.dispose(); + frame.setUndecorated(frame.isUndecorated()); // Forces decoration refresh + frame.setVisible(true); + } + + if (frameValidBefore && !frame.isValid()) { + frame.validate(); // setResizable can invalidate frame so here we validate it if it was previously valid + } } } @@ -600,20 +618,22 @@ public void setVisible(boolean visible) { // removing per https://github.com/processing/processing/pull/3162 // can remove the code below once 3.0a6 is tested and behaving -/* + if (visible && PApplet.platform == PConstants.LINUX) { // Linux doesn't deal with insets the same way. We get fake insets // earlier, and then the window manager will slap its own insets // onto things once the frame is realized on the screen. Awzm. - if (PApplet.platform == PConstants.LINUX) { Insets insets = frame.getInsets(); frame.setSize(Math.max(sketchWidth, MIN_WINDOW_WIDTH) + insets.left + insets.right, Math.max(sketchHeight, MIN_WINDOW_HEIGHT) + insets.top + insets.bottom); - } } -*/ + + // Moved here to handle issue on linux mint because it needs to happen after frame was already visible. + // On linux, we now recreate the frame. It seems the frame resizable state doesn't fully change without dispose(). + // https://github.com/processing/processing4/issues/1003 + this.setResizable(false); }