diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c index f0db4ed2..5035316e 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "workspace.h" | 13 | #include "workspace.h" |
14 | #include "commands.h" | 14 | #include "commands.h" |
15 | #include "container.h" | 15 | #include "container.h" |
16 | #include "handlers.h" | ||
16 | 17 | ||
17 | struct modifier_key { | 18 | struct modifier_key { |
18 | char *name; | 19 | char *name; |
@@ -169,6 +170,77 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) { | |||
169 | return true; | 170 | return true; |
170 | } | 171 | } |
171 | 172 | ||
173 | static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | ||
174 | if (strcasecmp(argv[0], "toggle") == 0) { | ||
175 | swayc_t *view = get_focused_container(&root_container); | ||
176 | // Prevent running floating commands on things like workspaces | ||
177 | if (view->type != C_VIEW) { | ||
178 | return true; | ||
179 | } | ||
180 | int i; | ||
181 | // Change from nonfloating to floating | ||
182 | if (!view->is_floating) { | ||
183 | view->is_floating = true; | ||
184 | for (i = 0; i < view->parent->children->length; i++) { | ||
185 | if (view->parent->children->items[i] == view) { | ||
186 | // Try to use desired geometry to set w/h | ||
187 | if (view->desired_width != -1) { | ||
188 | view->width = view->desired_width; | ||
189 | } | ||
190 | if (view->desired_height != -1) { | ||
191 | view->height = view->desired_height; | ||
192 | } | ||
193 | |||
194 | // Swap from the list of whatever container the view was in | ||
195 | // to the workspace->floating list | ||
196 | list_del(view->parent->children, i); | ||
197 | list_add(active_workspace->floating, view); | ||
198 | destroy_container(view->parent); | ||
199 | |||
200 | // Set the new position of the container and arrange windows | ||
201 | view->x = (active_workspace->width - view->width)/2; | ||
202 | view->y = (active_workspace->height - view->height)/2; | ||
203 | sway_log(L_INFO, "Setting container %p to floating at coordinates X:%d Y:%d, W:%d, H:%d", view, view->x, view->y, view->width, view->height); | ||
204 | // Change parent to active_workspace | ||
205 | view->parent = active_workspace; | ||
206 | arrange_windows(active_workspace, -1, -1); | ||
207 | return true; | ||
208 | } | ||
209 | } | ||
210 | } else { | ||
211 | // Delete the view from the floating list and unset its is_floating flag | ||
212 | // Using length-1 as the index is safe because the view must be the currently | ||
213 | // focused floating output | ||
214 | list_del(active_workspace->floating, active_workspace->floating->length - 1); | ||
215 | view->is_floating = false; | ||
216 | active_workspace->focused = NULL; | ||
217 | // Get the properly focused container, and add in the view there | ||
218 | swayc_t *focused = focus_pointer(); | ||
219 | // If focused is null, it's because the currently focused container is a workspace | ||
220 | if (focused == NULL) { | ||
221 | focused = active_workspace; | ||
222 | } | ||
223 | |||
224 | sway_log(L_DEBUG, "Non-floating focused container is %p", focused); | ||
225 | |||
226 | //Case of focused workspace, just create as child of it | ||
227 | if (focused->type == C_WORKSPACE) { | ||
228 | add_child(focused, view); | ||
229 | } | ||
230 | //Regular case, create as sibling of current container | ||
231 | else { | ||
232 | add_sibling(focused, view); | ||
233 | } | ||
234 | // Refocus on the view once its been put back into the layout | ||
235 | focus_view(view); | ||
236 | arrange_windows(active_workspace, -1, -1); | ||
237 | return true; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | return true; | ||
242 | } | ||
243 | |||
172 | static bool cmd_focus(struct sway_config *config, int argc, char **argv) { | 244 | static bool cmd_focus(struct sway_config *config, int argc, char **argv) { |
173 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { | 245 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { |
174 | return false; | 246 | return false; |
@@ -378,6 +450,7 @@ static struct cmd_handler handlers[] = { | |||
378 | { "exec", cmd_exec }, | 450 | { "exec", cmd_exec }, |
379 | { "exec_always", cmd_exec_always }, | 451 | { "exec_always", cmd_exec_always }, |
380 | { "exit", cmd_exit }, | 452 | { "exit", cmd_exit }, |
453 | { "floating", cmd_floating }, | ||
381 | { "focus", cmd_focus }, | 454 | { "focus", cmd_focus }, |
382 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | 455 | { "focus_follows_mouse", cmd_focus_follows_mouse }, |
383 | { "fullscreen", cmd_fullscreen }, | 456 | { "fullscreen", cmd_fullscreen }, |