Skip to content
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 @@ -703,13 +703,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]);
}
Comment on lines +706 to +709
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remnant from debugging session?

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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this doesn't accept the px suffix anymore?

We already have a parse_movement_amount() function to parse an amount of px/ppt, could we re-use it here?

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 @@ -726,16 +734,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 @@ -981,7 +989,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]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should read <amount> instead of <px>?

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