*/
Con *get_existing_workspace_by_name(const char *name);
+/**
+ * Returns the workspace with the given number or NULL if such a workspace does
+ * not exist.
+ *
+ */
+Con *get_existing_workspace_by_num(int num);
+
/**
* Returns a pointer to the workspace with the given number (starting at 0),
* creating the workspace if necessary (by allocating the necessary amount of
}
LOG("should move window to workspace %s\n", which);
- /* get the workspace */
- Con *output, *ws = NULL;
long parsed_num = ws_name_to_number(which);
-
if (parsed_num == -1) {
LOG("Could not parse initial part of \"%s\" as a number.\n", which);
yerror("Could not parse number \"%s\"", which);
return;
}
- TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
- GREP_FIRST(ws, output_get_content(output),
- child->num == parsed_num);
-
+ Con *ws = get_existing_workspace_by_num(parsed_num);
if (!ws) {
ws = workspace_get(which, NULL);
}
*/
void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
- Con *output, *workspace = NULL;
if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
LOG("Cannot switch workspace while in global fullscreen\n");
}
long parsed_num = ws_name_to_number(which);
-
if (parsed_num == -1) {
LOG("Could not parse initial part of \"%s\" as a number.\n", which);
yerror("Could not parse number \"%s\"", which);
return;
}
- TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
- GREP_FIRST(workspace, output_get_content(output),
- child->num == parsed_num);
-
+ Con *workspace = get_existing_workspace_by_num(parsed_num);
if (!workspace) {
LOG("There is no workspace with number %ld, creating a new one.\n", parsed_num);
ysuccess(true);
Con *assigned_ws = NULL;
if (assignment->type == A_TO_WORKSPACE_NUMBER) {
- Con *output = NULL;
long parsed_num = ws_name_to_number(assignment->dest.workspace);
- /* This will only work for workspaces that already exist. */
- TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
- GREP_FIRST(assigned_ws, output_get_content(output), child->num == parsed_num);
- }
+ assigned_ws = get_existing_workspace_by_num(parsed_num);
}
/* A_TO_WORKSPACE type assignment or fallback from A_TO_WORKSPACE_NUMBER
* when the target workspace number does not exist yet. */
return workspace;
}
+/*
+ * Returns the workspace with the given number or NULL if such a workspace does
+ * not exist.
+ *
+ */
+Con *get_existing_workspace_by_num(int num) {
+ Con *output, *workspace = NULL;
+ TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
+ GREP_FIRST(workspace, output_get_content(output), child->num == num);
+ }
+
+ return workspace;
+}
+
/*
* Sets ws->layout to splith/splitv if default_orientation was specified in the
* configfile. Otherwise, it uses splith/splitv depending on whether the output
DLOG("Getting next unused workspace by number\n");
int c = 0;
while (exists) {
- c++;
-
- ws->num = c;
-
- Con *out, *current = NULL;
- TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
- GREP_FIRST(current, output_get_content(out), child->num == ws->num);
- exists = (current != NULL);
-
+ exists = (get_existing_workspace_by_num(++c) != NULL);
DLOG("result for ws %d: exists = %d\n", c, exists);
}
+ ws->num = c;
sasprintf(&(ws->name), "%d", c);
}
con_attach(ws, content, false);