aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
authorLibravatar Nils Schulte <git@nilsschulte.de>2020-07-16 12:04:29 +0200
committerLibravatar Simon Ser <contact@emersion.fr>2020-07-21 10:07:01 +0200
commitb513981378f0ba79a5d3b80b7410addf5595a8ee (patch)
treed9a2357a34c476c1d6fe28e28f5bd369bf1aa40e /sway/commands/move.c
parentmoved and renamed movement-unit parsing to common (diff)
downloadsway-b513981378f0ba79a5d3b80b7410addf5595a8ee.tar.gz
sway-b513981378f0ba79a5d3b80b7410addf5595a8ee.tar.zst
sway-b513981378f0ba79a5d3b80b7410addf5595a8ee.zip
added ppt unit to move position command
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c88
1 files changed, 66 insertions, 22 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 03839083..8111a07c 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -820,37 +820,81 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
820 return cmd_results_new(CMD_FAILURE, expected_position_syntax); 820 return cmd_results_new(CMD_FAILURE, expected_position_syntax);
821 } 821 }
822 822
823 double lx, ly; 823 struct movement_amount lx = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID };
824 char *inv; 824 // X direction
825 lx = (double)strtol(argv[0], &inv, 10); 825 int num_consumed_args = parse_movement_amount(argc, argv, &lx);
826 if (*inv != '\0' && strcasecmp(inv, "px") != 0) { 826 argc -= num_consumed_args;
827 return cmd_results_new(CMD_FAILURE, "Invalid position specified"); 827 argv += num_consumed_args;
828 if (lx.unit == MOVEMENT_UNIT_INVALID) {
829 return cmd_results_new(CMD_INVALID, "Invalid x position specified");
830 }
831
832 struct movement_amount ly = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID };
833 // Y direction
834 num_consumed_args = parse_movement_amount(argc, argv, &ly);
835 argc -= num_consumed_args;
836 argv += num_consumed_args;
837 if (argc > 0) {
838 return cmd_results_new(CMD_INVALID, expected_position_syntax);
828 } 839 }
829 if (strcmp(argv[1], "px") == 0) { 840 if (ly.unit == MOVEMENT_UNIT_INVALID) {
830 --argc; 841 return cmd_results_new(CMD_INVALID, "Invalid y position specified");
831 ++argv;
832 } 842 }
833 843
834 if (argc > 3) { 844 struct sway_workspace *ws = container->workspace;
835 return cmd_results_new(CMD_FAILURE, expected_position_syntax); 845 if (!ws) {
846 struct sway_seat *seat = config->handler_context.seat;
847 ws = seat_get_focused_workspace(seat);
836 } 848 }
837 849
838 ly = (double)strtol(argv[1], &inv, 10); 850 switch (lx.unit) {
839 if ((*inv != '\0' && strcasecmp(inv, "px") != 0) || 851 case MOVEMENT_UNIT_PPT:
840 (argc == 3 && strcmp(argv[2], "px") != 0)) { 852 if (container_is_scratchpad_hidden(container)) {
841 return cmd_results_new(CMD_FAILURE, "Invalid position specified"); 853 return cmd_results_new(CMD_FAILURE,
854 "Cannot move a hidden scratchpad container by ppt");
855 }
856 if (absolute) {
857 return cmd_results_new(CMD_FAILURE,
858 "Cannot move to absolute positions by ppt");
859 }
860 // Convert to px
861 lx.amount = ws->width * lx.amount / 100;
862 lx.unit = MOVEMENT_UNIT_PX;
863 // Falls through
864 case MOVEMENT_UNIT_PX:
865 case MOVEMENT_UNIT_DEFAULT:
866 break;
867 case MOVEMENT_UNIT_INVALID:
868 sway_assert(false, "invalid x unit");
869 break;
842 } 870 }
843 871
844 if (!absolute) { 872 switch (ly.unit) {
845 struct sway_workspace *ws = container->workspace; 873 case MOVEMENT_UNIT_PPT:
846 if (!ws) { 874 if (container_is_scratchpad_hidden(container)) {
847 struct sway_seat *seat = config->handler_context.seat; 875 return cmd_results_new(CMD_FAILURE,
848 ws = seat_get_focused_workspace(seat); 876 "Cannot move a hidden scratchpad container by ppt");
849 } 877 }
850 lx += ws->x; 878 if (absolute) {
851 ly += ws->y; 879 return cmd_results_new(CMD_FAILURE,
880 "Cannot move to absolute positions by ppt");
881 }
882 // Convert to px
883 ly.amount = ws->height * ly.amount / 100;
884 ly.unit = MOVEMENT_UNIT_PX;
885 // Falls through
886 case MOVEMENT_UNIT_PX:
887 case MOVEMENT_UNIT_DEFAULT:
888 break;
889 case MOVEMENT_UNIT_INVALID:
890 sway_assert(false, "invalid y unit");
891 break;
892 }
893 if (!absolute) {
894 lx.amount += ws->x;
895 ly.amount += ws->y;
852 } 896 }
853 container_floating_move_to(container, lx, ly); 897 container_floating_move_to(container, lx.amount, ly.amount);
854 return cmd_results_new(CMD_SUCCESS, NULL); 898 return cmd_results_new(CMD_SUCCESS, NULL);
855} 899}
856 900