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/output.h"
7 #include "sway/tree/arrange.h"
8 #include "sway/tree/container.h"
9 #include "sway/tree/view.h"
10 #include "sway/tree/workspace.h"
11 #include "list.h"
12 #include "util.h"
13
cmd_floating(int argc,char ** argv)14 struct cmd_results *cmd_floating(int argc, char **argv) {
15 struct cmd_results *error = NULL;
16 if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) {
17 return error;
18 }
19 if (!root->outputs->length) {
20 return cmd_results_new(CMD_INVALID,
21 "Can't run this command while there's no outputs connected.");
22 }
23 struct sway_container *container = config->handler_context.container;
24 struct sway_workspace *workspace = config->handler_context.workspace;
25 if (!container && workspace->tiling->length == 0) {
26 return cmd_results_new(CMD_INVALID, "Can't float an empty workspace");
27 }
28 if (!container) {
29 // Wrap the workspace's children in a container so we can float it
30 container = workspace_wrap_children(workspace);
31 workspace->layout = L_HORIZ;
32 seat_set_focus_container(config->handler_context.seat, container);
33 }
34
35 if (container_is_scratchpad_hidden(container)) {
36 return cmd_results_new(CMD_INVALID,
37 "Can't change floating on hidden scratchpad container");
38 }
39
40 // If the container is in a floating split container,
41 // operate on the split container instead of the child.
42 if (container_is_floating_or_child(container)) {
43 while (container->parent) {
44 container = container->parent;
45 }
46 }
47
48 bool wants_floating =
49 parse_boolean(argv[0], container_is_floating(container));
50
51 container_set_floating(container, wants_floating);
52
53 // Floating containers in the scratchpad should be ignored
54 if (container->workspace) {
55 arrange_workspace(container->workspace);
56 }
57
58 return cmd_results_new(CMD_SUCCESS, NULL);
59 }
60