-Workspace *workspace_get(int number) {
- if (number > (num_workspaces-1)) {
- int old_num_workspaces = num_workspaces;
-
- /* Convert all container->workspace and client->workspace
- * pointers to numbers representing their workspace. Necessary
- * because the realloc() may make all the pointers invalid, so
- * we need to preserve them this way and restore them later.
- *
- * To distinguish between the first workspace and a NULL
- * pointer, we store <workspace number> + 1. */
- for (int c = 0; c < num_workspaces; c++)
- FOR_TABLE(&(workspaces[c])) {
- Container *con = workspaces[c].table[cols][rows];
- if (con->workspace != NULL) {
- LOG("Handling con %p with pointer %p (num %d)\n", con, con->workspace, con->workspace->num);
- con->workspace = (Workspace*)(con->workspace->num + 1);
- }
- Client *current;
- SLIST_FOREACH(current, &(workspaces[c].focus_stack), focus_clients) {
- if (current->workspace == NULL)
- continue;
- LOG("Handling client %p with pointer %p (num %d)\n", current, current->workspace, current->workspace->num);
- current->workspace = (Workspace*)(current->workspace->num + 1);
- }
- }
-
- /* preserve c_ws */
- c_ws = (Workspace*)(c_ws->num);
-
- LOG("We need to initialize that one\n");
- num_workspaces = number+1;
- workspaces = realloc(workspaces, num_workspaces * sizeof(Workspace));
- /* Zero out the new workspaces so that we have sane default values */
- for (int c = old_num_workspaces; c < num_workspaces; c++)
- memset(&workspaces[c], 0, sizeof(Workspace));
-
- /* Immediately after the realloc(), we restore the pointers.
- * They may be used when initializing the new workspaces, for
- * example when the user configures containers to be stacking
- * by default, thus requiring re-rendering the layout. */
- c_ws = workspace_get((int)c_ws);
-
- for (int c = 0; c < old_num_workspaces; c++)
- FOR_TABLE(&(workspaces[c])) {
- Container *con = workspaces[c].table[cols][rows];
- if (con->workspace != NULL) {
- LOG("Handling con %p with (num %d)\n", con, con->workspace);
- con->workspace = workspace_get((int)con->workspace - 1);
- }
- Client *current;
- SLIST_FOREACH(current, &(workspaces[c].focus_stack), focus_clients) {
- if (current->workspace == NULL)
- continue;
- LOG("Handling client %p with (num %d)\n", current, current->workspace);
- current->workspace = workspace_get((int)current->workspace - 1);
- }
- }
-
- /* Initialize the new workspaces */
- for (int c = old_num_workspaces; c < num_workspaces; c++) {
- memset(&workspaces[c], 0, sizeof(Workspace));
- workspaces[c].num = c;
- TAILQ_INIT(&(workspaces[c].floating_clients));
- expand_table_cols(&(workspaces[c]));
- expand_table_rows(&(workspaces[c]));
- workspace_set_name(&(workspaces[c]), NULL);
- }
+Con *workspace_get(const char *num, bool *created) {
+ Con *output, *workspace = NULL, *child;
+
+ /* TODO: could that look like this in the future?
+ GET_MATCHING_NODE(workspace, croot, strcasecmp(current->name, num) != 0);
+ */
+ TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
+ TAILQ_FOREACH(child, &(output_get_content(output)->nodes_head), nodes) {
+ if (strcasecmp(child->name, num) != 0)
+ continue;
+
+ workspace = child;
+ break;
+ }