summaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 441b6fd7..00a4d1b0 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -21,6 +21,7 @@
21#include "handlers.h" 21#include "handlers.h"
22#include "sway.h" 22#include "sway.h"
23#include "resize.h" 23#include "resize.h"
24#include "input_state.h"
24 25
25typedef struct cmd_results *sway_cmd(int argc, char **argv); 26typedef struct cmd_results *sway_cmd(int argc, char **argv);
26 27
@@ -45,6 +46,7 @@ static sway_cmd cmd_kill;
45static sway_cmd cmd_layout; 46static sway_cmd cmd_layout;
46static sway_cmd cmd_log_colors; 47static sway_cmd cmd_log_colors;
47static sway_cmd cmd_mode; 48static sway_cmd cmd_mode;
49static sway_cmd cmd_mouse_warping;
48static sway_cmd cmd_move; 50static sway_cmd cmd_move;
49static sway_cmd cmd_output; 51static sway_cmd cmd_output;
50static sway_cmd cmd_reload; 52static sway_cmd cmd_reload;
@@ -383,9 +385,13 @@ static struct cmd_results *cmd_focus(int argc, char **argv) {
383 } else if (!workspace_switch(swayc_active_workspace_for(output))) { 385 } else if (!workspace_switch(swayc_active_workspace_for(output))) {
384 return cmd_results_new(CMD_FAILURE, "focus output", 386 return cmd_results_new(CMD_FAILURE, "focus output",
385 "Switching to workspace on output '%s' was blocked", argv[1]); 387 "Switching to workspace on output '%s' was blocked", argv[1]);
386 } else { 388 } else if (config->mouse_warping) {
387 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 389 swayc_t *focused = get_focused_view(output);
390 if (focused && focused->type == C_VIEW) {
391 center_pointer_on(focused);
392 }
388 } 393 }
394 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
389 } else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) { 395 } else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) {
390 return error; 396 return error;
391 } 397 }
@@ -528,6 +534,20 @@ static struct cmd_results *cmd_mode(int argc, char **argv) {
528 return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL); 534 return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL);
529} 535}
530 536
537static struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
538 struct cmd_results *error = NULL;
539 if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) {
540 return error;
541 } else if (strcasecmp(argv[0], "output") == 0) {
542 config->mouse_warping = true;
543 } else if (strcasecmp(argv[0], "none") == 0) {
544 config->mouse_warping = false;
545 } else {
546 return cmd_results_new(CMD_FAILURE, "mouse_warping", "Expected 'mouse_warping output|none'");
547 }
548 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
549}
550
531static struct cmd_results *cmd_move(int argc, char **argv) { 551static struct cmd_results *cmd_move(int argc, char **argv) {
532 struct cmd_results *error = NULL; 552 struct cmd_results *error = NULL;
533 if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); 553 if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file.");
@@ -1165,7 +1185,16 @@ static struct cmd_results *cmd_workspace(int argc, char **argv) {
1165 ws = workspace_create(argv[0]); 1185 ws = workspace_create(argv[0]);
1166 } 1186 }
1167 } 1187 }
1188 swayc_t *old_output = swayc_active_output();
1168 workspace_switch(ws); 1189 workspace_switch(ws);
1190 swayc_t *new_output = swayc_active_output();
1191
1192 if (config->mouse_warping && old_output != new_output) {
1193 swayc_t *focused = get_focused_view(ws);
1194 if (focused && focused->type == C_VIEW) {
1195 center_pointer_on(focused);
1196 }
1197 }
1169 } else { 1198 } else {
1170 if (strcasecmp(argv[1], "output") == 0) { 1199 if (strcasecmp(argv[1], "output") == 0) {
1171 if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3))) { 1200 if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3))) {
@@ -1217,6 +1246,7 @@ static struct cmd_handler handlers[] = {
1217 { "layout", cmd_layout }, 1246 { "layout", cmd_layout },
1218 { "log_colors", cmd_log_colors }, 1247 { "log_colors", cmd_log_colors },
1219 { "mode", cmd_mode }, 1248 { "mode", cmd_mode },
1249 { "mouse_warping", cmd_mouse_warping },
1220 { "move", cmd_move }, 1250 { "move", cmd_move },
1221 { "output", cmd_output }, 1251 { "output", cmd_output },
1222 { "reload", cmd_reload }, 1252 { "reload", cmd_reload },