Display problems with Beryl (or Compiz) and Java

Please refer to the following link ;-)
you will find it useful
copy of this is when you click on “more”from http://wiki.beryl-project.org/wiki/Java on 29/04/2007 @02:10 GMT+8

Java

From Beryl Wiki

Jump to: navigation, search

Java SE 6 gui applications such as Netbeans and possibly other AWT and Swing applications do not display correctly when using Beryl. Some people have stated that setting AWT_TOOLKIT=MToolkit (causing the Motif toolkit to be used instead of the X toolkit) fixes the display problems for Java SE 5. (See bottom of page)

Note: Switching to Metacity Window Manager then back to Beryl Window Manager seems to fix the problem for both Java 5 & 6. Dialogs have strange behavior though, like not resizing correctly.

 

Contents

[hide]

[edit]

Fixing Java 6

The Motif toolkit seems to be missing for the latest Java SE 6 JDK on Linux so this is not a valid option. The following steps are needed to get Java SE 6 working with Beryl. This was based on information found at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6509038

Prepare some directories

mkdir -p /tmp/java/src
mkdir -p /tmp/java/rt

Extract the Java SE 6 runtime classes

cp /usr/java/jdk1.6.0/jre/lib/rt.jar /usr/java/jdk1.6.0/jre/lib/rt.jar.orig
cp /usr/java/jdk1.6.0/jre/lib/rt.jar /tmp/java/rt/rt.zip
cd /tmp/java/rt
unzip rt.zip

Get the source code (check for a later version at the JDK download page)

cd ../src
wget http://www.java.net/download/jdk6/6u2/promoted/b01/jdk-6u2-ea-src-b01-jrl-29_mar_2007.jar

Extract the source code. Switch back to Metacity (Gnome Window Manager) if you are already using Beryl. Run the following (choosing /tmp/java/src to extract to):

java -jar jdk-6u1-ea-src-b03-jrl-19_jan_2007.jar

To patch j2se/src/solaris/classes/sun/awt/X11/XWM.java and j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java

touch patch
nano patch

Copy the following text code into the new file:

diff -ur src.orig/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java src/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java
--- src.orig/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java	2007-02-24 08:21:07.000000000 -0500
+++ src/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java	2007-02-24 08:23:40.000000000 -0500
@@ -692,7 +692,7 @@
                 // ConfigureNotify, only the one from X with zero
                 // coordinates.  This is the workaround to get real
                 // location, 6261336
-                // Do the same for non-reparenting WMs (Compiz, Looking Glass)
+                // Do the same for non-reparenting WMs (Compiz, Looking Glass, Beryl)
                 switch (XWM.getWMID()) {
                   case XWM.CDE_WM:
                   case XWM.MOTIF_WM:
@@ -700,6 +700,7 @@
                   case XWM.SAWFISH_WM:
                   case XWM.COMPIZ_WM:
                   case XWM.LG3D_WM:
+                  case XWM.BERYL_WM:
                   {
                       Point xlocation = queryXLocation();
                       if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "New X location: {0}", new Object[]{xlocation});
diff -ur src.orig/j2se/src/solaris/classes/sun/awt/X11/XWM.java src/j2se/src/solaris/classes/sun/awt/X11/XWM.java
--- src.orig/j2se/src/solaris/classes/sun/awt/X11/XWM.java	2007-02-24 08:21:07.000000000 -0500
+++ src/j2se/src/solaris/classes/sun/awt/X11/XWM.java	2007-02-24 08:22:58.000000000 -0500
@@ -79,7 +79,8 @@
         ICE_WM = 10,
         METACITY_WM = 11,
         COMPIZ_WM = 12,
-        LG3D_WM = 13;
+        LG3D_WM = 13,
+        BERYL_WM = 14;
     public String toString() {
         switch  (WMID) {
           case NO_WM:
@@ -106,6 +107,8 @@
               return "Compiz";
           case LG3D_WM:
               return "LookingGlass";
+          case BERYL_WM:
+              return "Beryl";
           case UNDETERMINED_WM:
           default:
               return "Undetermined WM";
@@ -534,6 +537,10 @@
         return isNetWMName("LG3D");
     }

+    static boolean isBeryl() {
+        return isNetWMName("beryl");
+    }
+
     /*
      * Is Metacity running?
      */
@@ -546,7 +553,7 @@
     }

     static boolean isNonReparentingWM() {
-        return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM);
+        return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM || XWM.getWMID() == XWM.BERYL_WM);
     }

     /*
@@ -738,6 +745,8 @@
                 awt_wmgr = XWM.COMPIZ_WM;
             } else if (isLookingGlass()) {
                 awt_wmgr = LG3D_WM;
+            } else if (isBeryl()) {
+                awt_wmgr = BERYL_WM;
             } else if (doIsIceWM && isIceWM()) {
                 awt_wmgr = XWM.ICE_WM;
             }
@@ -1387,6 +1396,7 @@
           case XWM.ENLIGHTEN_WM:
               return readInsetsArray(window, XA_E_FRAME_SIZE, insets);
           case XWM.COMPIZ_WM:
+          case XWM.BERYL_WM:
               return readInsetsArray(window, XA_FRAME_EXTENTS, insets);
           default:
               return false;

Use Ctrl + X, Y, Enter to exit saving changes. Go ahead and make it executable.

chmod +x patch

Now apply the patch file

patch -p1 < patch

Remove the classes we are going to replace

cd ../rt
rm sun/awt/X11/XDecoratedPeer*
rm sun/awt/X11/XWM.*
rm sun/awt/X11/XWM$*

Copy the modified source files in (so we don’t have to mess with destinations or classpath)

cp ../src/j2se/src/solaris/classes/sun/awt/X11/XWM.java sun/awt/X11
cp ../src/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java sun/awt/X11

Compile the modified classes

javac -d . sun/awt/X11/*.java

Update the changed files

zip -f rt.zip sun/awt/X11/*

Replace the old rt.jar

cp rt.zip /usr/java/jdk1.6.0/jre/lib/rt.jar

[edit]

Fixing Java 5

Open up ~/.bashrc or /etc/bashrc for editing

nano ~/.bashrc

Insert as the first line

export AWT_TOOLKIT=MToolkit

Restart window manager and all terminal windows. Known to work for Ubuntu 6.10, Java 5. See for more information.

[edit]

Fixing Java 6 by auto scriting

Create new file:

  vim beryl.jdk6.fix.sh

Copy the following text code into the new file:

CODES:

#!/bin/bash
# testing pass in archlinux 0.8 by SCys
# Write for beryl fix jdk 6!

checkAll()
{
	[ ! -x "`which zip`" ] && echo "no zip!" && exit 0
	[ ! -x "`which unzip`" ] && echo "no unzip!" && exit 0
	[ ! -x "`which wget`" ] && echo "no wget!" && exit 0
	[ ! -x "`which awk`" ] && echo "no awk!" && exit 0
}
checkAll
setJdkPath()
{
	if [ "$CLASSPATH" ]
	then
		LIB_PATH=`echo ${CLASSPATH} | awk -F : '{print $3}'`
	elif [ "$1" ]
	then
		LIB_PATH=$1
	elif [ -x $LIB_PATH/rt.jar ]
	then
		echo "JRE LIB PATH not set up!please set like \"this beryl.jdk.fix.sh /opt/java/jre/lib\" "
		exit 0
	fi
	echo $LIB_PATH
}
#
#--MAIN---
#
#1: Set var
setJdkPath $1
#2: Prepare some directories
mkdir -p /tmp/java
mkdir -p /tmp/java/src
mkdir -p /tmp/java/rt
#3: Extract the Java SE 6 runtime classes
if [ ! -x /tmp/java/rt/rt.zip ]
then
	cp $LIB_PATH/rt.jar $LIB_PATH/rt.jar.orig
	cp $LIB_PATH/rt.jar /tmp/java/rt/rt.zip
fi
cd /tmp/java/rt
echo "Please waiting for unzip all files"
unzip rt.zip > /dev/null
echo "Unzip ok."
#4: Get the source code
cd ../src
wget http://www.java.net/download/jdk6/6u2/promoted/b01/jdk-6u2-ea-src-b01-jrl-29_mar_2007.jar
java -jar jdk-6u2-ea-src-b01-jrl-29_mar_2007.jar
#5: To patch:
#	j2se/src/solaris/classes/sun/awt/X11/XWM.java
#	j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java
echo 'diff -ur src.orig/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java src/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java
--- src.orig/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java	2007-02-24 08:21:07.000000000 -0500
+++ src/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java	2007-02-24 08:23:40.000000000 -0500
@@ -692,7 +692,7 @@
                 // ConfigureNotify, only the one from X with zero
                 // coordinates.  This is the workaround to get real
                 // location, 6261336
-                // Do the same for non-reparenting WMs (Compiz, Looking Glass)
+                // Do the same for non-reparenting WMs (Compiz, Looking Glass, Beryl)
                 switch (XWM.getWMID()) {
                   case XWM.CDE_WM:
                   case XWM.MOTIF_WM:
@@ -700,6 +700,7 @@
                   case XWM.SAWFISH_WM:
                   case XWM.COMPIZ_WM:
                   case XWM.LG3D_WM:
+                  case XWM.BERYL_WM:
                   {
                       Point xlocation = queryXLocation();
                       if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "New X location: {0}", new Object[]{xlocation});
diff -ur src.orig/j2se/src/solaris/classes/sun/awt/X11/XWM.java src/j2se/src/solaris/classes/sun/awt/X11/XWM.java
--- src.orig/j2se/src/solaris/classes/sun/awt/X11/XWM.java	2007-02-24 08:21:07.000000000 -0500
+++ src/j2se/src/solaris/classes/sun/awt/X11/XWM.java	2007-02-24 08:22:58.000000000 -0500
@@ -79,7 +79,8 @@
         ICE_WM = 10,
         METACITY_WM = 11,
         COMPIZ_WM = 12,
-        LG3D_WM = 13;
+        LG3D_WM = 13,
+        BERYL_WM = 14;
     public String toString() {
         switch  (WMID) {
           case NO_WM:
@@ -106,6 +107,8 @@
               return "Compiz";
           case LG3D_WM:
               return "LookingGlass";
+          case BERYL_WM:
+              return "Beryl";
           case UNDETERMINED_WM:
           default:
               return "Undetermined WM";
@@ -534,6 +537,10 @@
         return isNetWMName("LG3D");
     }

+    static boolean isBeryl() {
+        return isNetWMName("beryl");
+    }
+
     /*
      * Is Metacity running?
      */
@@ -546,7 +553,7 @@
     }

     static boolean isNonReparentingWM() {
-        return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM);
+        return (XWM.getWMID() == XWM.COMPIZ_WM || XWM.getWMID() == XWM.LG3D_WM || XWM.getWMID() == XWM.BERYL_WM);
     }

     /*
@@ -738,6 +745,8 @@
                 awt_wmgr = XWM.COMPIZ_WM;
             } else if (isLookingGlass()) {
                 awt_wmgr = LG3D_WM;
+            } else if (isBeryl()) {
+                awt_wmgr = BERYL_WM;
             } else if (doIsIceWM && isIceWM()) {
                 awt_wmgr = XWM.ICE_WM;
             }
@@ -1387,6 +1396,7 @@
           case XWM.ENLIGHTEN_WM:
               return readInsetsArray(window, XA_E_FRAME_SIZE, insets);
           case XWM.COMPIZ_WM:
+          case XWM.BERYL_WM:
               return readInsetsArray(window, XA_FRAME_EXTENTS, insets);
           default:
               return false;' > patch
chmod +x patch
patch -p1 < patch
#6: Replace classes
cd ../rt
rm sun/awt/X11/XDecoratedPeer*
rm sun/awt/X11/XWM.*
rm sun/awt/X11/XWM$*
cp ../src/j2se/src/solaris/classes/sun/awt/X11/XWM.java sun/awt/X11
cp ../src/j2se/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java sun/awt/X11
#7: Compile the modified classes
echo "Please waiting for complie."
javac -d . sun/awt/X11/*.java
echo "complie ok."
#8: Update the changed files
zip -f rt.zip sun/awt/X11/*
#9: Replace the old rt.jar
cp rt.zip $LIB_PATH/rt.jar
echo "All ok, start some java application to try. "

Make it executable:

   chmod +x beryl.jdk6.fix.sh

Run it:

   sh beryl.jdk6.fix.sh

There is a much easyer way to resolve that problem:

type the following in a console window:

sudo gedit /etc/environment

then add the following line at the bottom and save the file.

AWT_TOOLKIT=”MToolkit”

finally restart x (ctrl+alt+backspace)

[edit]

Alternative Fix

There is also a sure shot method posted to get Java applications to work if the above method does not work.

Refer to http://www.vikrammohan.com/blog/2006/12/31/how-to-make-java-swing-work-on-beryl-with-aiglx/