From 174dc389ffe840e89199b07e6d08317ebbc9f725 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sun, 18 Mar 2018 02:08:16 +0200 Subject: [PATCH 1/2] Remove 'method' from cmd_move_window_to_position For command: move window to [absolute] position X px Y px if the optional keyword 'absolute' is provided the end result is the same even though it is implemented differently. Only difference is that with absolute the floating window can move completely outside of any output. This commit removes the 'method' argument and only keeps the sane implementation. --- docs/userguide | 11 +++++++---- include/commands.h | 2 +- parser-specs/commands.spec | 2 +- src/commands.c | 23 ++++++----------------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/docs/userguide b/docs/userguide index ccedc577..7240409c 100644 --- a/docs/userguide +++ b/docs/userguide @@ -2030,10 +2030,13 @@ Use the +move+ command to move a container. # defaults to 10 pixels. move [ px] -# Moves the container either to a specific location -# or to the center of the screen. If 'absolute' is -# used, it is moved to the center of all outputs. -move [absolute] position [px] [px] +# Moves the container to the specified pos_x and pos_y +# coordinates on the screen. +move position [px] [px] + +# Moves the container to the center of the screen. +# If 'absolute' is used, it is moved to the center of +# all outputs. move [absolute] position center # Moves the container to the current position of the diff --git a/include/commands.h b/include/commands.h index 1057f021..aaa0875f 100644 --- a/include/commands.h +++ b/include/commands.h @@ -264,7 +264,7 @@ void cmd_focus_output(I3_CMD, const char *name); * Implementation of 'move [window|container] [to] [absolute] position [px] [px] * */ -void cmd_move_window_to_position(I3_CMD, const char *method, long x, long y); +void cmd_move_window_to_position(I3_CMD, long x, long y); /** * Implementation of 'move [window|container] [to] [absolute] position center diff --git a/parser-specs/commands.spec b/parser-specs/commands.spec index 0289fa1a..4048768e 100644 --- a/parser-specs/commands.spec +++ b/parser-specs/commands.spec @@ -396,7 +396,7 @@ state MOVE_TO_POSITION_X: state MOVE_TO_POSITION_Y: 'px', end - -> call cmd_move_window_to_position($method, &coord_x, &coord_y) + -> call cmd_move_window_to_position(&coord_x, &coord_y) # mode state MODE: diff --git a/src/commands.c b/src/commands.c index 899bbb90..b62daad9 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1694,7 +1694,7 @@ void cmd_focus_output(I3_CMD, const char *name) { * Implementation of 'move [window|container] [to] [absolute] position [px] [px] * */ -void cmd_move_window_to_position(I3_CMD, const char *method, long x, long y) { +void cmd_move_window_to_position(I3_CMD, long x, long y) { bool has_error = false; owindow *current; @@ -1712,24 +1712,13 @@ void cmd_move_window_to_position(I3_CMD, const char *method, long x, long y) { continue; } - if (strcmp(method, "absolute") == 0) { - current->con->parent->rect.x = x; - current->con->parent->rect.y = y; + Rect newrect = current->con->parent->rect; - DLOG("moving to absolute position %ld %ld\n", x, y); - floating_maybe_reassign_ws(current->con->parent); - cmd_output->needs_tree_render = true; - } + DLOG("moving to position %ld %ld\n", x, y); + newrect.x = x; + newrect.y = y; - if (strcmp(method, "position") == 0) { - Rect newrect = current->con->parent->rect; - - DLOG("moving to position %ld %ld\n", x, y); - newrect.x = x; - newrect.y = y; - - floating_reposition(current->con->parent, newrect); - } + floating_reposition(current->con->parent, newrect); } // XXX: default reply for now, make this a better reply From 5e8a3f3f0cd2a986b721e1480831ca5ff80713c5 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sun, 18 Mar 2018 02:41:12 +0200 Subject: [PATCH 2/2] cmd_move_window_to_position: improve error message --- include/floating.h | 2 +- src/commands.c | 6 ++++-- src/floating.c | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/floating.h b/include/floating.h index babfafc9..4382437b 100644 --- a/include/floating.h +++ b/include/floating.h @@ -143,7 +143,7 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event, * outputs. * */ -void floating_reposition(Con *con, Rect newrect); +bool floating_reposition(Con *con, Rect newrect); /** * Sets size of the CT_FLOATING_CON to specified dimensions. Might limit the diff --git a/src/commands.c b/src/commands.c index b62daad9..98625a91 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1718,10 +1718,12 @@ void cmd_move_window_to_position(I3_CMD, long x, long y) { newrect.x = x; newrect.y = y; - floating_reposition(current->con->parent, newrect); + if (!floating_reposition(current->con->parent, newrect)) { + yerror("Cannot move window/container out of bounds."); + has_error = true; + } } - // XXX: default reply for now, make this a better reply if (!has_error) ysuccess(true); } diff --git a/src/floating.c b/src/floating.c index e958153d..2130d673 100644 --- a/src/floating.c +++ b/src/floating.c @@ -864,12 +864,12 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_ * outputs. * */ -void floating_reposition(Con *con, Rect newrect) { +bool floating_reposition(Con *con, Rect newrect) { /* Sanity check: Are the new coordinates on any output? If not, we * ignore that request. */ if (!contained_by_output(newrect)) { ELOG("No output found at destination coordinates. Not repositioning.\n"); - return; + return false; } con->rect = newrect; @@ -881,6 +881,7 @@ void floating_reposition(Con *con, Rect newrect) { con->scratchpad_state = SCRATCHPAD_CHANGED; tree_render(); + return true; } /*