diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-16 16:46:16 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-16 16:46:16 -0400 |
commit | 7f4529ec8b6362ef36ce546cfe34d816f1b708f0 (patch) | |
tree | 45de60347ce0fc86e4ac1ee9e814152aee9929c6 /sway | |
parent | c5d98fe6febc705487f4a8871f5abeb3aa36890b (diff) | |
parent | 0a0fe18fd6126941b3518652c935da1d81249a19 (diff) |
Merge pull request #44 from Luminarys/master
Added in workspace next/prev and workspace output_next/prev
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 22 | ||||
-rw-r--r-- | sway/workspace.c | 88 |
2 files changed, 110 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c index 842142e2..d4f588de 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -342,6 +342,28 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { return false; } + // Handle workspace next/prev + if (strcmp(argv[0], "next") == 0) { + workspace_next(); + return true; + } + + if (strcmp(argv[0], "prev") == 0) { + workspace_next(); + return true; + } + + // Handle workspace output_next/prev + if (strcmp(argv[0], "output_next") == 0) { + workspace_output_next(); + return true; + } + + if (strcmp(argv[0], "output_prev") == 0) { + workspace_output_prev(); + return true; + } + swayc_t *workspace = workspace_find_by_name(argv[0]); if (!workspace) { workspace = workspace_create(argv[0]); diff --git a/sway/workspace.c b/sway/workspace.c index 49a1224f..a3238da6 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -93,6 +93,94 @@ swayc_t *workspace_find_by_name(const char* name) { return find_container(&root_container, workspace_by_name, (void *) name); } +void workspace_output_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, switch to the first + swayc_t *current_output = 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), active_workspace->name) == 0) { + workspace_switch(current_output->children->items[i + 1]); + return; + } + } + workspace_switch(current_output->children->items[0]); +} + +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 = 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), active_workspace->name) == 0) { + workspace_switch(current_output->children->items[i + 1]); + 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; + } + } + // 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]); + } +} + +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 = active_workspace->parent; + int i; + for (i = 1; i < current_output->children->length; i++) { + if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { + workspace_switch(current_output->children->items[i - 1]); + return; + } + } + workspace_switch(current_output->children->items[current_output->children->length - 1]); +} + +void workspace_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, change focus to there + // and call workspace_output_next(), as long as another output actually exists + + swayc_t *current_output = active_workspace->parent; + int i; + for (i = 1; i < current_output->children->length; i++) { + if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { + workspace_switch(current_output->children->items[i - 1]); + 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; + } + } + // 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]); + } + +} + void workspace_switch(swayc_t *workspace) { swayc_t *ws_output = workspace->parent; while (ws_output->type != C_OUTPUT) { |