}
}
+public class CloseOrBack : Gtk.StatusIcon
+{
+ public CloseOrBack()
+ {
+ activate += on_activate;
+ zavai.app.visibility_changed += on_visibility_changed;
+ update_icon();
+ }
+
+ private void on_visibility_changed(bool visible)
+ {
+ update_icon();
+ }
+
+ private void on_activate()
+ {
+ if (zavai.app.visibility)
+ {
+ // Back
+ zavai.app.back();
+ } else {
+ // Close current app
+ Gdk.Window w = zavai.app.get_screen().get_active_window();
+ if (w != zavai.app.window)
+ {
+ w.destroy();
+ }
+ }
+ }
+
+ protected void update_icon()
+ {
+ string name = zavai.config.icondir + "/";
+ if (!zavai.app.visibility)
+ name += "quit_on.png";
+ else
+ name += "quit_off.png";
+ set_from_file(name);
+ }
+}
+
+public class WindowList : Applet
+{
+ Wnck.Tasklist selector;
+
+ public WindowList(string label)
+ {
+ _label = label;
+ selector = new Wnck.Tasklist(Wnck.Screen.get_default());
+ pack_start(selector, true, true, 0);
+ }
+}
+
+public class LauncherButton : Gtk.Button
+{
+ private string exec;
+
+ public LauncherButton(string name, string exec)
+ {
+ label = name;
+ this.exec = exec;
+ clicked += on_clicked;
+ set_size_request(0, zavai.config.min_button_height);
+ }
+
+ public void on_clicked()
+ {
+ zavai.log.info("Run program: " + exec);
+ string[] args = exec.split(" ");
+ string[] args1 = new string[args.length + 1];
+ int cout = 0;
+ for (int cin = 0; cin < args.length; ++cin)
+ {
+ if (args[cin][0] == '%') continue;
+ args1[cout++] = args[cin];
+ }
+ args1[cout] = null;
+ Pid pid;
+ Process.spawn_async(
+ Environment.get_home_dir(),
+ args1,
+ null,
+ SpawnFlags.SEARCH_PATH,
+ null,
+ out pid);
+ }
+}
+
+public class Launcher: Applet
+{
+ static const string DENTRY_GROUP = "Desktop Entry";
+
+ public Launcher(string label)
+ {
+ _label = label;
+
+ var dir = File.new_for_path(zavai.config.homedir);
+ var enumerator = dir.enumerate_children(FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
+
+ FileInfo file_info;
+ var icon_theme = Gtk.IconTheme.get_default();
+ Gee.ArrayList<LauncherButton> buttons = new Gee.ArrayList<LauncherButton>();
+ while ((file_info = enumerator.next_file(null)) != null)
+ {
+ if (!file_info.get_name().has_suffix(".desktop")) continue;
+
+ string pathname = zavai.config.homedir + "/" + file_info.get_name();
+ //stdout.printf("Load %s\n", pathname);
+
+ string icon = null;
+ var kf = new KeyFile();
+ try {
+ kf.load_from_file(pathname, KeyFileFlags.NONE);
+ if (! kf.has_group(DENTRY_GROUP)) continue;
+ if (! kf.has_key(DENTRY_GROUP, "Name")) continue;
+ if (! kf.has_key(DENTRY_GROUP, "Exec")) continue;
+ if (kf.has_key(DENTRY_GROUP, "Icon"))
+ icon = kf.get_string(DENTRY_GROUP, "Icon");
+ } catch (Error e) {
+ zavai.log.error("Skipping file " + pathname + ": " + e.message);
+ continue;
+ }
+ var name = kf.get_string(DENTRY_GROUP, "Name");
+ var exec = kf.get_string(DENTRY_GROUP, "Exec");
+ var button = new LauncherButton(name, exec);
+ if (icon != null && icon_theme.has_icon(icon))
+ {
+ try {
+ var pb = icon_theme.load_icon(icon, zavai.config.min_button_height * 2 / 3, 0);
+ button.image = new Gtk.Image.from_pixbuf(pb);
+ } catch (Error e) {
+ zavai.log.error("Skipping icon " + icon + ": " + e.message);
+ }
+ }
+ buttons.add(button);
+ }
+
+ // Create the table with the launcher buttons
+ uint ROWMAX = 5; // Maximum number of rows
+ uint cols = 1 + (buttons.size + 1) / ROWMAX; // ceil(size/ROWMAX)
+ uint rows = (buttons.size + 1) / cols; // ceil(size/cols)
+ var table = new Gtk.Table(rows, cols, true);
+
+ // Attach the buttons in the table
+ uint row = 0;
+ uint col = 0;
+ foreach (LauncherButton b in buttons)
+ {
+ table.attach(b, col, col+1, row, row+1,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+ 0, 0);
+ ++col;
+ if (col == cols)
+ {
+ col = 0;
+ ++row;
+ }
+ }
+
+ pack_start(table, true, true, 0);
+
+/*
+ try {
+ } catch (Error e) {
+ stderr.printf ("Error: %s\n", e.message);
+ return 1;
+ }
+
+ for (string file in confdir)
+ {
+ }
+*/
+ }
+}
+
RaiseIcon raise_icon;
+CloseOrBack close_or_back;
+WindowList window_list;
+Launcher launcher;
public void init()
{
raise_icon = new RaiseIcon();
raise_icon.set_visible(true);
+
+ close_or_back = new CloseOrBack();
+ close_or_back.set_visible(true);
+
+ window_list = new WindowList("Current apps");
+ zavai.registry.register_applet("wm.list", window_list);
+ zavai.registry.getmenu("menu.main").add_applet("wm.list");
+
+ try {
+ launcher = new Launcher("Run program");
+ } catch (Error e) {
+ zavai.log.error("Not running launcher: " + e.message);
+ launcher = null;
+ }
+
+ if (launcher != null)
+ {
+ zavai.registry.register_applet("wm.launcher", launcher);
+ zavai.registry.getmenu("menu.main").add_applet("wm.launcher");
+ }
}
}