diff options
author | Nils Schulte <git@nilsschulte.de> | 2020-07-16 12:04:29 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-07-21 10:07:01 +0200 |
commit | b513981378f0ba79a5d3b80b7410addf5595a8ee (patch) | |
tree | d9a2357a34c476c1d6fe28e28f5bd369bf1aa40e /sway | |
parent | 6898d1963f7a7f6dcc0bff5d4c484818f38cdacf (diff) |
added ppt unit to move position command
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/move.c | 88 | ||||
-rw-r--r-- | sway/sway.5.scd | 8 |
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) { return cmd_results_new(CMD_FAILURE, expected_position_syntax); } - double lx, ly; - char *inv; - lx = (double)strtol(argv[0], &inv, 10); - if (*inv != '\0' && strcasecmp(inv, "px") != 0) { - return cmd_results_new(CMD_FAILURE, "Invalid position specified"); + struct movement_amount lx = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID }; + // X direction + int num_consumed_args = parse_movement_amount(argc, argv, &lx); + argc -= num_consumed_args; + argv += num_consumed_args; + if (lx.unit == MOVEMENT_UNIT_INVALID) { + return cmd_results_new(CMD_INVALID, "Invalid x position specified"); + } + + struct movement_amount ly = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID }; + // Y direction + num_consumed_args = parse_movement_amount(argc, argv, &ly); + argc -= num_consumed_args; + argv += num_consumed_args; + if (argc > 0) { + return cmd_results_new(CMD_INVALID, expected_position_syntax); } - if (strcmp(argv[1], "px") == 0) { - --argc; - ++argv; + if (ly.unit == MOVEMENT_UNIT_INVALID) { + return cmd_results_new(CMD_INVALID, "Invalid y position specified"); } - if (argc > 3) { - return cmd_results_new(CMD_FAILURE, expected_position_syntax); + struct sway_workspace *ws = container->workspace; + if (!ws) { + struct sway_seat *seat = config->handler_context.seat; + ws = seat_get_focused_workspace(seat); } - ly = (double)strtol(argv[1], &inv, 10); - if ((*inv != '\0' && strcasecmp(inv, "px") != 0) || - (argc == 3 && strcmp(argv[2], "px") != 0)) { - return cmd_results_new(CMD_FAILURE, "Invalid position specified"); + switch (lx.unit) { + case MOVEMENT_UNIT_PPT: + if (container_is_scratchpad_hidden(container)) { + return cmd_results_new(CMD_FAILURE, + "Cannot move a hidden scratchpad container by ppt"); + } + if (absolute) { + return cmd_results_new(CMD_FAILURE, + "Cannot move to absolute positions by ppt"); + } + // Convert to px + lx.amount = ws->width * lx.amount / 100; + lx.unit = MOVEMENT_UNIT_PX; + // Falls through + case MOVEMENT_UNIT_PX: + case MOVEMENT_UNIT_DEFAULT: + break; + case MOVEMENT_UNIT_INVALID: + sway_assert(false, "invalid x unit"); + break; } - if (!absolute) { - struct sway_workspace *ws = container->workspace; - if (!ws) { - struct sway_seat *seat = config->handler_context.seat; - ws = seat_get_focused_workspace(seat); + switch (ly.unit) { + case MOVEMENT_UNIT_PPT: + if (container_is_scratchpad_hidden(container)) { + return cmd_results_new(CMD_FAILURE, + "Cannot move a hidden scratchpad container by ppt"); } - lx += ws->x; - ly += ws->y; + if (absolute) { + return cmd_results_new(CMD_FAILURE, + "Cannot move to absolute positions by ppt"); + } + // Convert to px + ly.amount = ws->height * ly.amount / 100; + ly.unit = MOVEMENT_UNIT_PX; + // Falls through + case MOVEMENT_UNIT_PX: + case MOVEMENT_UNIT_DEFAULT: + break; + case MOVEMENT_UNIT_INVALID: + sway_assert(false, "invalid y unit"); + break; + } + if (!absolute) { + lx.amount += ws->x; + ly.amount += ws->y; } - container_floating_move_to(container, lx, ly); + container_floating_move_to(container, lx.amount, ly.amount); return cmd_results_new(CMD_SUCCESS, NULL); } 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> If unspecified, the default is 10 pixels. Pixels are ignored when moving tiled containers. -*move* [absolute] position <pos_x> [px] <pos_y> [px] - Moves the focused container to the specified position in the workspace. If - _absolute_ is used, the position is relative to all outputs. +*move* [absolute] position <pos_x> [px|ppt] <pos_y> [px|ptt] + Moves the focused container to the specified position in the workspace. + The position can be specified in pixels or percentage points, ommitting + the unit defualts to pixels. If _absolute_ is used, the position is + relative to all outputs. _absolute_ can not be used with percentage points. *move* [absolute] position center Moves the focused container to be centered on the workspace. If _absolute_ |