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 ");
133 if (strncasecmp(target,
"next", strlen(
"next")) == 0 ||
134 strncasecmp(target,
"prev", strlen(
"prev")) == 0 ||
135 strncasecmp(target,
"next_on_output", strlen(
"next_on_output")) == 0 ||
136 strncasecmp(target,
"prev_on_output", strlen(
"prev_on_output")) == 0 ||
137 strncasecmp(target,
"number", strlen(
"number")) == 0 ||
138 strncasecmp(target,
"back_and_forth", strlen(
"back_and_forth")) == 0 ||
139 strncasecmp(target,
"current", strlen(
"current")) == 0)
144 ws->
name = strdup(target);
145 if (ws->
name[strlen(ws->
name)-1] ==
'"')
146 ws->
name[strlen(ws->
name)-1] =
'\0';
147 DLOG(
"trying name *%s*\n", ws->
name);
152 bool assigned =
false;
155 if (strcmp(assignment->
name, ws->
name) != 0 ||
156 strcmp(assignment->
output, output->
name) == 0)
170 exists = (current != NULL);
175 long parsed_num = strtol(ws->
name, &endptr, 10);
176 if (parsed_num == LONG_MIN ||
177 parsed_num == LONG_MAX ||
181 else ws->
num = parsed_num;
182 LOG(
"Used number %d for workspace with name %s\n", ws->
num, ws->
name);
190 DLOG(
"Getting next unused workspace by number\n");
201 exists = (current != NULL);
203 DLOG(
"result for ws %s / %d: exists = %d\n", ws->
name, c, exists);
232 LOG(
"workspace visible? fs = %p, ws = %p\n", fs, ws);
244 if (current != exclude &&
246 current->
window != NULL &&
255 TAILQ_FOREACH(current, &(con->floating_head), floating_windows) {
256 if (current != exclude &&
258 current->
window != NULL &&
288 LOG(
"Ah, this one is sticky: %s / %p\n", current->
name, current);
294 LOG(
"No window found for this sticky group\n");
307 LOG(
"re-assigned window from src %p to dest %p\n", src, current);
310 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
316 Con *current, *old = NULL;
319 if (workspace->
name[0] ==
'_' && workspace->
name[1] ==
'_')
334 if (workspace == current) {
335 DLOG(
"Not switching, already there.\n");
350 LOG(
"switching to %p\n", workspace);
356 LOG(
"Closing old workspace (%p / %s), it is empty\n", old, old->
name);
358 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"empty\"}");
371 if (old_output != new_output) {
378 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"focus\"}");
395 bool changed_num_workspaces;
409 if (current->
num == -1) {
416 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
419 if (child->type != CT_WORKSPACE)
421 if (child->num == -1)
426 if (current->
num < child->num && (!next || child->
num < next->
num))
434 bool found_current =
false;
437 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
440 if (child->type != CT_WORKSPACE)
442 if (child == current) {
444 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
446 goto workspace_next_end;
456 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
459 if (child->type != CT_WORKSPACE)
461 if (!next || (child->num != -1 && child->num < next->
num))
479 if (current->
num == -1) {
481 prev =
TAILQ_PREV(current, nodes_head, nodes);
482 if (prev && prev->
num != -1)
488 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
491 if (child->type != CT_WORKSPACE || child->num == -1)
496 if (current->
num > child->num && (!prev || child->
num > prev->
num))
504 bool found_current =
false;
507 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
510 if (child->type != CT_WORKSPACE)
512 if (child == current) {
513 found_current =
true;
514 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
516 goto workspace_prev_end;
526 if (output->
name[0] ==
'_' && output->
name[1] ==
'_')
529 if (child->type != CT_WORKSPACE)
531 if (!prev || child->
num > prev->
num)
551 if (current->
num == -1) {
557 if (child->type != CT_WORKSPACE)
559 if (child->num == -1)
564 if (current->
num < child->num && (!next || child->
num < next->
num))
571 bool found_current =
false;
573 if (child->type != CT_WORKSPACE)
575 if (child == current) {
577 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
579 goto workspace_next_on_output_end;
587 if (child->type != CT_WORKSPACE)
589 if (!next || (child->num != -1 && child->num < next->
num))
593 workspace_next_on_output_end:
605 DLOG(
"output = %s\n", output->
name);
607 if (current->
num == -1) {
609 prev =
TAILQ_PREV(current, nodes_head, nodes);
610 if (prev && prev->
num != -1)
615 if (child->type != CT_WORKSPACE || child->num == -1)
620 if (current->
num > child->num && (!prev || child->
num > prev->
num))
627 bool found_current =
false;
629 if (child->type != CT_WORKSPACE)
631 if (child == current) {
632 found_current =
true;
633 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
635 goto workspace_prev_on_output_end;
643 if (child->type != CT_WORKSPACE)
645 if (!prev || child->
num > prev->
num)
650 workspace_prev_on_output_end:
660 DLOG(
"No previous workspace name set. Not switching.");
673 TAILQ_FOREACH(child, &(con->floating_head), floating_windows)
686 bool old_flag = ws->
urgent;
688 DLOG(
"Workspace urgency flag changed from %d to %d\n", old_flag, ws->
urgent);
690 if (old_flag != ws->
urgent)
691 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"urgent\"}");
711 DLOG(
"Moving cons\n");
719 ws->
layout = (orientation ==
HORIZ) ? L_SPLITH : L_SPLITV;
723 DLOG(
"Attaching new split (%p) to ws (%p)\n", split, ws);
744 DLOG(
"Attaching a window to workspace %p / %s\n", ws, ws->
name);
747 DLOG(
"Default layout, just attaching it to the workspace itself.\n");
751 DLOG(
"Non-default layout, creating a new split container\n");
761 DLOG(
"Attaching new split %p to workspace %p\n",
new, ws);