Lay out launcher in a grid
authorEnrico Zini <enrico@enricozini.org>
Fri, 7 Aug 2009 11:00:48 +0000 (12:00 +0100)
committerEnrico Zini <enrico@enricozini.org>
Fri, 7 Aug 2009 11:00:48 +0000 (12:00 +0100)
src/app_wm.vala

index 68cb28c08411f76358bba362e5d60aea1b4ba9d8..833a4e541679608947d8634e1ffa0daf9223d86e 100644 (file)
@@ -181,6 +181,7 @@ 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;
@@ -213,9 +214,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) {