diff options
-rw-r--r-- | include/sway/container.h | 3 | ||||
-rw-r--r-- | include/sway/layout.h | 2 | ||||
-rw-r--r-- | sway/commands/layout.c | 48 | ||||
-rw-r--r-- | sway/commands/workspace_layout.c | 10 | ||||
-rw-r--r-- | sway/container.c | 23 | ||||
-rw-r--r-- | sway/sway.5.txt | 2 |
6 files changed, 70 insertions, 18 deletions
diff --git a/include/sway/container.h b/include/sway/container.h index 1d0fb265..f0574b1b 100644 --- a/include/sway/container.h +++ b/include/sway/container.h | |||
@@ -44,6 +44,9 @@ enum swayc_layouts { | |||
44 | L_AUTO_TOP, | 44 | L_AUTO_TOP, |
45 | L_AUTO_BOTTOM, | 45 | L_AUTO_BOTTOM, |
46 | 46 | ||
47 | L_AUTO_FIRST = L_AUTO_LEFT, | ||
48 | L_AUTO_LAST = L_AUTO_BOTTOM, | ||
49 | |||
47 | // Keep last | 50 | // Keep last |
48 | L_LAYOUTS, | 51 | L_LAYOUTS, |
49 | }; | 52 | }; |
diff --git a/include/sway/layout.h b/include/sway/layout.h index 38096947..a771a72e 100644 --- a/include/sway/layout.h +++ b/include/sway/layout.h | |||
@@ -76,6 +76,6 @@ void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, .. | |||
76 | enum swayc_layouts default_layout(swayc_t *output); | 76 | enum swayc_layouts default_layout(swayc_t *output); |
77 | 77 | ||
78 | inline bool is_auto_layout(enum swayc_layouts layout) { | 78 | inline bool is_auto_layout(enum swayc_layouts layout) { |
79 | return (layout >= L_AUTO_LEFT) && (layout <= L_AUTO_BOTTOM); | 79 | return (layout >= L_AUTO_FIRST) && (layout <= L_AUTO_LAST); |
80 | } | 80 | } |
81 | #endif | 81 | #endif |
diff --git a/sway/commands/layout.c b/sway/commands/layout.c index 9e468c21..5426186e 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c | |||
@@ -56,24 +56,12 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
56 | swayc_change_layout(parent, L_HORIZ); | 56 | swayc_change_layout(parent, L_HORIZ); |
57 | } | 57 | } |
58 | } else if (strcasecmp(argv[0], "auto_left") == 0) { | 58 | } else if (strcasecmp(argv[0], "auto_left") == 0) { |
59 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
60 | parent = new_container(parent, L_AUTO_LEFT); | ||
61 | } | ||
62 | swayc_change_layout(parent, L_AUTO_LEFT); | 59 | swayc_change_layout(parent, L_AUTO_LEFT); |
63 | } else if (strcasecmp(argv[0], "auto_right") == 0) { | 60 | } else if (strcasecmp(argv[0], "auto_right") == 0) { |
64 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
65 | parent = new_container(parent, L_AUTO_RIGHT); | ||
66 | } | ||
67 | swayc_change_layout(parent, L_AUTO_RIGHT); | 61 | swayc_change_layout(parent, L_AUTO_RIGHT); |
68 | } else if (strcasecmp(argv[0], "auto_top") == 0) { | 62 | } else if (strcasecmp(argv[0], "auto_top") == 0) { |
69 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
70 | parent = new_container(parent, L_AUTO_TOP); | ||
71 | } | ||
72 | swayc_change_layout(parent, L_AUTO_TOP); | 63 | swayc_change_layout(parent, L_AUTO_TOP); |
73 | } else if (strcasecmp(argv[0], "auto_bot") == 0) { | 64 | } else if (strcasecmp(argv[0], "auto_bot") == 0) { |
74 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
75 | parent = new_container(parent, L_AUTO_BOTTOM); | ||
76 | } | ||
77 | swayc_change_layout(parent, L_AUTO_BOTTOM); | 65 | swayc_change_layout(parent, L_AUTO_BOTTOM); |
78 | } else if (strcasecmp(argv[0], "incnmaster") == 0) { | 66 | } else if (strcasecmp(argv[0], "incnmaster") == 0) { |
79 | if ((error = checkarg(argc, "layout incnmaster", | 67 | if ((error = checkarg(argc, "layout incnmaster", |
@@ -105,6 +93,42 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
105 | ((int)container->parent->nb_slave_groups + inc >= 1)) { | 93 | ((int)container->parent->nb_slave_groups + inc >= 1)) { |
106 | container->parent->nb_slave_groups += inc; | 94 | container->parent->nb_slave_groups += inc; |
107 | } | 95 | } |
96 | } else if (strcasecmp(argv[0], "auto") == 0) { | ||
97 | if ((error = checkarg(argc, "auto", EXPECTED_EQUAL_TO, 2))) { | ||
98 | return error; | ||
99 | } | ||
100 | swayc_t *container = get_focused_view(swayc_active_workspace()); | ||
101 | swayc_t *parent = container->parent; | ||
102 | enum swayc_layouts layout; | ||
103 | if (strcasecmp(argv[1], "next") == 0) { | ||
104 | if (is_auto_layout(parent->layout) && parent->layout < L_AUTO_LAST) { | ||
105 | layout = parent->layout + 1; | ||
106 | } else { | ||
107 | layout = L_AUTO_FIRST; | ||
108 | } | ||
109 | } else if (strcasecmp(argv[1], "prev") == 0) { | ||
110 | if (is_auto_layout(parent->layout) && parent->layout > L_AUTO_FIRST) { | ||
111 | layout = parent->layout - 1; | ||
112 | } else { | ||
113 | layout = L_AUTO_FIRST; | ||
114 | } | ||
115 | } else { | ||
116 | return cmd_results_new(CMD_FAILURE, "layout auto", | ||
117 | "Must be one of <prev|next>."); | ||
118 | } | ||
119 | swayc_change_layout(parent, layout); | ||
120 | } else if (strcasecmp(argv[0], "promote") == 0) { | ||
121 | // swap first child in auto layout with currently focused child | ||
122 | swayc_t *container = get_focused_view(swayc_active_workspace()); | ||
123 | swayc_t *parent = container->parent; | ||
124 | if (is_auto_layout(parent->layout)) { | ||
125 | int focused_idx = index_child(container); | ||
126 | swayc_t *first = parent->children->items[0]; | ||
127 | if (focused_idx > 0) { | ||
128 | list_swap(parent->children, 0, focused_idx); | ||
129 | swap_geometry(first, container); | ||
130 | } | ||
131 | } | ||
108 | } | 132 | } |
109 | } | 133 | } |
110 | 134 | ||
diff --git a/sway/commands/workspace_layout.c b/sway/commands/workspace_layout.c index b7b4b033..3e0a12ce 100644 --- a/sway/commands/workspace_layout.c +++ b/sway/commands/workspace_layout.c | |||
@@ -13,8 +13,16 @@ struct cmd_results *cmd_workspace_layout(int argc, char **argv) { | |||
13 | config->default_layout = L_STACKED; | 13 | config->default_layout = L_STACKED; |
14 | } else if (strcasecmp(argv[0], "tabbed") == 0) { | 14 | } else if (strcasecmp(argv[0], "tabbed") == 0) { |
15 | config->default_layout = L_TABBED; | 15 | config->default_layout = L_TABBED; |
16 | } else if (strcasecmp(argv[0], "auto_left") == 0) { | ||
17 | config->default_layout = L_AUTO_LEFT; | ||
18 | } else if (strcasecmp(argv[0], "auto_right") == 0) { | ||
19 | config->default_layout = L_AUTO_RIGHT; | ||
20 | } else if (strcasecmp(argv[0], "auto_top") == 0) { | ||
21 | config->default_layout = L_AUTO_TOP; | ||
22 | } else if (strcasecmp(argv[0], "auto_bottom") == 0) { | ||
23 | config->default_layout = L_AUTO_BOTTOM; | ||
16 | } else { | 24 | } else { |
17 | return cmd_results_new(CMD_INVALID, "workspace_layout", "Expected 'workspace_layout <default|stacking|tabbed>'"); | 25 | return cmd_results_new(CMD_INVALID, "workspace_layout", "Expected 'workspace_layout <default|stacking|tabbed|auto_left|auto_right|auto_top|auto_bottom>'"); |
18 | } | 26 | } |
19 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 27 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
20 | } | 28 | } |
diff --git a/sway/container.c b/sway/container.c index d034115f..3bdc8b6c 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -962,11 +962,28 @@ swayc_t *swayc_tabbed_stacked_parent(swayc_t *con) { | |||
962 | } | 962 | } |
963 | 963 | ||
964 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { | 964 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { |
965 | // if layout change modifies the auto layout's major axis, swap width and height | ||
966 | // to preserve current ratios. | ||
967 | if (is_auto_layout(layout) && is_auto_layout(container->layout)) { | ||
968 | enum swayc_layouts prev_major = (container->layout == L_AUTO_LEFT || | ||
969 | container->layout == L_AUTO_RIGHT) | ||
970 | ? L_HORIZ : L_VERT; | ||
971 | enum swayc_layouts new_major = (layout == L_AUTO_LEFT || layout == L_AUTO_RIGHT) | ||
972 | ? L_HORIZ : L_VERT; | ||
973 | if (new_major != prev_major) { | ||
974 | for (int i = 0; i < container->children->length; ++i) { | ||
975 | swayc_t *child = container->children->items[i]; | ||
976 | double h = child->height; | ||
977 | child->height = child->width; | ||
978 | child->width = h; | ||
979 | } | ||
980 | } | ||
981 | } | ||
965 | if (container->type == C_WORKSPACE) { | 982 | if (container->type == C_WORKSPACE) { |
966 | container->workspace_layout = layout; | 983 | container->workspace_layout = layout; |
967 | if (layout == L_HORIZ || layout == L_VERT) { | 984 | if (layout == L_HORIZ || layout == L_VERT || is_auto_layout(layout)) { |
968 | container->layout = layout; | 985 | container->layout = layout; |
969 | } | 986 | } |
970 | } else { | 987 | } else { |
971 | container->layout = layout; | 988 | container->layout = layout; |
972 | } | 989 | } |
diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 8f8302f0..c0c4bfb2 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt | |||
@@ -371,7 +371,7 @@ The default colors are: | |||
371 | switch to workspace 2, then invoke the "workspace 2" command again, you | 371 | switch to workspace 2, then invoke the "workspace 2" command again, you |
372 | will be returned to workspace 1. Defaults to _no_. | 372 | will be returned to workspace 1. Defaults to _no_. |
373 | 373 | ||
374 | **workspace_layout** <default|stacking|tabbed>:: | 374 | **workspace_layout** <default|stacking|tabbed|auto_left|auto_right|auto_top|auto_bottom>:: |
375 | Specifies the start layout for new workspaces. | 375 | Specifies the start layout for new workspaces. |
376 | 376 | ||
377 | **include** <path>:: | 377 | **include** <path>:: |