Skip to content

Commit ccaa58f

Browse files
committed
fixing issues related to the displays pref processing#3264
1 parent 1d02336 commit ccaa58f

File tree

5 files changed

+61
-31
lines changed

5 files changed

+61
-31
lines changed

app/src/processing/app/PreferencesFrame.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public void actionPerformed(ActionEvent e) {
143143
// get a wide name in there before getPreferredSize() is called
144144
fontSelectionBox = new JComboBox<String>(new String[] { Toolkit.getMonoFontName() });
145145
fontSelectionBox.setToolTipText(fontTip);
146-
//updateDisplayList();
147146
fontSelectionBox.setEnabled(false); // don't enable until fonts are loaded
148147

149148

@@ -317,17 +316,18 @@ public void stateChanged(ChangeEvent e) {
317316

318317
// Run sketches on display [ 1 ]
319318

320-
JLabel displayLabel = new JLabel(Language.text("preferences.run_sketches_on_display")+": ");
319+
JLabel displayLabel = new JLabel(Language.text("preferences.run_sketches_on_display") + ": ");
321320
final String tip = "<html>" + Language.text("preferences.run_sketches_on_display.tip");
322321
displayLabel.setToolTipText(tip);
323322
displaySelectionBox = new JComboBox<String>();
324323
updateDisplayList(); // needs to happen here for getPreferredSize()
325324

325+
326326
// [ ] Automatically associate .pde files with Processing
327327

328-
autoAssociateBox =
329-
new JCheckBox(Language.text("preferences.automatically_associate_pde_files"));
330-
autoAssociateBox.setVisible(false);
328+
autoAssociateBox =
329+
new JCheckBox(Language.text("preferences.automatically_associate_pde_files"));
330+
autoAssociateBox.setVisible(false);
331331

332332

333333
// More preferences are in the ...
@@ -577,17 +577,21 @@ protected void applyFrame() {
577577
Language.saveLanguage(language);
578578
}
579579

580-
int oldDisplayIndex = Preferences.getInteger("run.display"); //$NON-NLS-1$
581-
int displayIndex = 0;
582-
for (int d = 0; d < displaySelectionBox.getItemCount(); d++) {
583-
if (displaySelectionBox.getSelectedIndex() == d) {
584-
displayIndex = d;
580+
// The preference will have already been reset when the window was created
581+
if (displaySelectionBox.isEnabled()) {
582+
int oldDisplayNum = Preferences.getInteger("run.display");
583+
int displayNum = -1;
584+
for (int d = 0; d < displaySelectionBox.getItemCount(); d++) {
585+
if (displaySelectionBox.getSelectedIndex() == d) {
586+
displayNum = d + 1;
587+
}
585588
}
586-
}
587-
if (oldDisplayIndex != displayIndex) {
588-
Preferences.setInteger("run.display", displayIndex); //$NON-NLS-1$
589-
for (Editor editor : base.getEditors()) {
590-
editor.setSketchLocation(null);
589+
if ((displayNum != -1) && (displayNum != oldDisplayNum)) {
590+
Preferences.setInteger("run.display", displayNum); //$NON-NLS-1$
591+
// Reset the location of the sketch, the window has changed
592+
for (Editor editor : base.getEditors()) {
593+
editor.setSketchLocation(null);
594+
}
591595
}
592596
}
593597

@@ -670,11 +674,14 @@ protected void showFrame() {
670674
sketchbookLocationField.setText(Preferences.getSketchbookPath());
671675
checkUpdatesBox.setSelected(Preferences.getBoolean("update.check")); //$NON-NLS-1$
672676

673-
updateDisplayList();
677+
int defaultDisplayNum = updateDisplayList();
674678
int displayNum = Preferences.getInteger("run.display"); //$NON-NLS-1$
675-
if (displayNum >= 0 && displayNum < displayCount) {
676-
displaySelectionBox.setSelectedIndex(displayNum);
679+
//if (displayNum > 0 && displayNum <= displayCount) {
680+
if (displayNum < 1 || displayNum > displayCount) {
681+
displayNum = defaultDisplayNum;
682+
Preferences.setInteger("run.display", displayNum);
677683
}
684+
displaySelectionBox.setSelectedIndex(displayNum-1);
678685

679686
// This takes a while to load, so run it from a separate thread
680687
//EventQueue.invokeLater(new Runnable() {
@@ -749,11 +756,15 @@ public void run() {
749756
}
750757

751758

752-
void updateDisplayList() {
759+
/**
760+
* @return the number (1..whatever, not 0-indexed) of the default display
761+
*/
762+
int updateDisplayList() {
753763
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
754764
GraphicsDevice defaultDevice = ge.getDefaultScreenDevice();
755765
GraphicsDevice[] devices = ge.getScreenDevices();
756766

767+
int defaultNum = -1;
757768
displayCount = devices.length;
758769
String[] items = new String[displayCount];
759770
for (int i = 0; i < displayCount; i++) {
@@ -762,6 +773,7 @@ void updateDisplayList() {
762773
i + 1, mode.getWidth(), mode.getHeight());
763774
if (devices[i] == defaultDevice) {
764775
title += " default";
776+
defaultNum = i + 1;
765777
}
766778
items[i] = title;
767779
}
@@ -771,5 +783,6 @@ void updateDisplayList() {
771783
if (displayCount == 1) {
772784
displaySelectionBox.setEnabled(false);
773785
}
786+
return defaultNum;
774787
}
775788
}

core/src/processing/core/PApplet.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9655,8 +9655,10 @@ static public int blendColor(int c1, int c2, int mode) {
96559655

96569656

96579657
void frameMoved(int x, int y) {
9658-
System.err.println(EXTERNAL_MOVE + " " + x + " " + y);
9659-
System.err.flush(); // doesn't seem to help or hurt
9658+
if (!fullScreen) {
9659+
System.err.println(EXTERNAL_MOVE + " " + x + " " + y);
9660+
System.err.flush(); // doesn't seem to help or hurt
9661+
}
96609662
}
96619663

96629664

@@ -9818,7 +9820,7 @@ static public void runSketch(final String[] args,
98189820
int stopColor = 0xff808080;
98199821
boolean hideStop = false;
98209822

9821-
int displayIndex = -1; // use default
9823+
int displayNum = -1; // use default
98229824
// boolean fullScreen = false;
98239825
boolean present = false;
98249826
// boolean spanDisplays = false;
@@ -9838,8 +9840,8 @@ static public void runSketch(final String[] args,
98389840
editorLocation = parseInt(split(value, ','));
98399841

98409842
} else if (param.equals(ARGS_DISPLAY)) {
9841-
displayIndex = parseInt(value, -1);
9842-
if (displayIndex == -1) {
9843+
displayNum = parseInt(value, -1);
9844+
if (displayNum == -1) {
98439845
System.err.println("Could not parse " + value + " for " + ARGS_DISPLAY);
98449846
}
98459847

@@ -9926,6 +9928,10 @@ static public void runSketch(final String[] args,
99269928
}
99279929
}
99289930

9931+
// Set the suggested display that's coming from the command line
9932+
// (and most likely, from the PDE's preference setting).
9933+
sketch.display = displayNum;
9934+
99299935
// Call the settings() method which will give us our size() call
99309936
// try {
99319937
sketch.handleSettings();

core/src/processing/core/PSurfaceAWT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ public void initFrame(PApplet sketch) {/*, int backgroundColor,
398398
GraphicsEnvironment.getLocalGraphicsEnvironment();
399399

400400
int displayNum = sketch.sketchDisplay();
401+
// System.out.println("display from sketch is " + displayNum);
401402
if (displayNum > 0) { // if -1, use the default device
402403
GraphicsDevice[] devices = environment.getScreenDevices();
403404
if (displayNum <= devices.length) {
@@ -694,6 +695,7 @@ public void placeWindow(int[] location, int[] editorLocation) {
694695
int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
695696
int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
696697

698+
// Ignore previous sketch placement when dealing with full screen
697699
if (sketch.sketchFullScreen()) {
698700
location = null;
699701
}

java/src/processing/mode/java/runner/Runner.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public VirtualMachine vm() {
153153
public boolean launchVirtualMachine(boolean presenting) {
154154
String[] vmParams = getMachineParams();
155155
String[] sketchParams = getSketchParams(presenting);
156+
// PApplet.printArray(sketchParams);
156157
int port = 8000 + (int) (Math.random() * 1000);
157158
String portStr = String.valueOf(port);
158159

@@ -308,7 +309,7 @@ protected String[] getSketchParams(boolean presenting) {
308309
} else {
309310
params.add("processing.core.PApplet");
310311

311-
// get the stored device index (starts at 0)
312+
// get the stored device index (starts at 1)
312313
int runDisplay = Preferences.getInteger("run.display");
313314

314315
// If there was a saved location (this guy has been run more than once)
@@ -327,17 +328,23 @@ protected String[] getSketchParams(boolean presenting) {
327328

328329
// Make sure the display set in Preferences actually exists
329330
GraphicsDevice runDevice = editorDevice;
330-
if (runDisplay >= 0 && runDisplay < devices.length) {
331-
runDevice = devices[runDisplay];
331+
if (runDisplay > 0 && runDisplay <= devices.length) {
332+
runDevice = devices[runDisplay-1];
332333
} else {
334+
// If a bad display is selected, use the same display as the editor
335+
if (runDisplay > 0) { // don't complain about -1 or 0
336+
System.err.println("Display " + runDisplay + " not available.");
337+
}
333338
runDevice = editorDevice;
334339
for (int i = 0; i < devices.length; i++) {
335340
if (devices[i] == runDevice) {
336-
runDisplay = i;
341+
// Wasn't setting the pref to avoid screwing things up with
342+
// something temporary. But not setting it makes debugging one's
343+
// setup just too damn weird, so changing that behavior.
344+
runDisplay = i + 1;
345+
System.err.println("Setting 'Run Sketches on Display' preference to display " + runDisplay);
346+
Preferences.setInteger("run.display", runDisplay);
337347
break;
338-
// Don't set the pref, might be a temporary thing. Users can
339-
// open/close Preferences to reset the device themselves.
340-
// Preferences.setInteger("run.display", runDisplay);
341348
}
342349
}
343350
}

todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ X https://github.com/processing/processing/issues/2843
2626
o Update Windows icons for multiple sizes, implement them in the PDE
2727
o http://code.google.com/p/processing/issues/detail?id=632
2828
X closed during the 2.x cycle
29+
X try to clean up the Recent menu with the home icon
30+
_ make sure it doesn't break on Windows
2931

3032
contribs
3133
X several Greek translation updates

0 commit comments

Comments
 (0)