summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-10-28 15:54:28 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-10-28 15:54:28 -0400
commit239f4bd0ba9e849a7041cfed2dcc16e1a484b5cc (patch)
treeb35493c3ef4b83f8ef4b344ad7e0683e58200654
parentMerge pull request #209 from sce/fix_seamless_mouse (diff)
parentcommands: Learn 'focus output <direction|name>' (diff)
downloadsway-239f4bd0ba9e849a7041cfed2dcc16e1a484b5cc.tar.gz
sway-239f4bd0ba9e849a7041cfed2dcc16e1a484b5cc.tar.zst
sway-239f4bd0ba9e849a7041cfed2dcc16e1a484b5cc.zip
Merge pull request #210 from sce/focus_output
commands: Learn 'focus output <direction|name>'
-rw-r--r--sway.5.txt5
-rw-r--r--sway/commands.c19
-rw-r--r--sway/layout.c7
3 files changed, 27 insertions, 4 deletions
diff --git a/sway.5.txt b/sway.5.txt
index d97720c5..dad55c5f 100644
--- a/sway.5.txt
+++ b/sway.5.txt
@@ -53,6 +53,11 @@ Commands
53 container, which is useful, for example, to open a sibling of the parent 53 container, which is useful, for example, to open a sibling of the parent
54 container, or to move the entire container around. 54 container, or to move the entire container around.
55 55
56**focus** output <direction|name>::
57 Direction may be one of _up_, _down_, _left_, _right_. The directional focus
58 commands will move the focus to the output in that direction. When name is
59 given the focus is changed to the output with that name.
60
56**focus** mode_toggle:: 61**focus** mode_toggle::
57 Toggles focus between floating view and tiled view. 62 Toggles focus between floating view and tiled view.
58 63
diff --git a/sway/commands.c b/sway/commands.c
index c81379fd..441b6fd7 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -17,6 +17,7 @@
17#include "workspace.h" 17#include "workspace.h"
18#include "commands.h" 18#include "commands.h"
19#include "container.h" 19#include "container.h"
20#include "output.h"
20#include "handlers.h" 21#include "handlers.h"
21#include "sway.h" 22#include "sway.h"
22#include "resize.h" 23#include "resize.h"
@@ -372,7 +373,20 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) {
372static struct cmd_results *cmd_focus(int argc, char **argv) { 373static struct cmd_results *cmd_focus(int argc, char **argv) {
373 if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file."); 374 if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file.");
374 struct cmd_results *error = NULL; 375 struct cmd_results *error = NULL;
375 if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) { 376 if (argc > 0 && strcasecmp(argv[0], "output") == 0) {
377 swayc_t *output = NULL;
378 if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 2))) {
379 return error;
380 } else if (!(output = output_by_name(argv[1]))) {
381 return cmd_results_new(CMD_FAILURE, "focus output",
382 "Can't find output with name/at direction %s", argv[1]);
383 } else if (!workspace_switch(swayc_active_workspace_for(output))) {
384 return cmd_results_new(CMD_FAILURE, "focus output",
385 "Switching to workspace on output '%s' was blocked", argv[1]);
386 } else {
387 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
388 }
389 } else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) {
376 return error; 390 return error;
377 } 391 }
378 static int floating_toggled_index = 0; 392 static int floating_toggled_index = 0;
@@ -424,6 +438,9 @@ static struct cmd_results *cmd_focus(int argc, char **argv) {
424 } 438 }
425 } 439 }
426 } 440 }
441 } else {
442 return cmd_results_new(CMD_INVALID, "focus",
443 "Expected 'focus <direction|parent|mode_toggle>' or 'focus output <direction|name>'");
427 } 444 }
428 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 445 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
429} 446}
diff --git a/sway/layout.c b/sway/layout.c
index 6388a9b2..29772172 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -289,15 +289,16 @@ void move_container_to(swayc_t* container, swayc_t* destination) {
289 return; 289 return;
290 } 290 }
291 swayc_t *parent = remove_child(container); 291 swayc_t *parent = remove_child(container);
292 // reset container geometry
293 container->width = container->height = 0;
294
295 // Send to new destination 292 // Send to new destination
296 if (container->is_floating) { 293 if (container->is_floating) {
297 add_floating(swayc_active_workspace_for(destination), container); 294 add_floating(swayc_active_workspace_for(destination), container);
298 } else if (destination->type == C_WORKSPACE) { 295 } else if (destination->type == C_WORKSPACE) {
296 // reset container geometry
297 container->width = container->height = 0;
299 add_child(destination, container); 298 add_child(destination, container);
300 } else { 299 } else {
300 // reset container geometry
301 container->width = container->height = 0;
301 add_sibling(destination, container); 302 add_sibling(destination, container);
302 } 303 }
303 // Destroy old container if we need to 304 // Destroy old container if we need to