diff options
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r-- | sway/commands/move.c | 189 |
1 files changed, 0 insertions, 189 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c deleted file mode 100644 index 52c73e22..00000000 --- a/sway/commands/move.c +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include <wlc/wlc.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/layout.h" | ||
8 | #include "sway/output.h" | ||
9 | #include "sway/workspace.h" | ||
10 | #include "list.h" | ||
11 | #include "stringop.h" | ||
12 | |||
13 | struct cmd_results *cmd_move(int argc, char **argv) { | ||
14 | struct cmd_results *error = NULL; | ||
15 | int move_amt = 10; | ||
16 | |||
17 | if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); | ||
18 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { | ||
19 | return error; | ||
20 | } | ||
21 | const char* expected_syntax = "Expected 'move <left|right|up|down|next|prev|first> <[px] px>' or " | ||
22 | "'move <container|window> to workspace <name>' or " | ||
23 | "'move <container|window|workspace> to output <name|direction>' or " | ||
24 | "'move position mouse'"; | ||
25 | swayc_t *view = current_container; | ||
26 | |||
27 | if (argc == 2 || (argc == 3 && strcasecmp(argv[2], "px") == 0 )) { | ||
28 | char *inv; | ||
29 | move_amt = (int)strtol(argv[1], &inv, 10); | ||
30 | if (*inv != '\0' && strcasecmp(inv, "px") != 0) { | ||
31 | move_amt = 10; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | if (strcasecmp(argv[0], "left") == 0) { | ||
36 | move_container(view, MOVE_LEFT, move_amt); | ||
37 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
38 | move_container(view, MOVE_RIGHT, move_amt); | ||
39 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
40 | move_container(view, MOVE_UP, move_amt); | ||
41 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
42 | move_container(view, MOVE_DOWN, move_amt); | ||
43 | } else if (strcasecmp(argv[0], "next") == 0) { | ||
44 | move_container(view, MOVE_NEXT, move_amt); | ||
45 | } else if (strcasecmp(argv[0], "prev") == 0) { | ||
46 | move_container(view, MOVE_PREV, move_amt); | ||
47 | } else if (strcasecmp(argv[0], "first") == 0) { | ||
48 | move_container(view, MOVE_FIRST, move_amt); | ||
49 | } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { | ||
50 | // "move container ... | ||
51 | if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) { | ||
52 | return error; | ||
53 | } else if (strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "workspace") == 0) { | ||
54 | // move container to workspace x | ||
55 | if (view->type == C_WORKSPACE) { | ||
56 | if (!view->children || view->children->length == 0) { | ||
57 | return cmd_results_new(CMD_FAILURE, "move", "Cannot move an empty workspace"); | ||
58 | } | ||
59 | view = new_container(view, view->workspace_layout); | ||
60 | } if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
61 | return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); | ||
62 | } | ||
63 | |||
64 | swayc_t *ws; | ||
65 | const char *num_name = NULL; | ||
66 | char *ws_name = NULL; | ||
67 | if (argc == 5 && strcasecmp(argv[3], "number") == 0) { | ||
68 | // move "container to workspace number x" | ||
69 | num_name = argv[4]; | ||
70 | ws = workspace_by_number(num_name); | ||
71 | } else { | ||
72 | ws_name = join_args(argv + 3, argc - 3); | ||
73 | ws = workspace_by_name(ws_name); | ||
74 | } | ||
75 | |||
76 | if (ws == NULL) { | ||
77 | ws = workspace_create(ws_name ? ws_name : num_name); | ||
78 | } | ||
79 | if (ws_name) { | ||
80 | free(ws_name); | ||
81 | } | ||
82 | move_container_to(view, get_focused_container(ws)); | ||
83 | } else if (strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "output") == 0) { | ||
84 | // move container to output x | ||
85 | swayc_t *output = NULL; | ||
86 | struct wlc_point abs_pos; | ||
87 | get_absolute_center_position(view, &abs_pos); | ||
88 | if (view->type == C_WORKSPACE) { | ||
89 | if (!view->children || view->children->length == 0) { | ||
90 | return cmd_results_new(CMD_FAILURE, "move", "Cannot move an empty workspace"); | ||
91 | } | ||
92 | view = new_container(view, view->workspace_layout); | ||
93 | } else if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
94 | return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); | ||
95 | } else if (!(output = output_by_name(argv[3], &abs_pos))) { | ||
96 | return cmd_results_new(CMD_FAILURE, "move", | ||
97 | "Can't find output with name/direction '%s' @ (%i,%i)", argv[3], abs_pos.x, abs_pos.y); | ||
98 | } | ||
99 | |||
100 | swayc_t *container = get_focused_container(output); | ||
101 | if (container->is_floating) { | ||
102 | move_container_to(view, container->parent); | ||
103 | } else { | ||
104 | move_container_to(view, container); | ||
105 | } | ||
106 | } else { | ||
107 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
108 | } | ||
109 | } else if (strcasecmp(argv[0], "workspace") == 0) { | ||
110 | // move workspace (to output x) | ||
111 | swayc_t *output = NULL; | ||
112 | struct wlc_point abs_pos; | ||
113 | get_absolute_center_position(view, &abs_pos); | ||
114 | if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 4))) { | ||
115 | return error; | ||
116 | } else if (strcasecmp(argv[1], "to") != 0 || strcasecmp(argv[2], "output") != 0) { | ||
117 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
118 | } else if (!(output = output_by_name(argv[3], &abs_pos))) { | ||
119 | return cmd_results_new(CMD_FAILURE, "move workspace", | ||
120 | "Can't find output with name/direction '%s' @ (%i,%i)", argv[3], abs_pos.x, abs_pos.y); | ||
121 | } | ||
122 | if (view->type == C_WORKSPACE) { | ||
123 | // This probably means we're moving an empty workspace, but | ||
124 | // that's fine. | ||
125 | move_workspace_to(view, output); | ||
126 | } else { | ||
127 | swayc_t *workspace = swayc_parent_by_type(view, C_WORKSPACE); | ||
128 | move_workspace_to(workspace, output); | ||
129 | } | ||
130 | } else if (strcasecmp(argv[0], "scratchpad") == 0 || (strcasecmp(argv[0], "to") == 0 && strcasecmp(argv[1], "scratchpad") == 0)) { | ||
131 | // move scratchpad ... | ||
132 | if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
133 | return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views."); | ||
134 | } | ||
135 | swayc_t *view = current_container; | ||
136 | int i; | ||
137 | for (i = 0; i < scratchpad->length; i++) { | ||
138 | if (scratchpad->items[i] == view) { | ||
139 | hide_view_in_scratchpad(view); | ||
140 | sp_view = NULL; | ||
141 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
142 | } | ||
143 | } | ||
144 | list_add(scratchpad, view); | ||
145 | if (!view->is_floating) { | ||
146 | destroy_container(remove_child(view)); | ||
147 | } else { | ||
148 | remove_child(view); | ||
149 | } | ||
150 | wlc_view_set_mask(view->handle, 0); | ||
151 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
152 | swayc_t *focused = container_under_pointer(); | ||
153 | if (focused == NULL) { | ||
154 | focused = swayc_active_workspace(); | ||
155 | } | ||
156 | set_focused_container(focused); | ||
157 | } else if (strcasecmp(argv[0], "position") == 0) { | ||
158 | if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 2))) { | ||
159 | return error; | ||
160 | } | ||
161 | if (strcasecmp(argv[1], "mouse")) { | ||
162 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
163 | } | ||
164 | |||
165 | if (view->is_floating) { | ||
166 | swayc_t *output = swayc_parent_by_type(view, C_OUTPUT); | ||
167 | struct wlc_geometry g; | ||
168 | wlc_view_get_visible_geometry(view->handle, &g); | ||
169 | const struct wlc_size *size = wlc_output_get_resolution(output->handle); | ||
170 | |||
171 | double x_pos, y_pos; | ||
172 | wlc_pointer_get_position_v2(&x_pos, &y_pos); | ||
173 | |||
174 | int32_t x = x_pos - g.size.w / 2; | ||
175 | int32_t y = y_pos - g.size.h / 2; | ||
176 | |||
177 | uint32_t w = size->w - g.size.w; | ||
178 | uint32_t h = size->h - g.size.h; | ||
179 | |||
180 | view->x = g.origin.x = MIN((int32_t)w, MAX(x, 0)); | ||
181 | view->y = g.origin.y = MIN((int32_t)h, MAX(y, 0)); | ||
182 | |||
183 | wlc_view_set_geometry(view->handle, 0, &g); | ||
184 | } | ||
185 | } else { | ||
186 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
187 | } | ||
188 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
189 | } | ||