This commit is contained in:
Absobel 2025-03-27 20:03:45 +02:00 committed by GitHub
commit 224fe2d46e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 11 deletions

View file

@ -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>'";
@ -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;
@ -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);
@ -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'"

View file

@ -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.