Screen-Insets for Gnome/Linux

Hi, I'm currently working on a small lib that's meant for displaying, aranging, animating custom user notification popups (like the "new email popup" from Thunderbird in Windows for example).

Of course I'd like to display the popups in respect to the size and position of the taskbar.

I'm using the Toolkit#getScreenInsets Method to calculate the correct place for the popups and it works fine with Windows, but not at all with my Linux system.

The Insets are always 0,0,0,0.

So far I've tried Gnome/Metacity and Beryl.

I've also found some (closed) bugs on that issue but there was no workaround mentioned.

It looks as if it's not really possible to do what I'm planning to do with Gnome.

How about other Window Managers?

Maybe there is a dirty trick that I could use to make it work?

Thanks in advance for any idea.

[886 byte] By [Wildcard82a] at [2007-11-27 3:27:08]
# 1

Toolkit depends on the OS :

See getDefaultToolkit here http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html

try this:

under unix, execute your program like the following:

java -Djava.awt.headless=true yourMainProgram

(i'm not sure this will help you)

java_2006a at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hi and thanks for your reply.

>>Toolkit depends on the OS :

of course it depends on the OS, the problem is how to get the correct insets for a screen when the Toolkit seems to be unable to do the job.

>>try this:

>>under unix, execute your program like the following:

>>java -Djava.awt.headless=true yourMainProgram

I don't see how this would help me.

I'm not in an Headless Environment.

I'm just looking for a way to get the correct screen insets (the area that a maximized JFrame would use) and maximizing a frame to get it's bound is not a valid option in my opinion.

Wildcard82a at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 3
by the way, this is the related (closed) bug. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4737732Is there really no solution at all?
Wildcard82a at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 4
What if you just made an invisible maximized frame/dialog and stole it's dimensions?Lol... I've been doing some cross-platform hacking myself... I can appreciate the need. :)P.S. Beryl rocks! :P-FBL
FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 5

Lol i was having fun writing a hack, then found this out:

To determine if your environment is a virtual device environment, call getBounds on all of the GraphicsConfiguration objects in your system. If any of the origins of the returned bounds is not (0, 0), your environment is a virtual device environment.

You can also use getBounds to determine the bounds of the virtual device. To do this, first call getBounds on all of the GraphicsConfiguration objects in your system. Then calculate the union of all of the bounds returned from the calls to getBounds. The union is the bounds of the virtual device. The following code sample calculates the bounds of the virtual device.

Here's their code:

Rectangle virtualBounds = new Rectangle();

GraphicsEnvironment ge = GraphicsEnvironment.

getLocalGraphicsEnvironment();

GraphicsDevice[] gs =

ge.getScreenDevices();

for (int j = 0; j < gs.length; j++) {

GraphicsDevice gd = gs[j];

GraphicsConfiguration[] gc =

gd.getConfigurations();

for (int i=0; i < gc.length; i++) {

virtualBounds =

virtualBounds.union(gc[i].getBounds());

}

}

Here's their code rewritten for a compiz dude :P

Rectangle r = new Rectangle();

for (GraphicsDevice gs : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices())

for (GraphicsConfiguration gc : gs.getConfigurations())

r = r.union(gc.getBounds());

Now i'm going to see if getInsets can work too...

-FBL

FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 6
Tried and failed.Even with this code, Linux returns insets of 0.I'm afraid a fake maximized window may be your best bet... :\-FBL
FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 7

Wildcard,

I even made a dummy panel and got the wrong results (linux only)

Here's my test project:

import javax.swing.*;

import java.awt.*;

/*

* Hack stylz for the compiz dude

* GPL cuz ROFLCOPTER pwnz Vista

*/

public class ScreenSize {

public static Insets getScreenInsets(GraphicsConfiguration gc){

if (!System.getProperty("os.name").toLowerCase().startsWith("linux"))

return Toolkit.getDefaultToolkit().getScreenInsets(gc);

else {

JFrame j = new JFrame();

j.setExtendedState(Frame.MAXIMIZED_BOTH);

int left = j.getX();

int top = j.getY();

int right = left + j.getWidth();

int bottom = j.getHeight() + j.getY();

j.dispose();

return new Insets(top, left, bottom, right);

}

}

public static void main(String[] args) {

System.out.println("\n" + System.getProperty("os.name")+":");

Rectangle r = new Rectangle();

Insets i = new Insets(0,0,0,0);

Insets fake = new Insets(0,0,0,0);

for (GraphicsDevice gs : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices())

for (GraphicsConfiguration gc : gs.getConfigurations()) {

r = r.union(gc.getBounds());

i = Toolkit.getDefaultToolkit().getScreenInsets(gc);

fake = getScreenInsets(gc);

System.out.println("" + i.toString());

}

System.out.println("" + r.toString());

i.set(r.y + i.top, r.x + i.left, r.height - i.bottom, r.width - i.right);

fake.set(r.y + fake.top, r.x + fake.left, r.height - fake.bottom, r.width - fake.right);

System.out.println("\nYour insets should be: " + i.toString());

System.out.println("\nA maximized window would be: " + fake.toString());

}

}

-Tres

FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 8
Hi FBL.Thank you very much for your efforts.Of course I'm getting wrong results as well, and that's easy to explain:It's not possible under Linux to maximize a JFrame programatically. :-|I'm really out of ideas...Any more ideas for dirty hacks?
Wildcard82a at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 9
Not without using JNI, which defeats the purpose of using java IMO... I'll keep looking! Cheers.-Tres
FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 10

Ok... I just sunk some more hacking into this...

I tried the Java 6 TrayIcon class.

It lets you put a tray icon in the corner of the screen.

Sounds perfect right? Wrong.

It's only compatible with AWT, and no swing components.

And to top it off, there's no way to grab it's location.

What does work, is displayMessage("caption", "text", type), however its a OS component, so you can't manipulate it's contents with HTML, and of course, you can't grab it's coordinates either.

I figured I could show the popup menu, and grab it's coordinates, but they're decided by where your mouse is.

This bothers me, because I know java places the menus effectively to not overlap your start bar, but they don't give us access to do the same thing.

I'm sure the notifications you're placing down there are much more elaborate than an annoying baloon, but that's all I've found so far...

-Tres

FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 11
Just tried GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds() with no luck either... :(Does kde/gnome control this? I can't imagine it does.-Tres
FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 12
I just found this [url= http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5036549]similar bug[/url] too...Apparently the insets are pretty buggy all over the board! :)-Tres
FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 13

Hi FBL,

Thanks a lot for all the efforts you're putting into my problem.

It looks as if there is no good solution to get those insets at all...

I found out that it's at least possible with Gnome to parse the xml files it uses to place the widgets on the screen, but I can't say that I'm exactly happy with that solution. :-/

>>I tried the Java 6 TrayIcon class.

>>It lets you put a tray icon in the corner of the screen.

>>Sounds perfect right? Wrong.

>>It's only compatible with AWT, and no swing components.

>>I'm sure the notifications you're placing down there are much more elaborate than an

>>annoying baloon, but that's all I've found so far...

I know about the TrayIcon. That it's AWT wouldn't be a problem for me, but it's not that I want to display some popups, but I wrote a little library that should help programmers to use notifications like the 'new email popup' from Thunderbird, a notification for a new phone call, stuff like that....

It takes care of putting them over each other (if there are multiple notification at once), disposes them, orders them, animates them....

Of course a Java library that's not really cross-plattform isn't as useful as it should be so I'm rather disappointed that I can't get it to work the way it is meant to work.

That's how it currently looks like

http://www.jutzig.de/java/jnotification/screenDemo.png

but unfortunately I could only place them on top of my taskbar by hard-coding an offset to the edge of the screen where the popups are 'docked'.

Wildcard82a at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 14

Hmm... we'll, i'm all for hacks.

I can help you parse the xml file if you want... It'll be something that is long overdue.

KDE has a similar way of storing these settings to, and with luck, XFCE will work like Gnome, since it's GTK based.

I think OSX has problems with this too (although OSX isn't even at 1.5 yet).

Can you drop me a path to this xml? I have Gnome, KDE, windows, and possibly OSX around me most of the day. I think it will be worth it!

-Tres

FBLa at 2007-7-12 8:29:53 > top of Java-index,Desktop,Core GUI APIs...
# 15
>>Can you drop me a path to this xml?Of course I can.There is one file for each panel underhome/username/.gconf/apps/panel/toplevels
Wildcard82a at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 16
woah... pg2...almost missed it. : )i'll look into those files right now.-FBl
FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 17

Alright, this station at home doesn't have gdm. Station at work does, though.

root@bjorn:/home/lite/.gconf/apps# ls -al

total 16

drwx 4 lite lite 4096 2007-05-08 04:41 .

drwx 5 lite lite 4096 2007-05-08 05:01 ..

drwx 2 lite lite 4096 2007-05-08 04:42 gconf-editor

-rw- 1 lite lite0 2007-05-08 04:40 %gconf.xml

drwx 2 lite lite 4096 2007-05-08 04:41 nautilus

Any chance you can drop me a zip of the files? That way I can start working on it today and tmw. :beer:

Email is tres dot finocchiaro at gmail

-Tres

Message was edited by:

FBL

FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 18
Sorry that my reply took so long, I've been quite busy lately :-/Ok, I'll send you a zip of my toplevels directory.Seems easy enough to get the sizes out of the XMLs, although I'm kinda surprised that nobody seems to know a better solution.
Wildcard82a at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 19

Here's what I whipped up.

It's not specific to each screen, but let me know how it works.

-Tres

/*

* A quick hack to grab gnome (gdm) screen insets

*

* By: A. Tres Finocchiaro

* Released GPL - http://www.gnu.org/copyleft/gpl.html

*/

import java.util.*;

import java.awt.*;

import java.io.*;

public class GnomeInsets {

public static final String GNOME_CONFIG = "%gconf.xml";

public static final String GNOME_PANEL = "_panel_screen";

public static final String GNOME_ROOT = System.getProperty("user.home") + "/.gnome/";

public static void main(String[] args) {

System.out.println("\n\nInsets:\n\t" + getInsets() + "\n\n");

}

public static Insets getInsets() {

String fileName = GNOME_CONFIG;

String panelName = GNOME_PANEL;

File gnomeRoot = new File(GNOME_ROOT);

int n=0; int s=0; int e=0; int w=0;

for (File f : gnomeRoot.listFiles()) {

String folder = f.getName();

if (f.isDirectory() && folder.contains(panelName)) {

int val = getSizeFromXML(new File(gnomeRoot.getPath() + "/" + folder + "/" + fileName));

if (val == -1)

; //Skip

else if (folder.startsWith("top" + panelName))

n = Math.max(val, n);

else if (folder.startsWith("bottom" + panelName))

s = Math.max(val, s);

else if (folder.startsWith("right" + panelName))

e = Math.max(val, e);

else if (folder.startsWith("left" + panelName))

w = Math.max(val, w);

}

}

return new Insets(n, w, s, e);

}

private static int getSizeFromXML(File xmlFile) {

try {

boolean found = false; String temp = "";

FileReader reader = new FileReader(xmlFile);

BufferedReader buffer = new BufferedReader(reader);

while (temp != null) {

temp = buffer.readLine();

if (temp.contains("<entry name=\"size\"")) {

found = true; break;

}

}

buffer.close();reader.close();

if (found) {

temp = temp.substring(temp.indexOf("value=\"") + 7);

return Integer.parseInt(temp.substring(0, temp.indexOf("\">")));

}

}

catch (Exception e) {}

return -1;

}

}

FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 20

Hi FBL,

I updated the path to:

public static final String GNOME_ROOT = System.getProperty("user.home") + "/.gconf/apps/panel/toplevels/";

and now your snippet works perfectly.

Thank you very much!

One question's left:

I'll probably publish the lib under the Apache Licence.

Would you mind if I use the snippet the way it is under that licence?

Best regards

Wildcard82a at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 21

That sounds fine. I'm not sure about the technicalities on licensing. :\

Updated code:

/*

* A quick hack to grab gnome (gdm) screen insets

*

* By: A. Tres Finocchiaro

* Released GPL - http://www.gnu.org/copyleft/gpl.html

*/

import java.util.*;

import java.awt.*;

import java.io.*;

public class GnomeInsets {

private static final String GNOME_CONFIG = "%gconf.xml";

private static final String GNOME_PANEL = "_panel_screen";

private static final String GNOME_ROOT = System.getProperty("user.home") + "/.gconf/apps/panel/toplevels/";

public static void main(String[] args) {

System.out.println("\n\nInsets:\n\t" + getInsets() + "\n\n");

}

public static Insets getInsets() {

String fileName = GNOME_CONFIG;

String panelName = GNOME_PANEL;

File gnomeRoot = new File(GNOME_ROOT);

int n=0; int s=0; int e=0; int w=0;

for (File f : gnomeRoot.listFiles()) {

String folder = f.getName();

if (f.isDirectory() && folder.contains(panelName)) {

int val = getSizeFromXML(new File(gnomeRoot.getPath() + "/" + folder + "/" + fileName));

if (val == -1)

; //Skip

else if (folder.startsWith("top" + panelName))

n = Math.max(val, n);

else if (folder.startsWith("bottom" + panelName))

s = Math.max(val, s);

else if (folder.startsWith("right" + panelName))

e = Math.max(val, e);

else if (folder.startsWith("left" + panelName))

w = Math.max(val, w);

}

}

return new Insets(n, w, s, e);

}

private static int getSizeFromXML(File xmlFile) {

try {

boolean found = false; String temp = "";

FileReader reader = new FileReader(xmlFile);

BufferedReader buffer = new BufferedReader(reader);

while (temp != null) {

temp = buffer.readLine();

if (temp.contains("<entry name=\"size\"")) {

found = true; break;

}

}

buffer.close();reader.close();

if (found) {

temp = temp.substring(temp.indexOf("value=\"") + 7);

return Integer.parseInt(temp.substring(0, temp.indexOf("\">")));

}

}

catch (Exception e) {}

return -1;

}

}

Usage:

Insets screenInsets = GnomeInsets.getInsets();

The next step would be doing the same for KDE, and trying to determine which one people are running...

-Tres

FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 22

>>That sounds fine. I'm not sure about the technicalities on licensing. :\

If a code is under GPL, every code that links against GPL classes has to be GPL as well.

Apache Licence is less restrictive. As long as the author is mentioned, the source of the used classes is available, and the licence is attached, you can use it with every other licence.

Unfortunately the GPL is not compatible with the Apache Licence, that's why I'm asking.

I don't want to limit the library to GPL code.

Wildcard82a at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 23
Sounds great! :)I wrote it for your project, so its cool w/ me!Should I start working on KDE now?-Tres
FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 24
Well, to be honest, I have no idea how KDE panels are managed and I don't have a KDE environment to check.
Wildcard82a at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 25
I do.I found the kicker stuff in:/home/USER/.kde/share/config/kickerrc, but nothing regarding its size settings.I grep'd the config folder for 48, the size of the bar, and found nothing... -Tres
FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 26
Ok, I found "CustomSize" only when specifying a size. Most people use a built-in size, and I have no idea how to find it! lol-Tres
FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 27
Figured it out. Will post in a few.
FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 28

Not yet tested. Uses 3rd party class "QuickIni". I may write my own quick ini parser later today.

-Tres

public class KdeInsets {

public static void main(String[] args) {

System.out.println("\n\nInsets:\n\t" + getInsets() + "\n\n");

}

public static Insets getInsets() {

/** KDE: */

//

//2 Top

//0 Left1 Right

//3 Bottom

//

/** JAVA: */

//

//0 Top

//1 Left 3 Right

//2 Bottom

//

int[] sizes = {24, 30, 46, 58, 0};// 0, 1, 2, 3, 4, Null

int[] i = {0, 0, 0, 0, 0}; // Left, Right, Top, Bottom, Null

/* #### Needs 3rd party class "QuickIni" #### */

QuickIni kdeIni = new QuickIni("/home/lite/.kde/share/config/kickerrc");

Integer pos = kdeIni.getIntegerProperty("General", "Position");

Integer siz = kdeIni.getIntegerProperty("General", "Size");

Integer customSiz = kdeIni.getIntegerProperty("General", "CustomSize");

int position = (int)(pos==null?4:pos);

int size = (int)(siz==null?(customSiz==null?4:customSiz):siz);

size = size<24?sizes[size]:size;

i[position]=size;

return new Insets(i[2],i[0],i[3],i[1]);

}

}

FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 29

This should cover KDE and Gnome in one class. Please add if you can code for other desktops/OS's.

Usage:

Insets screenInsets = Linsets.getInsets();

Code:

/* Linsets

*

* A class for getting the screen

* insets for non-Windows Operating Systems

*

* By:

* A. Tres Finocchiaro

* Liscense:

* http://www.gnu.org/copyleft/gpl.html

*Compatible with:

*Java 1.5 SE, Java 1.6 SE

*Keywords:

*insets, osx, linux, unix,

*solaris, kde, gnome, xfce,

*ubuntu, java, darwin

*/

import java.io.*;

import java.util.*;

import java.awt.*;

public class Linsets {

private static final String DESKTOP_ENVIRONMENTS = "kdesktop|gnome-panel|xfce|darwin";

private static final String GNOME_CONFIG = "%gconf.xml";

private static final String GNOME_PANEL = "_panel_screen";

private static final String GNOME_ROOT = System.getProperty("user.home") + "/.gconf/apps/panel/toplevels/";

private static final String KDE_CONFIG = System.getProperty("user.home") + "/.kde/share/config/kickerrc";

private static final String XFCE_CONFIG = System.getProperty("user.home") + "/.config/xfce4/mcs_settings/panel.xml";

private static final String OS_NAME = System.getProperty("os.name");

public static void main(String[] args) {

System.out.println("\n\nInsets:\n\t" + getInsets() + "\n\n");

}

public static Insets getInsets() {

switch (isCompatibleOS()) {

case 0: return getKDEInsets();

case 1: return getGnomeInsets();

case 2: return getXfceInsets();

case 3: return getDarwinInsets();

default: return getDefaultInsets();

}

}

/*

* Default insets if an error occured

*/

private static Insets getDefaultInsets() {

System.err.println("\nPlease see: http://www.google.com/search?q=gnome+kde+insets\n\n");

System.err.println("\nTrying default insets for " + OS_NAME);

try {

for (GraphicsDevice gs : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices())

for (GraphicsConfiguration gc : gs.getConfigurations())

return(Toolkit.getDefaultToolkit().getScreenInsets(gc));

}

catch (HeadlessException h) {

System.err.println("Error: Headless error (you aren't running a GUI)");

}

return new Insets(0,0,0,0);

}

/*

* Created for Mac OS 10.x.x

*/

private static Insets getDarwinInsets() {

return getDefaultInsets();

}

/*

* Created for Gnome 2.12.x.x

*/

private static Insets getGnomeInsets() {

File gnomeRoot = new File(GNOME_ROOT);

int n=0; int s=0; int e=0; int w=0;

for (File f : gnomeRoot.listFiles()) {

String folder = f.getName();

if (f.isDirectory() && folder.contains(GNOME_PANEL)) {

int val = getGnomeXML(new File(GNOME_ROOT + "/" + folder + "/" + GNOME_CONFIG));

if (val == -1)

; //Skip

else if (folder.startsWith("top" + GNOME_PANEL))

n = Math.max(val, n);

else if (folder.startsWith("bottom" + GNOME_PANEL))

s = Math.max(val, s);

else if (folder.startsWith("right" + GNOME_PANEL))

e = Math.max(val, e);

else if (folder.startsWith("left" + GNOME_PANEL))

w = Math.max(val, w);

}

}

return new Insets(n, w, s, e);

}

private static Insets getXfceInsets() {

return getDefaultInsets();

}

/*

* Created for KDE 3.5

*/

private static Insets getKDEInsets() {

/* KDE:2 Top|JAVA:0 Top

*0 Left1 Right|1 Left 3 Right

*3 Bottom|2 Bottom

*/

int[] sizes = {24, 30, 46, 58, 0};// xSmall, Small, Medium, Large, xLarge, Null

int[] i = {0, 0, 0, 0, 0}; // Left, Right, Top, Bottom, Null

/* Needs to be fixed. Doesn't know the difference between CustomSize and Size */

int customSiz = getKdeINI("General", "CustomSize");

int siz = getKdeINI("General", "Size");

int pos = getKdeINI("General", "Position");

int position = pos==-1?3:pos;

int size = (customSiz==-1||siz!=4)?siz:customSiz;

size = size<24?sizes[size]:size;

i[position]=size;

return new Insets(i[2],i[0],i[3],i[1]);

}

/*

* Determine if current Operating System is a *nix flavor

*/

private static int isCompatibleOS() {

if (!OS_NAME.toLowerCase().startsWith("windows")) {

try {

Process p = Runtime.getRuntime().exec("ps ax");

BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));

java.util.List<String> desktopList = Arrays.asList(DESKTOP_ENVIRONMENTS.split("\\|"));

String line = r.readLine();

while (line != null) {

for (String s : desktopList)

if (line.contains(s) && !line.contains("grep"))

return desktopList.indexOf(s);

line = r.readLine();

}

}

catch (Exception e) {

e.printStackTrace();

System.out.println("Error: IO Exception during Runtime exec");

}

}

return -1;

}

/*

* Parse XML file for some gnome sizes

*/

private static int getGnomeXML(File xmlFile) {

try {

boolean found = false;

FileReader reader = new FileReader(xmlFile);

BufferedReader buffer = new BufferedReader(reader);

String temp = buffer.readLine();

while (temp != null) {

if (temp.contains("<entry name=\"size\"")) {

found = true; break;

}

temp = buffer.readLine();

}

buffer.close();reader.close();

if (found) {

temp = temp.substring(temp.indexOf("value=\"") + 7);

return Integer.parseInt(temp.substring(0, temp.indexOf("\">")));

}

}

catch (Exception e) {}

return -1;

}

private static int getKdeINI(String category, String component) {

try {

File f = new File(KDE_CONFIG);

if (!f.exists() || category == null || component == null) return -1;

boolean found = false;

FileReader reader = new FileReader(f);

BufferedReader buffer = new BufferedReader(reader);

String value = null;

String temp = buffer.readLine();

while (temp != null) {

if (temp.trim().equals("[" + category + "]")) {

temp = buffer.readLine();

while (temp != null) {

if (temp.trim().startsWith("["))

return -1;

else if (temp.startsWith(component + "=")) {

value = temp.substring(component.length() + 1);

found = true;

break;

}

temp = buffer.readLine();

}

}

if (found == true) break;

temp = buffer.readLine();

}

buffer.close();reader.close();

if (found)

return Integer.parseInt(value);

}

catch (Exception e) {}

return -1;

}

}

FBLa at 2007-7-21 20:46:21 > top of Java-index,Desktop,Core GUI APIs...
# 30

Hi,

here is my own modification of the gnome's function:

private static Insets getGnomeInsets() {

int n=0; int s=0; int e=0; int w=0;

try {

// get the list of panels

Process p = Runtime.getRuntime().exec("gconftool --all-dirs /apps/panel/toplevels");

BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));

Process p2;

BufferedReader r2;

String line = r.readLine();

while (line != null) {

// get the orientation of the panel (top/bottom/left/right

p2 = Runtime.getRuntime().exec("gconftool -g "+line+"/orientation");

r2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));

String orientation = r2.readLine();

// get the auto_hide value to know witch size to get

p2 = Runtime.getRuntime().exec("gconftool -g "+line+"/auto_hide");

r2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));

String auto_hide = r2.readLine();

// get the right size

int theSize = 0;

if(auto_hide.toLowerCase().startsWith("true")) {

p2 = Runtime.getRuntime().exec("gconftool -g "+line+"/auto_hide_size");

r2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));

theSize = Integer.parseInt(r2.readLine());

}

else {

p2 = Runtime.getRuntime().exec("gconftool -g "+line+"/size");

r2 = new BufferedReader(new InputStreamReader(p2.getInputStream()));

theSize = Integer.parseInt(r2.readLine());

}

// affect the right size's value to the good variable (n, s, e, w)

if(orientation.toLowerCase().startsWith("top")) {

n += theSize;

}

else if(orientation.toLowerCase().startsWith("bottom")) {

s += theSize;

}

else if(orientation.toLowerCase().startsWith("left")) {

w += theSize;

}

else if(orientation.toLowerCase().startsWith("right")) {

e += theSize;

}

line = r.readLine();

}

}

catch (Exception ex) {

ex.printStackTrace();

System.out.println("Error: IO Exception during Runtime exec");

}

return new Insets(n, w, s, e);

}

this way, I can detect hidden panels and the orientation matches correctly (on my own conf, the bottom panel stands on the right but is always named bottom, so I had to find out how to get the right orientation...

Message was edited by:

povtux

povtuxa at 2007-7-21 20:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 31
This is great!The main difference is you rely on the runtime.exec function. Do you find more accurate results with this? Perhaps we should use your code instead!? :)-Tres
FBLa at 2007-7-21 20:46:26 > top of Java-index,Desktop,Core GUI APIs...