Detecting the Cinnamon Desktop using a D-Bus property and Vala 
Saturday, March 16, 2013, 11:45 AM
Gnome-Shell and Cinnamon behave differently, which includes how tray notification icons are being treated. While Cinnamon uses the classic approach of showing them, the Gnome-Shell developers would like to see them avoided.

Therefore it's currently the application's job to figure out what to do. Unfortunately Gnome-Shell and Cinnamon have many similar properties from an application's point of view, so it's necessary to find a way to distinguish them from within the code.

Thanks to Bastien Nocera and Shaun McCance for suggesting the use of D-Bus to distinguish between Gnome-Shell and Cinnamon.

As I was driven to fix the deja-dup backup tool, I was looking for a solution in the Vala programming language, and below is some code to detect a running Cinnamon desktop environment. I tested that the code works in Cinnamon version 1.4.0 and 1.6.7.

[DBus (name = "org.Cinnamon")]

public interface cinna : GLib.Object {
public abstract string CinnamonVersion { owned get; }
}

int main (string[] args) {
string cv;

try {
cinna c = GLib.Bus.get_proxy_sync (BusType.SESSION, "org.Cinnamon", "/org/Cinnamon");
cv = c.CinnamonVersion;
} catch (Error e) {
stderr.printf ("%s\n", e.message);
return 1;
}

if (cv == null) {
stdout.printf ("not running cinnamon\n");
}
else {
stdout.printf ("running cinnamon version %s\n", cv);
}

return 0;
}


I'd like to thank Evan Nemerson who helped me understand the correct syntax to access a D-Bus property using Vala.

Update March 18
Below is a reverse test, which tests for a property found in Gnome-Shell:

[DBus (name = "org.gnome.Shell")]
public interface GnomeShell : GLib.Object {
public abstract string ShellVersion { owned get; }
}

int main (string[] args) {
string gsv = null;

try {
GnomeShell gs = GLib.Bus.get_proxy_sync (BusType.SESSION, "org.gnome.Shell", "/org/gnome/Shell");
gsv = gs.ShellVersion;
} catch (Error e) {
stderr.printf ("%s\n", e.message);
return 1;
}

if (gsv == null) {
stdout.printf ("not running gnome-shell\n");
}
else {
stdout.printf ("running gnome-shell version %s\n", gsv);
}

return 0;
}


Comments

Add Comment
Comments are not available for this entry.