From 121c8172688a003776d5c8b75ebe6076750dd2ec Mon Sep 17 00:00:00 2001
From: mathiasdm <mathiasdm@mail.i2p>
Date: Fri, 4 Feb 2011 17:09:13 +0000
Subject: [PATCH] Fix for headless.

---
 .../src/net/i2p/desktopgui/Main.java           | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/apps/desktopgui/src/net/i2p/desktopgui/Main.java b/apps/desktopgui/src/net/i2p/desktopgui/Main.java
index 56abf9e2c5..03aa216b6e 100644
--- a/apps/desktopgui/src/net/i2p/desktopgui/Main.java
+++ b/apps/desktopgui/src/net/i2p/desktopgui/Main.java
@@ -7,6 +7,7 @@ package net.i2p.desktopgui;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.UnsupportedLookAndFeelException;
+import java.awt.GraphicsEnvironment;
 
 import net.i2p.I2PAppContext;
 import net.i2p.desktopgui.router.RouterManager;
@@ -54,7 +55,21 @@ public class Main {
      * Main method launching the application.
      */
     public static void beginStartup(String[] args) {
-        System.setProperty("java.awt.headless", "false");
+        boolean wasHeadless = Boolean.valueOf(System.getProperty("java.awt.headless")).booleanValue();
+        if(wasHeadless) {
+            System.setProperty("java.awt.headless", "false");
+        }
+        boolean headless_check = true;
+        try {
+            // X permissions error is a java.lang.InternalError (a Throwable)
+            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+            headless_check = ge.isHeadlessInstance();
+        } catch (Throwable t) {}
+        if (wasHeadless)
+            System.setProperty("java.awt.headless", "true");
+        if (headless_check) {
+            return;
+        }
         try {
             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         } catch (ClassNotFoundException ex) {
@@ -87,6 +102,7 @@ public class Main {
             }
             
         });
+
     }
     
     /**
-- 
GitLab