added ppt unit to move position command

master
Nils Schulte 5 years ago committed by Simon Ser
parent 6898d1963f
commit b513981378

@ -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); return cmd_results_new(CMD_FAILURE, expected_position_syntax);
} }
double lx, ly; struct movement_amount lx = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID };
char *inv; // X direction
lx = (double)strtol(argv[0], &inv, 10); int num_consumed_args = parse_movement_amount(argc, argv, &lx);
if (*inv != '\0' && strcasecmp(inv, "px") != 0) { argc -= num_consumed_args;
return cmd_results_new(CMD_FAILURE, "Invalid position specified"); 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) { if (ly.unit == MOVEMENT_UNIT_INVALID) {
--argc; return cmd_results_new(CMD_INVALID, "Invalid y position specified");
++argv;
} }
if (argc > 3) { struct sway_workspace *ws = container->workspace;
return cmd_results_new(CMD_FAILURE, expected_position_syntax); if (!ws) {
struct sway_seat *seat = config->handler_context.seat;
ws = seat_get_focused_workspace(seat);
} }
ly = (double)strtol(argv[1], &inv, 10); switch (lx.unit) {
if ((*inv != '\0' && strcasecmp(inv, "px") != 0) || case MOVEMENT_UNIT_PPT:
(argc == 3 && strcmp(argv[2], "px") != 0)) { if (container_is_scratchpad_hidden(container)) {
return cmd_results_new(CMD_FAILURE, "Invalid position specified"); 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) { switch (ly.unit) {
struct sway_workspace *ws = container->workspace; case MOVEMENT_UNIT_PPT:
if (!ws) { if (container_is_scratchpad_hidden(container)) {
struct sway_seat *seat = config->handler_context.seat; return cmd_results_new(CMD_FAILURE,
ws = seat_get_focused_workspace(seat); "Cannot move a hidden scratchpad container by ppt");
} }
lx += ws->x; if (absolute) {
ly += ws->y; 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); return cmd_results_new(CMD_SUCCESS, NULL);
} }

@ -215,9 +215,11 @@ set|plus|minus <amount>
If unspecified, the default is 10 pixels. Pixels are ignored when moving If unspecified, the default is 10 pixels. Pixels are ignored when moving
tiled containers. tiled containers.
*move* [absolute] position <pos_x> [px] <pos_y> [px] *move* [absolute] position <pos_x> [px|ppt] <pos_y> [px|ptt]
Moves the focused container to the specified position in the workspace. If Moves the focused container to the specified position in the workspace.
_absolute_ is used, the position is relative to all outputs. 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 *move* [absolute] position center
Moves the focused container to be centered on the workspace. If _absolute_ Moves the focused container to be centered on the workspace. If _absolute_

Loading…
Cancel
Save