diff options
-rw-r--r-- | sway/commands/move.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index 8111a07c..23d392f9 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <ctype.h> | 2 | #include <ctype.h> |
3 | #include <math.h> | ||
3 | #include <stdbool.h> | 4 | #include <stdbool.h> |
4 | #include <string.h> | 5 | #include <string.h> |
5 | #include <strings.h> | 6 | #include <strings.h> |
@@ -753,6 +754,39 @@ static struct cmd_results *cmd_move_in_direction( | |||
753 | return cmd_results_new(CMD_SUCCESS, NULL); | 754 | return cmd_results_new(CMD_SUCCESS, NULL); |
754 | } | 755 | } |
755 | 756 | ||
757 | static struct cmd_results *cmd_move_to_position_pointer( | ||
758 | struct sway_container *container) { | ||
759 | struct sway_seat *seat = config->handler_context.seat; | ||
760 | if (!seat->cursor) { | ||
761 | return cmd_results_new(CMD_FAILURE, "No cursor device"); | ||
762 | } | ||
763 | struct wlr_cursor *cursor = seat->cursor->cursor; | ||
764 | /* Determine where to put the window. */ | ||
765 | double lx = cursor->x - container->width / 2; | ||
766 | double ly = cursor->y - container->height / 2; | ||
767 | |||
768 | /* Correct target coordinates to be in bounds (on screen). */ | ||
769 | for (int i = 0; i < root->outputs->length; ++i) { | ||
770 | struct wlr_box box; | ||
771 | output_get_box(root->outputs->items[i], &box); | ||
772 | if (wlr_box_contains_point(&box, cursor->x, cursor->y)) { | ||
773 | lx = fmax(lx, box.x); | ||
774 | ly = fmax(ly, box.y); | ||
775 | if (lx + container->width > box.x + box.width) { | ||
776 | lx = box.x + box.width - container->width; | ||
777 | } | ||
778 | if (ly + container->height > box.y + box.height) { | ||
779 | ly = box.y + box.height - container->height; | ||
780 | } | ||
781 | break; | ||
782 | } | ||
783 | } | ||
784 | |||
785 | /* Actually move the container. */ | ||
786 | container_floating_move_to(container, lx, ly); | ||
787 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
788 | } | ||
789 | |||
756 | static const char expected_position_syntax[] = | 790 | static const char expected_position_syntax[] = |
757 | "Expected 'move [absolute] position <x> [px] <y> [px]' or " | 791 | "Expected 'move [absolute] position <x> [px] <y> [px]' or " |
758 | "'move [absolute] position center' or " | 792 | "'move [absolute] position center' or " |
@@ -790,14 +824,7 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) { | |||
790 | if (absolute) { | 824 | if (absolute) { |
791 | return cmd_results_new(CMD_INVALID, expected_position_syntax); | 825 | return cmd_results_new(CMD_INVALID, expected_position_syntax); |
792 | } | 826 | } |
793 | struct sway_seat *seat = config->handler_context.seat; | 827 | return cmd_move_to_position_pointer(container); |
794 | if (!seat->cursor) { | ||
795 | return cmd_results_new(CMD_FAILURE, "No cursor device"); | ||
796 | } | ||
797 | double lx = seat->cursor->cursor->x - container->width / 2; | ||
798 | double ly = seat->cursor->cursor->y - container->height / 2; | ||
799 | container_floating_move_to(container, lx, ly); | ||
800 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
801 | } else if (strcmp(argv[0], "center") == 0) { | 828 | } else if (strcmp(argv[0], "center") == 0) { |
802 | double lx, ly; | 829 | double lx, ly; |
803 | if (absolute) { | 830 | if (absolute) { |