Migrate the move command to use typed numbers.

This commit is contained in:
Ingo Bürk 2015-09-27 16:59:36 +02:00 committed by Michael Stapelberg
parent a271666fa7
commit 9978050d91
4 changed files with 20 additions and 25 deletions

View File

@ -214,7 +214,7 @@ void cmd_sticky(I3_CMD, char *action);
* Implementation of 'move <direction> [<pixels> [px]]'. * Implementation of 'move <direction> [<pixels> [px]]'.
* *
*/ */
void cmd_move_direction(I3_CMD, char *direction, char *move_px); void cmd_move_direction(I3_CMD, char *direction, long move_px);
/** /**
* Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'. * Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
@ -262,7 +262,7 @@ void cmd_focus_output(I3_CMD, char *name);
* Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px] * Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
* *
*/ */
void cmd_move_window_to_position(I3_CMD, char *method, char *x, char *y); void cmd_move_window_to_position(I3_CMD, char *method, long x, long y);
/** /**
* Implementation of 'move [window|container] [to] [absolute] position center * Implementation of 'move [window|container] [to] [absolute] position center

View File

@ -320,16 +320,16 @@ state MOVE:
-> MOVE_TO_ABSOLUTE_POSITION -> MOVE_TO_ABSOLUTE_POSITION
state MOVE_DIRECTION: state MOVE_DIRECTION:
pixels = word pixels = number
-> MOVE_DIRECTION_PX -> MOVE_DIRECTION_PX
end end
-> call cmd_move_direction($direction, "10") -> call cmd_move_direction($direction, 10)
state MOVE_DIRECTION_PX: state MOVE_DIRECTION_PX:
'px' 'px'
-> call cmd_move_direction($direction, $pixels) -> call cmd_move_direction($direction, &pixels)
end end
-> call cmd_move_direction($direction, $pixels) -> call cmd_move_direction($direction, &pixels)
state MOVE_WORKSPACE: state MOVE_WORKSPACE:
'to ' 'to '
@ -370,18 +370,18 @@ state MOVE_TO_POSITION:
-> call cmd_move_window_to_center($method) -> call cmd_move_window_to_center($method)
'mouse', 'cursor', 'pointer' 'mouse', 'cursor', 'pointer'
-> call cmd_move_window_to_mouse() -> call cmd_move_window_to_mouse()
coord_x = word coord_x = number
-> MOVE_TO_POSITION_X -> MOVE_TO_POSITION_X
state MOVE_TO_POSITION_X: state MOVE_TO_POSITION_X:
'px' 'px'
-> ->
coord_y = word coord_y = number
-> MOVE_TO_POSITION_Y -> MOVE_TO_POSITION_Y
state MOVE_TO_POSITION_Y: state MOVE_TO_POSITION_Y:
'px', end 'px', end
-> call cmd_move_window_to_position($method, $coord_x, $coord_y) -> call cmd_move_window_to_position($method, &coord_x, &coord_y)
# mode <string> # mode <string>
state MODE: state MODE:

View File

@ -1565,28 +1565,25 @@ void cmd_sticky(I3_CMD, char *action) {
* Implementation of 'move <direction> [<pixels> [px]]'. * Implementation of 'move <direction> [<pixels> [px]]'.
* *
*/ */
void cmd_move_direction(I3_CMD, char *direction, char *move_px) { void cmd_move_direction(I3_CMD, char *direction, long move_px) {
// TODO: We could either handle this in the parser itself as a separate token (and make the stack typed) or we need a better way to convert a string to a number with error checking
int px = atoi(move_px);
owindow *current; owindow *current;
HANDLE_EMPTY_MATCH; HANDLE_EMPTY_MATCH;
Con *initially_focused = focused; Con *initially_focused = focused;
TAILQ_FOREACH(current, &owindows, owindows) { TAILQ_FOREACH(current, &owindows, owindows) {
DLOG("moving in direction %s, px %s\n", direction, move_px); DLOG("moving in direction %s, px %ld\n", direction, move_px);
if (con_is_floating(current->con)) { if (con_is_floating(current->con)) {
DLOG("floating move with %d pixels\n", px); DLOG("floating move with %ld pixels\n", move_px);
Rect newrect = current->con->parent->rect; Rect newrect = current->con->parent->rect;
if (strcmp(direction, "left") == 0) { if (strcmp(direction, "left") == 0) {
newrect.x -= px; newrect.x -= move_px;
} else if (strcmp(direction, "right") == 0) { } else if (strcmp(direction, "right") == 0) {
newrect.x += px; newrect.x += move_px;
} else if (strcmp(direction, "up") == 0) { } else if (strcmp(direction, "up") == 0) {
newrect.y -= px; newrect.y -= move_px;
} else if (strcmp(direction, "down") == 0) { } else if (strcmp(direction, "down") == 0) {
newrect.y += px; newrect.y += move_px;
} }
floating_reposition(current->con->parent, newrect); floating_reposition(current->con->parent, newrect);
} else { } else {
@ -1788,9 +1785,7 @@ void cmd_focus_output(I3_CMD, char *name) {
* Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px] * Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
* *
*/ */
void cmd_move_window_to_position(I3_CMD, char *method, char *cx, char *cy) { void cmd_move_window_to_position(I3_CMD, char *method, long x, long y) {
int x = atoi(cx);
int y = atoi(cy);
bool has_error = false; bool has_error = false;
owindow *current; owindow *current;
@ -1812,7 +1807,7 @@ void cmd_move_window_to_position(I3_CMD, char *method, char *cx, char *cy) {
current->con->parent->rect.x = x; current->con->parent->rect.x = x;
current->con->parent->rect.y = y; current->con->parent->rect.y = y;
DLOG("moving to absolute position %d %d\n", x, y); DLOG("moving to absolute position %ld %ld\n", x, y);
floating_maybe_reassign_ws(current->con->parent); floating_maybe_reassign_ws(current->con->parent);
cmd_output->needs_tree_render = true; cmd_output->needs_tree_render = true;
} }
@ -1820,7 +1815,7 @@ void cmd_move_window_to_position(I3_CMD, char *method, char *cx, char *cy) {
if (strcmp(method, "position") == 0) { if (strcmp(method, "position") == 0) {
Rect newrect = current->con->parent->rect; Rect newrect = current->con->parent->rect;
DLOG("moving to position %d %d\n", x, y); DLOG("moving to position %ld %ld\n", x, y);
newrect.x = x; newrect.x = x;
newrect.y = y; newrect.y = y;

View File

@ -216,7 +216,7 @@ is(parser_calls('workspace "foo\\\\\\"bar"'),
################################################################################ ################################################################################
is(parser_calls("resize shrink width 10 px or"), is(parser_calls("resize shrink width 10 px or"),
"ERROR: Expected one of these tokens: <word>\n" . "ERROR: Expected one of these tokens: <number>\n" .
"ERROR: Your command: resize shrink width 10 px or\n" . "ERROR: Your command: resize shrink width 10 px or\n" .
"ERROR: ", "ERROR: ",
"error for resize command with incomplete 'or'-construction ok"); "error for resize command with incomplete 'or'-construction ok");