summaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c
index f0db4ed2..91dfa2b2 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
17struct modifier_key { 18struct modifier_key {
18 char *name; 19 char *name;
@@ -169,6 +170,72 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) {
169 return true; 170 return true;
170} 171}
171 172
173static 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 // Cut down on width/height so it's obvious that you've gone floating
187 // if this is the only view
188 view->width = view->width - 30;
189 view->height = view->height - 30;
190
191 // Swap from the list of whatever container the view was in
192 // to the workspace->floating list
193 // TODO: Destroy any remaining empty containers
194 list_del(view->parent->children, i);
195 list_add(active_workspace->floating, view);
196
197 // Set the new position of the container and arrange windows
198 view->x = (active_workspace->width - view->width)/2;
199 view->y = (active_workspace->height - view->height)/2;
200 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);
201 // Change parent to active_workspace
202 view->parent = active_workspace;
203 arrange_windows(active_workspace, -1, -1);
204 return true;
205 }
206 }
207 } else {
208 // Delete the view from the floating list and unset its is_floating flag
209 // Using length-1 as the index is safe because the view must be the currently
210 // focused floating output
211 list_del(active_workspace->floating, active_workspace->floating->length - 1);
212 view->is_floating = false;
213 active_workspace->focused = NULL;
214 // Get the properly focused container, and add in the view there
215 swayc_t *focused = focus_pointer();
216 // If focused is null, it's because the currently focused container is a workspace
217 if (focused == NULL) {
218 focused = active_workspace;
219 }
220
221 sway_log(L_DEBUG, "Non-floating focused container is %p", focused);
222
223 //Case of focused workspace, just create as child of it
224 if (focused->type == C_WORKSPACE) {
225 add_child(focused, view);
226 }
227 //Regular case, create as sibling of current container
228 else {
229 add_sibling(focused, view);
230 }
231 arrange_windows(active_workspace, -1, -1);
232 return true;
233 }
234 }
235
236 return true;
237}
238
172static bool cmd_focus(struct sway_config *config, int argc, char **argv) { 239static bool cmd_focus(struct sway_config *config, int argc, char **argv) {
173 if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { 240 if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) {
174 return false; 241 return false;
@@ -378,6 +445,7 @@ static struct cmd_handler handlers[] = {
378 { "exec", cmd_exec }, 445 { "exec", cmd_exec },
379 { "exec_always", cmd_exec_always }, 446 { "exec_always", cmd_exec_always },
380 { "exit", cmd_exit }, 447 { "exit", cmd_exit },
448 { "floating", cmd_floating },
381 { "focus", cmd_focus }, 449 { "focus", cmd_focus },
382 { "focus_follows_mouse", cmd_focus_follows_mouse }, 450 { "focus_follows_mouse", cmd_focus_follows_mouse },
383 { "fullscreen", cmd_fullscreen }, 451 { "fullscreen", cmd_fullscreen },