Kill button as back button when on zavai
[gregoa/zavai.git] / src / app_wm.vala
index 2b5dc5aac0cca9d71ace6a311f1f1df7d890adde..6882e6567e319258d99c779b314a6bc9386ee282 100644 (file)
@@ -100,6 +100,7 @@ public class CloseOrBack : Gtk.StatusIcon
                if (zavai.app.visibility)
                {
                        // Back
+                       zavai.app.back();
                } else {
                        // Close current app
                        Gdk.Window w = zavai.app.get_screen().get_active_window();
@@ -148,11 +149,19 @@ public class LauncherButton : Gtk.Button
        public void on_clicked()
        {
                zavai.log.info("Run program: " + exec);
-               string[] args = new string[] { exec, null };
+               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(),
-                       args,
+                       args1,
                        null,
                        SpawnFlags.SEARCH_PATH,
                        null,
@@ -173,8 +182,11 @@ public class Launcher: Applet
 
                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);
 
@@ -203,9 +215,34 @@ public class Launcher: Applet
                                        zavai.log.error("Skipping icon " + icon + ": " + e.message);
                                }
                        }
-                       pack_start(button, false, false, 0);
+                       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) {