24 Con *output, *workspace = NULL;
29 if (workspace == NULL) {
30 LOG(
"Creating new workspace \"%s\"\n", num);
36 if (strcmp(assignment->
name, num) != 0)
39 LOG(
"Found workspace assignment to output \"%s\"\n", assignment->
output);
44 LOG(
"got output %p with content %p\n", output, content);
47 workspace =
con_new(NULL, NULL);
49 sasprintf(&name,
"[i3 con] workspace %s", num);
52 workspace->
type = CT_WORKSPACE;
58 long parsed_num = strtol(num, &endptr, 10);
59 if (parsed_num == LONG_MIN ||
60 parsed_num == LONG_MAX ||
64 else workspace->
num = parsed_num;
65 LOG(
"num = %d\n", workspace->
num);
72 DLOG(
"Auto orientation. Output resolution set to (%d,%d), setting orientation to %d.\n",
80 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"init\"}");
84 else if (created != NULL) {
103 ws->
type = CT_WORKSPACE;
109 if (strlen(bind->
command) < strlen(
"workspace ") ||
110 strncasecmp(bind->
command,
"workspace", strlen(
"workspace")) != 0)
113 char *target = bind->
command + strlen(
"workspace ");
119 if (strncasecmp(target,
"next", strlen(
"next")) == 0 ||
120 strncasecmp(target,
"prev", strlen(
"prev")) == 0 ||
121 strncasecmp(target,
"next_on_output", strlen(
"next_on_output")) == 0 ||
122 strncasecmp(target,
"prev_on_output", strlen(
"prev_on_output")) == 0 ||
123 strncasecmp(target,
"back_and_forth", strlen(
"back_and_forth")) == 0)
128 ws->
name = strdup(target);
129 if (ws->
name[strlen(ws->
name)-1] ==
'"')
130 ws->
name[strlen(ws->
name)-1] =
'\0';
131 DLOG(
"trying name *%s*\n", ws->
name);
136 bool assigned =
false;
139 if (strcmp(assignment->
name, ws->
name) != 0 ||
140 strcmp(assignment->
output, output->
name) == 0)
154 exists = (current != NULL);
159 long parsed_num = strtol(ws->
name, &endptr, 10);
160 if (parsed_num == LONG_MIN ||
161 parsed_num == LONG_MAX ||
165 else ws->
num = parsed_num;
166 LOG(
"Used number %d for workspace with name %s\n", ws->
num, ws->
name);
174 DLOG(
"Getting next unused workspace by number\n");
185 exists = (current != NULL);
187 DLOG(
"result for ws %s / %d: exists = %d\n", ws->
name, c, exists);
203 DLOG(
"Auto orientation. Workspace size set to (%d,%d), setting orientation to %d.\n",
223 LOG(
"workspace visible? fs = %p, ws = %p\n", fs, ws);
235 if (current != exclude &&
237 current->
window != NULL &&
246 TAILQ_FOREACH(current, &(con->floating_head), floating_windows) {
247 if (current != exclude &&
249 current->
window != NULL &&
279 LOG(
"Ah, this one is sticky: %s / %p\n", current->
name, current);
285 LOG(
"No window found for this sticky group\n");
298 LOG(
"re-assigned window from src %p to dest %p\n", src, current);
301 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
307 Con *current, *old = NULL;
310 if (workspace->
name[0] ==
'_' && workspace->
name[1] ==
'_')
325 if (workspace == current) {
326 DLOG(
"Not switching, already there.\n");
341 LOG(
"switching to %p\n", workspace);
347 LOG(
"Closing old workspace (%p / %s), it is empty\n", old, old->
name);
349 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"empty\"}");
350 changed_num_workspaces =
true;
363 if (old_output != new_output) {
370 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"focus\"}");
387 bool changed_num_workspaces;
401 if (current->
num == -1) {
408 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
411 if (child->type != CT_WORKSPACE)
413 if (child->num == -1)
418 if (current->
num < child->num && (!next || child->
num < next->
num))
426 bool found_current =
false;
429 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
432 if (child->type != CT_WORKSPACE)
434 if (child == current) {
436 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
438 goto workspace_next_end;
448 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
451 if (child->type != CT_WORKSPACE)
453 if (!next || (child->num != -1 && child->num < next->
num))
471 if (current->
num == -1) {
473 prev =
TAILQ_PREV(current, nodes_head, nodes);
474 if (prev && prev->
num != -1)
480 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
483 if (child->type != CT_WORKSPACE || child->num == -1)
488 if (current->
num > child->num && (!prev || child->
num > prev->
num))
496 bool found_current =
false;
499 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
502 if (child->type != CT_WORKSPACE)
504 if (child == current) {
505 found_current =
true;
506 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
508 goto workspace_prev_end;
518 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
521 if (child->type != CT_WORKSPACE)
523 if (!prev || child->
num > prev->
num)
543 if (current->
num == -1) {
549 if (child->type != CT_WORKSPACE)
551 if (child->num == -1)
556 if (current->
num < child->num && (!next || child->
num < next->
num))
563 bool found_current =
false;
565 if (child->type != CT_WORKSPACE)
567 if (child == current) {
569 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
571 goto workspace_next_on_output_end;
579 if (child->type != CT_WORKSPACE)
581 if (!next || (child->num != -1 && child->num < next->
num))
585 workspace_next_on_output_end:
597 DLOG(
"output = %s\n", output->
name);
599 if (current->
num == -1) {
601 prev =
TAILQ_PREV(current, nodes_head, nodes);
602 if (prev && prev->
num != -1)
607 if (child->type != CT_WORKSPACE || child->num == -1)
612 if (current->
num > child->num && (!prev || child->
num > prev->
num))
619 bool found_current =
false;
621 if (child->type != CT_WORKSPACE)
623 if (child == current) {
624 found_current =
true;
625 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
627 goto workspace_prev_on_output_end;
635 if (child->type != CT_WORKSPACE)
637 if (!prev || child->
num > prev->
num)
642 workspace_prev_on_output_end:
652 DLOG(
"No previous workspace name set. Not switching.");
665 TAILQ_FOREACH(child, &(con->floating_head), floating_windows)
678 bool old_flag = ws->
urgent;
680 DLOG(
"Workspace urgency flag changed from %d to %d\n", old_flag, ws->
urgent);
682 if (old_flag != ws->
urgent)
683 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"urgent\"}");
704 DLOG(
"Moving cons\n");
715 DLOG(
"Attaching new split to ws\n");
736 DLOG(
"Attaching a window to workspace %p / %s\n", ws, ws->
name);
739 DLOG(
"Default layout, just attaching it to the workspace itself.\n");
743 DLOG(
"Non-default layout, creating a new split container\n");
761 DLOG(
"Attaching new split %p to workspace %p\n",
new, ws);