aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--sway/commands/move.c88
-rw-r--r--sway/sway.5.scd8
2 files changed, 71 insertions, 25 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
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 6e3ae86d..65ae9087 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -215,9 +215,11 @@ set|plus|minus <amount>
215 If unspecified, the default is 10 pixels. Pixels are ignored when moving 215 If unspecified, the default is 10 pixels. Pixels are ignored when moving
216 tiled containers. 216 tiled containers.
217 217
218*move* [absolute] position <pos_x> [px] <pos_y> [px] 218*move* [absolute] position <pos_x> [px|ppt] <pos_y> [px|ptt]
219 Moves the focused container to the specified position in the workspace. If 219 Moves the focused container to the specified position in the workspace.
220 _absolute_ is used, the position is relative to all outputs. 220 The position can be specified in pixels or percentage points, ommitting
221 the unit defualts to pixels. If _absolute_ is used, the position is
222 relative to all outputs. _absolute_ can not be used with percentage points.
221 223
222*move* [absolute] position center 224*move* [absolute] position center
223 Moves the focused container to be centered on the workspace. If _absolute_ 225 Moves the focused container to be centered on the workspace. If _absolute_