2 #define I3__FILE__ "workspace.c"
16 #include <yajl/yajl_gen.h>
34 DLOG(
"Auto orientation. Workspace size set to (%d,%d), setting layout to %d.\n",
48 Con *output, *workspace = NULL;
53 if (workspace == NULL) {
54 LOG(
"Creating new workspace \"%s\"\n", num);
60 if (strcmp(assignment->
name, num) != 0)
63 LOG(
"Found workspace assignment to output \"%s\"\n", assignment->
output);
68 LOG(
"got output %p with content %p\n", output, content);
71 workspace =
con_new(NULL, NULL);
73 sasprintf(&name,
"[i3 con] workspace %s", num);
76 workspace->
type = CT_WORKSPACE;
83 long parsed_num = strtol(num, &endptr, 10);
84 if (parsed_num == LONG_MIN ||
85 parsed_num == LONG_MAX ||
89 else workspace->
num = parsed_num;
90 LOG(
"num = %d\n", workspace->
num);
92 workspace->
parent = content;
97 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"init\"}");
101 else if (created != NULL) {
120 ws->
type = CT_WORKSPACE;
126 if (strlen(bind->
command) < strlen(
"workspace ") ||
127 strncasecmp(bind->
command,
"workspace", strlen(
"workspace")) != 0)
130 char *target = bind->
command + strlen(
"workspace ");
131 while((*target ==
' ' || *target ==
'\t') && target !=
'\0')
138 if (strncasecmp(target,
"next", strlen(
"next")) == 0 ||
139 strncasecmp(target,
"prev", strlen(
"prev")) == 0 ||
140 strncasecmp(target,
"next_on_output", strlen(
"next_on_output")) == 0 ||
141 strncasecmp(target,
"prev_on_output", strlen(
"prev_on_output")) == 0 ||
142 strncasecmp(target,
"number", strlen(
"number")) == 0 ||
143 strncasecmp(target,
"back_and_forth", strlen(
"back_and_forth")) == 0 ||
144 strncasecmp(target,
"current", strlen(
"current")) == 0)
149 ws->
name = strdup(target);
150 if (ws->
name[strlen(ws->
name)-1] ==
'"')
151 ws->
name[strlen(ws->
name)-1] =
'\0';
152 DLOG(
"trying name *%s*\n", ws->
name);
157 bool assigned =
false;
160 if (strcmp(assignment->
name, ws->
name) != 0 ||
161 strcmp(assignment->
output, output->
name) == 0)
175 exists = (current != NULL);
180 long parsed_num = strtol(ws->
name, &endptr, 10);
181 if (parsed_num == LONG_MIN ||
182 parsed_num == LONG_MAX ||
186 else ws->
num = parsed_num;
187 LOG(
"Used number %d for workspace with name %s\n", ws->
num, ws->
name);
195 DLOG(
"Getting next unused workspace by number\n");
206 exists = (current != NULL);
208 DLOG(
"result for ws %s / %d: exists = %d\n", ws->
name, c, exists);
238 LOG(
"workspace visible? fs = %p, ws = %p\n", fs, ws);
250 if (current != exclude &&
252 current->
window != NULL &&
261 TAILQ_FOREACH(current, &(con->floating_head), floating_windows) {
262 if (current != exclude &&
264 current->
window != NULL &&
294 LOG(
"Ah, this one is sticky: %s / %p\n", current->
name, current);
300 LOG(
"No window found for this sticky group\n");
313 LOG(
"re-assigned window from src %p to dest %p\n", src, current);
316 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
329 DLOG(
"Resetting urgency flag of con %p by timer\n", con);
344 setlocale(LC_NUMERIC,
"C");
363 const unsigned char *payload;
365 y(get_buf, &payload, &length);
367 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE, (
const char *)payload);
369 setlocale(LC_NUMERIC,
"");
373 Con *current, *old = NULL;
391 if (workspace == current) {
392 DLOG(
"Not switching, already there.\n");
412 DLOG(
"switching to %p / %s\n", workspace, workspace->
name);
431 DLOG(
"Deferring reset of urgency flag of con %p on newly shown workspace %p\n",
440 DLOG(
"Resetting urgency timer of con %p on workspace %p\n",
449 DLOG(
"old = %p / %s\n", old, (old ? old->
name :
"(null)"));
458 LOG(
"Closing old workspace (%p / %s), it is empty\n", old, old->
name);
460 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"empty\"}");
469 if (old_output != new_output) {
504 if (current->
num == -1) {
514 if (child->type != CT_WORKSPACE)
516 if (child->num == -1)
521 if (current->
num < child->num && (!next || child->
num < next->
num))
529 bool found_current =
false;
535 if (child->type != CT_WORKSPACE)
537 if (child == current) {
539 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
541 goto workspace_next_end;
554 if (child->type != CT_WORKSPACE)
556 if (!next || (child->num != -1 && child->num < next->
num))
574 if (current->
num == -1) {
576 prev =
TAILQ_PREV(current, nodes_head, nodes);
577 if (prev && prev->
num != -1)
586 if (child->type != CT_WORKSPACE || child->num == -1)
591 if (current->
num > child->num && (!prev || child->
num > prev->
num))
599 bool found_current =
false;
605 if (child->type != CT_WORKSPACE)
607 if (child == current) {
608 found_current =
true;
609 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
611 goto workspace_prev_end;
624 if (child->type != CT_WORKSPACE)
626 if (!prev || child->
num > prev->
num)
646 if (current->
num == -1) {
652 if (child->type != CT_WORKSPACE)
654 if (child->num == -1)
659 if (current->
num < child->num && (!next || child->
num < next->
num))
666 bool found_current =
false;
668 if (child->type != CT_WORKSPACE)
670 if (child == current) {
672 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
674 goto workspace_next_on_output_end;
682 if (child->type != CT_WORKSPACE)
684 if (!next || (child->num != -1 && child->num < next->
num))
688 workspace_next_on_output_end:
700 DLOG(
"output = %s\n", output->
name);
702 if (current->
num == -1) {
704 prev =
TAILQ_PREV(current, nodes_head, nodes);
705 if (prev && prev->
num != -1)
710 if (child->type != CT_WORKSPACE || child->num == -1)
715 if (current->
num > child->num && (!prev || child->
num > prev->
num))
722 bool found_current =
false;
724 if (child->type != CT_WORKSPACE)
726 if (child == current) {
727 found_current =
true;
728 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
730 goto workspace_prev_on_output_end;
738 if (child->type != CT_WORKSPACE)
740 if (!prev || child->
num > prev->
num)
745 workspace_prev_on_output_end:
755 DLOG(
"No previous workspace name set. Not switching.");
768 DLOG(
"no previous workspace name set.");
784 TAILQ_FOREACH(child, &(con->floating_head), floating_windows)
797 bool old_flag = ws->
urgent;
799 DLOG(
"Workspace urgency flag changed from %d to %d\n", old_flag, ws->
urgent);
801 if (old_flag != ws->
urgent)
802 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"urgent\"}");
821 DLOG(
"Moving cons\n");
833 DLOG(
"Attaching new split (%p) to ws (%p)\n", split, ws);
854 DLOG(
"Attaching a window to workspace %p / %s\n", ws, ws->
name);
857 DLOG(
"Default layout, just attaching it to the workspace itself.\n");
861 DLOG(
"Non-default layout, creating a new split container\n");
870 DLOG(
"Attaching new split %p to workspace %p\n",
new, ws);
884 ELOG(
"Workspace %p / %s has no children to encapsulate\n", ws, ws->
name);
892 DLOG(
"Moving children of workspace %p / %s into container %p\n",