Skip to content

Commit 600c9b2

Browse files
author
mgricken
committed
Added Compiz warning.
git-svn-id: file:///tmp/test-svn/trunk@4947 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent e240585 commit 600c9b2

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

drjava/src/edu/rice/cs/drjava/DrJava.java

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838

3939
import static edu.rice.cs.drjava.config.OptionConstants.*;
4040

41-
import java.io.File;
42-
import java.io.IOException;
41+
import java.io.*;
4342
import java.util.ArrayList;
4443
import java.util.LinkedList;
4544
import java.util.List;
@@ -118,6 +117,8 @@ public static void main(final String[] args) {
118117
// Platform-specific UI setup.
119118
PlatformFactory.ONLY.beforeUISetup();
120119

120+
warnIfLinuxWithCompiz();
121+
121122
if (!_forceNewInstance &&
122123
DrJava.getConfig().getSetting(edu.rice.cs.drjava.config.OptionConstants.REMOTE_CONTROL_ENABLED) &&
123124
(_filesToOpen.size() > 0)) {
@@ -506,5 +507,71 @@ public static void cleanUp() {
506507
_jvmArgs.clear();
507508
// Do not set _config or _propertiesFile to null because THEY ARE static
508509
}
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+
}
510577
}

drjava/src/edu/rice/cs/drjava/config/OptionConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ public static ArrayList<String> evaluate() {
10601060

10611061
/** The port where DrJava will listen for remote control requests. */
10621062
public static final IntegerOption REMOTE_CONTROL_PORT = new IntegerOption("remote.control.port", Integer.valueOf(4444));
1063+
1064+
/** Whether to warn if Compiz is being used */
1065+
public static final BooleanOption WARN_IF_COMPIZ = new BooleanOption("warn.if.compiz", Boolean.TRUE);
10631066

10641067
/* ---------- COMPILER OPTIONS ------------- */
10651068

drjava/src/edu/rice/cs/drjava/ui/config/ConfigFrame.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,11 @@ protected boolean verify(String s) {
12161216
};
12171217
addOptionComponent(panel, autoImportClasses);
12181218

1219+
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.WARN_IF_COMPIZ,
1220+
"Warn If Compiz Detected", this,
1221+
"<html>Whether DrJava should warn the user if Compiz is running.<br>"+
1222+
"Compiz and Java Swing are incompatible and can lead to crashes.</html>"));
1223+
12191224
// Any lightweight parsing has been disabled until we have something that is beneficial and works better in the background.
12201225
// addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.LIGHTWEIGHT_PARSING_ENABLED,
12211226
// "Perform lightweight parsing", this,

0 commit comments

Comments
 (0)