Archive for the ‘upstream’ Category

Turn your Java apps Gnome-Shell friendly
August 30, 2011

The Problem

When you try to add a java application as favorite into the Gnome Shell‘s lateral dock and run it you’ll end up having duplicated icons, one for the launcher and one for the running app. This happens b/c the shell uses an application based system for grouping tasks, so the idea is, if you add an application as a favorite launcher and you start it you’ll end having that launcher icon highlighted. Internally the shell matches the running process with the Exec clause of the .desktop file .
This works well except for applications running inside a VM or being interpreted b/c those will share the same running process. On that situation the shell inspects the WM_CLASS X Window property [1] and matches it with the full name of the desktop file. E.g. if your applications has the WM_CLASS set as “mySwingApp”, for this to successfully matched in the dock with its launcher, that launcher must be called mySwingApp.desktop located according XDG.

Note: for inspecting that value on any window you just need to run xprop WM_CLASS and click into the target window

Why is this happening?

Even if you are creating a swing application from scratch there is no easy way to tweak that X Window property using plain and portable APIs. Taking a look into openjdk sources, this is how them manages it

String mainClassName = null;

StackTraceElement trace[] = (new Throwable()).getStackTrace();
int bottom = trace.length - 1;
if (bottom >= 0) {
    mainClassName = trace[bottom].getClassName();
}
if (mainClassName == null || mainClassName.equals("")) {
    mainClassName = "AWT";
}
awtAppClassName = getCorrectXIDString(mainClassName);

As you may note what is used for this value is the name of the class running the Swing main loop.

Da solution

Digging around the web I founded a java agent and a pretty similar explanation on what’s going on.
So what I did was to fork that agent and improve it a little bit. What I did was to move it into a maven structure and remove its packaging as a fat-jar (I’m radically against fat-jars as you can see in my comments here).

The forked project is located in my github here:
https://github.com/diega/window-matching-agent
and please take a look to the README there

A practical example

My first motivation on doing this was based on IntelliJ IDEA so I’ll paste here my environment.

  • Download the agent-1.0.jar and put it wherever you want (I put it into IntelliJ’s bin/ folder)
  • Edit the file bin/idea.vmoptions adding this line

    -javaagent:agent-1.0.jar=intellij-ultimate

  • Create the file ~/.local/share/applications/intellij-ultimate.desktop with the following content

    [Desktop Entry]
    Version=10.5.1
    Name=IntelliJ IDEA Ultimate Edition
    Comment=The Most Intelligent Java IDE
    Categories=Applications;Development;
    Encoding=UTF-8
    Exec=env IDEA_CLASSPATH\=../lib/asm.jar /home/diego/bin/ideaIU-10.5/bin/idea.sh
    GenericName=IntelliJ
    Icon=/home/diego/bin/ideaIU-10.5/bin/idea128.png
    MimeType=text/x-java
    Terminal=false
    Type=Application
    URL=http://www.jetbrains.com/idea
    

Latest notes

If you download the agent-1.0.jar into another location (or with another name) you must adjust the -javaagent: parameter.
Of course, change the path in the Exec entry to point to your own executable.

Hope this helps somebody, it took me a while to figure out the-right-things-to-do™ :)


[1]: Application Based GNOME 3

Iniciandome con clutter y gnome-games
April 26, 2009

Como proyecto personal voy a intentar migrar a Clutter el juego gnobots2 utilizando el upstream de Clutter al menos hasta que salga la primer 1.0 estable.

Comienzo haciendo clone de todo gnome-games, clutter y clutter-gtk
$ git clone http://git.gnome.org/gnome-games
$ git clone git://git.clutter-project.org/clutter
$ git clone git://git.clutter-project.org/clutter-gtk

Compilo clutter y clutter-gtk.
Dentro de la carpeta gnome-games aplico el siguiente parche para que me deje funcionando clutter adentro de gnobots2 aplico estos dos pareches.

From 98601c7991dfed4b8a544133866070ffe11d7261 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Diego=20L=C3=B3pez=20Le=C3=B3n?=
Date: Sun, 26 Apr 2009 03:09:40 -0300
Subject: [PATCH] modified to use clutter 0.9

---
configure.in | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/configure.in b/configure.in
index 968405e..3329f08 100644
--- a/configure.in
+++ b/configure.in
@@ -562,8 +562,8 @@ fi
if test "$enable_clutter" = "yes"; then
CLUTTER_API_VERSION=
AC_MSG_CHECKING([for clutter API version])
- for API_VERSION in 0.8; do
- PKG_CHECK_EXISTS([clutter-$API_VERSION clutter-cairo-$API_VERSION],
+ for API_VERSION in 0.9; do
+ PKG_CHECK_EXISTS([clutter-$API_VERSION],
[CLUTTER_API_VERSION=$API_VERSION; break],[])
done
if test -z "$CLUTTER_API_VERSION"; then
@@ -571,13 +571,11 @@ if test "$enable_clutter" = "yes"; then
fi
AC_MSG_RESULT([$CLUTTER_API_VERSION])

- CLUTTER_REQUIRED=0.8.8
- CLUTTER_GTK_REQUIRED=0.8.3
- CLUTTER_CAIRO_REQUIRED=0.8.2
+ CLUTTER_REQUIRED=0.9.3
+ CLUTTER_GTK_REQUIRED=0.9.0

PKG_CHECK_MODULES([CLUTTER],[
- clutter-$CLUTTER_API_VERSION >= $CLUTTER_REQUIRED
- clutter-cairo-$CLUTTER_API_VERSION >= $CLUTTER_CAIRO_REQUIRED])
+ clutter-$CLUTTER_API_VERSION >= $CLUTTER_REQUIRED])
AC_SUBST([CLUTTER_CFLAGS])
AC_SUBST([CLUTTER_LIBS])

--
1.6.2.4

y luego

From 7517b3108fd3dce3bfb03b272c13115d0025db08 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Diego=20L=C3=B3pez=20Le=C3=B3n?=
Date: Sun, 26 Apr 2009 05:03:08 -0300
Subject: [PATCH] add clutter as dependency for gnobots2

---
gnobots2/Makefile.am | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/gnobots2/Makefile.am b/gnobots2/Makefile.am
index 377ad20..0924855 100644
--- a/gnobots2/Makefile.am
+++ b/gnobots2/Makefile.am
@@ -59,6 +59,12 @@ gnobots2_CFLAGS += $(GHTREAD_CFLAGS)
gnobots2_LDADD += $(GTHREAD_LIBS)
endif

+if HAVE_CLUTTER
+gnobots2_CFLAGS += $(CLUTTER_CFLAGS) $(CLUTTER_GTK_CFLAGS)
+gnobots2_LDADD += $(CLUTTER_LIBS) $(CLUTTER_GTK_LIBS)
+endif
+
+
pixmapdir = $(pkgdatadir)/gnobots2/pixmaps
pixmap_DATA = gnomes.png \
yahoo.png \
--
1.6.2.4

Esto nos va a dar la posibilidad de habilitar clutter en el desarrollo de gnobots2.
Antes de trabajar hay que decirle a dónde buscar los .pc de clutter que acabamos de compilar. En mi caso sería:
$ export PKG_CONFIG_PATH=~/dev-new/c/clutter-upstream/dist/lib/pkgconfig:~/dev-new/c/clutter-gtk-upstream/dist/lib/pkgconfig
Ahora corremos el autogen.sh, con el fin que yo persigo sería:
$ ./autogen.sh –prefix=`pwd`/dist –enable-games=gnobots2 –enable-clutter
$ make && make install
esto nos dejaría listo en dist/bin/gnobots2 el ejecutable y ya en el código podemos agregar nuestras amigas líneas de uso de clutter

Más info de clutter, leer este tutorial.
En la próxima espero ya postear avances concretos sobre el juego