diff options
author | Ryan Dwyer <RyanDwyer@users.noreply.github.com> | 2018-08-25 13:24:12 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-25 13:24:12 +1000 |
commit | 33d102265098f76517be7a6032d4f828c6bd32f4 (patch) | |
tree | f1ed7e866d4e34f5ef9b8f72ec8095369619aaa7 | |
parent | Merge pull request #2499 from RyanDwyer/refactor-destroy-functions (diff) | |
parent | Merge branch 'master' into commands (diff) | |
download | sway-33d102265098f76517be7a6032d4f828c6bd32f4.tar.gz sway-33d102265098f76517be7a6032d4f828c6bd32f4.tar.zst sway-33d102265098f76517be7a6032d4f828c6bd32f4.zip |
Merge pull request #2495 from ianyfan/commands
commands: implement move absolute
-rw-r--r-- | sway/commands/move.c | 26 | ||||
-rw-r--r-- | sway/sway.5.scd | 11 |
2 files changed, 29 insertions, 8 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index 4c0189ec..087423de 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 | ||
360 | static const char *expected_position_syntax = | 360 | static 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 | ||
364 | static struct cmd_results *move_to_position(struct sway_container *container, | 365 | static 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 | } |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 83188067..927bf55c 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -133,10 +133,15 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1). | |||
133 | tiled containers. | 133 | tiled containers. |
134 | 134 | ||
135 | *move* [absolute] position <pos\_x> [px] <pos\_y> [px] | 135 | *move* [absolute] position <pos\_x> [px] <pos\_y> [px] |
136 | Moves the focused container to the specified position. | 136 | Moves the focused container to the specified position in the workspace. If |
137 | _absolute_ is used, the position is relative to all outputs. | ||
137 | 138 | ||
138 | *move* [absolute] position center|mouse | 139 | *move* [absolute] position center |
139 | Moves the focused container to be centered on the workspace or mouse. | 140 | Moves the focused container to be centered on the workspace. If _absolute_ |
141 | is used, it is moved to the center of all outputs. | ||
142 | |||
143 | *move* position cursor|mouse|pointer | ||
144 | Moves the focused container to be centered on the cursor. | ||
140 | 145 | ||
141 | *move* container|window [to] mark <mark> | 146 | *move* container|window [to] mark <mark> |
142 | Moves the focused container to the specified mark. | 147 | Moves the focused container to the specified mark. |