From d2f0a1db94b90134fefdab28a98172fd9ff88fc5 Mon Sep 17 00:00:00 2001 From: David Eklov Date: Sun, 17 Jul 2016 16:31:33 -0500 Subject: [PATCH 1/2] Function to move floating containers --- include/layout.h | 1 + sway/layout.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/layout.h b/include/layout.h index c05e9e699..e8238e207 100644 --- a/include/layout.h +++ b/include/layout.h @@ -48,6 +48,7 @@ void swap_container(swayc_t *a, swayc_t *b); // 2 Containers geometry are swapped, used with `swap_container` void swap_geometry(swayc_t *a, swayc_t *b); +void move_floating_container(swayc_t *container, int dx, int dy); void move_container(swayc_t* container, enum movement_direction direction); void move_container_to(swayc_t* container, swayc_t* destination); void move_workspace_to(swayc_t* workspace, swayc_t* destination); diff --git a/sway/layout.c b/sway/layout.c index 3d746ebe9..90ab0ba85 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -226,6 +226,15 @@ void swap_geometry(swayc_t *a, swayc_t *b) { b->height = h; } +void move_floating_container(swayc_t *container, int dx, int dy) { + if (!sway_assert(container->is_floating, "Container has to be floating")) { + return; + } + container->x += dx; + container->y += dy; + update_geometry(container); +} + void move_container(swayc_t *container, enum movement_direction dir) { enum swayc_layouts layout; if (container->is_floating From eb231a9e1ca19d486f79047c88d917626ff0b062 Mon Sep 17 00:00:00 2001 From: David Eklov Date: Sun, 17 Jul 2016 16:34:10 -0500 Subject: [PATCH 2/2] Add support to move command to move floating containers --- sway/commands.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index 73f245c13..2db1bd747 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1009,19 +1009,35 @@ static struct cmd_results *cmd_move(int argc, char **argv) { if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { return error; } - const char* expected_syntax = "Expected 'move ' or " + const char* expected_syntax = "Expected 'move [ px]' or " "'move to workspace ' or " "'move to output '"; swayc_t *view = get_focused_container(&root_container); if (strcasecmp(argv[0], "left") == 0) { - move_container(view, MOVE_LEFT); + if (argc == 3 && !strcasecmp(argv[2], "px")) { + move_floating_container(view, -1 * atoi(argv[1]), 0); + } else { + move_container(view, MOVE_LEFT); + } } else if (strcasecmp(argv[0], "right") == 0) { - move_container(view, MOVE_RIGHT); + if (argc == 3 && !strcasecmp(argv[2], "px")) { + move_floating_container(view, atoi(argv[1]), 0); + } else { + move_container(view, MOVE_RIGHT); + } } else if (strcasecmp(argv[0], "up") == 0) { - move_container(view, MOVE_UP); + if (argc == 3 && !strcasecmp(argv[2], "px")) { + move_floating_container(view, 0, -1 * atoi(argv[1])); + } else { + move_container(view, MOVE_UP); + } } else if (strcasecmp(argv[0], "down") == 0) { - move_container(view, MOVE_DOWN); + if (argc == 3 && !strcasecmp(argv[2], "px")) { + move_floating_container(view, 0, atoi(argv[1])); + } else { + move_container(view, MOVE_DOWN); + } } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { // "move container ... if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) {