diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-05-04 08:24:25 -0400 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-01 23:14:58 +1000 |
commit | f3ab895916ca1a0f004b5ceaefa90eee90676532 (patch) | |
tree | aa572c41265fae21617b13b62b1c8d5df1f2d47d | |
parent | Merge pull request #2081 from RedSoxFan/fix-2077 (diff) | |
download | sway-f3ab895916ca1a0f004b5ceaefa90eee90676532.tar.gz sway-f3ab895916ca1a0f004b5ceaefa90eee90676532.tar.zst sway-f3ab895916ca1a0f004b5ceaefa90eee90676532.zip |
Implement `floating enable`
-rw-r--r-- | include/sway/tree/container.h | 3 | ||||
-rw-r--r-- | include/sway/tree/layout.h | 3 | ||||
-rw-r--r-- | include/sway/tree/workspace.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 3 | ||||
-rw-r--r-- | sway/commands/floating.c | 48 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/tree/layout.c | 43 | ||||
-rw-r--r-- | sway/tree/workspace.c | 2 |
8 files changed, 99 insertions, 5 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index bb6c04a6..fa2f9286 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -76,6 +76,9 @@ struct sway_container { | |||
76 | enum sway_container_layout layout; | 76 | enum sway_container_layout layout; |
77 | enum sway_container_layout prev_layout; | 77 | enum sway_container_layout prev_layout; |
78 | 78 | ||
79 | // Saves us from searching the list of children/floating in the parent | ||
80 | bool is_floating; | ||
81 | |||
79 | // For C_ROOT, this has no meaning | 82 | // For C_ROOT, this has no meaning |
80 | // For C_OUTPUT, this is the output position in layout coordinates | 83 | // For C_OUTPUT, this is the output position in layout coordinates |
81 | // For other types, this is the position in output-local coordinates | 84 | // For other types, this is the position in output-local coordinates |
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 2e0f2abf..33d0a5d0 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h | |||
@@ -46,6 +46,9 @@ struct sway_container *container_add_sibling(struct sway_container *parent, | |||
46 | 46 | ||
47 | struct sway_container *container_remove_child(struct sway_container *child); | 47 | struct sway_container *container_remove_child(struct sway_container *child); |
48 | 48 | ||
49 | void container_add_floating(struct sway_container *workspace, | ||
50 | struct sway_container *child); | ||
51 | |||
49 | struct sway_container *container_replace_child(struct sway_container *child, | 52 | struct sway_container *container_replace_child(struct sway_container *child, |
50 | struct sway_container *new_child); | 53 | struct sway_container *new_child); |
51 | 54 | ||
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 35e1df3b..ece0ab5c 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h | |||
@@ -8,6 +8,7 @@ struct sway_view; | |||
8 | struct sway_workspace { | 8 | struct sway_workspace { |
9 | struct sway_container *swayc; | 9 | struct sway_container *swayc; |
10 | struct sway_view *fullscreen; | 10 | struct sway_view *fullscreen; |
11 | list_t *floating; | ||
11 | }; | 12 | }; |
12 | 13 | ||
13 | extern char *prev_workspace_name; | 14 | extern char *prev_workspace_name; |
diff --git a/sway/commands.c b/sway/commands.c index 6f5113f8..4a8d11ba 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -110,7 +110,6 @@ static struct cmd_handler handlers[] = { | |||
110 | { "font", cmd_font }, | 110 | { "font", cmd_font }, |
111 | { "for_window", cmd_for_window }, | 111 | { "for_window", cmd_for_window }, |
112 | { "force_focus_wrapping", cmd_force_focus_wrapping }, | 112 | { "force_focus_wrapping", cmd_force_focus_wrapping }, |
113 | { "fullscreen", cmd_fullscreen }, | ||
114 | { "hide_edge_borders", cmd_hide_edge_borders }, | 113 | { "hide_edge_borders", cmd_hide_edge_borders }, |
115 | { "include", cmd_include }, | 114 | { "include", cmd_include }, |
116 | { "input", cmd_input }, | 115 | { "input", cmd_input }, |
@@ -176,7 +175,9 @@ static struct cmd_handler config_handlers[] = { | |||
176 | static struct cmd_handler command_handlers[] = { | 175 | static struct cmd_handler command_handlers[] = { |
177 | { "border", cmd_border }, | 176 | { "border", cmd_border }, |
178 | { "exit", cmd_exit }, | 177 | { "exit", cmd_exit }, |
178 | { "floating", cmd_floating }, | ||
179 | { "focus", cmd_focus }, | 179 | { "focus", cmd_focus }, |
180 | { "fullscreen", cmd_fullscreen }, | ||
180 | { "kill", cmd_kill }, | 181 | { "kill", cmd_kill }, |
181 | { "layout", cmd_layout }, | 182 | { "layout", cmd_layout }, |
182 | { "mark", cmd_mark }, | 183 | { "mark", cmd_mark }, |
diff --git a/sway/commands/floating.c b/sway/commands/floating.c new file mode 100644 index 00000000..8432b0dc --- /dev/null +++ b/sway/commands/floating.c | |||
@@ -0,0 +1,48 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/seat.h" | ||
5 | #include "sway/ipc-server.h" | ||
6 | #include "sway/tree/arrange.h" | ||
7 | #include "sway/tree/container.h" | ||
8 | #include "sway/tree/layout.h" | ||
9 | #include "list.h" | ||
10 | |||
11 | struct cmd_results *cmd_floating(int argc, char **argv) { | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | struct sway_container *container = | ||
17 | config->handler_context.current_container; | ||
18 | if (container->type != C_VIEW) { | ||
19 | // TODO: This doesn't strictly speaking have to be true | ||
20 | return cmd_results_new(CMD_INVALID, "float", "Only views can float"); | ||
21 | } | ||
22 | |||
23 | bool wants_floating; | ||
24 | if (strcasecmp(argv[0], "enable") == 0) { | ||
25 | wants_floating = true; | ||
26 | } else if (strcasecmp(argv[0], "disable") == 0) { | ||
27 | wants_floating = false; | ||
28 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
29 | wants_floating = !container->is_floating; | ||
30 | } else { | ||
31 | return cmd_results_new(CMD_FAILURE, "floating", | ||
32 | "Expected 'floating <enable|disable|toggle>"); | ||
33 | } | ||
34 | |||
35 | // Change from tiled to floating | ||
36 | if (!container->is_floating && wants_floating) { | ||
37 | struct sway_container *workspace = container_parent( | ||
38 | container, C_WORKSPACE); | ||
39 | container_remove_child(container); | ||
40 | container_add_floating(workspace, container); | ||
41 | seat_set_focus(config->handler_context.seat, container); | ||
42 | arrange_workspace(workspace); | ||
43 | } else if (container->is_floating && !wants_floating) { | ||
44 | // TODO | ||
45 | } | ||
46 | |||
47 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
48 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index 68675f67..5618a257 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -36,6 +36,7 @@ sway_sources = files( | |||
36 | 'commands/exit.c', | 36 | 'commands/exit.c', |
37 | 'commands/exec.c', | 37 | 'commands/exec.c', |
38 | 'commands/exec_always.c', | 38 | 'commands/exec_always.c', |
39 | 'commands/floating.c', | ||
39 | 'commands/focus.c', | 40 | 'commands/focus.c', |
40 | 'commands/focus_follows_mouse.c', | 41 | 'commands/focus_follows_mouse.c', |
41 | 'commands/focus_wrapping.c', | 42 | 'commands/focus_wrapping.c', |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 2f4ae667..7bbeb4b1 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -142,11 +142,26 @@ struct sway_container *container_remove_child(struct sway_container *child) { | |||
142 | } | 142 | } |
143 | 143 | ||
144 | struct sway_container *parent = child->parent; | 144 | struct sway_container *parent = child->parent; |
145 | for (int i = 0; i < parent->children->length; ++i) { | 145 | if (!child->is_floating) { |
146 | if (parent->children->items[i] == child) { | 146 | for (int i = 0; i < parent->children->length; ++i) { |
147 | list_del(parent->children, i); | 147 | if (parent->children->items[i] == child) { |
148 | break; | 148 | list_del(parent->children, i); |
149 | break; | ||
150 | } | ||
151 | } | ||
152 | } else { | ||
153 | if (!sway_assert(parent->type == C_WORKSPACE && child->type == C_VIEW, | ||
154 | "Found floating non-view and/or in non-workspace")) { | ||
155 | return parent; | ||
156 | } | ||
157 | struct sway_workspace *ws = parent->sway_workspace; | ||
158 | for (int i = 0; i < ws->floating->length; ++i) { | ||
159 | if (ws->floating->items[i] == child) { | ||
160 | list_del(ws->floating, i); | ||
161 | break; | ||
162 | } | ||
149 | } | 163 | } |
164 | child->is_floating = false; | ||
150 | } | 165 | } |
151 | child->parent = NULL; | 166 | child->parent = NULL; |
152 | container_notify_subtree_changed(parent); | 167 | container_notify_subtree_changed(parent); |
@@ -154,6 +169,26 @@ struct sway_container *container_remove_child(struct sway_container *child) { | |||
154 | return parent; | 169 | return parent; |
155 | } | 170 | } |
156 | 171 | ||
172 | void container_add_floating(struct sway_container *workspace, | ||
173 | struct sway_container *child) { | ||
174 | if (!sway_assert(workspace->type == C_WORKSPACE && child->type == C_VIEW, | ||
175 | "Attempted to float non-view and/or in non-workspace")) { | ||
176 | return; | ||
177 | } | ||
178 | if (!sway_assert(!child->parent, | ||
179 | "child already has a parent (invalid call)")) { | ||
180 | return; | ||
181 | } | ||
182 | if (!sway_assert(!child->is_floating, | ||
183 | "child is already floating (invalid state)")) { | ||
184 | return; | ||
185 | } | ||
186 | struct sway_workspace *ws = workspace->sway_workspace; | ||
187 | list_add(ws->floating, child); | ||
188 | child->parent = workspace; | ||
189 | child->is_floating = true; | ||
190 | } | ||
191 | |||
157 | void container_move_to(struct sway_container *container, | 192 | void container_move_to(struct sway_container *container, |
158 | struct sway_container *destination) { | 193 | struct sway_container *destination) { |
159 | if (container == destination | 194 | if (container == destination |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index f34baa9e..c4f8ac5e 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "sway/tree/arrange.h" | 12 | #include "sway/tree/arrange.h" |
13 | #include "sway/tree/container.h" | 13 | #include "sway/tree/container.h" |
14 | #include "sway/tree/workspace.h" | 14 | #include "sway/tree/workspace.h" |
15 | #include "list.h" | ||
15 | #include "log.h" | 16 | #include "log.h" |
16 | #include "util.h" | 17 | #include "util.h" |
17 | 18 | ||
@@ -64,6 +65,7 @@ struct sway_container *workspace_create(struct sway_container *output, | |||
64 | return NULL; | 65 | return NULL; |
65 | } | 66 | } |
66 | swayws->swayc = workspace; | 67 | swayws->swayc = workspace; |
68 | swayws->floating = create_list(); | ||
67 | workspace->sway_workspace = swayws; | 69 | workspace->sway_workspace = swayws; |
68 | 70 | ||
69 | container_add_child(output, workspace); | 71 | container_add_child(output, workspace); |