From fda1a0b36053de094bcb655db4d7c6ae4e3cf8e7 Mon Sep 17 00:00:00 2001 From: duskvirkus Date: Mon, 12 May 2025 11:52:44 -0600 Subject: [PATCH 1/4] fixed bug --- core/examples/src/main/java/Issue1003.java | 34 ++++++++++++++++++++++ core/src/processing/awt/PSurfaceAWT.java | 26 +++++++++++++---- core/src/processing/core/PApplet.java | 7 +++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 core/examples/src/main/java/Issue1003.java diff --git a/core/examples/src/main/java/Issue1003.java b/core/examples/src/main/java/Issue1003.java new file mode 100644 index 0000000000..84bca8fbe6 --- /dev/null +++ b/core/examples/src/main/java/Issue1003.java @@ -0,0 +1,34 @@ +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() { + ((PSurfaceAWT) surface).setTitle("Hello world!"); + ((PSurfaceAWT) surface).setResizable(true); +// surface.setLocation(100, 100); + } + + public void draw(){ +// ((PSurfaceAWT) surface).setResizable(true); + + 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 57649d6ba9..2a27939ec4 100644 --- a/core/src/processing/awt/PSurfaceAWT.java +++ b/core/src/processing/awt/PSurfaceAWT.java @@ -49,7 +49,7 @@ public class PSurfaceAWT extends PSurfaceNone { GraphicsDevice displayDevice; // used for canvas to determine whether resizable or not -// boolean resizable; // default is false + boolean resizable; // default is false // Internally, we know it's always a JFrame (not just a Frame) // JFrame frame; @@ -57,6 +57,7 @@ public class PSurfaceAWT extends PSurfaceNone { // In the past, AWT Frames caused some problems on Windows and Linux, // but those may not be a problem for our reworked PSurfaceAWT class. JFrame frame; + boolean frameSetupComplete; // Note that x and y may not be zero, depending on the display configuration Rectangle screenRect; @@ -85,6 +86,8 @@ public PSurfaceAWT(PGraphics graphics) { //this.graphics = graphics; super(graphics); + this.resizable = false; // Default is false, can be changed with surface.setResizable() + /* if (checkRetina()) { // System.out.println("retina in use"); @@ -196,8 +199,7 @@ public Dimension getMinimumSize() { @Override public Dimension getMaximumSize() { - //return resizable ? super.getMaximumSize() : getPreferredSize(); - return frame.isResizable() ? super.getMaximumSize() : getPreferredSize(); + return resizable ? super.getMaximumSize() : getPreferredSize(); } @@ -442,7 +444,12 @@ 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); + // Must use this.resizable to avoid bug where value is set before initFrame is finished + // https://github.com/processing/processing4/issues/1003 + System.out.println("Resizable in initFrame: " + this.resizable); +// setResizable(this.resizable); +// frame.setResizable(true); +// frame.setResizable(this.resizable); frame.addWindowListener(new WindowAdapter() { @Override @@ -484,11 +491,18 @@ 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; // we need to store this so if frame init is not complete then we know the value + System.out.println("Frame in setResizable:" + frame); if (frame != null) { - frame.setResizable(resizable); + frame.setResizable(this.resizable); + System.out.println("PSurfaceAWT.frame.resizable set to:" + frame.isResizable()); +// frame.isValid(); + frame.validate(); + System.out.println("PSurfaceAWT.frame.isValid():" + frame.isValid()); } + + System.out.println("PSurfaceAWT.resizable set to:" + this.resizable); } diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 9f3486a10d..c43615274b 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -10145,8 +10145,15 @@ static public void runSketch(final String[] args, } */ + + sketch.showSurface(); + + surface.setResizable(false); + + sketch.startSurface(); + } From 5478aad59cab4ed7d16ca689e37417206fc991cd Mon Sep 17 00:00:00 2001 From: duskvirkus Date: Mon, 12 May 2025 12:46:26 -0600 Subject: [PATCH 2/4] Actually fix the bug this time --- core/examples/src/main/java/Issue1003.java | 6 +-- core/src/processing/awt/PSurfaceAWT.java | 52 ++++++++++++---------- core/src/processing/core/PApplet.java | 4 -- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/core/examples/src/main/java/Issue1003.java b/core/examples/src/main/java/Issue1003.java index 84bca8fbe6..6886cd08e7 100644 --- a/core/examples/src/main/java/Issue1003.java +++ b/core/examples/src/main/java/Issue1003.java @@ -10,9 +10,9 @@ public void settings(){ } public void setup() { - ((PSurfaceAWT) surface).setTitle("Hello world!"); - ((PSurfaceAWT) surface).setResizable(true); -// surface.setLocation(100, 100); + surface.setTitle("Hello resize!"); + surface.setResizable(true); + surface.setLocation(100, 100); } public void draw(){ diff --git a/core/src/processing/awt/PSurfaceAWT.java b/core/src/processing/awt/PSurfaceAWT.java index 2a27939ec4..ddc4cd90b2 100644 --- a/core/src/processing/awt/PSurfaceAWT.java +++ b/core/src/processing/awt/PSurfaceAWT.java @@ -49,7 +49,7 @@ public class PSurfaceAWT extends PSurfaceNone { GraphicsDevice displayDevice; // used for canvas to determine whether resizable or not - boolean resizable; // default is false +// boolean resizable; // default is false // Internally, we know it's always a JFrame (not just a Frame) // JFrame frame; @@ -57,7 +57,6 @@ public class PSurfaceAWT extends PSurfaceNone { // In the past, AWT Frames caused some problems on Windows and Linux, // but those may not be a problem for our reworked PSurfaceAWT class. JFrame frame; - boolean frameSetupComplete; // Note that x and y may not be zero, depending on the display configuration Rectangle screenRect; @@ -86,8 +85,6 @@ public PSurfaceAWT(PGraphics graphics) { //this.graphics = graphics; super(graphics); - this.resizable = false; // Default is false, can be changed with surface.setResizable() - /* if (checkRetina()) { // System.out.println("retina in use"); @@ -199,7 +196,8 @@ public Dimension getMinimumSize() { @Override public Dimension getMaximumSize() { - return resizable ? super.getMaximumSize() : getPreferredSize(); + //return resizable ? super.getMaximumSize() : getPreferredSize(); + return frame.isResizable() ? super.getMaximumSize() : getPreferredSize(); } @@ -444,12 +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 - // Must use this.resizable to avoid bug where value is set before initFrame is finished - // https://github.com/processing/processing4/issues/1003 - System.out.println("Resizable in initFrame: " + this.resizable); // setResizable(this.resizable); -// frame.setResizable(true); -// frame.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 @@ -491,18 +487,26 @@ 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; // we need to store this so if frame init is not complete then we know the value + //this.resizable = resizable; // really only used for canvas - System.out.println("Frame in setResizable:" + frame); if (frame != null) { - frame.setResizable(this.resizable); - System.out.println("PSurfaceAWT.frame.resizable set to:" + frame.isResizable()); -// frame.isValid(); - frame.validate(); - System.out.println("PSurfaceAWT.frame.isValid():" + frame.isValid()); - } + boolean frameValidBefore = frame.isValid(); + frame.setResizable(resizable); - System.out.println("PSurfaceAWT.resizable set to:" + this.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 + } + } } @@ -614,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); } diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index c43615274b..2764713797 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -10148,10 +10148,6 @@ static public void runSketch(final String[] args, sketch.showSurface(); - - surface.setResizable(false); - - sketch.startSurface(); } From 8d2340774dca4f588529c31b903a19d42857f3c5 Mon Sep 17 00:00:00 2001 From: duskvirkus Date: Mon, 12 May 2025 12:47:53 -0600 Subject: [PATCH 3/4] clean up --- core/src/processing/core/PApplet.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 2764713797..9f3486a10d 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -10145,11 +10145,8 @@ static public void runSketch(final String[] args, } */ - - sketch.showSurface(); sketch.startSurface(); - } From b4359b48592f1b335b970f3bef9badb473121d11 Mon Sep 17 00:00:00 2001 From: duskvirkus Date: Mon, 12 May 2025 12:49:03 -0600 Subject: [PATCH 4/4] More cleanup --- core/examples/src/main/java/Issue1003.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/examples/src/main/java/Issue1003.java b/core/examples/src/main/java/Issue1003.java index 6886cd08e7..52dacf8601 100644 --- a/core/examples/src/main/java/Issue1003.java +++ b/core/examples/src/main/java/Issue1003.java @@ -16,12 +16,11 @@ public void setup() { } public void draw(){ -// ((PSurfaceAWT) surface).setResizable(true); - 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) {