diff --git a/include/container.h b/include/container.h index 2ced248b3..6f1fcdec9 100644 --- a/include/container.h +++ b/include/container.h @@ -30,6 +30,9 @@ enum swayc_layouts{ struct sway_container { wlc_handle handle; + // Internal container, e.g. scratchpad + bool internal; + enum swayc_types type; enum swayc_layouts layout; diff --git a/sway/layout.c b/sway/layout.c index 48af3bf53..5b1fa9743 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -14,15 +14,26 @@ swayc_t root_container; int min_sane_h = 60; int min_sane_w = 100; +static swayc_t null_output; static swayc_t *scratchpad = NULL; void init_layout(void) { root_container.type = C_ROOT; root_container.layout = L_NONE; + null_output.name = "root"; root_container.children = create_list(); root_container.handle = -1; - scratchpad = new_workspace(&root_container, "__i3_scratch"); + null_output.type = C_OUTPUT; + null_output.layout = L_NONE; + null_output.name = "__i3"; + null_output.children = create_list(); + null_output.handle = -1; + null_output.internal = true; + add_child(&root_container, &null_output); + + scratchpad = new_workspace(&null_output, "__i3_scratch"); + scratchpad->internal = true; } static int index_child(swayc_t *parent, swayc_t *child) { diff --git a/sway/workspace.c b/sway/workspace.c index 80b67128d..a7b9a7eda 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -113,20 +113,17 @@ void workspace_next() { return; } } - if (root_container.children->length > 1) { - for (i = 0; i < root_container.children->length - 1; i++) { - if (root_container.children->items[i] == current_output) { - workspace_switch(((swayc_t *)root_container.children->items[i + 1])->focused); - workspace_output_next(); - return; + + for (i = 0; i < root_container.children->length; i++) { + if (root_container.children->items[i] == current_output) { + swayc_t *next_output = root_container.children->items[(i + 1)%root_container.children->length]; + if (next_output->internal) { + next_output = root_container.children->items[(i + 2)%root_container.children->length]; } + workspace_switch(next_output->focused); + workspace_output_next(); + return; } - // If we're at the last output, then go to the first - workspace_switch(((swayc_t *)root_container.children->items[0])->focused); - workspace_output_next(); - return; - } else { - workspace_switch(current_output->children->items[0]); } } @@ -157,20 +154,18 @@ void workspace_prev() { return; } } - if (root_container.children->length > 1) { - for (i = 1; i < root_container.children->length; i++) { - if (root_container.children->items[i] == current_output) { - workspace_switch(((swayc_t *)root_container.children->items[i - 1])->focused); - workspace_output_next(); - return; + + int num_outputs = root_container.children->length; + for (i = 0; i < num_outputs; i++) { + if (root_container.children->items[i] == current_output) { + swayc_t *next_output = root_container.children->items[(num_outputs + i - 1)%num_outputs]; + if (next_output->internal) { + next_output = root_container.children->items[(num_outputs + i - 2)%num_outputs]; } + workspace_switch(next_output->focused); + workspace_output_next(); + return; } - // If we're at the first output, then go to the last - workspace_switch(((swayc_t *)root_container.children->items[root_container.children->length-1])->focused); - workspace_output_next(); - return; - } else { - workspace_switch(current_output->children->items[current_output->children->length - 1]); } }