|
|
@ -11,6 +11,7 @@
|
|
|
|
#include "config.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "stringop.h"
|
|
|
|
#include "stringop.h"
|
|
|
|
#include "focus.h"
|
|
|
|
#include "focus.h"
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
|
|
char *workspace_next_name(void) {
|
|
|
|
char *workspace_next_name(void) {
|
|
|
|
sway_log(L_DEBUG, "Workspace: Generating new name");
|
|
|
|
sway_log(L_DEBUG, "Workspace: Generating new name");
|
|
|
@ -84,95 +85,95 @@ static bool _workspace_by_name(swayc_t *view, void *data) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
swayc_t *workspace_by_name(const char* name) {
|
|
|
|
swayc_t *workspace_by_name(const char* name) {
|
|
|
|
return swayc_by_test(&root_container, _workspace_by_name, (void *) name);
|
|
|
|
if (strcmp(name, "prev") == 0) {
|
|
|
|
|
|
|
|
return workspace_prev();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(name, "prev_on_output") == 0) {
|
|
|
|
void workspace_output_next() {
|
|
|
|
return workspace_output_prev();
|
|
|
|
// Get the index of the workspace in the current output, and change the view to index+1 workspace.
|
|
|
|
|
|
|
|
// if we're currently focused on the last workspace in the output, switch to the first
|
|
|
|
|
|
|
|
swayc_t *current_output = swayc_active_workspace()->parent;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < current_output->children->length - 1; i++) {
|
|
|
|
|
|
|
|
if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) {
|
|
|
|
|
|
|
|
workspace_switch(current_output->children->items[i + 1]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (strcmp(name, "next") == 0) {
|
|
|
|
|
|
|
|
return workspace_next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
workspace_switch(current_output->children->items[0]);
|
|
|
|
else if (strcmp(name, "next_on_output") == 0) {
|
|
|
|
}
|
|
|
|
return workspace_output_next();
|
|
|
|
|
|
|
|
|
|
|
|
void workspace_next() {
|
|
|
|
|
|
|
|
// Get the index of the workspace in the current output, and change the view to index+1 workspace.
|
|
|
|
|
|
|
|
// if we're currently focused on the last workspace in the output, change focus to there
|
|
|
|
|
|
|
|
// and call workspace_output_next(), as long as another output actually exists
|
|
|
|
|
|
|
|
swayc_t *current_output = swayc_active_workspace()->parent;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < current_output->children->length - 1; i++) {
|
|
|
|
|
|
|
|
if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) {
|
|
|
|
|
|
|
|
workspace_switch(current_output->children->items[i + 1]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (root_container.children->length > 1) {
|
|
|
|
else if (strcmp(name, "current") == 0) {
|
|
|
|
for (i = 0; i < root_container.children->length - 1; i++) {
|
|
|
|
return swayc_active_workspace();
|
|
|
|
if (root_container.children->items[i] == current_output) {
|
|
|
|
|
|
|
|
workspace_switch(((swayc_t *)root_container.children->items[i + 1])->focused);
|
|
|
|
|
|
|
|
workspace_output_next();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
return swayc_by_test(&root_container, _workspace_by_name, (void *) name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get the previous or next workspace on the specified output.
|
|
|
|
|
|
|
|
* Wraps around at the end and beginning.
|
|
|
|
|
|
|
|
* If next is false, the previous workspace is returned, otherwise the next one is returned.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
|
|
|
|
|
|
|
|
if (!sway_assert(output->type == C_OUTPUT, "Argument must be an output, is %d", output->type)) {
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void workspace_output_prev() {
|
|
|
|
|
|
|
|
// Get the index of the workspace in the current output, and change the view to index+1 workspace
|
|
|
|
|
|
|
|
// if we're currently focused on the first workspace in the output, do nothing and return false
|
|
|
|
|
|
|
|
swayc_t *current_output = swayc_active_workspace()->parent;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < current_output->children->length; i++) {
|
|
|
|
for (i = 0; i < output->children->length; i++) {
|
|
|
|
if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) {
|
|
|
|
if (output->children->items[i] == output->focused) {
|
|
|
|
workspace_switch(current_output->children->items[i - 1]);
|
|
|
|
return output->children->items[wrap(i + (next ? 1 : -1), output->children->length)];
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
workspace_switch(current_output->children->items[current_output->children->length - 1]);
|
|
|
|
|
|
|
|
|
|
|
|
// Doesn't happen, at worst the for loop returns the previously active workspace
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void workspace_prev() {
|
|
|
|
/**
|
|
|
|
// Get the index of the workspace in the current output, and change the view to index-1 workspace.
|
|
|
|
* Get the previous or next workspace. If the first/last workspace on an output is active,
|
|
|
|
// if we're currently focused on the last workspace in the output, change focus to there
|
|
|
|
* proceed to the previous/next output's previous/next workspace.
|
|
|
|
// and call workspace_output_next(), as long as another output actually exists
|
|
|
|
* If next is false, the previous workspace is returned, otherwise the next one is returned.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
|
|
|
|
|
|
|
|
if (!sway_assert(workspace->type == C_WORKSPACE, "Argument must be a workspace, is %d", workspace->type)) {
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
swayc_t *current_output = swayc_active_workspace()->parent;
|
|
|
|
swayc_t *current_output = workspace->parent;
|
|
|
|
|
|
|
|
int offset = next ? 1 : -1;
|
|
|
|
|
|
|
|
int start = next ? 0 : 1;
|
|
|
|
|
|
|
|
int end = next ? (current_output->children->length) - 1 : current_output->children->length;
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < current_output->children->length; i++) {
|
|
|
|
for (i = start; i < end; i++) {
|
|
|
|
if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) {
|
|
|
|
if (current_output->children->items[i] == workspace) {
|
|
|
|
workspace_switch(current_output->children->items[i - 1]);
|
|
|
|
return current_output->children->items[i + offset];
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (root_container.children->length > 1) {
|
|
|
|
|
|
|
|
for (i = 1; i < root_container.children->length; i++) {
|
|
|
|
// Given workspace is the first/last on the output, jump to the previous/next output
|
|
|
|
|
|
|
|
int num_outputs = root_container.children->length;
|
|
|
|
|
|
|
|
for (i = 0; i < num_outputs; i++) {
|
|
|
|
if (root_container.children->items[i] == current_output) {
|
|
|
|
if (root_container.children->items[i] == current_output) {
|
|
|
|
workspace_switch(((swayc_t *)root_container.children->items[i - 1])->focused);
|
|
|
|
swayc_t *next_output = root_container.children->items[wrap(i + offset, num_outputs)];
|
|
|
|
workspace_output_next();
|
|
|
|
return workspace_output_prev_next_impl(next_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);
|
|
|
|
// Doesn't happen, at worst the for loop returns the previously active workspace on the active output
|
|
|
|
workspace_output_next();
|
|
|
|
return NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
workspace_switch(current_output->children->items[current_output->children->length - 1]);
|
|
|
|
swayc_t *workspace_output_next() {
|
|
|
|
|
|
|
|
return workspace_output_prev_next_impl(swayc_active_output(), true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
swayc_t *workspace_next() {
|
|
|
|
|
|
|
|
return workspace_prev_next_impl(swayc_active_workspace(), true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
swayc_t *workspace_output_prev() {
|
|
|
|
|
|
|
|
return workspace_output_prev_next_impl(swayc_active_output(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
swayc_t *workspace_prev() {
|
|
|
|
|
|
|
|
return workspace_prev_next_impl(swayc_active_workspace(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void workspace_switch(swayc_t *workspace) {
|
|
|
|
void workspace_switch(swayc_t *workspace) {
|
|
|
|