diff options
-rw-r--r-- | include/sway/output.h | 2 | ||||
-rw-r--r-- | include/sway/tree/container.h | 8 | ||||
-rw-r--r-- | include/sway/tree/layout.h | 2 | ||||
-rw-r--r-- | include/sway/tree/workspace.h | 7 | ||||
-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 |
12 files changed, 54 insertions, 54 deletions
diff --git a/include/sway/output.h b/include/sway/output.h index 80dcd37b..8bdd1919 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -58,6 +58,8 @@ void output_damage_whole_container(struct sway_output *output, | |||
58 | 58 | ||
59 | struct sway_container *output_by_name(const char *name); | 59 | struct sway_container *output_by_name(const char *name); |
60 | 60 | ||
61 | void output_sort_workspaces(struct sway_container *output); | ||
62 | |||
61 | void output_enable(struct sway_output *output); | 63 | void output_enable(struct sway_output *output); |
62 | 64 | ||
63 | bool output_has_opaque_overlay_layer_surface(struct sway_output *output); | 65 | bool output_has_opaque_overlay_layer_surface(struct sway_output *output); |
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index fdcc31ec..d866ec03 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -361,12 +361,4 @@ bool container_is_floating_or_child(struct sway_container *container); | |||
361 | */ | 361 | */ |
362 | bool container_is_fullscreen_or_child(struct sway_container *container); | 362 | bool container_is_fullscreen_or_child(struct sway_container *container); |
363 | 363 | ||
364 | /** | ||
365 | * Wrap the children of parent in a new container. The new container will be the | ||
366 | * only child of parent. | ||
367 | * | ||
368 | * The new container is returned. | ||
369 | */ | ||
370 | struct sway_container *container_wrap_children(struct sway_container *parent); | ||
371 | |||
372 | #endif | 364 | #endif |
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 77cd954b..5b803dfe 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h | |||
@@ -45,8 +45,6 @@ void container_move(struct sway_container *container, | |||
45 | enum sway_container_layout container_get_default_layout( | 45 | enum sway_container_layout container_get_default_layout( |
46 | struct sway_container *con); | 46 | struct sway_container *con); |
47 | 47 | ||
48 | void container_sort_workspaces(struct sway_container *output); | ||
49 | |||
50 | struct sway_container *container_get_in_direction(struct sway_container | 48 | struct sway_container *container_get_in_direction(struct sway_container |
51 | *container, struct sway_seat *seat, enum movement_direction dir); | 49 | *container, struct sway_seat *seat, enum movement_direction dir); |
52 | 50 | ||
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 056f2329..5b43ae87 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h | |||
@@ -50,4 +50,11 @@ struct sway_container *workspace_output_get_highest_available( | |||
50 | 50 | ||
51 | void workspace_detect_urgent(struct sway_container *workspace); | 51 | void workspace_detect_urgent(struct sway_container *workspace); |
52 | 52 | ||
53 | /** | ||
54 | * Wrap the workspace's tiling children in a new container. | ||
55 | * The new container will be the only direct tiling child of the workspace. | ||
56 | * The new container is returned. | ||
57 | */ | ||
58 | struct sway_container *workspace_wrap_children(struct sway_container *ws); | ||
59 | |||
53 | #endif | 60 | #endif |
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 @@ | |||
8 | #include "sway/tree/container.h" | 8 | #include "sway/tree/container.h" |
9 | #include "sway/tree/layout.h" | 9 | #include "sway/tree/layout.h" |
10 | #include "sway/tree/view.h" | 10 | #include "sway/tree/view.h" |
11 | #include "sway/tree/workspace.h" | ||
11 | #include "list.h" | 12 | #include "list.h" |
12 | 13 | ||
13 | struct cmd_results *cmd_floating(int argc, char **argv) { | 14 | struct cmd_results *cmd_floating(int argc, char **argv) { |
@@ -24,7 +25,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) { | |||
24 | if (container->type == C_WORKSPACE) { | 25 | if (container->type == C_WORKSPACE) { |
25 | // Wrap the workspace's children in a container so we can float it | 26 | // Wrap the workspace's children in a container so we can float it |
26 | struct sway_container *workspace = container; | 27 | struct sway_container *workspace = container; |
27 | container = container_wrap_children(container); | 28 | container = workspace_wrap_children(container); |
28 | workspace->layout = L_HORIZ; | 29 | workspace->layout = L_HORIZ; |
29 | seat_set_focus(config->handler_context.seat, container); | 30 | seat_set_focus(config->handler_context.seat, container); |
30 | } | 31 | } |
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 @@ | |||
4 | #include "sway/tree/arrange.h" | 4 | #include "sway/tree/arrange.h" |
5 | #include "sway/tree/container.h" | 5 | #include "sway/tree/container.h" |
6 | #include "sway/tree/view.h" | 6 | #include "sway/tree/view.h" |
7 | #include "sway/tree/workspace.h" | ||
7 | #include "sway/tree/layout.h" | 8 | #include "sway/tree/layout.h" |
8 | #include "util.h" | 9 | #include "util.h" |
9 | 10 | ||
@@ -21,7 +22,7 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) { | |||
21 | if (container->type == C_WORKSPACE) { | 22 | if (container->type == C_WORKSPACE) { |
22 | // Wrap the workspace's children in a container so we can fullscreen it | 23 | // Wrap the workspace's children in a container so we can fullscreen it |
23 | struct sway_container *workspace = container; | 24 | struct sway_container *workspace = container; |
24 | container = container_wrap_children(container); | 25 | container = workspace_wrap_children(container); |
25 | workspace->layout = L_HORIZ; | 26 | workspace->layout = L_HORIZ; |
26 | seat_set_focus(config->handler_context.seat, container); | 27 | seat_set_focus(config->handler_context.seat, container); |
27 | } | 28 | } |
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, | |||
64 | return cmd_results_new(CMD_FAILURE, "move", | 64 | return cmd_results_new(CMD_FAILURE, "move", |
65 | "Can't move an empty workspace"); | 65 | "Can't move an empty workspace"); |
66 | } | 66 | } |
67 | current = container_wrap_children(current); | 67 | current = workspace_wrap_children(current); |
68 | } else if (current->type != C_CONTAINER && current->type != C_VIEW) { | 68 | } else if (current->type != C_CONTAINER && current->type != C_VIEW) { |
69 | return cmd_results_new(CMD_FAILURE, "move", | 69 | return cmd_results_new(CMD_FAILURE, "move", |
70 | "Can only move containers and views."); | 70 | "Can only move containers and views."); |
@@ -245,7 +245,7 @@ static void workspace_move_to_output(struct sway_container *workspace, | |||
245 | // Try to remove an empty workspace from the destination output. | 245 | // Try to remove an empty workspace from the destination output. |
246 | container_reap_empty_recursive(new_output_focus); | 246 | container_reap_empty_recursive(new_output_focus); |
247 | 247 | ||
248 | container_sort_workspaces(output); | 248 | output_sort_workspaces(output); |
249 | seat_set_focus(seat, output); | 249 | seat_set_focus(seat, output); |
250 | workspace_output_raise_priority(workspace, old_output, output); | 250 | workspace_output_raise_priority(workspace, old_output, output); |
251 | ipc_event_workspace(NULL, workspace, "move"); | 251 | ipc_event_workspace(NULL, workspace, "move"); |
@@ -437,7 +437,7 @@ static struct cmd_results *move_to_scratchpad(struct sway_container *con) { | |||
437 | if (con->type == C_WORKSPACE) { | 437 | if (con->type == C_WORKSPACE) { |
438 | // Wrap the workspace's children in a container | 438 | // Wrap the workspace's children in a container |
439 | struct sway_container *workspace = con; | 439 | struct sway_container *workspace = con; |
440 | con = container_wrap_children(con); | 440 | con = workspace_wrap_children(con); |
441 | workspace->layout = L_HORIZ; | 441 | workspace->layout = L_HORIZ; |
442 | } | 442 | } |
443 | 443 | ||
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 @@ | |||
6 | #include "sway/commands.h" | 6 | #include "sway/commands.h" |
7 | #include "sway/config.h" | 7 | #include "sway/config.h" |
8 | #include "sway/ipc-server.h" | 8 | #include "sway/ipc-server.h" |
9 | #include "sway/output.h" | ||
9 | #include "sway/tree/container.h" | 10 | #include "sway/tree/container.h" |
10 | #include "sway/tree/workspace.h" | 11 | #include "sway/tree/workspace.h" |
11 | 12 | ||
@@ -82,7 +83,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
82 | free(workspace->name); | 83 | free(workspace->name); |
83 | workspace->name = new_name; | 84 | workspace->name = new_name; |
84 | 85 | ||
85 | container_sort_workspaces(workspace->parent); | 86 | output_sort_workspaces(workspace->parent); |
86 | ipc_event_workspace(NULL, workspace, "rename"); | 87 | ipc_event_workspace(NULL, workspace, "rename"); |
87 | 88 | ||
88 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 89 | 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( | |||
270 | container_destroy(workspace); | 270 | container_destroy(workspace); |
271 | } | 271 | } |
272 | 272 | ||
273 | container_sort_workspaces(new_output); | 273 | output_sort_workspaces(new_output); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
@@ -1305,15 +1305,3 @@ bool container_is_fullscreen_or_child(struct sway_container *container) { | |||
1305 | 1305 | ||
1306 | return false; | 1306 | return false; |
1307 | } | 1307 | } |
1308 | |||
1309 | struct sway_container *container_wrap_children(struct sway_container *parent) { | ||
1310 | struct sway_container *middle = container_create(C_CONTAINER); | ||
1311 | middle->layout = parent->layout; | ||
1312 | while (parent->children->length) { | ||
1313 | struct sway_container *child = parent->children->items[0]; | ||
1314 | container_remove_child(child); | ||
1315 | container_add_child(middle, child); | ||
1316 | } | ||
1317 | container_add_child(parent, middle); | ||
1318 | return middle; | ||
1319 | } | ||
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 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <ctype.h> | ||
3 | #include <math.h> | 2 | #include <math.h> |
4 | #include <stdbool.h> | 3 | #include <stdbool.h> |
5 | #include <stdlib.h> | 4 | #include <stdlib.h> |
@@ -591,28 +590,6 @@ enum sway_container_layout container_get_default_layout( | |||
591 | } | 590 | } |
592 | } | 591 | } |
593 | 592 | ||
594 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | ||
595 | struct sway_container *a = *(void **)_a; | ||
596 | struct sway_container *b = *(void **)_b; | ||
597 | int retval = 0; | ||
598 | |||
599 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { | ||
600 | int a_num = strtol(a->name, NULL, 10); | ||
601 | int b_num = strtol(b->name, NULL, 10); | ||
602 | retval = (a_num < b_num) ? -1 : (a_num > b_num); | ||
603 | } else if (isdigit(a->name[0])) { | ||
604 | retval = -1; | ||
605 | } else if (isdigit(b->name[0])) { | ||
606 | retval = 1; | ||
607 | } | ||
608 | |||
609 | return retval; | ||
610 | } | ||
611 | |||
612 | void container_sort_workspaces(struct sway_container *output) { | ||
613 | list_stable_sort(output->children, sort_workspace_cmp_qsort); | ||
614 | } | ||
615 | |||
616 | /** | 593 | /** |
617 | * Get swayc in the direction of newly entered output. | 594 | * Get swayc in the direction of newly entered output. |
618 | */ | 595 | */ |
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 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <ctype.h> | ||
2 | #include <string.h> | 3 | #include <string.h> |
3 | #include <strings.h> | 4 | #include <strings.h> |
4 | #include "sway/ipc-server.h" | 5 | #include "sway/ipc-server.h" |
@@ -28,7 +29,7 @@ static void restore_workspaces(struct sway_container *output) { | |||
28 | } | 29 | } |
29 | } | 30 | } |
30 | 31 | ||
31 | container_sort_workspaces(output); | 32 | output_sort_workspaces(output); |
32 | } | 33 | } |
33 | 34 | ||
34 | struct sway_container *output_create( | 35 | struct sway_container *output_create( |
@@ -102,3 +103,23 @@ struct sway_container *output_create( | |||
102 | return output; | 103 | return output; |
103 | } | 104 | } |
104 | 105 | ||
106 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | ||
107 | struct sway_container *a = *(void **)_a; | ||
108 | struct sway_container *b = *(void **)_b; | ||
109 | |||
110 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { | ||
111 | int a_num = strtol(a->name, NULL, 10); | ||
112 | int b_num = strtol(b->name, NULL, 10); | ||
113 | return (a_num < b_num) ? -1 : (a_num > b_num); | ||
114 | } else if (isdigit(a->name[0])) { | ||
115 | return -1; | ||
116 | } else if (isdigit(b->name[0])) { | ||
117 | return 1; | ||
118 | } | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | void output_sort_workspaces(struct sway_container *output) { | ||
123 | list_stable_sort(output->children, sort_workspace_cmp_qsort); | ||
124 | } | ||
125 | |||
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, | |||
75 | workspace_output_add_priority(workspace, output); | 75 | workspace_output_add_priority(workspace, output); |
76 | 76 | ||
77 | container_add_child(output, workspace); | 77 | container_add_child(output, workspace); |
78 | container_sort_workspaces(output); | 78 | output_sort_workspaces(output); |
79 | container_create_notify(workspace); | 79 | container_create_notify(workspace); |
80 | 80 | ||
81 | return workspace; | 81 | return workspace; |
@@ -537,3 +537,15 @@ void workspace_detect_urgent(struct sway_container *workspace) { | |||
537 | container_damage_whole(workspace); | 537 | container_damage_whole(workspace); |
538 | } | 538 | } |
539 | } | 539 | } |
540 | |||
541 | struct sway_container *workspace_wrap_children(struct sway_container *ws) { | ||
542 | struct sway_container *middle = container_create(C_CONTAINER); | ||
543 | middle->layout = ws->layout; | ||
544 | while (ws->children->length) { | ||
545 | struct sway_container *child = ws->children->items[0]; | ||
546 | container_remove_child(child); | ||
547 | container_add_child(middle, child); | ||
548 | } | ||
549 | container_add_child(ws, middle); | ||
550 | return middle; | ||
551 | } | ||