|
38 | 38 |
|
39 | 39 | import static edu.rice.cs.drjava.config.OptionConstants.*; |
40 | 40 |
|
41 | | -import java.io.File; |
42 | | -import java.io.IOException; |
| 41 | +import java.io.*; |
43 | 42 | import java.util.ArrayList; |
44 | 43 | import java.util.LinkedList; |
45 | 44 | import java.util.List; |
@@ -118,6 +117,8 @@ public static void main(final String[] args) { |
118 | 117 | // Platform-specific UI setup. |
119 | 118 | PlatformFactory.ONLY.beforeUISetup(); |
120 | 119 |
|
| 120 | + warnIfLinuxWithCompiz(); |
| 121 | + |
121 | 122 | if (!_forceNewInstance && |
122 | 123 | DrJava.getConfig().getSetting(edu.rice.cs.drjava.config.OptionConstants.REMOTE_CONTROL_ENABLED) && |
123 | 124 | (_filesToOpen.size() > 0)) { |
@@ -506,5 +507,71 @@ public static void cleanUp() { |
506 | 507 | _jvmArgs.clear(); |
507 | 508 | // Do not set _config or _propertiesFile to null because THEY ARE static |
508 | 509 | } |
509 | | - |
| 510 | + |
| 511 | + /** Warn if this system is Linux with Compiz. */ |
| 512 | + public static boolean warnIfLinuxWithCompiz() { |
| 513 | + try { |
| 514 | + if (!System.getProperty("os.name").equals("Linux")) return false; // not Linux |
| 515 | + if (!DrJava.getConfig().getSetting(edu.rice.cs.drjava.config.OptionConstants.WARN_IF_COMPIZ)) return false; // set to ignore |
| 516 | + |
| 517 | + // get /bin/ps |
| 518 | + File ps = new File("/bin/ps"); |
| 519 | + |
| 520 | + // execute ps |
| 521 | + ProcessBuilder pb = new ProcessBuilder(ps.getAbsolutePath(), "-A"); |
| 522 | + Process psProc = pb.start(); |
| 523 | + psProc.waitFor(); |
| 524 | + |
| 525 | + // read the output of ps |
| 526 | + BufferedReader br = new BufferedReader(new InputStreamReader(psProc.getInputStream())); |
| 527 | + boolean compiz = false; |
| 528 | + String line = null; |
| 529 | + while((line=br.readLine())!=null) { |
| 530 | + // find the PID of JUnitTestRunner, i.e. the PID of the current process |
| 531 | + if ((line.endsWith("compiz")) || |
| 532 | + (line.endsWith("compiz.real"))) { |
| 533 | + compiz = true; |
| 534 | + break; |
| 535 | + } |
| 536 | + } |
| 537 | + if (!compiz) return false; // no Compiz |
| 538 | + |
| 539 | + String[] options = new String[] { "Yes", "Yes, and ignore from now on", "No" }; |
| 540 | + int res = javax.swing.JOptionPane.showOptionDialog(null, |
| 541 | + "<html>DrJava has detected that you are using Compiz.<br>"+ |
| 542 | + "<br>"+ |
| 543 | + "Compiz and Java Swing are currently incompatible and can cause<br>"+ |
| 544 | + "DrJava or your computer to crash.<br>"+ |
| 545 | + "<br>"+ |
| 546 | + "We recommend that you <b>disable Compiz</b>. On Ubuntu, go to<br>"+ |
| 547 | + "System->Preferences->Appearence, display the Visual Effects tab,<br>"+ |
| 548 | + "and select 'None'.<br>"+ |
| 549 | + "<br>"+ |
| 550 | + "For more information, please go to http://drjava.org/compiz.html<br>"+ |
| 551 | + "<br>"+ |
| 552 | + "Do you want to start DrJava anyway?</html>", |
| 553 | + "Compiz detected", |
| 554 | + JOptionPane.DEFAULT_OPTION, |
| 555 | + javax.swing.JOptionPane.WARNING_MESSAGE, |
| 556 | + null, |
| 557 | + options, |
| 558 | + options[0]); |
| 559 | + switch(res) { |
| 560 | + case 1: |
| 561 | + // set "ignore" option |
| 562 | + DrJava.getConfig().setSetting(edu.rice.cs.drjava.config.OptionConstants.WARN_IF_COMPIZ, false); |
| 563 | + break; |
| 564 | + case 2: |
| 565 | + System.exit(0); |
| 566 | + break; |
| 567 | + } |
| 568 | + return compiz; |
| 569 | + } |
| 570 | + catch(IOException ioe) { |
| 571 | + return false; // do not warn |
| 572 | + } |
| 573 | + catch(InterruptedException ie) { |
| 574 | + return false; // do not warn |
| 575 | + } |
| 576 | + } |
510 | 577 | } |
0 commit comments