static void grid_arrange(struct velox_area * area, struct list_head * windows, struct velox_layout_state * generic_state) { /* For looping through the window list */ struct velox_window_entry * entry; /* Window counts */ uint16_t window_count = 0; uint16_t column_count; /* The current row count */ uint16_t row_count; /* Indices */ uint16_t index = 0; uint16_t column_index = 0; uint16_t row_index = 0; /* Areas */ struct velox_area column_area; struct velox_area window_area; DEBUG_ENTER if (list_empty(windows)) return; /* Calculate number of windows */ list_for_each_entry(entry, windows, head) ++window_count; /* FIXME: Is this the best column count to use? */ column_count = round(sqrt(window_count)); /* Arrange the windows */ entry = list_entry(windows->next, struct velox_window_entry, head); for (index = 0, column_index = 0; index < window_count; ++column_index) { velox_area_split_horizontally(area, column_count, column_index, &column_area); if (column_index >= window_count % column_count) row_count = window_count / column_count; else row_count = window_count / column_count + 1; for (row_index = 0; row_index < row_count; ++row_index, entry = list_entry(entry->head.next, struct velox_window_entry, head)) { velox_area_split_vertically(&column_area, row_count, row_index, &window_area); window_set_geometry(entry->window, &window_area); arrange_window(entry->window); ++index; } } }
/* Present the created window on the screen. */ void window_present(GtkWidget *win) { window_geometry_t geom; const gchar *name; /* present this window */ gtk_window_present(GTK_WINDOW(win)); /* do we have a previously saved size and position of this window? */ name = g_object_get_data(G_OBJECT(win), WINDOW_GEOM_KEY); if(name) { if(window_geom_load(name, &geom)) { /* XXX - use prefs to select which values to set? */ geom.set_pos = TRUE; geom.set_size = TRUE; geom.set_maximized = TRUE; window_set_geometry(win, &geom); } } }
/* Same as window_new(), but will keep it's geometry values (size, position, ...). * Be sure to use window_present() and window_destroy() appropriately! */ GtkWidget * window_new_with_geom(GtkWindowType type, const gchar *title, const gchar *geom_name) { window_geometry_t geom; GtkWidget *win = window_new(type, title); g_object_set_data(G_OBJECT(win), WINDOW_GEOM_KEY, (gpointer)g_strdup(geom_name)); /* do we have a previously saved size and position of this window? */ if(geom_name) { /* It's a good idea to set the position and size of the window already here, * as it's still invisible and won't "flicker the screen" while initially resizing. */ if(window_geom_load(geom_name, &geom)) { /* XXX - use prefs to select which values to set? */ geom.set_pos = TRUE; geom.set_size = TRUE; geom.set_maximized = FALSE; /* don't maximize until window is shown */ window_set_geometry(win, &geom); } } return win; }