diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-18 21:54:09 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-18 22:02:03 +1000 |
commit | 16c663ed49e3950388901f220066e4da69956dfb (patch) | |
tree | bf71a43528328a786be1a4de02781e6e83aea406 /sway | |
parent | cfe205b36fba77ba64184e0c1e8dcb211a7a8904 (diff) |
Rename container_sort_workspaces and container_wrap_children
This commit renames container_sort_workspaces to output_sort_workspaces
and moves it to output.c.
This also renames container_wrap_children to workspace_wrap_children and
moves it to workspace.c. This function is only called with workspaces.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/floating.c | 3 | ||||
-rw-r--r-- | sway/commands/fullscreen.c | 3 | ||||
-rw-r--r-- | sway/commands/move.c | 6 | ||||
-rw-r--r-- | sway/commands/rename.c | 3 | ||||
-rw-r--r-- | sway/tree/container.c | 14 | ||||
-rw-r--r-- | sway/tree/layout.c | 23 | ||||
-rw-r--r-- | sway/tree/output.c | 23 | ||||
-rw-r--r-- | sway/tree/workspace.c | 14 |
8 files changed, 45 insertions, 44 deletions
diff --git a/sway/commands/floating.c b/sway/commands/floating.c index 31de5ec3..c9467ef0 100644 --- a/sway/commands/floating.c +++ b/sway/commands/floating.c @@ -8,6 +8,7 @@ #include "sway/tree/container.h" #include "sway/tree/layout.h" #include "sway/tree/view.h" +#include "sway/tree/workspace.h" #include "list.h" struct cmd_results *cmd_floating(int argc, char **argv) { @@ -24,7 +25,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) { if (container->type == C_WORKSPACE) { // Wrap the workspace's children in a container so we can float it struct sway_container *workspace = container; - container = container_wrap_children(container); + container = workspace_wrap_children(container); workspace->layout = L_HORIZ; seat_set_focus(config->handler_context.seat, container); } diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c index 5ad06e40..a0661200 100644 --- a/sway/commands/fullscreen.c +++ b/sway/commands/fullscreen.c @@ -4,6 +4,7 @@ #include "sway/tree/arrange.h" #include "sway/tree/container.h" #include "sway/tree/view.h" +#include "sway/tree/workspace.h" #include "sway/tree/layout.h" #include "util.h" @@ -21,7 +22,7 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) { if (container->type == C_WORKSPACE) { // Wrap the workspace's children in a container so we can fullscreen it struct sway_container *workspace = container; - container = container_wrap_children(container); + container = workspace_wrap_children(container); workspace->layout = L_HORIZ; seat_set_focus(config->handler_context.seat, container); } diff --git a/sway/commands/move.c b/sway/commands/move.c index de6b1b0a..acdc50b5 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -64,7 +64,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, return cmd_results_new(CMD_FAILURE, "move", "Can't move an empty workspace"); } - current = container_wrap_children(current); + current = workspace_wrap_children(current); } else if (current->type != C_CONTAINER && current->type != C_VIEW) { return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); @@ -245,7 +245,7 @@ static void workspace_move_to_output(struct sway_container *workspace, // Try to remove an empty workspace from the destination output. container_reap_empty_recursive(new_output_focus); - container_sort_workspaces(output); + output_sort_workspaces(output); seat_set_focus(seat, output); workspace_output_raise_priority(workspace, old_output, output); ipc_event_workspace(NULL, workspace, "move"); @@ -437,7 +437,7 @@ static struct cmd_results *move_to_scratchpad(struct sway_container *con) { if (con->type == C_WORKSPACE) { // Wrap the workspace's children in a container struct sway_container *workspace = con; - con = container_wrap_children(con); + con = workspace_wrap_children(con); workspace->layout = L_HORIZ; } diff --git a/sway/commands/rename.c b/sway/commands/rename.c index c6952bbb..c69bbdac 100644 --- a/sway/commands/rename.c +++ b/sway/commands/rename.c @@ -6,6 +6,7 @@ #include "sway/commands.h" #include "sway/config.h" #include "sway/ipc-server.h" +#include "sway/output.h" #include "sway/tree/container.h" #include "sway/tree/workspace.h" @@ -82,7 +83,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) { free(workspace->name); workspace->name = new_name; - container_sort_workspaces(workspace->parent); + output_sort_workspaces(workspace->parent); ipc_event_workspace(NULL, workspace, "rename"); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/tree/container.c b/sway/tree/container.c index db780270..337245fd 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -270,7 +270,7 @@ static struct sway_container *container_output_destroy( container_destroy(workspace); } - container_sort_workspaces(new_output); + output_sort_workspaces(new_output); } } } @@ -1305,15 +1305,3 @@ bool container_is_fullscreen_or_child(struct sway_container *container) { return false; } - -struct sway_container *container_wrap_children(struct sway_container *parent) { - struct sway_container *middle = container_create(C_CONTAINER); - middle->layout = parent->layout; - while (parent->children->length) { - struct sway_container *child = parent->children->items[0]; - container_remove_child(child); - container_add_child(middle, child); - } - container_add_child(parent, middle); - return middle; -} diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 2b710403..49ec806e 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -1,5 +1,4 @@ #define _POSIX_C_SOURCE 200809L -#include <ctype.h> #include <math.h> #include <stdbool.h> #include <stdlib.h> @@ -591,28 +590,6 @@ enum sway_container_layout container_get_default_layout( } } -static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { - struct sway_container *a = *(void **)_a; - struct sway_container *b = *(void **)_b; - int retval = 0; - - if (isdigit(a->name[0]) && isdigit(b->name[0])) { - int a_num = strtol(a->name, NULL, 10); - int b_num = strtol(b->name, NULL, 10); - retval = (a_num < b_num) ? -1 : (a_num > b_num); - } else if (isdigit(a->name[0])) { - retval = -1; - } else if (isdigit(b->name[0])) { - retval = 1; - } - - return retval; -} - -void container_sort_workspaces(struct sway_container *output) { - list_stable_sort(output->children, sort_workspace_cmp_qsort); -} - /** * Get swayc in the direction of newly entered output. */ diff --git a/sway/tree/output.c b/sway/tree/output.c index 31e3bf9b..ab955359 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -1,4 +1,5 @@ #define _POSIX_C_SOURCE 200809L +#include <ctype.h> #include <string.h> #include <strings.h> #include "sway/ipc-server.h" @@ -28,7 +29,7 @@ static void restore_workspaces(struct sway_container *output) { } } - container_sort_workspaces(output); + output_sort_workspaces(output); } struct sway_container *output_create( @@ -102,3 +103,23 @@ struct sway_container *output_create( return output; } +static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { + struct sway_container *a = *(void **)_a; + struct sway_container *b = *(void **)_b; + + if (isdigit(a->name[0]) && isdigit(b->name[0])) { + int a_num = strtol(a->name, NULL, 10); + int b_num = strtol(b->name, NULL, 10); + return (a_num < b_num) ? -1 : (a_num > b_num); + } else if (isdigit(a->name[0])) { + return -1; + } else if (isdigit(b->name[0])) { + return 1; + } + return 0; +} + +void output_sort_workspaces(struct sway_container *output) { + list_stable_sort(output->children, sort_workspace_cmp_qsort); +} + diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index e7383de0..1c0e6515 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -75,7 +75,7 @@ struct sway_container *workspace_create(struct sway_container *output, workspace_output_add_priority(workspace, output); container_add_child(output, workspace); - container_sort_workspaces(output); + output_sort_workspaces(output); container_create_notify(workspace); return workspace; @@ -537,3 +537,15 @@ void workspace_detect_urgent(struct sway_container *workspace) { container_damage_whole(workspace); } } + +struct sway_container *workspace_wrap_children(struct sway_container *ws) { + struct sway_container *middle = container_create(C_CONTAINER); + middle->layout = ws->layout; + while (ws->children->length) { + struct sway_container *child = ws->children->items[0]; + container_remove_child(child); + container_add_child(middle, child); + } + container_add_child(ws, middle); + return middle; +} |