aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Thayne McCombs <astrothayne@gmail.com>2020-01-21 01:32:22 -0700
committerLibravatar Simon Ser <contact@emersion.fr>2020-07-27 11:27:47 +0200
commitcfa403fc58f3df9cdef2bc03d0a8bbdd4333ed00 (patch)
treef3fe67513a7b4d574039d7f1b55b0cffc4cf673f /sway/commands
parentcommands: disallow runtime include (diff)
downloadsway-cfa403fc58f3df9cdef2bc03d0a8bbdd4333ed00.tar.gz
sway-cfa403fc58f3df9cdef2bc03d0a8bbdd4333ed00.tar.zst
sway-cfa403fc58f3df9cdef2bc03d0a8bbdd4333ed00.zip
Keep windows in bounds on move to position mouse
If the mouse/cursor/pointer is near the edge of an output when a "move position to pointer" command is run, then the floating container will be constrained to fit inside the bounds of the output as much as possible. This behavior matches what i3 does in this scenario. I also think it is a better user experience. Relates to #4906 The logic for the bounds check follows the implementation in i3: https://github.com/i3/i3/blob/733077822302d8b77eacb606a26fd002a42f534f/src/floating.c#L536
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/move.c43
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
757static 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
756static const char expected_position_syntax[] = 790static 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) {