Skip to content

Add unit ppt to 'move' + direction #8596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions sway/commands/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "util.h"

static const char expected_syntax[] =
"Expected 'move <left|right|up|down> <[px] px>' or "
"Expected 'move <left|right|up|down> [<amount> [px|ppt]]' or "
"'move [--no-auto-back-and-forth] <container|window> [to] workspace <name>' or "
"'move <container|window|workspace> [to] output <name|direction>' or "
"'move <container|window> [to] mark <mark>'";
Expand Down Expand Up @@ -702,13 +702,21 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {

static struct cmd_results *cmd_move_in_direction(
enum wlr_direction direction, int argc, char **argv) {
//DEBUG
for (int i = 0; i < argc; i++) {
printf("argv[%d]: %s\n", i, argv[i]);
}
int move_amt = 10;
bool is_ppt = false;
if (argc) {
char *inv;
move_amt = (int)strtol(argv[0], &inv, 10);
if (*inv != '\0' && strcasecmp(inv, "px") != 0) {
if (*inv != '\0') {
return cmd_results_new(CMD_FAILURE, "Invalid distance specified");
}
if (argc > 1 && strcasecmp(argv[1], "ppt") == 0) {
is_ppt = true;
}
}

struct sway_container *container = config->handler_context.container;
Expand All @@ -725,16 +733,16 @@ static struct cmd_results *cmd_move_in_direction(
double ly = container->pending.y;
switch (direction) {
case WLR_DIRECTION_LEFT:
lx -= move_amt;
lx -= is_ppt ? container->pending.width * ((double)move_amt / 100.0) : move_amt;
break;
case WLR_DIRECTION_RIGHT:
lx += move_amt;
lx += is_ppt ? container->pending.width * ((double)move_amt / 100.0) : move_amt;
break;
case WLR_DIRECTION_UP:
ly -= move_amt;
ly -= is_ppt ? container->pending.height * ((double)move_amt / 100.0) : move_amt;
break;
case WLR_DIRECTION_DOWN:
ly += move_amt;
ly += is_ppt ? container->pending.height * ((double)move_amt / 100.0) : move_amt;
break;
}
container_floating_move_to(container, lx, ly);
Expand Down Expand Up @@ -980,7 +988,7 @@ static struct cmd_results *cmd_move_to_scratchpad(void) {
}

static const char expected_full_syntax[] = "Expected "
"'move left|right|up|down [<amount> [px]]'"
"'move left|right|up|down [<amount> [px|ppt]]'"
" or 'move [--no-auto-back-and-forth] [window|container] [to] workspace"
" <name>|next|prev|next_on_output|prev_on_output|current|(number <num>)'"
" or 'move [window|container] [to] output <name/id>|left|right|up|down'"
Expand Down
9 changes: 5 additions & 4 deletions sway/sway.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,11 @@ set|plus|minus|toggle <amount>
the per-output *allow_tearing* setting. See *sway-output*(5)
for further details.

*move* left|right|up|down [<px> px]
Moves the focused container in the direction specified. The optional _px_
argument specifies how many pixels to move the container. If unspecified,
the default is 10 pixels. Pixels are ignored when moving tiled containers.
*move* left|right|up|down [<px> [px|ppt]]
Moves the focused container in the specified direction. The distance can be
specified in pixels or percentage points, omitting the unit defaults to pixels.
If unspecified, the default is 10 pixels. Pixels are ignored when moving tiled
containers.

*move* [absolute] position <pos_x> [px|ppt] <pos_y> [px|ppt]
Moves the focused container to the specified position in the workspace.
Expand Down