2 #define I3__FILE__ "workspace.c"
31 DLOG(
"Auto orientation. Workspace size set to (%d,%d), setting layout to %d.\n",
45 Con *output, *workspace = NULL;
50 if (workspace == NULL) {
51 LOG(
"Creating new workspace \"%s\"\n", num);
57 if (strcmp(assignment->
name, num) != 0)
60 LOG(
"Found workspace assignment to output \"%s\"\n", assignment->
output);
65 LOG(
"got output %p with content %p\n", output, content);
68 workspace =
con_new(NULL, NULL);
70 sasprintf(&name,
"[i3 con] workspace %s", num);
73 workspace->
type = CT_WORKSPACE;
80 long parsed_num = strtol(num, &endptr, 10);
81 if (parsed_num == LONG_MIN ||
82 parsed_num == LONG_MAX ||
86 else workspace->
num = parsed_num;
87 LOG(
"num = %d\n", workspace->
num);
89 workspace->
parent = content;
94 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"init\"}");
98 else if (created != NULL) {
117 ws->
type = CT_WORKSPACE;
123 if (strlen(bind->
command) < strlen(
"workspace ") ||
124 strncasecmp(bind->
command,
"workspace", strlen(
"workspace")) != 0)
127 char *target = bind->
command + strlen(
"workspace ");
128 while((*target ==
' ' || *target ==
'\t') && target !=
'\0')
135 if (strncasecmp(target,
"next", strlen(
"next")) == 0 ||
136 strncasecmp(target,
"prev", strlen(
"prev")) == 0 ||
137 strncasecmp(target,
"next_on_output", strlen(
"next_on_output")) == 0 ||
138 strncasecmp(target,
"prev_on_output", strlen(
"prev_on_output")) == 0 ||
139 strncasecmp(target,
"number", strlen(
"number")) == 0 ||
140 strncasecmp(target,
"back_and_forth", strlen(
"back_and_forth")) == 0 ||
141 strncasecmp(target,
"current", strlen(
"current")) == 0)
146 ws->
name = strdup(target);
147 if (ws->
name[strlen(ws->
name)-1] ==
'"')
148 ws->
name[strlen(ws->
name)-1] =
'\0';
149 DLOG(
"trying name *%s*\n", ws->
name);
154 bool assigned =
false;
157 if (strcmp(assignment->
name, ws->
name) != 0 ||
158 strcmp(assignment->
output, output->
name) == 0)
172 exists = (current != NULL);
177 long parsed_num = strtol(ws->
name, &endptr, 10);
178 if (parsed_num == LONG_MIN ||
179 parsed_num == LONG_MAX ||
183 else ws->
num = parsed_num;
184 LOG(
"Used number %d for workspace with name %s\n", ws->
num, ws->
name);
192 DLOG(
"Getting next unused workspace by number\n");
202 exists = (current != NULL);
204 DLOG(
"result for ws %d: exists = %d\n", c, exists);
234 LOG(
"workspace visible? fs = %p, ws = %p\n", fs, ws);
246 if (current != exclude &&
248 current->
window != NULL &&
257 TAILQ_FOREACH(current, &(con->floating_head), floating_windows) {
258 if (current != exclude &&
260 current->
window != NULL &&
290 LOG(
"Ah, this one is sticky: %s / %p\n", current->
name, current);
296 LOG(
"No window found for this sticky group\n");
309 LOG(
"re-assigned window from src %p to dest %p\n", src, current);
312 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
325 DLOG(
"Resetting urgency flag of con %p by timer\n", con);
336 Con *current, *old = NULL;
354 if (workspace == current) {
355 DLOG(
"Not switching, already there.\n");
375 DLOG(
"switching to %p / %s\n", workspace, workspace->
name);
394 DLOG(
"Deferring reset of urgency flag of con %p on newly shown workspace %p\n",
403 DLOG(
"Resetting urgency timer of con %p on workspace %p\n",
412 DLOG(
"old = %p / %s\n", old, (old ? old->
name :
"(null)"));
421 LOG(
"Closing old workspace (%p / %s), it is empty\n", old, old->
name);
423 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"empty\"}");
432 if (old_output != new_output) {
467 if (current->
num == -1) {
477 if (child->type != CT_WORKSPACE)
479 if (child->num == -1)
484 if (current->
num < child->num && (!next || child->
num < next->
num))
492 bool found_current =
false;
498 if (child->type != CT_WORKSPACE)
500 if (child == current) {
502 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
504 goto workspace_next_end;
517 if (child->type != CT_WORKSPACE)
519 if (!next || (child->num != -1 && child->num < next->
num))
537 if (current->
num == -1) {
539 prev =
TAILQ_PREV(current, nodes_head, nodes);
540 if (prev && prev->
num != -1)
549 if (child->type != CT_WORKSPACE || child->num == -1)
554 if (current->
num > child->num && (!prev || child->
num > prev->
num))
562 bool found_current =
false;
568 if (child->type != CT_WORKSPACE)
570 if (child == current) {
571 found_current =
true;
572 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
574 goto workspace_prev_end;
587 if (child->type != CT_WORKSPACE)
589 if (!prev || child->
num > prev->
num)
609 if (current->
num == -1) {
615 if (child->type != CT_WORKSPACE)
617 if (child->num == -1)
622 if (current->
num < child->num && (!next || child->
num < next->
num))
629 bool found_current =
false;
631 if (child->type != CT_WORKSPACE)
633 if (child == current) {
635 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
637 goto workspace_next_on_output_end;
645 if (child->type != CT_WORKSPACE)
647 if (!next || (child->num != -1 && child->num < next->
num))
651 workspace_next_on_output_end:
663 DLOG(
"output = %s\n", output->
name);
665 if (current->
num == -1) {
667 prev =
TAILQ_PREV(current, nodes_head, nodes);
668 if (prev && prev->
num != -1)
673 if (child->type != CT_WORKSPACE || child->num == -1)
678 if (current->
num > child->num && (!prev || child->
num > prev->
num))
685 bool found_current =
false;
687 if (child->type != CT_WORKSPACE)
689 if (child == current) {
690 found_current =
true;
691 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
693 goto workspace_prev_on_output_end;
701 if (child->type != CT_WORKSPACE)
703 if (!prev || child->
num > prev->
num)
708 workspace_prev_on_output_end:
718 DLOG(
"No previous workspace name set. Not switching.");
731 DLOG(
"no previous workspace name set.");
747 TAILQ_FOREACH(child, &(con->floating_head), floating_windows)
760 bool old_flag = ws->
urgent;
762 DLOG(
"Workspace urgency flag changed from %d to %d\n", old_flag, ws->
urgent);
764 if (old_flag != ws->
urgent)
765 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"urgent\"}");
784 DLOG(
"Moving cons\n");
796 DLOG(
"Attaching new split (%p) to ws (%p)\n", split, ws);
817 DLOG(
"Attaching a window to workspace %p / %s\n", ws, ws->
name);
820 DLOG(
"Default layout, just attaching it to the workspace itself.\n");
824 DLOG(
"Non-default layout, creating a new split container\n");
833 DLOG(
"Attaching new split %p to workspace %p\n",
new, ws);
847 ELOG(
"Workspace %p / %s has no children to encapsulate\n", ws, ws->
name);
855 DLOG(
"Moving children of workspace %p / %s into container %p\n",