Skip to content

Commit 5478aad

Browse files
committed
Actually fix the bug this time
1 parent fda1a0b commit 5478aad

3 files changed

Lines changed: 32 additions & 30 deletions

File tree

core/examples/src/main/java/Issue1003.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public void settings(){
1010
}
1111

1212
public void setup() {
13-
((PSurfaceAWT) surface).setTitle("Hello world!");
14-
((PSurfaceAWT) surface).setResizable(true);
15-
// surface.setLocation(100, 100);
13+
surface.setTitle("Hello resize!");
14+
surface.setResizable(true);
15+
surface.setLocation(100, 100);
1616
}
1717

1818
public void draw(){

core/src/processing/awt/PSurfaceAWT.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ public class PSurfaceAWT extends PSurfaceNone {
4949
GraphicsDevice displayDevice;
5050

5151
// used for canvas to determine whether resizable or not
52-
boolean resizable; // default is false
52+
// boolean resizable; // default is false
5353

5454
// Internally, we know it's always a JFrame (not just a Frame)
5555
// JFrame frame;
5656
// Trying Frame again with a11 to see if this avoids some Swing nastiness.
5757
// In the past, AWT Frames caused some problems on Windows and Linux,
5858
// but those may not be a problem for our reworked PSurfaceAWT class.
5959
JFrame frame;
60-
boolean frameSetupComplete;
6160

6261
// Note that x and y may not be zero, depending on the display configuration
6362
Rectangle screenRect;
@@ -86,8 +85,6 @@ public PSurfaceAWT(PGraphics graphics) {
8685
//this.graphics = graphics;
8786
super(graphics);
8887

89-
this.resizable = false; // Default is false, can be changed with surface.setResizable()
90-
9188
/*
9289
if (checkRetina()) {
9390
// System.out.println("retina in use");
@@ -199,7 +196,8 @@ public Dimension getMinimumSize() {
199196

200197
@Override
201198
public Dimension getMaximumSize() {
202-
return resizable ? super.getMaximumSize() : getPreferredSize();
199+
//return resizable ? super.getMaximumSize() : getPreferredSize();
200+
return frame.isResizable() ? super.getMaximumSize() : getPreferredSize();
203201
}
204202

205203

@@ -444,12 +442,10 @@ public void initFrame(final PApplet sketch) {/*, int backgroundColor,
444442

445443
// disabling resize has to happen after pack() to avoid apparent Apple bug
446444
// https://github.com/processing/processing/issues/506
447-
// Must use this.resizable to avoid bug where value is set before initFrame is finished
448-
// https://github.com/processing/processing4/issues/1003
449-
System.out.println("Resizable in initFrame: " + this.resizable);
450445
// setResizable(this.resizable);
451-
// frame.setResizable(true);
452-
// frame.setResizable(this.resizable);
446+
// disabling resize has been moved again because of a bug on linux mint
447+
// it can now be found in PSurfaceAWT.setVisible()
448+
// https://github.com/processing/processing4/issues/1003
453449

454450
frame.addWindowListener(new WindowAdapter() {
455451
@Override
@@ -491,18 +487,26 @@ public void setTitle(String title) {
491487
/** Set true if we want to resize things (default is not resizable) */
492488
@Override
493489
public void setResizable(boolean resizable) {
494-
this.resizable = resizable; // we need to store this so if frame init is not complete then we know the value
490+
//this.resizable = resizable; // really only used for canvas
495491

496-
System.out.println("Frame in setResizable:" + frame);
497492
if (frame != null) {
498-
frame.setResizable(this.resizable);
499-
System.out.println("PSurfaceAWT.frame.resizable set to:" + frame.isResizable());
500-
// frame.isValid();
501-
frame.validate();
502-
System.out.println("PSurfaceAWT.frame.isValid():" + frame.isValid());
503-
}
493+
boolean frameValidBefore = frame.isValid();
494+
frame.setResizable(resizable);
504495

505-
System.out.println("PSurfaceAWT.resizable set to:" + this.resizable);
496+
if (PApplet.platform == PConstants.LINUX) {
497+
// Because of a bug on linux mint where the window manager does not fully accept a change to
498+
// frame.setResizable() we are forced to recreate the frame.
499+
// To avoid extra overhead we skip this on other platforms.
500+
// https://github.com/processing/processing4/issues/1003
501+
frame.dispose();
502+
frame.setUndecorated(frame.isUndecorated()); // Forces decoration refresh
503+
frame.setVisible(true);
504+
}
505+
506+
if (frameValidBefore && !frame.isValid()) {
507+
frame.validate(); // setResizable can invalidate frame so here we validate it if it was previously valid
508+
}
509+
}
506510
}
507511

508512

@@ -614,20 +618,22 @@ public void setVisible(boolean visible) {
614618

615619
// removing per https://github.com/processing/processing/pull/3162
616620
// can remove the code below once 3.0a6 is tested and behaving
617-
/*
621+
618622
if (visible && PApplet.platform == PConstants.LINUX) {
619623
// Linux doesn't deal with insets the same way. We get fake insets
620624
// earlier, and then the window manager will slap its own insets
621625
// onto things once the frame is realized on the screen. Awzm.
622-
if (PApplet.platform == PConstants.LINUX) {
623626
Insets insets = frame.getInsets();
624627
frame.setSize(Math.max(sketchWidth, MIN_WINDOW_WIDTH) +
625628
insets.left + insets.right,
626629
Math.max(sketchHeight, MIN_WINDOW_HEIGHT) +
627630
insets.top + insets.bottom);
628-
}
629631
}
630-
*/
632+
633+
// Moved here to handle issue on linux mint because it needs to happen after frame was already visible.
634+
// On linux, we now recreate the frame. It seems the frame resizable state doesn't fully change without dispose().
635+
// https://github.com/processing/processing4/issues/1003
636+
this.setResizable(false);
631637
}
632638

633639

core/src/processing/core/PApplet.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10148,10 +10148,6 @@ static public void runSketch(final String[] args,
1014810148

1014910149

1015010150
sketch.showSurface();
10151-
10152-
surface.setResizable(false);
10153-
10154-
1015510151
sketch.startSurface();
1015610152

1015710153
}

0 commit comments

Comments
 (0)