aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-08-19 16:25:04 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-08-20 10:17:32 +0100
commitf51b9478f28143a4f1887711497ff131f26ab1c4 (patch)
treeb996f6b4372972b1fcc11c84371049fe867fefdb /sway/commands/move.c
parentMerge pull request #2498 from RyanDwyer/fix-jumping-views (diff)
downloadsway-f51b9478f28143a4f1887711497ff131f26ab1c4.tar.gz
sway-f51b9478f28143a4f1887711497ff131f26ab1c4.tar.zst
sway-f51b9478f28143a4f1887711497ff131f26ab1c4.zip
commands: implement move absolute
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index c6dc0775..b256584b 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -359,7 +359,8 @@ static struct cmd_results *move_in_direction(struct sway_container *container,
359 359
360static const char *expected_position_syntax = 360static const char *expected_position_syntax =
361 "Expected 'move [absolute] position <x> [px] <y> [px]' or " 361 "Expected 'move [absolute] position <x> [px] <y> [px]' or "
362 "'move [absolute] position center|mouse'"; 362 "'move [absolute] position center' or "
363 "'move position cursor|mouse|pointer'";
363 364
364static struct cmd_results *move_to_position(struct sway_container *container, 365static struct cmd_results *move_to_position(struct sway_container *container,
365 int argc, char **argv) { 366 int argc, char **argv) {
@@ -371,7 +372,10 @@ static struct cmd_results *move_to_position(struct sway_container *container,
371 if (!argc) { 372 if (!argc) {
372 return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax); 373 return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax);
373 } 374 }
375
376 bool absolute = false;
374 if (strcmp(argv[0], "absolute") == 0) { 377 if (strcmp(argv[0], "absolute") == 0) {
378 absolute = true;
375 --argc; 379 --argc;
376 ++argv; 380 ++argv;
377 } 381 }
@@ -385,7 +389,8 @@ static struct cmd_results *move_to_position(struct sway_container *container,
385 if (!argc) { 389 if (!argc) {
386 return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax); 390 return cmd_results_new(CMD_FAILURE, "move", expected_position_syntax);
387 } 391 }
388 if (strcmp(argv[0], "mouse") == 0) { 392 if (strcmp(argv[0], "cursor") == 0 || strcmp(argv[0], "mouse") == 0 ||
393 strcmp(argv[0], "pointer") == 0) {
389 struct sway_seat *seat = config->handler_context.seat; 394 struct sway_seat *seat = config->handler_context.seat;
390 if (!seat->cursor) { 395 if (!seat->cursor) {
391 return cmd_results_new(CMD_FAILURE, "move", "No cursor device"); 396 return cmd_results_new(CMD_FAILURE, "move", "No cursor device");
@@ -395,9 +400,15 @@ static struct cmd_results *move_to_position(struct sway_container *container,
395 container_floating_move_to(container, lx, ly); 400 container_floating_move_to(container, lx, ly);
396 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 401 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
397 } else if (strcmp(argv[0], "center") == 0) { 402 } else if (strcmp(argv[0], "center") == 0) {
398 struct sway_container *ws = container_parent(container, C_WORKSPACE); 403 double lx, ly;
399 double lx = ws->x + (ws->width - container->width) / 2; 404 if (absolute) {
400 double ly = ws->y + (ws->height - container->height) / 2; 405 lx = root_container.x + (root_container.width - container->width) / 2;
406 ly = root_container.y + (root_container.height - container->height) / 2;
407 } else {
408 struct sway_container *ws = container_parent(container, C_WORKSPACE);
409 lx = ws->x + (ws->width - container->width) / 2;
410 ly = ws->y + (ws->height - container->height) / 2;
411 }
401 container_floating_move_to(container, lx, ly); 412 container_floating_move_to(container, lx, ly);
402 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 413 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
403 } 414 }
@@ -429,6 +440,11 @@ static struct cmd_results *move_to_position(struct sway_container *container,
429 "Invalid position specified"); 440 "Invalid position specified");
430 } 441 }
431 442
443 if (!absolute) {
444 struct sway_container *ws = container_parent(container, C_WORKSPACE);
445 lx += ws->x;
446 ly += ws->y;
447 }
432 container_floating_move_to(container, lx, ly); 448 container_floating_move_to(container, lx, ly);
433 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 449 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
434} 450}