From e4f944275c67a8fd6d3f154ccb4791cb194b67a0 Mon Sep 17 00:00:00 2001 From: Elmo Todurov Date: Fri, 6 Mar 2026 17:43:15 +0200 Subject: [PATCH] sway/commands/move.c: negative coords move to the bottom/right edge --- sway/commands/move.c | 25 +++++++++++++++++++++++-- sway/sway.5.scd | 5 +++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/sway/commands/move.c b/sway/commands/move.c index 90e8585b4..7e606f3dc 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -809,9 +809,10 @@ static struct cmd_results *cmd_move_to_position_pointer( } static const char expected_position_syntax[] = - "Expected 'move [absolute] position [px] [px]' or " + "Expected 'move [absolute] position [px|ppt] [px|ppt]' or " "'move [absolute] position center' or " - "'move position cursor|mouse|pointer'"; + "'move position cursor|mouse|pointer' " + "(negative coordinates are relative to the workspace/screen bottom-right corner)"; static struct cmd_results *cmd_move_to_position(int argc, char **argv) { struct sway_container *container = config->handler_context.container; @@ -942,6 +943,26 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) { sway_assert(false, "invalid y unit"); break; } + // Negative coordinates are measured from the bottom-right corner of the + // screen/workspace rather than the top-left corner, so that e.g. + // "move position -10px -10px" places the window's bottom-right corner + // 10px from the screen/workspace bottom-right corner. + if (lx.amount < 0) { + if (absolute) { + lx.amount = root->x + root->width + lx.amount + - container->pending.width; + } else { + lx.amount = ws->width + lx.amount - container->pending.width; + } + } + if (ly.amount < 0) { + if (absolute) { + ly.amount = root->y + root->height + ly.amount + - container->pending.height; + } else { + ly.amount = ws->height + ly.amount - container->pending.height; + } + } if (!absolute) { lx.amount += ws->x; ly.amount += ws->y; diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 952d243d2..74b759dac 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -241,6 +241,11 @@ set|plus|minus|toggle The position can be specified in pixels or percentage points, omitting the unit defaults to pixels. If _absolute_ is used, the position is relative to all outputs. _absolute_ can not be used with percentage points. + Negative coordinates are measured from the bottom-right corner of the + workspace (or all outputs when _absolute_ is used): a negative value places + the container so that its bottom-right corner is that many pixels (or + percentage points of the workspace dimension) from the workspace bottom-right + corner. *move* [absolute] position center Moves the focused container to be centered on the workspace. If _absolute_